Repository navigation
Conversation
ed9d81f to
d8f52e5
Compare
Signed-off-by: Raul Estrada <[email protected]>
d8f52e5 to
345d912
Compare
|
Thanks for the PR. I'm putting this on hold, same as #398. In short, the mechanism can't land in this form, and before any reshape I'd like to to see the benefit measured. What this PR is about: Direct indexing is already handled by default since #397/#398: let c = coeffs[i]; // i runtime
// today: c = select(i==0, 4.0, select(i==1, -3.0, ...)) -> no .localThe iterator form escapes that pass because the access reaches us in a different shape: for v in coeffs.iter().copied().take(k) { ... }
// reaches the scalarizer as a pointer walk, not arr[i]:
// p = p + 4; v = *p; p != end
// so the landed pass doesn't match, the array stays in memory,
// and PTX keeps a per-thread .local slotWhat we'd need before we go further:
Findings from building and running this branch (pinned toolchain, RTX 5090):
What I'd recommend instead, if the measurement pans out:
Your fail-closed analysis rules (escape/volatile/atomic rejection, full-initialization requirement) are good and would carry straight over. |
|
Thanks for the detailed review. I measured the current prototype on an RTX 5060 Laptop GPU using a pointwise polynomial workload over small compiler-owned local arrays. The comparison used the PR's original base commit ( The MIR detector emitted zero bounded-unroll hints, matching your observation. The textual scalarizer performed the transformation and reported six replaced dynamic loads. A first matrix covering 1M, 4M, and 8M elements, traversal lengths of 4 and 8, and three independent runs showed the prototype consistently slower, with median relative performance of I then repeated the measurement with a heavier workload:
Results:
This corresponds to approximately 16–19% longer execution time for the prototype. Native Given the measurement and the architectural concerns you identified, I will not continue developing the textual scalarizer, bounded-unroll path, or environment-option plumbing in this PR. I will preserve the branch and benchmark artifacts as an experimental result. I may revisit issue #399 only if I find a real workload that demonstrates a material benefit and can justify a new typed implementation in I will leave the PR open for now in case you would like to keep the discussion and measurements as a reference. Please feel free to close it if you consider the experiment concluded. |
|
Closing as concluded, per the measurements included:
|
Summary
Part of #399.
This PR adds an opt-in optimization path for small compiler-owned local arrays consumed through Rust iterator adapters.
When enabled with:
the compiler:
This removes the
.local,ld.local, andst.localPTX operations previously emitted for iterator chains such as:iter().copied().take(...)iter().copied().skip(...).take(...).enumerate()Motivation
Rust slice iterators are lowered through helper functions such as
Iter::nextandIter::nth. Before inlining, the local array and its dynamic accesses are distributed across several functions, so the ordinary MIR-to-LLVM lowering cannot reliably scalarize them.After LLVM inlining, the accesses become visible as dynamic GEP/load operations rooted in a small immutable stack array. This PR adds a conservative post-inline scalarization step for that shape.
Implementation
MIR iterator analysis
mir-importernow:The optimization remains disabled unless explicitly requested through
CUDA_OXIDE_MIR_OPTS.Bounded loop unrolling
The bounded unroller now supports loops with:
Each ordinary exit is preserved in every cloned iteration. The impossible backedge of the final guard copy is replaced with
mir.unreachable.Post-inline array scalarization
cuda-oxide-codegenperforms the following opt-in sequence:The scalarizer is deliberately conservative. It only rewrites arrays that are:
Pointer provenance is followed through GEPs, casts, freezes, selects, and phi nodes.
The LLVM 22 GEP modifiers
nuw,nusw, andnsware accepted when parsing byte-offset GEPs.Dynamic loads are replaced with select chains over the known constant element values. The subsequent LLVM optimization pass eliminates the original array allocation and stores.
Validation
The focused scalarization tests cover:
getelementptr inbounds nuwsyntax;atomicrmwandcmpxchgrejection;Validation completed successfully:
The final PTX for both regression kernels contains no prohibited:
Scope
This is an experimental, opt-in optimization. The default compilation pipeline remains unchanged when
small-array-iteratorsis not enabled.