Skip to content

[BUG] c++ compile cache should be thread safe #2086

Closed

Description

@davidkoski

Describe the bug

The c++ compile cache should be thread safe -- whatever mutable state is behind mlx::core::detail::compile should be thread safe so it can safely be called from multiple threads (common in Swift, maybe C++).

See also:

To Reproduce

See:

Note that the fix for this was to protect the inner function that mutates the arguments (as that is where the crash was observed), during discussion with @awni we think that the cache of graphs also needs locking (or whatever technique is appropriate) as it is also mutable state.

Expected behavior

Inner state of mlx::core should be thread safe or documented as not (like MLXArray).

Desktop (please complete the following information):

  • OS Version: macOS15
  • Version 0.23.1

Activity

  1. awni commented on Apr 18, 2025

    @awni
    Member

    Inner state of mlx::core should be thread safe

    There are still a few places this is not true still. Off the top of my head:

    • rng state
    • compiler cache
    • transform state (e.g. InTracing)
  2. ashthedash2k commented on Jul 12, 2025

    @ashthedash2k

    I'd be interested in working on this issue, I have knowledge of threading and caches so I might be able to help out? I have not really ever contributed to open source, the code base is pretty large, I was wondering if I could get some pointers / a starting direction! Thanks so much.

  3. zcbenz commented on May 5, 2026

    @zcbenz
    Member

    Closing since compile cache is thread safe after 0.31.2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions