Skip to content

feat(mlxcelverse): standalone cuda-oxide fused residual-add + RMSNorm kernel with a GB10 oracle - #2953

Merged
inureyes merged 4 commits into
lablup:mainfrom
Jaeyeong-CHOI:feat/2832-cuda-oxide-fused-norm
Nov 15, 2026
Merged

inureyes merged 4 commits into
lablup:mainfrom
Jaeyeong-CHOI:feat/2832-cuda-oxide-fused-norm

Conversation

@Jaeyeong-CHOI

@Jaeyeong-CHOI Jaeyeong-CHOI commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds the second gated experiment from docs/mlxcelverse/cuda-oxide-feasibility.md: a standalone fused residual-add + RMSNorm kernel written in Rust, compiled with the cuda-oxide toolchain that #2831 validated, plus the numerical oracle the issue asks for. On a GB10 all 130 cases (2,181,390 elements) are bit-identical to the existing fused CUDA kernel and inside the frozen graph-path budgets.

The kernel lives in a new isolated package, spike/cuda-oxide-fused-norm (its own workspace root, never part of the mlxcel build graph; the application Rust pin stays at 1.97.1). Five entry points cover f32 / f16 / bf16 activations with the weight in the same dtype, and the two mixed pairs (16-bit activations, f32 weight). The only change inside the mlxcel workspace is a new mlxcel-core example, oxide_fused_norm_oracle, which replays the package's fixtures through fused_add_rms_norm and layers::graph_add_rms_norm and dumps their bits. No production code path changes.

Related issues

Closes #2832

Follows #2831. #2833 and #2834 can reuse the artifacts, fixtures and timing method.

Type of change

  • feat — new user-visible feature
  • fix — bug fix
  • perf — performance improvement (include before/after numbers in the PR body)
  • refactor — internal restructuring without behavior change
  • chore — build, CI, dependencies, release infrastructure
  • docs — documentation only
  • test — tests only

Acceptance criteria (issue #2832)

  • Both outputs, rounding before squaring, f32 accumulation, epsilon, weight-bias 0/1 semantics. One generic row routine follows the CUDA port in kernels/fused_norm.cpp term for term. results/compare-sm_121.json shows every normed and new_residual element equal to the existing fused CUDA kernel bit for bit.
  • Frozen per-dtype tolerances, deterministic fixtures, comparison against the fused CUDA and graph references. The tolerances are fused_norm_parity_tests::tolerance_for (f32 1e-6 / 1e-5, f16 2e-3 / 1.2e-2, bf16 1.6e-2 / 7e-2, normalized RMS / max), recorded in the README and the harness before the oracle ran. Fixtures are per-case seeded LCG normals already rounded to the case dtypes. Worst normed vs graph, normalized RMS: f32 9.1e-8, f16 9.4e-6, bf16 0, f16 with f32 weight 5.2e-4, bf16 with f32 weight 3.9e-3.
  • Small/odd/tail widths, 1024/4096/8192, one and multiple rows, mixed weight dtypes, NaN/Inf policy, explicit rejection. Widths 1, 3, 31, 32, 33, 100, 127, 128, 129, 1000, 1024, 2048, 3072, 4096, 4097, 8191, 8192 at 1 to 33 rows. Non-finite rows follow IEEE propagation and are compared class-exact across all three implementations. The host refuses rows = 0, dim = 0, length mismatches and more than 2^32-1 elements with a message; the run reports those five REJECT lines.
  • Machine-readable results; real GB10 tests under gpu-lock. results/compare-sm_121.json and results/bench-sm_121.json carry dtype, shape, error metrics, PTX/cubin SHA-256, GPU, driver, toolkit, mlxcel commit and executed case counts. The harness output is checked against the manifests, so a skipped or shortened run fails the script. See the note on gpu-lock below.
  • Standalone warm/cold benchmark with synchronized timing boundaries and reusable fixtures. scripts/bench.sh records CUDA-event timings for 18 shapes (cold first launch, warm mean of 200). No speedup claim is made.

Out of scope, as the issue states: no MLX runtime integration, attention, quantized matmul or inference engine.

Why the bits match

docs/mlxcelverse/cuda-oxide-fused-norm-evidence.md maps each numerical point of the contract to its lines in kernels/fused_norm.cpp and in the new kernel, and records what both compiled kernels execute (cuobjdump -sass on the NVRTC-cached reference cubins and on the committed cubin):

  • Both contract the square accumulation acc += sr * sr into one FMA per element, use the same warp butterfly order, and use MUFU.RSQ.
  • The reference is specialized per width, so at power-of-two widths it compiles total / dim + eps to one FMA with a constant reciprocal. That scaling is exact and equals the runtime division used here; other widths use a true division in both.
  • Control: replacing the explicit fma_rn_f32 with acc + sr * sr in an isolated copy gave the same PTX instruction stream and the same 130 of 130 identical cases. The pinned toolchain contracts by default; the explicit intrinsic keeps that from depending on a compiler default.

Test plan

Run on a DGX Spark GB10 (sm_121, driver 580.178.04, CUDA 13.0, LLVM 21.1.0 release tarball, Rust 1.99.1 for the package and 1.97.1 for the application), at 28d884a5.

  • cargo fmt --all -- --check
  • cargo clippy --workspace --all-targets --features metal,accelerate -- -D warnings (not run; Linux host. Ran cargo clippy -p mlxcel-core --features cuda --example oxide_fused_norm_oracle -- -D warnings for the one file added to the workspace, clean.)
  • cargo test --workspace --profile test-fast --features metal,accelerate --no-fail-fast -- --test-threads=1 (not run. Ran the existing fused_norm_parity_tests on the CUDA build of the same tree: 10 passed.)
  • cargo deny check (not run; the workspace Cargo.lock and dependency set are unchanged, and the package has its own lockfile outside the workspace.)
  • Validated with a real checkpoint: not applicable, no inference path changes.
  • If the change moves the numbers: not applicable, no production kernel or dispatch changes.

Package gates, all passing:

cd spike/cuda-oxide-fused-norm
scripts/check-lint.sh && scripts/build.sh sm_121 && scripts/run.sh sm_121 && \
scripts/oracle.sh && scripts/compare.sh sm_121 && scripts/bench.sh sm_121 && scripts/check-clean-build.sh
  • 130 of 130 cases pass the host model, the fused CUDA kernel and the graph path; 130 of 130 bit-identical to the fused kernel.
  • Compute Sanitizer memcheck, racecheck, synccheck, initcheck: 0 errors each over the full run.
  • Five manifests validated against the committed PTX/cubin (b54c1c93…, 677d6d6d…); launch check valid.
  • The Validate cuda-oxide artifacts and standalone execution on GB10 #2831 smoke package was rebuilt and run on this host first (14 of 14, exact bitwise).
  • Repository gates run locally: binary assets, env-var docs, kernel-port dispatch, kernel dtype keys, cross-repo refs.

Notes for reviewers

  • gpu-lock. The host used here is not one of the maintainers' machines and has no upstream gpu-lock. A user-local flock(1) shim with the same run --tag <tag> -- <cmd> shape serialized every GPU command; results/compare-sm_121.json records it as gpu_lock_kind. If the criterion needs the real tool, the scripts run unchanged on a host that has it.
  • Committed cubin. artifacts/fused_add_rms_norm.sm_121.cubin (77.5 KB) is declared in scripts/ci/check_binary_assets.py, following the Validate cuda-oxide artifacts and standalone execution on GB10 #2831 precedent, because rebuilding it needs LLVM 21, CUDA 13.0 and the pinned cuda-oxide compiler.
  • Bit identity is not the criterion. It was observed with this driver, toolchain and MLX pin. The frozen budgets are the acceptance criterion.
  • Not measured. A build with FMA contraction disabled was not made, so the deviation an uncontracted accumulation would cause is unknown.
  • Mixed pairs. The graph reference is rounded to the activation dtype after MLX's f32 promotion (rms_norm uses result_type); the fused reference is never converted.
  • f16. The f16 path uses the compiler's f16 casts; bf16 uses the explicit round-to-nearest-even intrinsic.
  • Benchmark. Kernel-only timings; batch-1 decode shapes are launch-bound at about 4 to 6 µs. They say nothing about the integrated path.

Checklist

  • PR title uses a Conventional Commits prefix (feat:, fix:, etc.)
  • One logical change per PR (split unrelated changes)
  • Updated docs/ if user-facing behavior or supported models changed
  • Updated // Used by: ... comments on any shared function I modified (see docs/code-guidelines.md) (no shared function modified)
  • No secrets, credentials, or .env files committed

… kernel with a GB10 oracle

Second step of the cuda-oxide experiment (docs/mlxcelverse/cuda-oxide-feasibility.md):
an isolated package, spike/cuda-oxide-fused-norm, with five entry points (f32, f16,
bf16 activations with the weight in the same dtype, and f16/bf16 activations with an
f32 weight) that follow kernels/fused_norm.cpp's CUDA port term for term, a host
harness (run / compare / bench), one ABI schema and validated manifest per entry,
and an mlxcel-core example (oxide_fused_norm_oracle) that replays the fixtures through
the existing fused CUDA kernel and the graph path.

On a DGX Spark GB10 (sm_121) all 130 cases (2,181,390 elements) pass the frozen
fused_norm_parity_tests budgets against both references and are bit-identical to the
existing fused CUDA kernel; Compute Sanitizer memcheck/racecheck/synccheck/initcheck
report 0 errors; results, artifacts and the evidence report are committed.

Closes lablup#2832
… lines and device code

Record, for issue lablup#2832, where each numerical point of the contract lives in
the reference kernel and in the standalone kernel, what the compiled code of
both executes on the GB10 (FMA-contracted square accumulation, butterfly
order, rsqrt, constant-width reciprocal in the reference), the control build
without the explicit FMA intrinsic, and the lablup#2831 smoke re-run this work
depends on.
…result

compare.sh wrote the absolute path of gpu-lock, which says nothing about a
stand-in lock and leaks a home directory. Record the path relative to HOME
and a gpu_lock_kind note (GPU_LOCK_KIND), and regenerate the result from the
same fixtures and oracle dump: only the notes changed, 130 of 130 cases
still pass and stay bit-identical.
@inureyes inureyes added area:core mlxcel-core: MLX FFI, primitives, KV cache, layers platform:linux Linux (CUDA / packaging) specific priority:medium Medium priority status:review Under review type:enhancement New features, capabilities, or significant additions labels Nov 15, 2026
An empty or truncated cases.tsv could produce a successful comparison without qualifying all dtype and shape cases. Require the canonical matrix in its deterministic seed order before reading oracle outputs.

The focused Rust test accepts the complete matrix and rejects empty, header-only, truncated, reordered and duplicate cases. Device kernel code and artifacts are unchanged.

Refs lablup#2953, lablup#2832
@inureyes

Copy link
Copy Markdown
Member

Implementation hardening for #2953.

Reviewed #2832: the standalone artifact, launch guards, dtype tolerances, and reference comparisons match the intended experiment. Fixed a reliability defect: an empty or incomplete cases.tsv could yield a vacuous all-pass comparison. The harness now requires the complete canonical case matrix, with regression coverage for empty, truncated, duplicate, and reordered cases.

Validation: The pinned oxide build, fmt/clippy, eight guard checks, and fixture regression test passed. The GPU host-reference run covered 130 cases and 2,181,390 elements, rejecting all five invalid launches.

The built oxide_fused_norm_oracle replayed all 130 fixtures on MLX CUDA. scripts/compare.sh sm_121 passed all 130 cases, bit-identical to the fused CUDA reference across 2,181,390 elements. Commands also included scripts/build.sh sm_121, scripts/run.sh sm_121, scripts/check-lint.sh, scripts/check-guards.py, and the pinned-toolchain fixture regression test. No further security or kernel-performance issue was found; this remains a standalone experiment.

@inureyes
inureyes merged commit ac506ba into lablup:main Nov 15, 2026
31 checks passed
@inureyes inureyes added status:done Completed and removed status:review Under review labels Nov 15, 2026
@inureyes inureyes added this to the 0.9 milestone Nov 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:core mlxcel-core: MLX FFI, primitives, KV cache, layers platform:linux Linux (CUDA / packaging) specific priority:medium Medium priority status:done Completed type:enhancement New features, capabilities, or significant additions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add a standalone cuda-oxide fused residual RMSNorm kernel

2 participants