Skip to content

fix(mir-importer): compute real element/field addresses for place projections - #240

Closed
haixuanTao wants to merge 1 commit into
NVIDIA:mainfrom
haixuanTao:fix/place-projection-addressing
Closed

haixuanTao wants to merge 1 commit into
NVIDIA:mainfrom
haixuanTao:fix/place-projection-addressing

Conversation

@haixuanTao

Copy link
Copy Markdown
Contributor

When auto porting khal_std/glam accessors like at_mut(i)/write(i,v) and raw &mut a[i].field lower to place projections (Ref, AddressOf and assignment) over slice/array references. The importer fell back to materialising the element into a fresh stack slot, so the store went to a dead copy -- writes through &mut [T] / &mut [T;N] were silently lost (e.g. gpu_add gave the unchanged output), and an atomic on a stack copy is illegal on NVPTX.

Compute the real address instead, for both the reference side and the store side:

  • Rvalue::Ref / Rvalue::AddressOf of (*slice)[i] / (*slice)[i].field / (*arr)[i]: fold [Deref, Index/ConstantIndex, ...fields] to data-pointer + ptr_offset (+ field GEPs), via translate_place_addr_from_slot (now handling Deref/runtime-Index/array) and a shared ref_index_operand / emit_index_operand helper.
  • Assignment to the same projections (statement.rs): the (Deref,Index)/(Deref, ConstantIndex) and general (Deref, Field-chain) store arms now emit a real element/field address store rather than writing a stack copy.

…jections

khal_std/glam accessors like at_mut(i)/write(i,v) and raw &mut a[i].field lower to
place projections (Ref, AddressOf and assignment) over slice/array references. The
importer fell back to materialising the element into a fresh stack slot, so the
store went to a dead copy -- writes through &mut [T] / &mut [T;N] were silently lost
(e.g. gpu_add gave the unchanged output), and an atomic on a stack copy is illegal
on NVPTX.

Compute the real address instead, for both the reference side and the store side:
- Rvalue::Ref / Rvalue::AddressOf of (*slice)[i] / (*slice)[i].field / (*arr)[i]:
  fold [Deref, Index/ConstantIndex, ...fields] to data-pointer + ptr_offset (+ field
  GEPs), via translate_place_addr_from_slot (now handling Deref/runtime-Index/array)
  and a shared ref_index_operand / emit_index_operand helper.
- Assignment to the same projections (statement.rs): the (Deref,Index)/(Deref,
  ConstantIndex) and general (Deref, Field-chain) store arms now emit a real
  element/field address store rather than writing a stack copy.
@nihalpasham

Copy link
Copy Markdown
Collaborator

Thanks for the PR.

But this was superseded by commits ab417b5, 1ce4e75, adaed3b, c89b480, f1c7436 that landed on main between June 11-17 via a shared translate_place_addr_from_slot walker. This also covers DisjointSliceType fat pointers, ZST tuple pointees, and slice-tailed structs.

Closing with already-fixed.

@nihalpasham nihalpasham added already-fixed Resolved on a newer commit or branch; no action needed 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
meefs pushed a commit to meefs/cuda-oxide that referenced this pull request Sep 30, 2026
…ases (NVIDIA#240)

This also adds program_id(axis) and num_programs(axis) as aliases to the tile block variants.

Signed-off-by: Melih Elibol <[email protected]>
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

already-fixed Resolved on a newer commit or branch; no action needed 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.

2 participants