Skip to content

fix(mir-lower): lower redux.sync results to signless integers - #1264

Merged
nihalpasham merged 2 commits into
NVIDIA:mainfrom
sachinsharma3191:fix/811-warp-reduce-lowering
Sep 18, 2026
Merged

nihalpasham merged 2 commits into
NVIDIA:mainfrom
sachinsharma3191:fix/811-warp-reduce-lowering

Conversation

@sachinsharma3191

@sachinsharma3191 sachinsharma3191 commented Sep 13, 2026 •

Copy link
Copy Markdown
Contributor

What this fixes

Device helpers can return integer redux.sync results directly. The lowerer previously kept the result's Rust signedness after converting the function signature to LLVM's signless integer type.

before: fn reduce(v: u32) -> u32 { redux_sync_add(FULL_MASK, v) }
        -> return-type verification failure
after:  the helper compiles and returns the reduction

What we fixed

  • Convert the reduction result through the existing type converter, shared by all 16 reduction operations.
  • Keep the real helper-return shape in redux_minmax.
  • I extended the lowering regression to all 16 operations and checked the exact intrinsic, value/mask order, integer result types and unchanged float types.
  • I rebased and signed the contributor commit, preserving its author and sign-off.

Verification

Checked at 5a3653e3:

  • All 293 unit and 136 lowering tests pass, along with formatting, strict Clippy for the crate and example, and rustdoc with warnings denied.
  • Restoring the unconverted result makes the regression fail at return-type verification.
  • redux_minmax passes on RTX 5090, SM120, through LLVM NVPTX and modern libNVVM. Helper results are -16 and 4294967295; memcheck and synccheck both report zero errors.
  • Generated PTX contains the helper's signed-min and unsigned-max reduction instructions.
  • Hosted CI also passes on this head.

This removes the reported lowering blocker in #811. The architecture selection and warp_reduce API work remain separate; #811 remains open for that work. Float operations were checked in lowering, not on hardware.

Known backend limit

Legacy libNVVM still emits unresolved llvm.nvvm.redux.sync.* calls. The existing direct-reduction kernels fail the same CUDA 13.0 PTX assembly check after removing the new helpers; this is an existing intrinsic-support gap, separate from the return-type fix. LLVM NVPTX and modern libNVVM execute correctly.

sachinsharma3191 and others added 2 commits September 18, 2026 09:08
`convert_redux` declared the `llvm_nvvm_redux_sync_*` intrinsic with the
dialect op's result type unconverted, so an integer reduction was declared
as returning `ui32`/`si32` while its operands were already signless `i32`.
A result that only feeds a store went unnoticed, but a device function
returning the reduction directly failed verification:

    ReturnOp operand type does not match the function's result type

This is the lowering failure blocking the `warp_reduce` fast path in NVIDIA#811.
Convert the result type with `convert_type`, as the other intrinsic
converters do. The fix covers all 16 `redux.sync` ops that share
`convert_redux`.

Adds a lowering test returning each integer redux op (and four f32
controls) from a device function, and a `redux_minmax` kernel that reduces
through out-of-line helpers so the GPU-less example compile gate covers
the real Rust shape.

Signed-off-by: sachin <[email protected]>
@nihalpasham
nihalpasham force-pushed the fix/811-warp-reduce-lowering branch from a18f1af to 5a3653e Compare September 18, 2026 03:49
@nihalpasham nihalpasham added bug Something isn't working intrinsics Device intrinsics and libdevice math mappings IR-lowering Lowering between dialects (dialect-mir to LLVM dialect) tests Adds or improves test coverage examples Example kernels and host harnesses under crates/rustc-codegen-cuda/examples labels Sep 18, 2026

@nihalpasham nihalpasham left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I kept the shared result-type conversion and added a few checks around it:

  • Covered all 16 reduction operations, including unchanged float results.
  • Checked the exact intrinsic and value/mask order so a different call cannot satisfy the regression.
  • Rebasing and signing preserved the contributor's original commit and sign-off.

All 429 MIR-lower tests, formatting, strict Clippy and docs pass. redux_minmax also passes on RTX 5090 with zero memcheck/synccheck errors, including both helper-returned results.

This removes the return-type blocker reported in #811; architecture selection and warp_reduce remain separate. Modern libNVVM also runs correctly. Legacy libNVVM retains its existing unresolved-redux-intrinsic failure, reproduced with the original direct kernels.

Checked at 5a3653e3. Hosted CI also passes on this head.

@nihalpasham
nihalpasham merged commit 8bc013b into NVIDIA:main Sep 18, 2026
54 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working examples Example kernels and host harnesses under crates/rustc-codegen-cuda/examples intrinsics Device intrinsics and libdevice math mappings IR-lowering Lowering between dialects (dialect-mir to LLVM dialect) tests Adds or improves test coverage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants