Skip to content

Fix metal scan#2591

Merged
awni merged 1 commit intomainfrom
fix_metal_scan
Sep 15, 2025
Merged

Fix metal scan#2591
awni merged 1 commit intomainfrom
fix_metal_scan

Conversation

@awni
Copy link
Copy Markdown
Member

@awni awni commented Sep 15, 2025

Fix race condition in metal kernel. It's quite difficult to get this to show up in a unit test.

Here's a test that triggers it every so often.

import mlx.core as mx

mx.random.seed(0)
int_arr = mx.random.randint(0, 4, (4000000,))
arr = mx.array(int_arr)
for i in range(200):
    print(mx.cumsum(arr))

And in a separate file:

import subprocess

command_arr = []
for i in range(100):
    command_ = "python test_mlx_cumsum.py"
    command_arr.append(command_)

# start all programs
processes = [subprocess.Popen(command_, shell=True) for command_ in command_arr]
# wait
for process in processes:
    process.wait()

@awni awni requested a review from angeloskath September 15, 2025 16:01
Copy link
Copy Markdown
Member

@angeloskath angeloskath left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great catch thanks!

@awni awni merged commit 6ccfa60 into main Sep 15, 2025
6 checks passed
@awni awni deleted the fix_metal_scan branch September 15, 2025 18:02
faisalmemon pushed a commit to faisalmemon/mlx that referenced this pull request Oct 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants