Repository navigation
mir-importer: index slice data pointers by element - #210
Merged
nihalpasham merged 2 commits intoJun 16, 2026
Merged
Conversation
Signed-off-by: nik <[email protected]>
…esting Two additions on top of the slice-data element-indexing fix: 1. Localize the current_is_slice_data invariant. Capture-and-clear the flag at the top of the address-walk loop and set it only in the Deref continuation that hands off a slice DATA pointer. This removes the per-arm resets and makes it structurally impossible for a future projection arm to leak the flag forward. Proven codegen-neutral: the slice_get_mut .ll is byte-identical before and after. 2. Add write_nested_slice_wide_nonzero_col, covering a wider nested element ([f32; 3]) written at a NON-ZERO inner column (col 2). The existing nested kernels all used column 0, so the 'inner index reverts to array-aware' half was exercised only at offset 0. The generated .ll confirms the row index strides by a whole [3 x float] and the column index lands at element 2.
nihalpasham
force-pushed
the
upstream-slice-array-index
branch
from
June 16, 2026 06:03
94a59a9 to
adaed3b
Compare
Collaborator
|
I was able to reproduce the wrong store address for
|
meefs
pushed a commit
to meefs/cuda-oxide
that referenced
this pull request
Sep 30, 2026
NVIDIA#236) * refactor: resolve check-placement policy once per compile The bounds-check gates were scattered environment reads: check_hoisting_disabled() and force_device_checks() consulted process globals at seven sites across classification, relocation, and proof discharge. They become one CheckOptimizations policy — three independent axes (hoist_to_preheaders, relocate_to_launch, discharge_proofs) with named constructors: release() (all on), device_debug() (checks stay where the source puts them; proofs still discharge), and disabled() (the differential harness's semantic reference, which inherits no proofs; 2026-08-12 review, S2). The policy is resolved from the environment once at compiler construction and carried on the function compiler, so it cannot change between classification and emission within a compile. The ablation env vars keep their names and semantics; behavior is unchanged under every existing switch combination (differential placement harness green). This is groundwork for NVIDIA#210, where --device-debug selects device_debug() per compile and joins the cache keys. Signed-off-by: Melih Elibol <[email protected]> * feat: device-debug, lineinfo, sanitizer, and opt-level compile options CompileOptions gains opt_level, device_debug, lineinfo, and sanitize_memcheck; a TileirasOptions carrier resolves them once and threads through run_tileiras (--opt-level / --device-debug / --lineinfo / --sanitize=memcheck), the disk-cache path, and both cache keys. device_debug implies --opt-level 0 unless a level is set explicitly, and selects the device_debug check policy: no preheader hoisting, so every device-resident bounds check sits at the source line that wrote it and inlined regions stay contiguous for the rangeless -O0 -G DWARF contract. Proof discharge and launch relocation are deliberately untouched — both remove a check from device code entirely, and the bounded family's launch checks are load-bearing (without relocation its undischarged checks are compile errors). Cache correctness: the flags join the L1 key via CompileOptions and the L2 key as new key material (existing disk entries recompile once), and cache entries validate the flags through a formerly-padding header byte — old release entries carry 0 there, which is exactly the release encoding, so they keep validating without a format bump. Tests: placement pins under device_debug (a hoistable check falls back in place; discharge and launch checks undisturbed), key separation per flag, entry-validation flag mismatches with legacy-zero acceptance, option resolution, and GPU end-to-end launches of debug, lineinfo, and memcheck-instrumented cubins through the real tileiras. Closes NVIDIA#210. Closes NVIDIA#219 (opt_level reaches KernelCompiler via .options(CompileOptions::new().opt_level(n)) and both cache keys). Signed-off-by: Melih Elibol <[email protected]> * docs: align device_debug and cache-entry comments with the implementation The CompileOptions doc claimed device_debug disables launch relocation; it only disables hoisting (relocation is load-bearing for the bounded family). And three comments claimed old cache entries keep validating via the flags byte — they cannot be reached at all, since the flags also joined the key material and orphaned pre-flags entries; the byte is defense in depth, now described as such, with a note on why the entry format version was deliberately not bumped. Signed-off-by: Melih Elibol <[email protected]> --------- Signed-off-by: Melih Elibol <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #209.
Problem
The place-address walker extracts field 0 from fat slice values so it can continue indexing through the original backing storage. When the slice element type is itself an array, such as
&mut [[f32; 2]], that extracted data pointer has typeptr<[f32; 2]>.The compiler rule is that this pointer addresses slice elements. Therefore the first
Indexor forwardConstantIndexafter the fat-slice deref must use pointer arithmetic over[f32; 2]rows. It must not be reclassified as a pointer to one array object and indexed inside row 0.Fix
Track when the current address is the data pointer just extracted from a fat slice. For the immediately following
Indexor forwardConstantIndex, force the address walker to use the direct pointer-offset path. Clear the marker after consuming that indexed projection, and also clear it for ordinary sized field access.This keeps ordinary array-object indexing unchanged: a true pointer to
[T; N]still usesmir.array_element_addr; only a pointer known to originate as fat-slice data uses element-sizedmir.ptr_offsetfor the first index.Diligence
I checked the sibling lowering paths that decide between pointer offset and array-element address:
translate_place_addr_from_slot, which servesRvalue::Ref,Rvalue::AddressOf, and projected assignment destinations;emit_indexed_element_addr, the shared dispatch point for runtime and forward constant indices;MirPtrOffsetOplowering, which scales by the pointer pointee type;MirArrayElementAddrOplowering, which is correct for indexing inside one array object.Tests
Extended
crates/rustc-codegen-cuda/examples/slice_get_mutwith three nested-array fat-slice cases:write_nested_slice_row_ref: takeslet elem = &mut rows[row][0]and writes through the reference;write_nested_slice_const_row_ref: takeslet elem = &mut rows[1][0]and writes through the reference;write_nested_slice_row_assign: writes through direct projected assignmentrows[row][0] = value.The runtime-row cases prove the
Indexpath, the literal-row case proves the forwardConstantIndexpath, and the assignment case proves the statement-level destination path that reuses the same address walker.I also checked the raw Rust MIR dump for the literal-row kernel; the relevant projection is emitted as
(*_9)[1 of 2][0 of 1], so this is covering the forward constant-index arm rather than another runtime-index lowering.All three cases initialize row 0 column 1 to a sentinel and row 1 column 0 to zero. On
upstream/mainwith only the regression applied, they write the sentinel column in row 0:On this branch, they write row 1 column 0:
Validation