Repository navigation
Description
Problem / Background
The MLX CUDA backend JIT-compiles a core set of kernels at runtime via NVRTC. gather/indexing kernels return precompiled=false and are always NVRTC-compiled from embedded sources (see mlx/backend/cuda/indexing.cpp and jit_module.cpp). gather is used for token-embedding lookup, so any model generate triggers NVRTC on first use. There is no global MLX_CUDA_JIT=OFF build switch (unlike the Metal backend), so the JIT cannot be compiled away; the kernels include <cuda/std/tuple> and therefore need the CCCL (libcu++) headers present at runtime.
jit_module.cpp::include_path_args() resolves the CCCL include path in this order:
<dir-of-executable>/../include/cccl(MLX'scmake --installlayout).- Fallback to the compile-time
MLX_CCCL_DIRdefine.
mlxcel's src/lib/mlx-cpp/CMakeLists.txt sets MLX_CCCL_DIR to the build tree's _deps/cccl-src/include (because the statically linked binary is not cmake installed). That absolute path only exists on the build machine. So a released binary run on any other host fails the first JIT with catastrophic error: cannot open source file "cuda/std/tuple" unless the CCCL headers are shipped in MLX's native <prefix>/include/cccl layout (which requires placing the binaries under bin/).
PR #262 addresses the release artifact by bundling the CCCL headers (~8.8 MB / ~953 files: include/cuda + include/nv) in that native layout. This issue is the complementary code-level change so the header location is overridable and a flat binary layout is supported, which matters when another application (Backend.AI:GO) embeds mlxcel and controls where the headers live.
Proposed Solution
Add an MLXCEL_CCCL_DIR environment variable (and a binary-adjacent cccl/ lookup) so the CUDA runtime NVRTC JIT can locate the CCCL (libcu++) headers at an operator-controlled path, instead of relying on either the build-time-baked MLX_CCCL_DIR (which points at the build machine) or MLX's fixed <binary_parent>/include/cccl install layout. This makes mlxcel portable as an embedded CUDA inference engine (e.g. the Backend.AI:GO engine) without forcing a specific on-disk artifact layout.
Patch the vendored MLX via src/lib/mlx-cpp/patches/ (so it survives MLX pin bumps and is attributed per the project's third-party attribution rules in CLAUDE.md). Extend the CCCL include-path resolution in mlx/backend/cuda/jit_module.cpp::include_path_args() to try, in priority order:
MLXCEL_CCCL_DIRenv var, if set and exists (highest priority).<dir-of-executable>/cccl(binary-adjacent, same directory as the executable — supports a flat artifact layout).- Existing
<dir-of-executable>/../include/cccl(MLX native install layout). - Existing compile-time
MLX_CCCL_DIRfallback.
The second NVRTC include path (CUDA runtime headers) already honors CUDA_HOME / CUDA_PATH; document that alongside.
Acceptance Criteria
- With
MLXCEL_CCCL_DIR=/path/to/ccclset, mlxcel runs a CUDA generate on a host whose CUDA install does not provide a compatible CCCL, with a flat binary layout (binary andmlxcel-servernot underbin/), and the first-run NVRTC JIT succeeds. - A binary-adjacent
./cccl/directory is found without any env var. - When neither is present, behavior is unchanged (still falls back to MLX's native layout / baked
MLX_CCCL_DIR). - The change is implemented as an mlx-cpp patch with the required per-file derivation note and NOTICE/README attribution updates, and survives an MLX pin bump.
- Document the variable in
docs/installation.md(and the environment-variables reference) next to the CUDA JIT notes.
Technical Considerations
- Discovered while bringing up the Linux x86_64 CUDA release build (issue Support Windows and Linux x86_64 binary builds and release artifacts #25 part A, PR feat(ci): add Linux x86_64 + aarch64 CUDA release builds with bundled CCCL #262). The build-machine smoke test passed because
MLX_CCCL_DIRexisted there; the failure only appeared when running the artifact on a separate Backend.AI GPU node. - Related to Support Windows and Linux x86_64 binary builds and release artifacts #25 and PR feat(ci): add Linux x86_64 + aarch64 CUDA release builds with bundled CCCL #262.
Activity
fix(ci): bundle CCCL headers in Linux CUDA release artifacts
inureyes commentedon Jun 13, 2026
Confirmed blocking: relative-invocation breaks the bundled-CCCL layout
Verified on a Backend.AI GPU node with the PR #262 artifact (
bin/+include/cccl/, bundle present and correct).Root cause confirmed. MLX resolves the CCCL include dir via
mlx/backend/common/utils.cpp::current_binary_dir(), which usesdladdr(¤t_binary_dir, &info)and returnsstd::filesystem::path(info.dli_fname).parent_path(). When the binary is launched by a relative path (./mlxcelfrom insidebin/), glibc returns a relativedli_fname(./mlxcel), so:current_binary_dir()=parent_path("./mlxcel")=.jit_module.cppthen doesroot_dir.parent_path()=""(empty)"" / "include" / "cccl"=include/cccl, resolved against the cwd (bin/) ->bin/include/cccl, which does not exist (the bundle is at../include/cccl)MLX_CCCL_DIRfallback points at the build machine and also does not exist--include-pathis added ->gather_*_int32_1.cuNVRTC compile fails withcannot open source file "cuda/std/tuple"Proof. Same artifact, same node:
cd ~ && ~/mlxcel-test/mlxcel-linux-x86_64-cuda13/bin/mlxcel run(absolute path) succeeds;cd bin && ./mlxcel run(relative) fails. The only difference is the invocation path feedingdladdr.So the
bin/+include/cccl/bundling from PR #262 is necessary but not sufficient: MLX's path resolution must be made invocation-independent. Two parts:MLXCEL_CCCL_DIR(and optionally a binary-adjacentcccl/) FIRST, before the dladdr-derived path. An absolute env value bypasses the whole problem and is the clean path for Backend.AI:GO embedding./proc/self/exe(canonical absolute) rather than relying ondladdr's possibly-relativedli_fname, so<exe-dir>/../include/ccclworks regardless of how the process was launched.Workaround until this lands: invoke mlxcel/mlxcel-server via an absolute path (which a service manager / Backend.AI:GO subprocess spawn already does).
feat(ci): add Linux x86_64 + aarch64 CUDA release builds with bundled…
feat(cuda): robust CCCL resolution, first-run JIT notice, and persist…
feat(ci): add Linux x86_64 + aarch64 CUDA release builds with bundled…
feat(cuda): robust CCCL resolution, first-run JIT notice, and persist…