fix: handle ComposedLayout slicing with dynamic strides (fixes #3255)#3261
Open
zhils wants to merge 1 commit into
Open
fix: handle ComposedLayout slicing with dynamic strides (fixes #3255)#3261zhils wants to merge 1 commit into
zhils wants to merge 1 commit into
Conversation
…#3255) When slicing a Tensor whose layout is a ComposedLayout (e.g., Swizzle composed with a dynamic outer Layout), _cute_ir.slice fails because the Swizzle composition requires static stride analysis that cannot be performed with runtime dynamic strides (represented as '?' / unknown values). The fix intercepts this case in _Tensor.__getitem__ and decomposes the ComposedLayout manually in the Python DSL layer: 1. Extract inner (Swizzle), offset, and outer (Layout) from the ComposedLayout 2. Slice only the outer Layout using slice_ (pure Layout slicing works with dynamic strides) 3. Compute the offset delta via crd2idx(coord_with_none_as_zero, outer) 4. Rebuild the ComposedLayout with the new offset and sliced outer 5. Construct a new Tensor with the original iterator This avoids passing the composed layout with dynamic strides to the MLIR slice operation, which triggers an MLIR verifier error and segfault.
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.
When slicing a Tensor whose layout is a ComposedLayout (e.g., Swizzle composed with a dynamic outer Layout), _cute_ir.slice fails because the Swizzle composition requires static stride analysis that cannot be performed with runtime dynamic strides (represented as '?' / unknown values).
The fix intercepts this case in _Tensor.getitem and decomposes the ComposedLayout manually in the Python DSL layer:
This avoids passing the composed layout with dynamic strides to the MLIR slice operation, which triggers an MLIR verifier error and segfault.