Skip to content

fix(#231): lower projected reads through place addresses - #249

Merged
nihalpasham merged 1 commit into
NVIDIA:mainfrom
pattersonjack:fix-231-addressable-place-read
Jun 18, 2026
Merged

nihalpasham merged 1 commit into
NVIDIA:mainfrom
pattersonjack:fix-231-addressable-place-read

Conversation

@pattersonjack

Copy link
Copy Markdown
Contributor

What

Closes #231.

Projected reads like scratch[row][col] from an addressable local array were lowered by materializing values at each projection step. For a nested array, that meant loading/copying the whole [4 x [2 x double]] local, indexing into the copy, then loading/copying the [2 x double] row before the final scalar read.

Fix

This PR adds a narrow, staged fix: an eligibility check for whether the projected place is representable as a real address, followed by the existing translate_place_address walker and one final MirLoadOp.

The eligibility check is separate from the address walker because the walker emits IR as it goes. Unsupported projections still fall back to the existing value-projection lowering.

This leaves the broader model refactor for a follow-up PR, where place-as-address can become the default for Copy/Move, value-projection can become the explicit fallback, and fallback cases such as unsupported enum/downcast projections, ZSTs, and computed aggregates with no addressable backing slot can be covered directly.

Test plan

  • cargo test --workspace
  • cargo oxide run projected_place_read
  • cargo oxide run ref_index_projections
  • cargo oxide build projected_place_read --emit-nvvm-ir --arch sm_100

@pattersonjack pattersonjack changed the title fix(#231): lower addressable place reads by address fix(#231): lower projected reads through place addresses Jun 18, 2026
@pattersonjack
pattersonjack force-pushed the fix-231-addressable-place-read branch from 86b4d73 to d086916 Compare June 18, 2026 11:33
@nihalpasham nihalpasham added bug Something isn't working miscompile Produces incorrect PTX/IR (wrong generated code) codegen Device code-generation pipeline (Rust MIR to IR to PTX) IR-lowering Lowering between dialects (dialect-mir to LLVM dialect) labels Jun 18, 2026
@nihalpasham

Copy link
Copy Markdown
Collaborator

Thanks again for the PR.

The design looks good i.e. dry-run eligibility check (can't call the address walker speculatively since it emits IR as it goes) along with the hard-error on checker/walker divergence.

A few quick notes:

  • Labels added on our end (bug, miscompile, codegen, IR-lowering).
  • projected_place_read is auto-discovered by smoketest, no manual registration needed.
  • is_mutable: false throughout the eligibility check is correct for reads; the actual walker inherits mutability from the alloca.

Just a quick follow-up question: if you plan to send the holistic refactor as a separate PR? The piece that makes place-as-address the default for all Copy/Move and demotes value-projection to the explicit fallback, with edge-case tests for enum downcast, ZST reads, and computed aggregates with no backing slot, it'd be great if you can drop a note in the discord chat, just so that folks know and don't end up working on the same thing.

nihalpasham added a commit that referenced this pull request Jun 18, 2026
…read

fix(#231): lower projected reads through place addresses
@nihalpasham
nihalpasham merged commit d086916 into NVIDIA:main Jun 18, 2026
23 of 24 checks passed
meefs pushed a commit to meefs/cuda-oxide that referenced this pull request Sep 30, 2026
Attribution lives in git history; the Sphinx author becomes the
corporate entity, matching the copyright line.
meefs pushed a commit to meefs/cuda-oxide that referenced this pull request Sep 30, 2026
…NVIDIA#225, NVIDIA#185) (NVIDIA#256)

Three squash merges landed from branches that had resolved a merge against
main by keeping pre-merge copies of files, so each one quietly reverted an
earlier, unrelated merge:

- NVIDIA#239 (2482cb9) reverted NVIDIA#240 (1216aef): the const raw-pointer surface
  (as_ptr, program_id/num_programs, the cast_* and get_tensor_base helpers,
  unsafe on load_ptr_tko/store_ptr_tko), the compiler's const-pointer
  typing, the two GPU test files and the matching book and tutorial text.
- NVIDIA#247 (5f5f4c5) reverted NVIDIA#225 (a2843e7): integer division and remainder
  serialization (rounding<zero> and inferred signedness on divi/remi) and
  its test.
- NVIDIA#187 (35a9cc2) reverted NVIDIA#185 (cbf52c0): the flake.nix toolkit-assembly
  hardening and host-arch driver directory derivation.

This re-applies all three verbatim as cherry-picks. The only overlapping
file, cutile-book/guide/performance.md, merges cleanly with NVIDIA#239's own
edits. A per-file scan of the last 60 merges finds no other reversal still
missing at HEAD: NVIDIA#249's removal of the About page was deliberate, and the
two setup-python flips in .github/workflows/pages.yml were re-applied by
the later dependabot bump.

Verified: cargo fmt, cargo build, and the restored GPU tests
(const_pointers, program_id) plus integer_ops, memory_and_atomic_ops and
optimization_hints pass on an RTX 5090 with CUDA 13.3.

Signed-off-by: Melih Elibol <[email protected]>
Co-authored-by: Gabriel Wu <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working codegen Device code-generation pipeline (Rust MIR to IR to PTX) IR-lowering Lowering between dialects (dialect-mir to LLVM dialect) miscompile Produces incorrect PTX/IR (wrong generated code)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Projected reads from local arrays copy the whole aggregate before scalar indexing

2 participants