Repository navigation
fix(cuda): compile MLX JIT kernels against MLX's CCCL outside the install prefix - #20
Merged
Merged
Conversation
…tall prefix libmlx is a static archive, so MLX derives its header root from the executable's location. A binary outside /usr/local (every go test binary, or mixlab built elsewhere) found no include/cccl and NVRTC fell back to the CUDA 12.8 toolkit's CCCL 2.7, which has no cuda::std::rint: QAT and other fused kernels failed on first compile. Upstream defines the MLX_CCCL_DIR fallback only for MLX's own test builds. A fifth pinned-MLX patch defines MLX_CCCL_DIR for normal builds as the installed include/cccl that MLX's install rule writes; executable- relative lookup still comes first. The base build checks the pinned CMake block and dirs.cpp before and after patching (as CI does), and the base and architecture builds link the installed dirs.cpp.o into an NVRTC probe that must compile cuda::std::rint against it, with a toolkit-only control that must fail. MIXLAB_MLX_CUDA_JIT_CCCL_FIX=1 marks the base; the architecture and app images reject a base without it. No CUDA toolkit change is needed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
On CUDA, any binary outside
/usr/local(everygo testbinary, ormixlabbuilt elsewhere) compiled MLX JIT kernels against the CUDA 12.8 toolkit's CCCL 2.7, which has nocuda::std::rint. QAT and other fused kernels failed on first compile. The installed/usr/local/bin/mixlabwas unaffected. No CUDA toolkit change is needed.Cause.
libmlxis a static archive, so MLX derives its header root from the executable path. MLX installs its own CCCL 3.1.3 to<prefix>/include/ccclfor JIT, but upstream defines the compiled-inMLX_CCCL_DIRfallback only for MLX's own test builds.Fix. A fifth pinned-MLX patch (
docker/patches/mlx-cuda-jit-cccl-install-dir.patch, 8 lines of CMake) definesMLX_CCCL_DIRfor normal builds as the installedinclude/cccl. Executable-relative lookup still comes first.docker/test_mlx_jit_cccl.pyconfigures the pinned CMake block with MLX's realdirs.cppand checkscccl_dir(): fails on pinned source (--expect-broken), passes patched. It runs in CI and in the base build.docker/test_mlx_jit_cccl_probe.cpplinks the installeddirs.cpp.oand uses NVRTC (no GPU) to compile acuda::std::rintkernel against it, with a toolkit-only control that must fail. It runs afterninja installin the base and architecture builds.MIXLAB_MLX_CUDA_JIT_CCCL_FIX=1marks the base; architecture and app images reject a base without it. Contract tests cover base, addarch, app and CI.Images (already built from this commit and promoted, so this PR's image check builds on them):
golf-mlx-cuda-base:mlx-0.32.0-go1.27.4(the previous base kept as…-pre-jitcccl). Architecture tiergolf-mlx-cuda:mlx-0.32.0-go1.27.4-jitcccl, nowlatest; the previous tier remainsmlx-0.32.0-go1.27.4for rollback. Both build logs show the source check and probe passing. Validation app build: success.GPU evidence.
rintfrom Go's temp dir and passed when the same binary was staged underbin/next toinclude;mixlabfailed at/tmp/mixlaband passed copied to/usr/local/bin. Productionmixlab:latestQAT int8/int6 passed (RTX A4000), losses identical to Metal./tmp/mixlabpasses (int8 4.2727→4.2593, int6 4.2727→4.2469). The fullgpusuite has norintfailure; 15 tests still fail in one process, all after an MLX CUDA graph cache-thrash error followed bycudaGraphAddDependencieserrors, and all 15 pass alone in fresh processes. The 4 dilated-convolution reference cases pass withMLX_ENABLE_TF32=0(earlier misses were TF32-sized).Local: contract tests,
make lint(0 issues) andCGO_ENABLED=0 go test ./...pass; the patch check passes in a non-git directory as in CI.Follow-ups, not in this PR: MLX's graph encoder is left half-reset after a cache-thrash exception (affects later work in the same process, e.g. the full test suite);
gpu/mlx_bridge.cppreplaces MLX's original cache-thrash text with tuning advice, hiding the real cause.