Repository navigation
Add cvt_f16x2_f32 intrinsic for f32-to-f16x2 packing - #66
Merged
Merged
Conversation
honeyspoon
force-pushed
the
upstream-cvt-f16x2
branch
from
June 7, 2026 23:59
9b8e62a to
21cb520
Compare
Signed-off-by: abder <[email protected]>
Add unit test for CvtF16x2F32Op verifying it lowers to inline asm containing the cvt.rn.f16x2.f32 PTX instruction. Also fix dialect_llvm → llvm_export import and add missing convergent parameter in convert.rs.
honeyspoon
force-pushed
the
upstream-cvt-f16x2
branch
from
June 11, 2026 00:29
de1bae5 to
f15567e
Compare
Contributor
Author
|
Hey could we run the ci checks on this plz |
CI runs a workspace-wide cargo fmt check; the two manually wrapped expressions in the new test fail it.
rustdoc treats [15:0], [31:16] and args[0]/args[1] as intra-doc links and fails the RUSTDOCFLAGS='-D warnings' doc gate with unresolved-link errors. Backtick them so they render as code instead. Also realign the lowering module's PTX table columns.
FP32Type::get takes a shared reference; passing &mut ctx trips clippy::unnecessary_mut_passed.
The inserted Type Conversions match arm consumed the opening '=====' line of the next section banner.
cvt_f16x2_f32 and cvt_f32x2_bf16x2 use different argument naming (lo/hi vs a/b) while sharing the same first-arg-low packing, and the PTX operand order is reversed relative to the Rust signature. Spell out the exact bit lanes on both stubs and link them to each other so neither convention has to be inferred from the lowering.
…nsic Promotes the PR #66 review repro to a feature-named example so the examples-compile CI gate covers the intrinsic. Verifies 256 packed values bit-exactly against a host scalar round-to-nearest-even reference, cross-checks a device-side scalar kernel against the intrinsic kernel, and pins the lane order with a constant-literal kernel (f16(1.5)=0x3E00 low, f16(-2.25)=0xC080 high).
Collaborator
|
Thanks for the PR. LGTM 👍🏾 |
This was referenced Jul 3, 2026
meefs
pushed a commit
to meefs/cuda-oxide
that referenced
this pull request
Sep 30, 2026
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.
Summary
Add
cvt_f16x2_f32— packs twof32values into a singleu32containing two packedf16values in a single PTX instruction.Maps to PTX:
cvt.rn.f16x2.f32 d, hi, lo;CUDA C equivalent:
__float2half2_rn()Motivation
WMMA GEMM epilogues accumulate in
f32but need to write half-precision output. The scalar approach requires two separatef32→f16conversions plus bit manipulation ((lo_bits) | (hi_bits << 16)). This intrinsic compiles to a single PTX instruction that does both conversions and the pack.Implementation
Follows the same 4-crate pattern as the existing
CvtF32x2Bf16x2Op(bfloat16 variant intcgen05.rs):cuda-device/src/convert.rs:cvt_f16x2_f32(lo: f32, hi: f32) -> u32stubdialect-nvvm/src/ops/convert.rs:CvtF16x2F32Op— 2 f32 operands, 1 i32 resultmir-importer/.../intrinsics/convert.rs: Standard 2-arg emit with result storage viaemit_store_result_and_gotomir-lower/.../intrinsics/convert.rs:llvm.inline_asmwith constraint string"=r,f,f"The lowering is structurally identical to the existing
convert_cvt_f32x2_bf16x2incrates/mir-lower/src/convert/intrinsics/tcgen05.rs(lines 510–539), differing only in the PTX instruction name.Testing
Validated in a WMMA GEMM kernel on SM_89: f32 accumulator → packed f16x2 output with correct values (cosine similarity 1.000000 vs scalar reference).