Skip to content

feat: add cp.async zero-fill variants (src_size parameter) - #305

Merged
nihalpasham merged 3 commits into
NVIDIA:mainfrom
honeyspoon:upstream-cp-async-zerofill
Jun 28, 2026
Merged

nihalpasham merged 3 commits into
NVIDIA:mainfrom
honeyspoon:upstream-cp-async-zerofill

Conversation

@honeyspoon

Copy link
Copy Markdown
Contributor

Add three cp.async.ca zero-fill variants that accept a src_size parameter for hardware-assisted zero-fill of boundary tiles. When src_size < cp_size, the remaining bytes are zero-filled.

Summary

Extends the cp.async support from #280 with the optional src_size parameter. This is the standard mechanism for handling boundary conditions in tiled algorithms where the last tile may be smaller than the full tile size, avoiding the need for manual zero-padding on the host or a separate kernel path.

Device API PTX Copy size
cp_async_ca_zfill_4 cp.async.ca.shared.global [smem], [gmem], 4, src_sz; 4 bytes
cp_async_ca_zfill_8 cp.async.ca.shared.global [smem], [gmem], 8, src_sz; 8 bytes
cp_async_ca_zfill_16 cp.async.ca.shared.global [smem], [gmem], 16, src_sz; 16 bytes

Part of #274. Depends on #280.

Changes

  • cuda-device: 3 new pub unsafe fn stubs in async_copy.rs (raw pointer operations require unsafe). Cross-references between zero-fill and non-zero-fill variants.
  • dialect-nvvm: 3 new NVVM ops (CpAsyncCaZfill{4,8,16}Op) with 3 operands (dst, src, src_size) and 0 results.
  • mir-importer: generalized emit_cp_async<T: Op> shared emitter (replaces the previous per-variant functions), 3 new zero-fill dispatch arms.
  • mir-lower: new convert_cp_async_zfill_impl shared lowering helper using inline_asm_sideeffect(); 3 MirToLlvmConversion impls.
  • tests: 3 new lowering tests verifying PTX output.
  • example: cp_async_zfill end-to-end GPU test exercising full copy (src_size=4), partial copy (src_size=2, upper bytes zeroed), and zero copy (src_size=0, entire word zeroed).

Testing

  • cargo test -p mir-lower --test lowering_test passes (5/5 cp.async tests)
  • cargo fmt --check and cargo clippy clean
  • E2E example included (cp_async_zfill)

Checklist

  • All commits signed off (git commit -s)
  • No files under cuda-bindings/ modified
  • SPDX headers on new source files

@honeyspoon
honeyspoon force-pushed the upstream-cp-async-zerofill branch from 5065f9c to 5b5a242 Compare June 26, 2026 17:43
@nihalpasham
nihalpasham force-pushed the upstream-cp-async-zerofill branch from 5b5a242 to 961479f Compare June 28, 2026 03:45
@nihalpasham nihalpasham added enhancement New feature or request safety Memory safety, soundness, or undefined behavior intrinsics Device intrinsics and libdevice math mappings 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) tests Adds or improves test coverage examples Example kernels and host harnesses under crates/rustc-codegen-cuda/examples Depends Blocked on another PR/issue or an upstream dependency labels Jun 28, 2026
honeyspoon and others added 3 commits June 28, 2026 09:51
Add three `cp.async.ca` zero-fill variants that accept a `src_size`
parameter for hardware-assisted zero-fill of boundary tiles. When
`src_size < cp_size`, the remaining bytes are zero-filled by hardware.

| Device API               | PTX                                                    |
|--------------------------|--------------------------------------------------------|
| `cp_async_ca_zfill_4`    | `cp.async.ca.shared.global [smem], [gmem], 4, src_sz;` |
| `cp_async_ca_zfill_8`    | `cp.async.ca.shared.global [smem], [gmem], 8, src_sz;` |
| `cp_async_ca_zfill_16`   | `cp.async.ca.shared.global [smem], [gmem],16, src_sz;` |

Changes:
- cuda-device: 3 new `pub unsafe fn` stubs in `async_copy.rs`
- dialect-nvvm: 3 new ops (CpAsyncCaZfill{4,8,16}Op) with 3 operands
- mir-importer: generalized `emit_cp_async<T: Op>` shared emitter,
  3 new zero-fill dispatch arms
- mir-lower: `convert_cp_async_zfill_impl` shared lowering with
  `inline_asm_sideeffect()`, 3 MirToLlvmConversion impls
- tests: 3 new lowering tests
- example: `cp_async_zfill` e2e GPU test (full copy, partial copy,
  zero copy)

Part of NVIDIA#274. Depends on NVIDIA#280.

Signed-off-by: abder <[email protected]>
@nihalpasham
nihalpasham force-pushed the upstream-cp-async-zerofill branch from 961479f to 3dc667e Compare June 28, 2026 04:23
@nihalpasham

Copy link
Copy Markdown
Collaborator

Thanks for the PR.

Small-copy work with hardware zero-fill: The full, partial, and zero-source cases make the boundary-tile behavior easy to understand.

I rebased the branch directly onto the corrected #280 head and added a few safety details:

  • completed the size, alignment, lifetime, and synchronization contract;
  • added the explicit global-address conversion and compiler memory barriers around completion;
  • added exact typed lowering checks for the 4-byte, 8-byte, and 16-byte forms, plus the standalone lockfile.

The corrected sm_80 output is accepted by ptxas; the 4-byte runtime example still covers full, partial, and zero-source copies.

@nihalpasham
nihalpasham merged commit 44e2dd6 into NVIDIA:main Jun 28, 2026
26 checks passed
@honeyspoon
honeyspoon deleted the upstream-cp-async-zerofill branch June 30, 2026 01:47
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) cuda-feature A CUDA hardware/toolkit feature (TMA, tcgen05, WGMMA) Depends Blocked on another PR/issue or an upstream dependency enhancement New feature or request 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) safety Memory safety, soundness, or undefined behavior tests Adds or improves test coverage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants