Skip to content

test(examples): pin DPX-shaped integer min/max chains to native PTX min/max - #951

Merged
nihalpasham merged 2 commits into
NVIDIA:mainfrom
almightychang:dpx-s32-minmax-regression
Aug 17, 2026
Merged

nihalpasham merged 2 commits into
NVIDIA:mainfrom
almightychang:dpx-s32-minmax-regression

Conversation

@almightychang

@almightychang almightychang commented Aug 16, 2026 •

Copy link
Copy Markdown
Contributor

Part of #338

Summary

No compiler code is changed. Hopper DPX operations are SASS VIMNMX-family instructions without dedicated PTX instructions; ptxas recognizes and fuses adjacent native integer min/max chains. Therefore, the five s32/u32 items in Phase 4 of #338 are covered here as code-generation regression tests rather than new compiler intrinsics.

The example contains ten kernels: vimax3, vimin3, vimnmx, viaddmax, and viaddmin, each in s32 and u32 forms. vimnmx is not a CUDA API name; it is the issue's name for the mixed min/max SASS pattern.

The runtime test validates every lane numerically and includes hand-computed pins for explicit MAX + 1 and MIN - 1 wrapping cases. verify-code-shape.sh checks each kernel's PTX body for the exact expected count and signedness of native min.* and max.* instructions, preventing regressions to compare/select or branch lowering.

SASS evidence

With CUDA 12.0.140 ptxas targeting sm_90, the Rust chains and the corresponding __vimax3_s32-family CUDA intrinsics produced the same SASS shape: VIMNMX x2 for three-input min/max and IADD3 + VIMNMX for add/min-max. All ten Rust kernels used VIMNMX/VIMNMX.U32 for their result calculation; none degraded to compare/select.

The CI contract intentionally stops at the canonical PTX shape. SASS fusion is a property of the ptxas version in use and may select newer fused opcodes in other toolkit versions.

The ReLU and 16x2 variants have no dedicated NVVM intrinsics and remain tracked by #338.

@almightychang
almightychang force-pushed the dpx-s32-minmax-regression branch from ebd4a67 to d215abb Compare August 16, 2026 16:52
@almightychang
almightychang force-pushed the dpx-s32-minmax-regression branch from d215abb to 8628383 Compare August 17, 2026 07:18
@nihalpasham nihalpasham added tests Adds or improves test coverage examples Example kernels and host harnesses under crates/rustc-codegen-cuda/examples codegen Device code-generation pipeline (Rust MIR to IR to PTX) labels Aug 17, 2026
…in/max

Hopper's DPX instructions (SASS VIMNMX/VIMNMX3) have no PTX spelling of
their own: ptxas builds them by fusing dataflow-adjacent min.s32/max.s32/
min.u32/max.u32 chains. How far that fusion goes is a property of the
ptxas in use; what the backend must guarantee — and what this example
pins — is the canonical PTX shape those chains must keep to stay fusable:
native min/max instructions rather than compare/select or branches.
(With CUDA 12.0 ptxas at sm_90, plain Rust x.max(y).max(z) was observed
to produce the same min/max SASS shape as the CUDA __vimax3_s32
intrinsic family.)

One kernel per issue-338 Phase 4 s32/u32 item (vimax3, vimin3, vimnmx,
viaddmax, viaddmin x s32/u32; vimnmx is the issue's pattern name --
CUDA's public API has no __vimnmx), verified numerically on the device
against a shared host reference, including hand-computed pins for the
explicit MAX+1 / MIN-1 wrapping lanes, plus a verify-code-shape.sh that
asserts each kernel keeps exactly its chain's min/max instructions in
the PTX.

The .relu and 16x2 DPX variants have no dedicated NVVM intrinsics and
are left to a follow-up; see issue NVIDIA#338.

Signed-off-by: almightychang (Sam, Joochul Chang) <[email protected]>
Signed-off-by: almightychang (Sam, Joochul Chang) <[email protected]>
@almightychang
almightychang force-pushed the dpx-s32-minmax-regression branch from 8628383 to bb732d8 Compare August 17, 2026 12:20
@nihalpasham

Copy link
Copy Markdown
Collaborator

Validated the latest push on a 5090:

  • scripts/smoketest.sh dpx_minmax_chains passes: runtime check across all 256 lanes plus the code-shape script
  • the shape script holds under our pinned llc/opt: exactly the expected native min/max.{s32,u32} counts per kernel, none of the opposite signedness, no setp/selp lowering
  • re-derived the wrapping edge cases by hand from the EDGES tables; they all match
  • the SPDX copyright line you added in the last push was the one gap we'd flagged, so nothing left on our side

The exact-count assertions will fail loudly if a future opt/llc bump changes instruction selection. That's the point of the test, so fine as is.

CI runs are approved. Merging once green.

@nihalpasham
nihalpasham merged commit 798e356 into NVIDIA:main Aug 17, 2026
44 checks passed
@almightychang
almightychang deleted the dpx-s32-minmax-regression 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

codegen Device code-generation pipeline (Rust MIR to IR to PTX) examples Example kernels and host harnesses under crates/rustc-codegen-cuda/examples tests Adds or improves test coverage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants