Skip to content

feat(intrinsics): add extended integer min/max (DPX relu and 16x2 forms) - #967

Merged
nihalpasham merged 3 commits into
NVIDIA:mainfrom
almightychang:dpx-relu-16x2-intrinsics
Aug 17, 2026
Merged

nihalpasham merged 3 commits into
NVIDIA:mainfrom
almightychang:dpx-relu-16x2-intrinsics

Conversation

@almightychang

@almightychang almightychang commented Aug 17, 2026 •

Copy link
Copy Markdown
Contributor

Part of #338

Summary

Add the integer_minmax intrinsic family with eight PTX ISA 8.0 / SM90+ integer min/max extensions: min/max across relu.s32, s16x2, u16x2, and relu.s16x2.

The pinned LLVM import has no NVVM intrinsic records for these operations; LLVM reaches them through generic smin/smax selection. Following the existing packed_alu precedent, this family therefore enters the catalog under a reviewed ptx_native contract.

Plain scalar s32 min/max is deliberately excluded because ordinary Rust min/max already lowers to native min.s32/max.s32. That path is handled separately in #951.

Changes

  • Add a closed eight-variant integer_minmax catalog recipe and ABI entries i0987 through i0994.
  • Generate public cuda_intrinsics::int and cuda_intrinsics::i16x2 APIs, with matching cuda_device compatibility modules.
  • Generate dialect operations and importer dispatch for all eight variants.
  • Lower scalar and packed carriers through the same pure two-operand inline-PTX path.
  • Gate the family on PTX 8.0 / SM90+.
  • Add a MIR lowering test that pins the exact instruction and register constraints for every variant.
  • Add examples/integer_minmax, which launches all eight intrinsics and checks scalar and individual packed-lane results against host references.

Evidence

All eight variants were probed successfully with the pinned Rust LLVM 22.1.2 llc at sm_90 +ptx80, producing the expected PTX instruction heads.

Only the llvm_nvptx evidence route is declared. This does not make the family unavailable in a lib_nvvm build: requirement_for_backend falls back to the top-level requirement, and the lowering does not consume the backend argument, so that build emits the same inline PTX. The route works, but remains unaudited until a CUDA 13.3 libNVVM evidence profile is recorded and added as a second route.

Evidence status is lowered and runtime_validation is unexecuted, matching the repository convention: all 547 existing evidence entries are unexecuted, with no executed precedent. Recorded terminal ptxas validation and runtime testing on physical SM90 hardware were not performed because the local toolkit is CUDA 12.0 and the available GPU is SM120.

Generated artifacts

The catalog grows from 986 to 994 ABI entries and adds eight probe files. Most of the 1,100-file diff is deterministic catalog SHA regeneration churn across checked-in generated outputs, following the same pattern as #721.

Testing

  • All eight pinned-llc probes passed.
  • Two consecutive generator regenerations were identical.
  • cargo run -p cuda-intrinsics-gen -- check
  • cargo test -p cuda-intrinsics-gen — 289 passed
  • cargo test -p mir-lower — 334 passed, including the new lowering coverage
  • cargo oxide run integer_minmax on an RTX 5080 (sm_120) — all eight intrinsics passed value verification
  • scripts/check-example-smoketest-contract.sh
  • cargo fmt --all -- --check

@almightychang
almightychang force-pushed the dpx-relu-16x2-intrinsics branch from 6e4681c to b0cfe40 Compare August 17, 2026 07:05
@almightychang
almightychang force-pushed the dpx-relu-16x2-intrinsics branch from b0cfe40 to 0630ae8 Compare August 17, 2026 09:35
@nihalpasham nihalpasham added enhancement New feature or request intrinsics Device intrinsics and libdevice math mappings cuda-feature A CUDA hardware/toolkit feature (TMA, tcgen05, WGMMA) device-apis User-facing device-side and kernel-authoring APIs (cuda-device, cuda-macros) labels Aug 17, 2026
@nihalpasham

Copy link
Copy Markdown
Collaborator

Reviewed and validated locally on a 5090 (sm_120):

  • catalog check clean, regen is byte-identical, intrinsics-gen / mir-lower / mir-importer suites all pass
  • the example passes on GPU and the PTX carries exactly the eight native instructions (min/max.relu.s32, min/max{.relu}.s16x2, min/max.u16x2)
  • relu semantics, the u32 packed carriers, and the PTX 8.0 / sm_90 floors all match the ISA

One coordination note: this PR and #946 were both written against the same ledger tail and both claim ABI IDs i0987-i0994. This one lands first and keeps the numbers; #946 renumbers.

Follow-ups we'll track separately, not blockers here:

CI runs are approved. Merging once they're green.

The PTX ISA 8.0 integer min/max extensions — the .relu qualifier on s32
and s16x2, and the packed s16x2/u16x2 pairs — are the remaining Phase 4
DPX gap of issue NVIDIA#338: ptxas fuses dataflow-adjacent chains of them into
VIMNMX-family SASS, but they have no NVVM intrinsic records in the pinned
LLVM import (LLVM reaches them from generic llvm.smin/llvm.smax selection
patterns), so the llvm_imported route cannot admit them. They enter the
catalog as ptx_native contracts instead, following the packed_alu
precedent. The plain scalar s32 forms are deliberately absent: ordinary
Rust min/max already lowers to native min.s32/max.s32.

The new integer_minmax family admits eight variants (min/max x relu.s32,
s16x2, u16x2, relu.s16x2) as a closed recipe: overlay shard, ABI ledger
entries i0987-i0994, generator model/resolve/render support, a dialect
op per variant, importer pure-value dispatch, and a two-operand =r,r,r
inline-PTX lowering shared by both scalar and packed carriers. Scalar
variants surface as cuda_intrinsics::int (i32), packed variants as
cuda_intrinsics::i16x2 (u32 carrier), with cuda_device compatibility
modules included from generated sources.

Evidence: each variant was probed with the pinned Rust LLVM 22.1.2 llc
(identity-matched to the rust-llvm-22.1.2-1cb4e383 profile) at
sm_90/+ptx80 through the candidate probe flow; the records are admitted
at status "lowered" because no pinned CUDA 13.3 ptxas was available for
the terminal PTX-assembly stage, and the lib_nvvm backend route is left
to a follow-up for the same reason. An end-to-end sm_90 device build was
verified to emit all eight instructions in PTX 8.0, and a mir-lower
lowering test pins the exact inline-asm shape per variant.

Signed-off-by: almightychang (Sam, Joochul Chang) <[email protected]>
Signed-off-by: almightychang (Sam, Joochul Chang) <[email protected]>
Signed-off-by: almightychang (Sam, Joochul Chang) <[email protected]>
@almightychang
almightychang force-pushed the dpx-relu-16x2-intrinsics branch from 0630ae8 to 6277133 Compare August 17, 2026 13:02
@nihalpasham
nihalpasham merged commit 1efa3f6 into NVIDIA:main Aug 17, 2026
nihalpasham added a commit that referenced this pull request Aug 18, 2026
…ted in #406 (#977)

* docs(mir-lower): the intrinsic converter table names two modules deleted in #406

`README.md`'s "GPU Intrinsic Converters (`convert/intrinsics/`)" table has 13
rows for a directory holding 24 modules. Two of the 13 do not exist:

  convert/intrinsics/stmatrix.rs   deleted in 6a9a637 (#406)
  convert/intrinsics/tcgen05.rs    deleted in 6a9a637 (#406)

Both were removed when "Generate CUDA intrinsics from pinned LLVM metadata"
moved those families onto the catalog path. The table still describes them as
hand-written converters with an "Inline PTX" strategy; `stmatrix` and
`tcgen05` are mentioned 460 times in `convert/generated_intrinsics.rs` today.
So a reader looking for where either is lowered is sent to a file that has not
existed for many releases. Same shape as #797, one crate over.

A third row, `generated_intrinsics`, is real but not in that directory -- it is
`convert/generated_intrinsics.rs`, one level up. That is the row most worth
getting right, since it is where nearly every intrinsic now goes.

Fourteen modules that do exist had no row at all: `asm`, `cp_async`,
`dotprod`, `execution_control`, `extended_minmax`, `integer_minmax`,
`ldmatrix`, `memory`, `packed`, `prmt`, `scalar_arithmetic`,
`scalar_conversion`, `scalar_math`, `wmma`. `integer_minmax` arrived last
batch with #967.

Rewritten as one row per file, with each description taken verbatim from that
module's own `//!` doc comment, so the table cannot drift from the code
without the doc comment drifting first. The "Strategy" and "GPU" columns are
dropped: they were per-module guesses at what are per-intrinsic properties,
and the catalog already records the PTX version and minimum SM for each,
rendered into `intrinsics/generated-reference.md` alongside the sources. The
page now points there instead of keeping a second copy by hand -- the same
treatment #964 gave the book's dialect-nvvm table.

The Core Modules table on the same page was short by four: the top-level
`type_conversion_interface`, `scalarize_block_args` and
`wgmma_deferred_accumulator`, plus `convert/enum_payload_storage`.

Verified by script: the converter table's rows are now exactly the set of
`.rs` files in `convert/intrinsics/` (24 and 24, no ghost and no missing), and
every top-level `src/*.rs` module and every `convert/*.rs` module has a row.

Signed-off-by: Vyncint Ng <[email protected]>

* docs(mir-lower): add the convert/type_interface_impls row

The Core Modules table listed convert/interface_impls but not its
type-conversion counterpart; description taken from the module's
own doc comment.

---------

Signed-off-by: Vyncint Ng <[email protected]>
Co-authored-by: nihalpasham <[email protected]>
nihalpasham pushed a commit that referenced this pull request Aug 18, 2026
…alidates (#969)

The obligation #964's merge comment attached to #946 landing. #946 has landed
(d485edb), and it was not the only batch member to move these numbers.

The page carries a self-invalidating stamp: "If the header stamp no longer
starts with `df42ef97`, the counts on this page predate the catalog you are
reading." Every `ops/generated/` header now prints `20440c06...`, so it does.

Recomputed from the tree at d485edb, with each delta attributed by
`git ls-tree` + `git show` per module rather than from a PR diff:

  generated/integer_minmax.rs   0 -> 8    new module (#967, DPX min/max)
  generated/packed_alu.rs      22 -> 30   f32x2 arithmetic (#946)
  ops/wgmma.rs                  6 -> 7    counted-K pipeline op (#935)

which moves five figures and adds a row:

  stamp                    df42ef97 -> 20440c06
  total                    543 across 41 modules -> 560 across 42
  hand-written             18 ops -> 19 (`wgmma` 6 -> 7)
  generated                34 modules / 525 ops / 986 catalog entries
                        -> 35 modules / 541 ops / 1002 catalog entries
  Packed (SIMD-in-reg)     43 -> 51
  Integer min/max (DPX)    new row, 8 -- `integer_minmax`

`integer_minmax` gets its own row rather than joining Scalar math beside
`extended_minmax`: six of its eight ops are `16x2` packed forms
(`max_s16x2`, `min_relu_s16x2`, ...) and two are scalar `s32`, so it is a
feature area rather than a scalar-math addition.

Checked and unchanged in the same pass: dialect-mir is still 62 ops across 12
modules with 9 types, and the `pliron` pin is still 8447aa42, so the LLVM
dialect's 69 stands.

**A correction to my own #964 while I am here.** That PR asserted #946 added
no ops, on the strength of `gh pr diff 946 | grep -c pliron_op` returning 0.
As the merge comment noted, `gh pr diff` returns empty on a diff that large,
so the grep was counting nothing rather than finding nothing -- an
unfalsifiable check that reads as a clean result. Every count in this commit
is derived from git objects in the tree instead.

Separately, the chapter's opening said cuda-oxide "works across three pliron
dialects ... two defined locally". Two more local pliron dialects exist and
the book never mentions either: `dialect-iket` (7 ops, 2 types) and
`dialect-ptx` (#917). The claim is now scoped to the lowering path, which is
what this chapter actually covers, with a pointer to the two crates' READMEs.
The same count appears in `pliron.md` and `architecture-overview.md`; those
are a separate change, and this one does not touch either file.

Verified: every figure on the page recomputed by script against the tree;
`just book` (`sphinx-build -W --keep-going`) succeeds; check-book-api-names
passes.

Signed-off-by: Vyncint Ng <[email protected]>
@almightychang
almightychang deleted the dpx-relu-16x2-intrinsics branch September 15, 2026 19:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants