Skip to content

gpu: refuse misaligned vector views at launch - #520

Merged
juliankang4 merged 1 commit into
midagedev:mainfrom
juliankang4:fix-nvfp4-plane-align
Oct 20, 2026
Merged

juliankang4 merged 1 commit into
midagedev:mainfrom
juliankang4:fix-nvfp4-plane-align

Conversation

@juliankang4

Copy link
Copy Markdown
Collaborator

벡터 정렬이 맞지 않는 양자화 텐서를 커널 실행 전에 이름이 있는 오류로 거부합니다.

Fixes #518

What and why

A u32 tensor window can start four bytes into its parent allocation, while the NVFP4 kernel needs its code plane aligned to 16 bytes. The launcher now checks that requirement before enqueueing, so an unavailable device vector view cannot leave the output unchanged behind an Ok result.

The same validator checks MXFP4 route gate/up and down planes and IQ row planes, including IQ4_XS metadata. It takes the alignment from the CUDA vector type. SSD's existing alignment checks use this helper too. Q8_0 keeps its scalar fallback for unaligned activations. Kernel bodies and valid-input arithmetic are unchanged.

Release notes: Added: Named launch errors for misaligned NVFP4, MXFP4 and IQ vector planes.

Code shape

  • No second copy. One buffer validator owns vector base-alignment checks.
  • Model code holds only architecture facts. No model-specific path changed.
  • Dead code is gone. The separate SSD alignment loop is removed.
  • No silent failure. Mandatory vector views are checked before launch.
  • Comments state what is true now.
  • No relaxed gate. The unsafe pin covers two test-only window constructions with SAFETY comments.
  • cargo fmt is clean. cargo clippy was not run here.

Duplication removed: crates/gpu/src/mamba2_ssd.rs, the vector base-alignment loop in refuse.

What I ran

Tested head: 5f83676053bd6a6be018113a7fc3435e502c56a8. Base: 146c13027d5311ee804f7094730b0a6f009f617f. These checks use synthetic tensors and need no model file.

cargo oxide test --arch sm_120 -- -p bloomery-gpu --release unaligned -- --ignored --nocapture --test-threads=1
cargo oxide test --arch sm_120 -- -p bloomery-gpu --release mxfp4::tests
cargo oxide test --arch sm_120 -- -p bloomery-gpu --release iq::tests
bash tools/check-unsafe.sh
cargo oxide build --arch sm_120 -- -p bloomery-gpu-gates --features gpu --release --bin gate_nvfp4 --bin gate_iq --bin gate_mamba2_ssd
Check Result
Hardware alignment regressions, including the 33-word NVFP4 reproduction and aligned launches 4 passed, 0 failed
Host MXFP4/NVFP4 tests 2 passed, 0 failed; 1 hardware test ignored
Host IQ tests 2 passed, 0 failed; 1 hardware test ignored
tools/check-unsafe.sh All crate counts match their pins

The hardware table covers each IQ vector format, both IQ4_XS planes, MXFP4 gate/up and down, and SSD conv/output/state. The NVFP4 case rejects a 1 x 32 window at byte offset 4 with aligned 1 x 4 scales, K=256 and one activation column, and keeps its output sentinel on refusal.

For the functional gates, use the local GPU lock directory and set BLOOMERY_DATA to the directory containing ref-synth:

export BLOOMERY_BOX_LOCAL=1 BLOOMERY_BOX_CARD=local
export BLOOMERY_LOCK_DIR="$HOME/.cache/bloomery-locks"
mkdir -p "$BLOOMERY_LOCK_DIR"
BLOOMERY_GATE_CARD=any bash tools/gpu-gate.sh gate_nvfp4
BLOOMERY_GATE_CARD=any bash tools/gpu-gate.sh gate_iq
BLOOMERY_GATE_CARD=any bash tools/gpu-gate.sh gate_mamba2_ssd
Gate Result
gate_nvfp4 PASS
gate_iq PASS
gate_mamba2_ssd PASS
bash tools/ptx-compare.sh 146c13027d5311ee804f7094730b0a6f009f617f gate_nvfp4 --features gpu
PTX comparison Result
All embedded entries, including the NVFP4, MXFP4 route, IQ and SSD kernels 277 entries identical; none added, removed or changed

The PTX scanner uses its fixed sm_86 target and JITs on the RTX 5090. The functional tests above use sm_120.

What I ran into

gate_dspark_experts was not run because the test machine has neither the DSpark checkpoint nor the dsref code64_n32_w3 reference set. This does not block this input-validation fix: the MXFP4 launcher hardware test exercises refusals and aligned execution, and the device code is unchanged.

Hardware

NVIDIA GeForce RTX 5090, driver 595.99.02, compute capability 12.0. The functional builds target sm_120.

AI help

AI 코딩 에이전트가 코드를 작성한 후 설명을 썼고, 테스트를 마쳤습니다. diff 리뷰와 PR 초안 리뷰는 제가 직접 했습니다.

@github-actions github-actions Bot added gpu The card engine: crates/gpu*, crates/app needs-gpu Changes code a card must check, and carries no gate run on a card labels Oct 20, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: CLEAN: The launchers reject misaligned vector planes before enqueueing, and the shared validator preserves SSD's alignment requirements.

Non-blocking

⚠ Show FAIL-first output: crates/gpu/src/mxfp4.rs:846. The PR reports passing alignment regressions but no failing run before the fix. Run the new NVFP4 regression on the base and attach its failing assertion, then the head's passing output, as CONTRIBUTING.md requires for a new gate.

⚠ Supply dispatch timing evidence: crates/gpu/src/tensor.rs:15. The valid path gains one alignment check per NVFP4 launch, three per MXFP4 gate/up/down pair, and one or two per IQ row launch. The reported identical PTX covers device code; AGENTS.md also requires a same-lease base/head A/B for dispatch changes. Attach the existing runner's output before this becomes the timing baseline.

Checked

Duplicates: 5 new functions checked; no duplicate owner found. Dryer reported 0 pairs. The shared validator replaces SSD's alignment loop.
Complexity: IqKernels::enqueue_rows 29 → 37 adds format-specific refusal branches; MxExpertKernels::enqueue_gate_up 19 → 21 and enqueue_down 18 → 19 add refusal paths. The shared validator owns the alignment decision.
Silent failure: 8 mandatory-vector conversion sites followed; all 10 quantized vector planes have matching host checks. The empty IQ3_S match arm still reaches its named unsupported-format error. No new failure defaults.
Tests: static mutation checks only. Removing the checks at mxfp4.rs:788, mxfp4_sel.rs:850/851/922, iq.rs:1512/1515/1516/1519, or mamba2_ssd.rs:605/606/607 makes the corresponding new test's error assertion fail. gate-gpu-lib includes all four ignored tests. CUDA tests were not rerun here.
Gates: no numeric bands moved or cases removed. The unsafe-block pin rises from 1958 to 1960 with a dated reason for the two test constructions.
Performance: the four device-code sections are byte-identical to the base. No valid-path allocation, launch, copy, synchronization, or reduction-order change was added.
Escape catalog: no C1–C4 pattern matched.

Notes

The PR names the RTX 5090 and driver, both commits, and synthetic inputs, but omits the nvidia-smi output and full functional gate output. gpu.json records evidence=false under the required evidence list.

Card check: needs-gpu. This pull request changes crates/gpu/src/iq.rs, crates/gpu/src/mamba2_ssd.rs, crates/gpu/src/mxfp4.rs … and carries no gate run on a card (CONTRIBUTING's evidence list); a maintainer adds gpu-verified after one.

🔨 Shingler, bloomery's review bot: approves a clean pull request and requests changes on a must-fix (how it works)

@juliankang4

Copy link
Copy Markdown
Collaborator Author

The review is done and the contribution check passed, so I'm merging this.

@juliankang4
juliankang4 merged commit fda5eca into midagedev:main Oct 20, 2026
6 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gpu The card engine: crates/gpu*, crates/app needs-gpu Changes code a card must check, and carries no gate run on a card

Projects

None yet

Development

Successfully merging this pull request may close these issues.

gpu: dense NVFP4 accepts an unaligned code plane and leaves output unchanged

1 participant