idea for doing synchronous evals but _not_ holding evalLock - #474
davidkoski wants to merge 3 commits into
Conversation
- do the synchronous mutation under lock with asyncEval - synchronous eval then does not need lock
| mlx_eval(vector_array) | ||
| mlx_async_eval(vector_array) | ||
| } | ||
| mlx_eval(vector_array) |
There was a problem hiding this comment.
This is the heart of the change. we need the evalLock to guard against mutation of shared state. python uses thread-local streams to scope this, but we can't do that on the swift side (at least not in the same way).
But what if we did the mutation part under lock and then just wait for the arrays to be ready outside the lock? The MLXArray instances are still not thread safe, so they can't escape to other threads where the mutation could be observed, so I think this is safe.
There was a problem hiding this comment.
FYI @aleroot -- I got this idea from the concurrent read work you did and this might be generally useful.
|
|
||
| @testable import MLX | ||
|
|
||
| // MARK: - Support |
There was a problem hiding this comment.
For now this is just some tests that I had claude throw together.
Proposed changes
Checklist
Put an
xin the boxes that apply.pre-commit run --all-filesto format my code / installed pre-commit prior to committing changes