Skip to content

Add packed f16x2 arithmetic intrinsics - #332

Closed
honeyspoon wants to merge 1 commit into
NVIDIA:mainfrom
honeyspoon:upstream/add-f16x2-arithmetic
Closed

honeyspoon wants to merge 1 commit into
NVIDIA:mainfrom
honeyspoon:upstream/add-f16x2-arithmetic

Conversation

@honeyspoon

Copy link
Copy Markdown
Contributor

Summary

Adds nine packed f16x2 arithmetic intrinsics across all four compiler layers (cuda-device, dialect-nvvm, mir-importer, mir-lower), mirroring the existing bf16x2 module (#279).

add.rn.f16x2    %d, %a, %b;
sub.rn.f16x2    %d, %a, %b;
mul.rn.f16x2    %d, %a, %b;
fma.rn.f16x2    %d, %a, %b, %c;
neg.f16x2       %d, %a;
abs.f16x2       %d, %a;
min.f16x2       %d, %a, %b;      // sm_80+
max.f16x2       %d, %a, %b;      // sm_80+
fma.rn.relu.f16x2 %d, %a, %b, %c; // sm_80+

f16 is more widely used than bf16 in many inference workloads. This closes the gap where bf16x2 had full arithmetic support but f16x2 did not.

Part of tracking issue #274 (Phase 6).

What changed

  • cuda-device: Added f16x2 module with 9 user-facing #[inline(never)] stubs.
  • dialect-nvvm: Added 9 operations (AddF16x2Op, SubF16x2Op, ...) with verifier tests.
  • mir-importer: Added dispatch table entries and f16x2 intrinsic emitter module.
  • mir-lower: Added lowering conversions (inline asm with =r,r,r constraints for binary ops, =r,r,r,r for ternary). sm_80+ ops added to pipeline feature detection.
  • Lowering tests for all 9 variants.

Testing

  • cargo fmt --check clean
  • cargo test -p dialect-nvvm --all-targets — verifier tests pass
  • cargo test -p mir-lower --all-targets — lowering tests pass
  • cargo oxide run e2e on sm_80+ GPU

Checklist

  • Signed-off-by DCO trailer
  • No crates/cuda-bindings/ changes
  • SPDX headers on new source files

Mirror the existing bf16x2 module to support packed f16x2 arithmetic
across all four compiler layers (cuda-device, dialect-nvvm, mir-importer,
mir-lower).

Nine new intrinsics:
- add_f16x2, sub_f16x2, mul_f16x2, fma_f16x2, neg_f16x2, abs_f16x2 (sm_53+)
- min_f16x2, max_f16x2, fma_relu_f16x2 (sm_80+)

All operands and results are u32 (packed f16x2). The sm_80+ operations
(min, max, fma.relu) are added to the pipeline's sm_80 feature detection.
The sm_53+ operations are below the project's Volta floor and do not
affect architecture target selection.

Includes dialect-nvvm verifier tests and mir-lower lowering tests.

Part of tracking issue NVIDIA#274 (Phase 6).

Signed-off-by: abder <[email protected]>
@nihalpasham nihalpasham added enhancement New feature or request already-fixed Resolved on a newer commit or branch; no action needed intrinsics Device intrinsics and libdevice math mappings device-apis User-facing device-side and kernel-authoring APIs (cuda-device, cuda-macros) codegen Device code-generation pipeline (Rust MIR to IR to PTX) IR-lowering Lowering between dialects (dialect-mir to LLVM dialect) cuda-feature A CUDA hardware/toolkit feature (TMA, tcgen05, WGMMA) labels Jul 18, 2026
@nihalpasham

Copy link
Copy Markdown
Collaborator

Thanks for putting this together. The generated-intrinsics work in #406 now covers all nine f16x2 operations from this PR while keeping the same cuda_device::f16x2::* APIs. I’m closing this as superseded by #406.

@honeyspoon
honeyspoon deleted the upstream/add-f16x2-arithmetic branch July 23, 2026 13:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

already-fixed Resolved on a newer commit or branch; no action needed codegen Device code-generation pipeline (Rust MIR to IR to PTX) cuda-feature A CUDA hardware/toolkit feature (TMA, tcgen05, WGMMA) device-apis User-facing device-side and kernel-authoring APIs (cuda-device, cuda-macros) enhancement New feature or request intrinsics Device intrinsics and libdevice math mappings IR-lowering Lowering between dialects (dialect-mir to LLVM dialect)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants