Skip to content

Support field projections of packed aggregates containing address-space 3 pointers #1036

Closed

Description

@nihalpasham

Problem

#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

Concretely, this compiles after #1001:

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;
  • same aggregate restrictions as Support packed aggregates containing AS3 pointers across the internal device ABI #1000 (packed struct, one direct AS3 pointer leaf, remaining non-ZST fields scalar);
  • 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.

Out of scope

Everything #1000 already excludes: kernel parameters, device globals, arrays/vectors/enums with AS3 leaves, multiple AS3 pointer leaves.

Activity

  1. added
    enhancement
    codegen
    IR-lowering
    on Aug 19, 2026
  2. 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
  3. uurl commented on Sep 4, 2026

    @uurl
    Contributor

    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:

    semantic value:  <{ u8, p3 }>
    local storage:   <{ u8, p0 }>
    

    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:

    store: p3 -> p0 -> carrier memory
    load:  carrier memory -> p0 -> p3
    

    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:

    • packed struct root;
    • exactly one direct AS3 pointer field;
    • remaining non-ZST fields scalar;
    • compiler-owned alloca only;
    • 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?

  4. vyncint commented on Sep 7, 2026

    @vyncint
    Contributor

    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.

  5. uurl commented on Sep 15, 2026

    @uurl
    Contributor

    @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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    IR-loweringcodegenenhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions