feat: Add ReplaceSliceCopyWithSlicePass for contiguous slice_copy detection (#10917) - #21552
feat: Add ReplaceSliceCopyWithSlicePass for contiguous slice_copy detection (#10917)#21552iRAFEEK wants to merge 2 commits into
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/21552
Note: Links to docs will display an error until the docs builds have been completed. ❗ 1 Active SEVsThere are 1 currently active SEVs. If your PR is affected, please view them below:
|
|
Hi @iRAFEEK! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
…torch#10917) Slice analog of ReplaceViewCopyWithViewPass. Detects contiguous (outermost-dim, unit-step) slice_copy nodes eligible to be re-inplaced as zero-copy slices. Rewrite is gated behind offset-based sub-buffer aliasing support in memory planning (pending design discussion), so the pass currently runs as a safe no-op.
Covers outermost-dim/unit-step eligibility, negative-dim resolution, strided/inner-dim rejection, and that the pass is a safe no-op until the offset-aliasing rewrite lands.
863138c to
a3fef4f
Compare
|
@pytorchbot label "release notes: none" |
Summary
Implements the first phase of the slice_copy→slice optimization (#10917): correctly identifying contiguous (outermost-dimension, unit-step) slice_copy nodes that are eligible for re-inplacing as zero-copy slices.
Problem
A contiguous slice (e.g.
x[0:2]on a contiguous input) is currently always emitted as a full-copyaten::slice_copykernel, even though it could alias the base buffer as a lightweight view (likeview_copydoes viaReplaceViewCopyWithViewPass).Solution
ReplaceSliceCopyWithSlicePass: a new graph pass that detects contiguous slice_copy nodesis_contiguous_slice_copy(node): correctly classifies outermost-dim, unit-step slices as eligibleThe actual zero-copy rewrite is gated behind offset-based sub-buffer aliasing support in memory planning (#10917 discussion), so this pass currently runs as a safe no-op until that design is complete.
Technical Note
Reading
ReplaceViewCopyWithViewPassrevealed that the existing "copy→view" machinery (memory.view+_ViewSpec) works because a view aliases the entire base buffer (same nbytes, offset 0). A slice aliases a sub-region at a non-zero offset, requiring new memory-planning infrastructure (et_slicekernel + offset aliasing). This change implements the correctness piece (identifying eligible slices) cleanly, and raises the design question with @metascroy on the offset-aliasing approach.Testing
exir/tests/test_replace_slice_copy_with_slice_pass.py(4 tests)Ran 4 tests in 0.561s — OKChecklist
et_slicekernel (pending discussion, Re-inplace slice_copy with slice #10917)Fixes #10917