Add cvt_f16x2_f32 intrinsic for f32-to-f16x2 packing#66
Open
honeyspoon wants to merge 1 commit into
Open
Conversation
Signed-off-by: abder <bobmatt911@gmail.com>
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).