Skip to content

Shared arrays lack a raw-pointer escape hatch for disjoint thread writes #623

Closed

Description

@niklebedenko

Shared arrays lack a raw-pointer escape hatch for disjoint thread writes

Problem

SharedArray::as_mut_ptr requires &mut self. When every CUDA thread needs a
pointer into one static mut SharedArray, obtaining that receiver can create
multiple overlapping &mut SharedArray references even when the threads only
access disjoint elements. The intended memory-access pattern is valid for CUDA,
but the only public pointer conversion expresses a stronger Rust aliasing claim
than the caller can uphold.

Why this matters

Per-thread writes into shared scratch storage are a basic building block for
reductions, tiled kernels, and cooperative algorithms. Users should be able to
express those writes without manufacturing whole-allocation mutable references.
The unsafety belongs at the point where callers establish disjoint access and
synchronization, not in an unavoidable aliasing violation in the API shape.

Expected behavior

SharedArray should offer an unsafe raw-receiver conversion that accepts a
*mut SharedArray, normally produced with &raw mut, and returns a mutable
element pointer. CUDA codegen should lower it through the same shared-to-generic
address conversion as the existing borrowed as_ptr and as_mut_ptr methods.

Acceptance criteria

  • CUDA threads can derive element pointers from &raw mut shared storage
    without first creating &mut SharedArray.
  • The returned pointer is classified as generic address space 0, consistently
    with the existing public SharedArray pointer conversions.
  • Intrinsic dispatch and result address-space classification use one exact
    recognizer, including rejection of similarly named methods and types.
  • A multithreaded GPU regression writes disjoint shared elements, synchronizes,
    and checks the computed result.

Activity

  1. added
    enhancement
    safety
    codegen
    intrinsics
    on Aug 1, 2026
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

    codegenenhancementintrinsicssafety

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions