Skip to content

fix: CPU-only Linux build fails to link kv_inplace_write #2108

Closed

Description

@inureyes

Problem

src/lib/mlxcel-core/build.rs:143 compiles ../mlx-cpp/turbo/kv_inplace_write.cpp (#1959/#1961) for every backend. Its InplaceSliceWrite::eval_gpu (kv_inplace_write.cpp:43-65) calls mx::copy_gpu_inplace at line 55, which MLX defines only when a GPU backend is built. A Linux build with no cuda/metal/rocm feature therefore fails at link time, e.g. cargo test --release --lib. Found while validating #2093, which needed a linker wrapper with --unresolved-symbols=ignore-in-object-files. Not re-run for this issue (cold MLX build).

No CI job catches it: the ubuntu-latest jobs only lint, every GB10 job passes --features cuda, and ci.yml:1072 is cargo check, which does not link.

Proposed fix

  • In build.rs, next to MLXCEL_BRIDGE_METAL_BACKEND (~172) and MLXCEL_BRIDGE_ROCM_BACKEND (~181), define MLXCEL_BRIDGE_GPU_BACKEND when the resolved metal_backend bool (not the cargo feature, see the comment at ~167-170) or CARGO_FEATURE_CUDA or CARGO_FEATURE_ROCM holds.
  • In kv_inplace_write.cpp, guard the <mlx/backend/gpu/copy.h> include and the eval_gpu body on that define; without it, eval_gpu throws std::runtime_error like eval_cpu (lines 38-41) does, keeping that explicit error.
  • Rejected: dropping the .file() line. cpp/mlx_cxx_ext.cpp:12 includes the header and the FFI symbol must still link; at runtime cache.rs:1043-1047 already skips the call when default_device_is_gpu() is false.
  • CI: add a CPU-only cargo test -p mlxcel-core --profile test-fast --lib --no-run step on GB10 with its own persistent target dir (pattern at ci.yml:657-661). If the warm runtime is too high, put the local command in docs/installation.md instead and say so in the PR.

Acceptance Criteria

Do it in one PR, run the checks once at the end, and push as few times as possible.

Verification

cargo test -p mlxcel-core --profile test-fast --lib --no-run
cargo test -p mlxcel-core --profile test-fast --features cuda --lib -- --test-threads=1

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:coremlxcel-core: MLX FFI, primitives, KV cache, layersplatform:linuxLinux (CUDA / packaging) specificpriority:mediumMedium prioritystatus:doneCompletedtype:bugBug fixes, error corrections, or issue resolutions

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions