You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Support field projections of packed aggregates containing address-space 3 pointers #1036
IR-loweringLowering between dialects (dialect-mir to LLVM dialect)codegenDevice code-generation pipeline (Rust MIR to IR to PTX)enhancementNew feature or request
#1001 lets a packed aggregate with a shared-memory pointer cross internal device calls and returns by coercing to a generic-pointer carrier at the boundary. But the value is only usable as a whole: any field projection (value.tag, value.ptr) routes through the local's stack slot, which is a whole-value store of the packed AS3 aggregate, and that store fails closed:
storing a packed aggregate containing a shared-memory pointer by value is
target-mode dependent and is not yet supported
let value = bounce_packed_shared(PackedShared{tag:0x21,ptr: raw });consume_packed_shared(value, raw, out);// whole-value use only
but reading value.ptr inside the callee (or the caller) does not. It also means no runtime test can observe the round-tripped pointer; #1001's coercion is proven structurally by unit tests instead.
Proposed approach
Reuse the target_stable_storage machinery #1001 generalized: give the local slot the carrier type (<{ scalar, p0 }>), coerce semantic-to-carrier on store and back on load, and keep field GEPs by-slot so the scalar fields stay byte-identical. The AS3 pointer field loads as p0 plus an addrspacecast, the same conversion the call boundary already does.
Scope
local-slot (alloca) storage and field projections only;
strengthen the packed_aggregate_abi example so consume_packed_shared writes through the round-tripped value.ptr and reads back through the raw pointer, making a caller-side reconstruction bug observable at runtime.
changed the title [-]Support field projections of packed aggregates containing AS3 pointers[/-][+]Support field projections of packed aggregates containing address-space 3 pointers[/+]on Aug 19, 2026
The previous approach in #1092 effectively tried to recover the fact that an opaque pointer referred to carrier storage from selected defining operations. That is not a stable contract: calls, block arguments, casts, or other rewrites can sever that history and later make a projection use the semantic AS3 representation against carrier storage.
I do not think MirPointerKind should encode this. #1186 makes pointer kind a source-level provenance fact; the carrier is instead a physical storage property.
Proposed narrow contract
For #1036, I would keep carrier-local support deliberately closed-world and local-only.
Immediately before MIR -> LLVM dialect conversion, after the final MIR-producing transform:
verified MIR
|
v
find eligible compiler-owned allocas
|
v
derive the complete use graph of each carrier address
|
v
validate every use
|
+-- load / store / one direct field_addr -> admitted
|
+-- debug use -> ignored
|
+-- call / block argument / cast / return
| pointer arithmetic / nested projection / unknown use
| -> reject
v
only after the complete graph validates:
stamp typed lowering facts on the exact MIR consumers
The facts would be lowering-private TypeAttrs carrying the exact physical LLVM storage/source type. Input MIR is not allowed to provide them.
The converters then consume those facts mechanically:
alloca:
allocate <{ u8, p0 }>
whole-value store:
<{ u8, p3 }> -> <{ u8, p0 }> -> memory
whole-value load:
memory -> <{ u8, p0 }> -> <{ u8, p3 }>
ptr field projection:
GEP through physical <{ u8, p0 }>
load p0
addrspacecast p0 -> p3
ptr field store:
p3 -> p0
store into the projected carrier field
No converter reconstructs carrier identity from OperandsInfo, an LLVM defining operation, or a GEP shape.
For the narrow issue I would prefer to reject call/block/cast propagation of the carrier address rather than define a representation protocol across those boundaries. Semantic packed values can still cross the already-supported internal call ABI; the restriction applies specifically to the compiler-owned local-storage address.
p3-width / lowering-order question
I think this also removes the local-memory dependency on when the physical p3 width is selected.
The carrier memory image never contains p3. It contains the target-stable generic pointer p0. AS3 exists only as the semantic SSA value on either side of the memory boundary:
So legacy-vs-modern NVVM selection can affect the lowering of the address-space conversion, but it does not change the type or byte layout allocated for the local carrier itself.
If that reasoning is incomplete with respect to the backend-mode selection order, that is the part I would like to settle before opening a PR.
whole-value load/store and one direct field projection.
Multiple leaves, nested aggregates, arrays, recursive projections, globals, kernel parameters, and arbitrary packed-AS3 memory remain out of scope.
I have a local prototype of this contract to check feasibility, including full-lowering rejection tests for carrier-address flow through calls, block arguments, and casts, plus the direct projection/runtime case. I have not opened a PR because I wanted to validate the representation contract first.
Would this fail-closed boundary model and the p0-only local memory representation be an acceptable basis for #1036?
Cross-reference from #1219: this refusal is also what fails packed_aggregate_abi under CUDA_OXIDE_DEBUG=full, and the reason is the mechanism you describe here.
You note that field projection "routes through the local's stack slot, which is a whole-value store of the packed AS3 aggregate". Full debug skips dialect-mir mem2reg, so every local routes through its slot — which turns the projection-only path into an unavoidable one. Verbatim, on an A10G at 26754ae5:
error: [rustc_codegen_cuda] Device codegen failed: PTX generation failed: Lowering failed:
Compilation error: invalid input program.
storing a packed aggregate containing a shared-memory pointer by value is
target-mode dependent and is not yet supported
Nothing new to fix here — recording it so whoever takes this knows it also clears one of #1219's four, and so that half is not tracked twice.
@nihalpasham Gentle ping on the representation contract above. Before I turn the local prototype into a PR, I'd like to confirm whether the fail-closed carrier-address model and p0-only local storage representation look like an acceptable basis for #1036.
IR-loweringLowering between dialects (dialect-mir to LLVM dialect)codegenDevice code-generation pipeline (Rust MIR to IR to PTX)enhancementNew feature or request
Activity
[-]Support field projections of packed aggregates containing AS3 pointers[/-][+]Support field projections of packed aggregates containing address-space 3 pointers[/+]uurl commentedon Sep 4, 2026
Following up on the design question from #1094, here is the narrow representation contract I have in mind for #1036 on top of #1186.
Problem
The semantic MIR type and the physical local-storage type cannot be treated as the same thing for a packed aggregate containing an AS3 pointer.
For the narrow #1036 shape:
The previous approach in #1092 effectively tried to recover the fact that an opaque pointer referred to carrier storage from selected defining operations. That is not a stable contract: calls, block arguments, casts, or other rewrites can sever that history and later make a projection use the semantic AS3 representation against carrier storage.
I do not think
MirPointerKindshould encode this. #1186 makes pointer kind a source-level provenance fact; the carrier is instead a physical storage property.Proposed narrow contract
For #1036, I would keep carrier-local support deliberately closed-world and local-only.
Immediately before MIR -> LLVM dialect conversion, after the final MIR-producing transform:
The facts would be lowering-private
TypeAttrs carrying the exact physical LLVM storage/source type. Input MIR is not allowed to provide them.The converters then consume those facts mechanically:
No converter reconstructs carrier identity from
OperandsInfo, an LLVM defining operation, or a GEP shape.For the narrow issue I would prefer to reject call/block/cast propagation of the carrier address rather than define a representation protocol across those boundaries. Semantic packed values can still cross the already-supported internal call ABI; the restriction applies specifically to the compiler-owned local-storage address.
p3-width / lowering-order question
I think this also removes the local-memory dependency on when the physical p3 width is selected.
The carrier memory image never contains p3. It contains the target-stable generic pointer p0. AS3 exists only as the semantic SSA value on either side of the memory boundary:
So legacy-vs-modern NVVM selection can affect the lowering of the address-space conversion, but it does not change the type or byte layout allocated for the local carrier itself.
If that reasoning is incomplete with respect to the backend-mode selection order, that is the part I would like to settle before opening a PR.
Scope
I would keep this exactly at #1036:
allocaonly;Multiple leaves, nested aggregates, arrays, recursive projections, globals, kernel parameters, and arbitrary packed-AS3 memory remain out of scope.
I have a local prototype of this contract to check feasibility, including full-lowering rejection tests for carrier-address flow through calls, block arguments, and casts, plus the direct projection/runtime case. I have not opened a PR because I wanted to validate the representation contract first.
Would this fail-closed boundary model and the p0-only local memory representation be an acceptable basis for #1036?
vyncint commentedon Sep 7, 2026
Cross-reference from #1219: this refusal is also what fails
packed_aggregate_abiunderCUDA_OXIDE_DEBUG=full, and the reason is the mechanism you describe here.You note that field projection "routes through the local's stack slot, which is a whole-value store of the packed AS3 aggregate". Full debug skips dialect-mir mem2reg, so every local routes through its slot — which turns the projection-only path into an unavoidable one. Verbatim, on an A10G at
26754ae5:Nothing new to fix here — recording it so whoever takes this knows it also clears one of #1219's four, and so that half is not tracked twice.
uurl commentedon Sep 15, 2026
@nihalpasham Gentle ping on the representation contract above. Before I turn the local prototype into a PR, I'd like to confirm whether the fail-closed carrier-address model and p0-only local storage representation look like an acceptable basis for #1036.