Repository navigation
feat: add bf16x2 packed arithmetic and ReLU-fused FMA (sm_80+) - #279
Merged
Merged
Conversation
49 tasks done
honeyspoon
force-pushed
the
upstream-bf16x2-arith
branch
3 times, most recently
from
June 26, 2026 17:44
a5567f0 to
99182c6
Compare
nihalpasham
force-pushed
the
upstream-bf16x2-arith
branch
from
June 28, 2026 03:32
99182c6 to
1700fcc
Compare
Add packed bf16x2 arithmetic operations extending the existing fma.rn.bf16x2: add, sub, mul, min, max, neg, abs, and fma.rn.relu. All are pure per-thread register arithmetic lowered to inline PTX with AsmKind::Pure. Part of NVIDIA#274 Signed-off-by: abder <[email protected]>
Signed-off-by: nihalp <[email protected]>
nihalpasham
force-pushed
the
upstream-bf16x2-arith
branch
from
June 28, 2026 05:00
1700fcc to
43219da
Compare
6 of 7 tasks
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 packed bf16x2 arithmetic operations extending the existing
fma.rn.bf16x2: binary ops (add, sub, mul, min, max), unary ops (neg, abs), and a ReLU-fused FMA variant. All are pure per-thread register arithmetic lowered to inline PTX withAsmKind::Pure.Summary
The existing
fma_bf16x2performs fused multiply-add on packed bf16x2 values. This PR adds the remaining packed bf16x2 arithmetic family, completing the ALU coverage needed for bf16 inference kernels. Each operation takes packed u32 (bf16x2) inputs and produces a packed u32 output, operating on both lanes in a single instruction.The
fma.rn.relu.bf16x2variant fuses a ReLU clamp into the FMA, eliminating a separatemax(x, 0)step in activation layers.add_bf16x2(a, b)add.rn.bf16x2sub_bf16x2(a, b)sub.rn.bf16x2mul_bf16x2(a, b)mul.rn.bf16x2min_bf16x2(a, b)min.bf16x2max_bf16x2(a, b)max.bf16x2neg_bf16x2(a)neg.bf16x2abs_bf16x2(a)abs.bf16x2fma_relu_bf16x2(a, b, c)fma.rn.relu.bf16x2Multi-variant families use parameterized dispatch helpers (
emit_binary_bf16x2,emit_unary_bf16x2,convert_binary_bf16x2,convert_unary_bf16x2) to avoid code duplication across variants.Part of #274
Changes
pub fnstubs inbf16x2.rs(pure register arithmetic, no safety contract needed).emit_binary_bf16x2/emit_unary_bf16x2helpers with thin per-variant wrappers, plus match arms intry_dispatch_intrinsic.convert_binary_bf16x2/convert_unary_bf16x2helpers; 8MirToLlvmConversionimpls. All useAsmKind::Pure.fma_relu_bf16x2.bf16x2_arithend-to-end GPU example testing all 8 ops with known values and bf16 tolerance comparison.Testing
cargo test -p mir-lower --test lowering_testpassescargo fmt --checkandcargo clippycleanbf16x2_arith)Checklist
git commit -s)cuda-bindings/modified