Repository navigation
feat: add packed cvt variants (rz, relu) for f16x2 and bf16x2 - #276
Merged
Merged
Conversation
honeyspoon
force-pushed
the
upstream-cvt-variants
branch
from
June 22, 2026 19:04
aa72b1f to
00b31a2
Compare
49 tasks done
nihalpasham
force-pushed
the
upstream-cvt-variants
branch
from
June 24, 2026 04:44
00b31a2 to
5741af2
Compare
Add four packed type-conversion intrinsics completing the f16x2/bf16x2 conversion family alongside the existing cvt.rn variants: - cvt.rz.f16x2.f32 / cvt.rz.bf16x2.f32: round-toward-zero truncation - cvt.rn.relu.f16x2.f32 / cvt.rn.relu.bf16x2.f32: ReLU-fused conversion Lowered to pure inline PTX assembly with AsmKind::Pure, matching the existing cvt_f16x2_f32 pattern. Critical for quantization-aware inference (truncation rounding) and fused activation layers (ReLU). Part of NVIDIA#274 Signed-off-by: abder <[email protected]>
Rebasing the rz/relu cvt intrinsics onto the post-NVIDIA#277 TypeHandle API surfaced two breaks the stale base hid: - The four new emit_* helpers built their result type with the removed `TypedHandle::to_ptr()`. Switch to `.to_handle()`, matching the sibling emit_cvt_f16x2_f32 on main. - The commit had picked up seven stray `*Bf16x2Op` arithmetic imports (Abs/Add/Sub/Mul/Min/Max/Neg) from an unrelated branch; they are undefined here and unused, so drop them to keep the PR cvt-only.
nihalpasham
force-pushed
the
upstream-cvt-variants
branch
from
June 24, 2026 05:02
5741af2 to
437f533
Compare
Collaborator
|
Thanks for the PR. LGTM 👍🏾
Rebased onto the
Reviewer note: no GPU e2e in this env. ReLU-on-negatives/NaN is only asserted via mnemonic substring, so an |
3 tasks done
honeyspoon
added a commit
to honeyspoon/cuda-oxide
that referenced
this pull request
Jun 24, 2026
Follow-up to NVIDIA#276, adds the GPU-verified example noted as owed. Tests cvt.rz, cvt.rn.relu for both f16x2 and bf16x2, verifying ReLU clamps negatives to zero and rz truncates toward zero. Part of NVIDIA#274 Signed-off-by: abder <[email protected]>
nihalpasham
pushed a commit
to honeyspoon/cuda-oxide
that referenced
this pull request
Jun 28, 2026
Follow-up to NVIDIA#276, adds the GPU-verified example noted as owed. Tests cvt.rz, cvt.rn.relu for both f16x2 and bf16x2, verifying ReLU clamps negatives to zero and rz truncates toward zero. Part of NVIDIA#274 Signed-off-by: abder <[email protected]>
nihalpasham
added a commit
that referenced
this pull request
Jun 28, 2026
* feat: add packed cvt variants end-to-end example (sm_80+) Follow-up to #276, adds the GPU-verified example noted as owed. Tests cvt.rz, cvt.rn.relu for both f16x2 and bf16x2, verifying ReLU clamps negatives to zero and rz truncates toward zero. Part of #274 Signed-off-by: abder <[email protected]> * fix: make packed conversion checks bit-exact Signed-off-by: nihalp <[email protected]> --------- Signed-off-by: abder <[email protected]> Signed-off-by: nihalp <[email protected]> Co-authored-by: nihalp <[email protected]>
3 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add four packed type-conversion intrinsics completing the f16x2/bf16x2 conversion family alongside the existing cvt.rn variants.
Summary
The existing
cvt_f16x2_f32converts two f32 values into a packed f16x2 using round-to-nearest-even (.rn). This PR adds the four remaining packed conversion variants that are important for inference workloads on sm_80+ hardware:cvt.rz.f16x2.f32andcvt.rz.bf16x2.f32: Round-toward-zero (truncation) instead of round-to-nearest-even. Truncation rounding is preferred in quantization-aware inference pipelines where deterministic floor-toward-zero behavior is needed, avoiding the slight upward bias of round-to-nearest-even on half-boundary values.cvt.rn.relu.f16x2.f32andcvt.rn.relu.bf16x2.f32: Fuse a ReLU clamp (negative values become zero) into the conversion in a single instruction. Fusing ReLU eliminates a separatemax(x, 0)step, saving one instruction per element pair in activation layers.All four instructions pack two f32 inputs into a single u32 (f16x2 or bf16x2), matching the existing
cvt_f16x2_f32calling convention(lo: f32, hi: f32) -> u32.cvt_rz_f16x2_f32(lo, hi)cvt.rz.f16x2.f32 d, hi, lo;cvt_rn_relu_f16x2_f32(lo, hi)cvt.rn.relu.f16x2.f32 d, hi, lo;cvt_rn_relu_bf16x2_f32(lo, hi)cvt.rn.relu.bf16x2.f32 d, hi, lo;cvt_rz_bf16x2_f32(lo, hi)cvt.rz.bf16x2.f32 d, hi, lo;Part of #274
Changes
convert.rs(cvt_rz_f16x2_f32,cvt_rn_relu_f16x2_f32,cvt_rn_relu_bf16x2_f32,cvt_rz_bf16x2_f32), each(lo: f32, hi: f32) -> u32,#[inline(never)].CvtRzF16x2F32Op,CvtRnReluF16x2F32Op,CvtRnReluBf16x2F32Op,CvtRzBf16x2F32Op) with 2 operands and 1 result.emit_cvt_*translation functions dispatched fromtry_dispatch_intrinsic.convert_cvt_*lowering functions emitting pure inline PTX assembly (=r,f,fconstraints,AsmKind::Pure); 4MirToLlvmConversiontrait impls.Testing
cargo check -p dialect-nvvm -p mir-lowerpassescargo test -p mir-lower --test lowering_testpasses (4 new + existing)cargo fmt --checkandcargo clippy --workspace -- -D warningscleanChecklist
git commit -s)cuda-bindings/modified