You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
BubbleExpandThroughExtract converts extract_slice -> expand_shape to expand_shape -> extract_slice. This allows cloning the extract_slice into it's consumer dispatch. This is useful in the case where the extract_slice is not contiguous and results in a slow memcpy.
However, this pattern is limited. From the pattern's comment:
/// Bubbles a `tensor.expand_shape` op through a `tensor.extract_slice` op. This/// pattern only gets applied when the `extract_slice` doesn't modify dimensions/// that are expanded by the `expand_shape` and when the `extract_slice` is/// completely static.
Some examples:
/// In the case below it should be possible to "bubble"util.funcpublic@possible(%arg0 : tensor<4096xf16>) -> (tensor<32x64xf16>) {
%extracted_slice = tensor.extract_slice%arg0[0] [2048] [1] : tensor<4096xf16> totensor<2048xf16>
%expanded_239 = tensor.expand_shape%extracted_slice[[0, 1]] output_shape [32, 64] : tensor<2048xf16> intotensor<32x64xf16>
util.return%expanded_239 : tensor<32x64xf16>
}
/// Can't bubble in this caseutil.funcpublic@impossible(%arg0 : tensor<2049xf16>) -> (tensor<32x64xf16>) {
%extracted_slice= tensor.extract_slice%arg0[0] [2048] [1] : tensor<2049xf16> totensor<2048xf16>
%expanded_239 = tensor.expand_shape%extracted_slice[[0, 1]] output_shape [32, 64] : tensor<2048xf16> intotensor<32x64xf16>
util.return%expanded_239 : tensor<32x64xf16>
}
I think the main constraint is that the product of all but the last output dimension must divide the input (pre-extracted) shape. I.e. 32 divides 4096 making the first one possible but 32 does not divide 2049 making it impossible.
Activity
IanWood1 commentedon Jun 16, 2025
@MaheshRavishankar here's an example of what we discussed:
The dynamic dim of
%arg0need to be known to be divisible by 32 to be able to propagate.IanWood1 commentedon Jun 18, 2025
I was a bit wrong above, here is the actual case that need to be bubbled:
[Dispatch Creation] Improve extract_slice expand_shape bubbling (#21121)
[Dispatch Creation] Improve extract_slice expand_shape bubbling (#21121)