Skip to content

feat: add missing special registers (warpid, smid, gridid, smem_size) - #309

Merged
nihalpasham merged 2 commits into
NVIDIA:mainfrom
honeyspoon:add-special-registers-v2
Jul 1, 2026
Merged

nihalpasham merged 2 commits into
NVIDIA:mainfrom
honeyspoon:add-special-registers-v2

Conversation

@honeyspoon

Copy link
Copy Markdown
Contributor

Summary

Add 7 PTX special register intrinsics across all four compiler layers
(cuda-device, dialect-nvvm, mir-importer, mir-lower):

  • warpid / nwarpid: hardware warp identification within the SM
  • smid / nsmid: streaming multiprocessor identification
  • gridid: grid launch identification
  • dynamic_smem_size / total_smem_size: shared memory size queries

All follow the established zero-operand, single-i32-result LLVM NVVM
intrinsic pattern (same as lane_id, lanemask_*).

Ref #274 (Phase 4: Miscellaneous)

Test plan

  • 4 new lowering tests verifying correct LLVM intrinsic names
  • cargo clippy -- -D warnings clean across all 4 crates
  • cargo fmt --check clean
  • All existing tests pass (31 integration + 80 unit in mir-lower)

@honeyspoon
honeyspoon force-pushed the add-special-registers-v2 branch 5 times, most recently from 37202a2 to f57797f Compare June 30, 2026 16:02
@nihalpasham
nihalpasham force-pushed the add-special-registers-v2 branch from f57797f to 75d496f Compare July 1, 2026 08:56
@nihalpasham

Copy link
Copy Markdown
Collaborator

Thanks for the PR. LGTM

I layered a couple of changes on top

  • The branch resolves both public paths, reads shared-memory sizes through portable inline PTX, preserves repeated warpid/smid samples, and returns the full 64-bit gridid.

Also, verified the generated PTX with LLVM 21 and 22 and CUDA 13.3 ptxas.

@nihalpasham
nihalpasham merged commit c2d6c2c into NVIDIA:main Jul 1, 2026
28 checks passed
@nihalpasham nihalpasham added enhancement New feature or request 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 labels Jul 1, 2026
@honeyspoon
honeyspoon deleted the add-special-registers-v2 branch July 23, 2026 13:53
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) 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) tests Adds or improves test coverage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants