Skip to content

Commit a3f8e58

Browse files
authored
refactor(core): split mlx_cxx_bridge.cpp by domain; bump mlxcel-core 0.2.0 (#277)
The cxx bridge implementation had grown to 6367 lines in one file. Split the cleanly-separable specialized blocks into their own translation units, sharing the few cross-domain helpers (to_shape/to_dtype/from_dtype/gelu_tanh_approx) via a new mlx_cxx_internal.h. The cxx FFI free functions stay callable across TUs through the generated header, so only those file-local helpers needed promotion; no behavior change. - cpp/mlx_cxx_internal.h: shared MLX/std includes + the dtype/shape helpers. - cpp/mlx_cxx_kernels.cpp: fused single-token decode Metal kernels (Mamba2/SSM, GatedDeltaNet, decode-MoE). - cpp/mlx_cxx_nemotron.cpp: NemotronH full-forward decode. - cpp/mlx_cxx_ext.cpp: native safetensors loading + Metal 4 / turbo / paged fused-attention launchers. - cpp/mlx_cxx_bridge.cpp: the remaining general FFI surface, 6367 -> 4616 lines. build.rs compiles the new files (it already built multiple .cpp via cxx_build::bridge). mlxcel-core bumped 0.1.0 -> 0.2.0. Validated: release build clean (fmt + clippy), greedy temp-0 output unchanged on qwen3-30b-a3b (incl. MLXCEL_FUSED_MOE, the moved kernels) and nemotron-h-30b (the moved full-forward + SSM/MoE kernels). The remaining bridge.cpp bulk (ops/quant/norm-rope/attention/activation) is heavily interleaved by domain; further extraction can follow.
1 parent 65abbd5 commit a3f8e58

8 files changed

Lines changed: 1818 additions & 1757 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/lib/mlxcel-core/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "mlxcel-core"
3-
version = "0.1.0"
3+
version = "0.2.0"
44
edition = "2021"
55
description = "Low-level MLX building blocks for mlxcel"
66
license = "Apache-2.0"

src/lib/mlxcel-core/build.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@ fn main() {
3535
let mut bridge = cxx_build::bridge("src/lib.rs");
3636
bridge
3737
.file("cpp/mlx_cxx_bridge.cpp")
38+
// Bridge implementation split out of mlx_cxx_bridge.cpp by domain
39+
// (shared helpers in cpp/mlx_cxx_internal.h): fused decode Metal
40+
// kernels, the NemotronH full-forward path, and safetensors loading +
41+
// Metal 4 / turbo / paged attention launchers.
42+
.file("cpp/mlx_cxx_kernels.cpp")
43+
.file("cpp/mlx_cxx_nemotron.cpp")
44+
.file("cpp/mlx_cxx_ext.cpp")
3845
// Fused Sparse-V SDPA kernel launcher. Lives under
3946
// `src/lib/mlx-cpp/turbo/` so the MLX-upstream-commit upgrade
4047
// checklist (CLAUDE.md) treats this directory as in-scope.
@@ -125,7 +132,11 @@ fn main() {
125132
// Rerun if bridge files change
126133
println!("cargo:rerun-if-changed=src/lib.rs");
127134
println!("cargo:rerun-if-changed=cpp/mlx_cxx_bridge.h");
135+
println!("cargo:rerun-if-changed=cpp/mlx_cxx_internal.h");
128136
println!("cargo:rerun-if-changed=cpp/mlx_cxx_bridge.cpp");
137+
println!("cargo:rerun-if-changed=cpp/mlx_cxx_kernels.cpp");
138+
println!("cargo:rerun-if-changed=cpp/mlx_cxx_nemotron.cpp");
139+
println!("cargo:rerun-if-changed=cpp/mlx_cxx_ext.cpp");
129140
println!("cargo:rerun-if-changed=metal/fused_attention_metal4.metal");
130141
println!("cargo:rerun-if-changed=../mlx-cpp/CMakeLists.txt");
131142
println!("cargo:rerun-if-changed=../mlx-cpp/patches");

0 commit comments

Comments
 (0)