You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Illegal memory access in reduce kernel when built with CUDA Toolkit 13.1 #3109
When building with CUDA Toolkit 13.1 the reduce kernels would fail with "an illegal memory access was encountered" errors.
Steps to reproduce:
$ cmake -B build . -DMLX_BUILD_CUDA=ON
$ cmake --build build -j 16
$ ./build/tests/tests -tc="test gpu reduce with axes"===============================================================================/home/zcbenz/codes/mlx/tests/gpu_tests.cpp:170:TEST CASE: test gpu reduce with axes/home/zcbenz/codes/mlx/tests/gpu_tests.cpp:175: ERROR: CHECK( array_equal(out_gpu, out_cpu, Device::cpu).item<bool>() ) THREW exception: "cudaMemcpy(&val, ptr(), sizeof(uint32_t), cudaMemcpyDeviceToHost) failed: an illegal memory access was encountered"===============================================================================
With initial debugging I think it is caused by LoopedElemToLoc being mis-compiled, which results in loop.location() returning wrong results and ends up out-of-bounds read in:
(Somehow printf does not work in CUDA kernels on Windows so I can not 100% verify, but replacing code using LoopedElemToLoc with elem_to_loc function can solve the crash.)
The same error happens for both Windows and Linux, and CUDA 13.0 is working fine, so I think this is very likely a nvcc bug.
Activity
zcbenz commentedon Feb 10, 2026
Independent test below. Note that the CUDA arch must be set to 120a.
Details