Repository navigation
feat(cuda-oxide): use 32-bit shared-memory pointers (p3:32:32:32 + --nvptx-short-ptr) in PTX backend - #1661
Merged
nihalpasham merged 1 commit intoOct 27, 2026
Conversation
…PTX backend - Set `NVPTX_DATALAYOUT_PTX = NVPTX_DATALAYOUT_FULL` (`p3:32:32:32`) and pass `--nvptx-short-ptr` to `llc` in `base_llc_args`, aligning the native PTX backend with `nvcc` and `libNVVM` on 32-bit shared-memory pointers. - Extend `mir-lower` internal function return ABI coercion (`shared_return_abi_info`) so device functions returning a bare `ptr addrspace(3)` pass a 64-bit generic `ptr` across the `.func` return slot (`func_retval0` / `retval0`) and coerce back to `ptr addrspace(3)` at the call site, avoiding LLVM 23 `NVPTXAsmPrinter`'s `.b64` vs `.b32` return-slot mismatch under `--nvptx-short-ptr`. Signed-off-by: nihalpasham <nihalp@nvidia.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What This PR Does
This PR aligns our native
opt+llcPTX backend withnvccandlibNVVMso shared-memory pointers (ptr addrspace(3)) use 32-bit (%r) registers instead of 64-bit (%rd) registers:NVPTX_DATALAYOUT_PTX = NVPTX_DATALAYOUT_FULL(llvm-export) soopt -O2seesp3:32:32:32.--nvptx-short-ptrtollc(cuda-oxide-codegen) sollcemits 32-bit%rshared-memory addresses.ptr addrspace(3)as a 64-bit genericptracross.funcreturn slots (mir-lower) so non-inlined device functions returning shared pointers work cleanly under--nvptx-short-ptr.1. Why
PtxExportConfigWas Emitting 64-Bit Shared PointersPreviously,
NvvmExportConfig(libNVVM) andPtxExportConfig(opt+llc) used two different data layouts:With
p3:32:32:32inNVPTX_DATALAYOUT_PTXand--nvptx-short-ptrinbase_llc_args:opt -O2narrowsaddrspace(3)GEP indices fromi64toi32.llcemits 32-bit%rregisters for all shared-memory operations:2. Why
mir-lowerCoercesptr addrspace(3)Returns Across.funcBoundariesIn PTX, a function returns its value through a named
.parambox (func_retval0in the definition,retval0at the call site), and both boxes must have the same bit width:When
--nvptx-short-ptris enabled, LLVM 23'sNVPTXAsmPrinterhas a bug when a non-inlined.funcreturns a 32-bitptr addrspace(3)directly (for example,#[inline(never)] fn bits_to_pointer(bits: usize) -> *mut SharedArray<u32, 32>inshared_ptr_transmute):Verification
scripts/smoketest.shon RTX 5090 (sm_120a): 238 / 238 examples PASS (includingshared_ptr_transmute,shared_memory_helper, andtma_copy).ptxas -v -arch=sm_120aonblockscale_gemm_ctm:162to160registers (0 bytes stack frame,0spill bytes).cargo test --all-targets -p mir-lower(331unit +150integration tests): PASScargo test --all-targets -p llvm-export(168tests): PASScargo test --all-targets -p cuda-oxide-codegen(1,294tests): PASSjust fmt-check,just clippy,just check-guards: all PASS