Skip to content

fix(cuda): compile MLX JIT kernels against MLX's CCCL outside the install prefix - #20

Merged
mrothroc merged 1 commit into
mainfrom
fix/mlx-cuda-jit-cccl
Nov 20, 2026
Merged

mrothroc merged 1 commit into
mainfrom
fix/mlx-cuda-jit-cccl

Conversation

@mrothroc

Copy link
Copy Markdown
Owner

On CUDA, any binary outside /usr/local (every go test binary, or mixlab built elsewhere) compiled MLX JIT kernels against the CUDA 12.8 toolkit's CCCL 2.7, which has no cuda::std::rint. QAT and other fused kernels failed on first compile. The installed /usr/local/bin/mixlab was unaffected. No CUDA toolkit change is needed.

Cause. libmlx is a static archive, so MLX derives its header root from the executable path. MLX installs its own CCCL 3.1.3 to <prefix>/include/cccl for JIT, but upstream defines the compiled-in MLX_CCCL_DIR fallback 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) defines MLX_CCCL_DIR for normal builds as the installed include/cccl. Executable-relative lookup still comes first.

  • docker/test_mlx_jit_cccl.py configures the pinned CMake block with MLX's real dirs.cpp and checks cccl_dir(): fails on pinned source (--expect-broken), passes patched. It runs in CI and in the base build.
  • docker/test_mlx_jit_cccl_probe.cpp links the installed dirs.cpp.o and uses NVRTC (no GPU) to compile a cuda::std::rint kernel against it, with a toolkit-only control that must fail. It runs after ninja install in the base and architecture builds.
  • MIXLAB_MLX_CUDA_JIT_CCCL_FIX=1 marks 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):

  • Base golf-mlx-cuda-base:mlx-0.32.0-go1.27.4 (the previous base kept as …-pre-jitcccl). Architecture tier golf-mlx-cuda:mlx-0.32.0-go1.27.4-jitcccl, now latest; the previous tier remains mlx-0.32.0-go1.27.4 for rollback. Both build logs show the source check and probe passing. Validation app build: success.

GPU evidence.

  • Before (RTX 4090, current image): the QAT test failed with rint from Go's temp dir and passed when the same binary was staged under bin/ next to include; mixlab failed at /tmp/mixlab and passed copied to /usr/local/bin. Production mixlab:latest QAT int8/int6 passed (RTX A4000), losses identical to Metal.
  • After (NVIDIA L4, patched image): the QAT test passes from Go's temp dir with a fresh PTX cache; QAT via /tmp/mixlab passes (int8 4.2727→4.2593, int6 4.2727→4.2469). The full gpu suite has no rint failure; 15 tests still fail in one process, all after an MLX CUDA graph cache-thrash error followed by cudaGraphAddDependencies errors, and all 15 pass alone in fresh processes. The 4 dilated-convolution reference cases pass with MLX_ENABLE_TF32=0 (earlier misses were TF32-sized).

Local: contract tests, make lint (0 issues) and CGO_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.cpp replaces MLX's original cache-thrash text with tuning advice, hiding the real cause.

…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.
@mrothroc
mrothroc merged commit 22c92d4 into main Nov 20, 2026
12 checks passed
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.

1 participant