Repository navigation
feat(cuda-device): add bf16x2 FMA intrinsic - #191
Merged
Merged
Conversation
Signed-off-by: nik <[email protected]>
…te, doc row Layered on top of the contributor PR: - replace 3 U+2014 em-dashes in the bf16x2 importer/lowering doc comments (tracked files must not contain em-dashes) - example: print a PASS/FAIL marker (it exited 0 silently on success, so a full smoketest run scored it FAIL despite correct output) and skip cleanly on pre-sm_80 devices via compute_capability() - supported-features: add a Packed bf16x2 FMA row
nihalpasham
force-pushed
the
prepare-bf16x2-fma
branch
from
June 17, 2026 04:27
7862260 to
f4aaab9
Compare
This was referenced Jun 17, 2026
Collaborator
|
LGTM
Reviewer note: GPU |
nihalpasham
added a commit
to honeyspoon/cuda-oxide
that referenced
this pull request
Jun 18, 2026
… bf16x2 to AsmKind::Pure The asm_kind docblock was accidentally prepended to asm_kind_opt in the original PR. Remove the stray block so asm_kind_opt has a single, accurate doc comment. Migrate convert_fma_bf16x2 from InlineAsmOp::new(..., false) to InlineAsmOp::build(..., AsmKind::Pure), covering the bf16x2 FMA op added by PR NVIDIA#191 after this branch was cut. The PTX instruction is a pure register-to-register FMA with no memory side effects and no warp synchronization, so Pure is the correct classification.
nihalpasham
added a commit
that referenced
this pull request
Jul 30, 2026
…licit std feature) (#593) * Port to pliron master API + timing-robust alignment stamping (pliron PR 182/191 testing) EXPERIMENTAL BRANCH - do not merge as-is. The workspace and rustc-codegen-cuda manifests carry a TEMPORARY [patch] section pointing pliron/pliron-derive/pliron-llvm at the local clone ~/dev/pliron so upstream PRs can be tested by switching branches there. Port to pliron master (4159dc0, 52 commits past our 222dd962 pin): - Type::register_instance -> Type::instantiate (renamed upstream) - drop unused get_existing() wrappers (Type::get_instance removed upstream) - DialectName::new -> DialectName::try_new - pliron::pass_manager::AnalysisManager -> pliron::pass::AnalysisManager Timing-robust alignment stamping (found while testing pliron PR #182, "[DialectConversion] Convert all block args, not just used ones"): stamp_memory_op_alignment ran inside the MirFuncOp rewrite and read live operand types to recover repr(align(N)) ABI alignment. That relied on the old driver's lazy block-arg conversion; PR #182 converts all block args before the first rewrite, so stores/refs of block args (params, mem2reg join/loop args) silently lost their alignment stamp (probe showed the Al16 entry spill store degrade from align 16 to align 4). Hoist the stamping to a whole-module pre-pass before apply_dialect_conversion, next to the dynamic-smem pre-pass, making it independent of conversion order under both old and new drivers. New example pr182_probe: over-aligned aggregates in block-arg positions (entry spill of a by-value repr(align(16)) param, mem2reg join struct, loop-carried tuple, dead params). Its .ll is byte-identical between pliron master and PR #182 with this fix. Validation (pliron clone on master and on pr-182, RTX 5090 / CC 12.0): cargo test --workspace 2992 passed, 0 failed; smoketest 171/171. * Opt in to pliron-llvm's std feature (pliron PR #191) pliron PR #191 makes pliron-llvm (without llvm-sys) no_std and gates its std support behind a new `std` feature. Our default-features = false dependency (which exists to keep llvm-sys out) must now request std explicitly. Note: cuda-oxide happens to build on PR #191 even without this, because our direct pliron dependency unifies pliron/std into the graph, but relying on that is fragile; declare the intent. This commit only resolves when the patched pliron-llvm has the std feature (pliron clone on pr-191); keep it at the branch tip until the PR lands upstream. Validation (pliron clone on pr-191): cargo test --workspace 2992 passed, 0 failed; smoketest 171/171. * Recover repr(align) from conversion history instead of a pre-pass Per upstream guidance (Vaivaswatha, on pliron PR #182): the dialect conversion driver records every value type change it makes, and hands each rewrite an OperandsInfo carrying the full pre-conversion type history of its operands. That is the intended way to read source-dialect types late, so use it instead of stamping alignment in a module pre-pass before conversion starts. - mir.store / mir.ref: recover the stored/referenced value's ABI alignment via value_abi_align (current type first, then the operand's recorded history, newest first) at the op's own rewrite. - mir.load / mir.alloca: read their own result types, which the driver never converts ahead of the op's rewrite. - Delete stamp_module_memory_op_alignments / stamp_memory_op_alignment and the copy_alignment attribute round-trip. Net -59 lines. Equivalence and validation (RTX 5090 / CC 12.0): - pr182_probe .ll byte-identical to the pre-pass fix on pliron master. - All 312 .ll artifacts across all 171 examples byte-identical between the pre-pass fix and this fix on pliron pr-182 (full-run comparison). - cargo test --workspace 2992 passed, 0 failed on pr-182 and pr-191. - smoketest 171/171 on pr-182 and pr-191. * Rename pr182_probe example to repr_align_block_args The example guards a durable compiler invariant, not a one-off PR test: repr(align(N)) ABI alignment must survive dialect conversion for values in block-arg positions (function params, mem2reg join/loop args), where the conversion driver may replace MIR types before any per-op rewrite runs. Name it for what it checks. Docs reframed the same way; the pliron PR #182 origin stays as context. * deps: bump pliron to master 0d3f25df and drop the local-clone patch Picks up DialectConversion converting all block args (pliron#182), no_std pliron-llvm behind an explicit std feature (pliron#191), BytesAttr global initializers (pliron#198), and the conversion-trait renames (pliron#201). The repr(align) recovery already reads the OperandsInfo conversion history at rewrite time, so no pre-pass is needed under the eager block-arg conversion. * fix(examples): keep device_ffi_test's nvvm-dis text dump best-effort An nvvm-dis older than the CUDA toolkit cannot parse newer LTOIR, and under set -e the inspection failure aborted the whole build. Guard it exactly like the small_type_ffi_test and mathdx_ffi_test siblings already do: the binary LTOIR is the consumed artifact, the text dump is debugging aid only. * style: rustfmt the port; re-resolve the standalone lock to the git pin The repr_align_block_args example and one blank line in dialect-mir predate the fmt gate; the rustc-codegen-cuda Cargo.lock still recorded pliron as a path dependency left over from the removed local-clone patch, and now records the pinned git source. * style(examples): collapse the guarded write in repr_align_block_args
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.
Closes #190.
Problem
cuda-oxide did not have an end-to-end representation for the PTX
fma.rn.bf16x2instruction even though it is the packed bf16 arithmetic operation available onsm_80+. That left users unable to express packed bf16x2 FMA through thecuda-deviceAPI and meant the compiler pipeline had no focused regression covering importer recognition and MIR lowering for this instruction.The general compiler/runtime rule is: a public CUDA device intrinsic for a concrete PTX instruction should be represented consistently through the device API, dialect op, MIR importer dispatch, MIR lowering, and a repo-native example that proves the path remains wired together.
Fix
Add
cuda_device::bf16x2::fma_bf16x2(a, b, c) -> u32, where eachu32stores two bf16 lanes. The importer recognizes that intrinsic path and emits a newnvvm.fma_bf16x2op, and MIR lowering converts that op to inline PTX:The new
bf16x2_fmarustc-codegen-cuda example exercises the path from device API through codegen and checks the packed result on execution-capable systems.Diligence
I checked the sibling packed intrinsic path used by
tcgen05::cvt_f32x2_bf16x2: public device declaration, dialect op registration, importer terminator dispatch, conversion interface registration, and inline-PTX emission. The new intrinsic follows that same abstraction boundary rather than adding an example-only workaround.This PR intentionally does not add packed bf16x2 add/mul intrinsics. PTX
fma.rn.bf16x2is supported onsm_80+, whileadd.bf16x2andmul.bf16x2requiresm_90+; adding all three under one Ampere-facing module would imply a common architecture contract that PTX does not provide. Ampere callers can express packed add as FMA with a packed1.0multiplier.All new Rust source files use the repository's NVIDIA copyright and SPDX header.
Tests
Added
crates/rustc-codegen-cuda/examples/bf16x2_fma, includingCargo.lockand a short README. The example converts(2.0, 4.0),(3.0, 5.0), and(7.0, 11.0)into packed bf16x2 operands, runs the FMA intrinsic in a kernel, and checks for packed(13.0, 31.0).Validation
Local results: all commands pass after applying
cargo fmt --all;cargo test -p dialect-nvvm --all-targetspassed with the focusedFmaBf16x2Opconstruction/verification test;scripts/smoketest.sh --compile-only --no-colorpassed 93/93 examples, includingbf16x2_fma;cargo oxide run bf16x2_fmapassed from the repository root on sm_86 and printed matchingexpectedandgotpacked bf16x2 values (0x41f84150).