Repository navigation
Fixes tiling sizes for pulled producers in TileAndDistribute - #12399
Merged
Merged
Conversation
The tiling sizes for producers are not always as same as the tiling
sizes for the consumers. The information is carried by the extract_slice
op. We should use the sizes and offsets from extract_slice op for tiling
the producers ops. E.g.,
```
%16:2 = linalg.generic { ...
} -> (tensor<384x512xf32>, tensor<384x512xf32>)
%18 = iree_linalg_ext.pack %16#0 ...
: tensor<384x512xf32> -> tensor<48x512x8x1xf32>
```
Say that the tiling sizes are [8, 64], the result after tiled
implementation is
```
scf.for ... {
scf.for ... {
%28 = affine.min affine_map<(d0, d1) -> (d0 * 8, d1 * -8 + 384)>(%21, %arg0)
%30 = affine.min affine_map<(d0, d1) -> (d0, -d1 + 512)>(%24, %arg1)
%extracted_slice = tensor.extract_slice %16#0[%25, %arg1] [%28, %30] [1, 1] : tensor<384x512xf32> to tensor<?x?xf32>
%extracted_slice_7 = tensor.extract_slice %17[%arg0, %arg1, 0, 0] [%21, %24, 8, 1] [1, 1, 1, 1] : tensor<48x512x8x1xf32> to tensor<?x?x8x1xf32>
%31 = iree_linalg_ext.pack %extracted_slice ...
: tensor<?x?xf32> -> tensor<?x?x8x1xf32>
}
}
```
The input slice sizes of `pack` op is 64x64 in this case. We should
propagate the information when tiling the producer. Otherwise, it
triggers an undefined behavior. The generic op produces a 64x64xf32
tensor. It is casted to ?x?xf32 when it's used in the tensor.pack
op. The ?x?xf32 tensor is casted to 8x64xf32 tensor when storing it into
the destination tensor. The cast ops are not folded away because the
shapes mismatch.
```
%21:2 = linalg.generic ...
} -> (tensor<64x64xf32>, tensor<64x64xf32>)
%cast = tensor.cast %21#0 : tensor<64x64xf32> to tensor<?x?xf32>
%cast_0 = tensor.cast %21#1 : tensor<64x64xf32> to tensor<?x?xf32>
%cast_1 = tensor.cast %cast : tensor<?x?xf32> to tensor<8x64xf32>
...
flow.dispatch.tensor.store %cast_1, %7, ... sizes = [8, 64]
%cast_2 = tensor.cast %cast_0 : tensor<?x?xf32> to tensor<8x64xf32>
flow.dispatch.tensor.store %cast_2, %8, ... sizes = [8, 64]
```
MaheshRavishankar
approved these changes
Feb 27, 2023
MaheshRavishankar
left a comment
Collaborator
There was a problem hiding this comment.
Good catch! I think upstream it does the right thing. I seemed to have messed it up here!
qedawkins
pushed a commit
to qedawkins/iree
that referenced
this pull request
Apr 2, 2023
…g#12399) The tiling sizes for producers are not always as same as the tiling sizes for the consumers. The information is carried by the extract_slice op. We should use the sizes and offsets from extract_slice op for tiling the producers ops. E.g., ``` %16:2 = linalg.generic { ... } -> (tensor<384x512xf32>, tensor<384x512xf32>) %18 = iree_linalg_ext.pack %16#0 ... : tensor<384x512xf32> -> tensor<48x512x8x1xf32> ``` Say that the tiling sizes are [8, 64], the result after tiled implementation is ``` scf.for ... { scf.for ... { %28 = affine.min affine_map<(d0, d1) -> (d0 * 8, d1 * -8 + 384)>(%21, %arg0) %30 = affine.min affine_map<(d0, d1) -> (d0, -d1 + 512)>(%24, %arg1) %extracted_slice = tensor.extract_slice %16#0[%25, %arg1] [%28, %30] [1, 1] : tensor<384x512xf32> to tensor<?x?xf32> %extracted_slice_7 = tensor.extract_slice %17[%arg0, %arg1, 0, 0] [%21, %24, 8, 1] [1, 1, 1, 1] : tensor<48x512x8x1xf32> to tensor<?x?x8x1xf32> %31 = iree_linalg_ext.pack %extracted_slice ... : tensor<?x?xf32> -> tensor<?x?x8x1xf32> } } ``` The input slice sizes of `pack` op is 64x64 in this case. We should propagate the information when tiling the producer. Otherwise, it triggers an undefined behavior. The generic op produces a 64x64xf32 tensor. It is casted to ?x?xf32 when it's used in the tensor.pack op. The ?x?xf32 tensor is casted to 8x64xf32 tensor when storing it into the destination tensor. The cast ops are not folded away because the shapes mismatch. ``` %21:2 = linalg.generic ... } -> (tensor<64x64xf32>, tensor<64x64xf32>) %cast = tensor.cast %21#0 : tensor<64x64xf32> to tensor<?x?xf32> %cast_0 = tensor.cast %21#1 : tensor<64x64xf32> to tensor<?x?xf32> %cast_1 = tensor.cast %cast : tensor<?x?xf32> to tensor<8x64xf32> ... flow.dispatch.tensor.store %cast_1, %7, ... sizes = [8, 64] %cast_2 = tensor.cast %cast_0 : tensor<?x?xf32> to tensor<8x64xf32> flow.dispatch.tensor.store %cast_2, %8, ... sizes = [8, 64] ``` Fixes iree-org#12286
jpienaar
pushed a commit
that referenced
this pull request
May 1, 2023
The tiling sizes for producers are not always as same as the tiling
sizes for the consumers. The information is carried by the extract_slice
op. We should use the sizes and offsets from extract_slice op for tiling
the producers ops. E.g.,
```
%16:2 = linalg.generic { ...
} -> (tensor<384x512xf32>, tensor<384x512xf32>)
%18 = iree_linalg_ext.pack %16#0 ...
: tensor<384x512xf32> -> tensor<48x512x8x1xf32>
```
Say that the tiling sizes are [8, 64], the result after tiled
implementation is
```
scf.for ... {
scf.for ... {
%28 = affine.min affine_map<(d0, d1) -> (d0 * 8, d1 * -8 + 384)>(%21, %arg0)
%30 = affine.min affine_map<(d0, d1) -> (d0, -d1 + 512)>(%24, %arg1)
%extracted_slice = tensor.extract_slice %16#0[%25, %arg1] [%28, %30] [1, 1] : tensor<384x512xf32> to tensor<?x?xf32>
%extracted_slice_7 = tensor.extract_slice %17[%arg0, %arg1, 0, 0] [%21, %24, 8, 1] [1, 1, 1, 1] : tensor<48x512x8x1xf32> to tensor<?x?x8x1xf32>
%31 = iree_linalg_ext.pack %extracted_slice ...
: tensor<?x?xf32> -> tensor<?x?x8x1xf32>
}
}
```
The input slice sizes of `pack` op is 64x64 in this case. We should
propagate the information when tiling the producer. Otherwise, it
triggers an undefined behavior. The generic op produces a 64x64xf32
tensor. It is casted to ?x?xf32 when it's used in the tensor.pack op.
The ?x?xf32 tensor is casted to 8x64xf32 tensor when storing it into the
destination tensor. The cast ops are not folded away because the shapes
mismatch.
```
%21:2 = linalg.generic ...
} -> (tensor<64x64xf32>, tensor<64x64xf32>)
%cast = tensor.cast %21#0 : tensor<64x64xf32> to tensor<?x?xf32>
%cast_0 = tensor.cast %21#1 : tensor<64x64xf32> to tensor<?x?xf32>
%cast_1 = tensor.cast %cast : tensor<?x?xf32> to tensor<8x64xf32>
...
flow.dispatch.tensor.store %cast_1, %7, ... sizes = [8, 64]
%cast_2 = tensor.cast %cast_0 : tensor<?x?xf32> to tensor<8x64xf32>
flow.dispatch.tensor.store %cast_2, %8, ... sizes = [8, 64]
```
Fixes #12286
rengolin
pushed a commit
to plaidml/iree
that referenced
this pull request
May 2, 2023
…g#12399) The tiling sizes for producers are not always as same as the tiling sizes for the consumers. The information is carried by the extract_slice op. We should use the sizes and offsets from extract_slice op for tiling the producers ops. E.g., ``` %16:2 = linalg.generic { ... } -> (tensor<384x512xf32>, tensor<384x512xf32>) %18 = iree_linalg_ext.pack %16#0 ... : tensor<384x512xf32> -> tensor<48x512x8x1xf32> ``` Say that the tiling sizes are [8, 64], the result after tiled implementation is ``` scf.for ... { scf.for ... { %28 = affine.min affine_map<(d0, d1) -> (d0 * 8, d1 * -8 + 384)>(%21, %arg0) %30 = affine.min affine_map<(d0, d1) -> (d0, -d1 + 512)>(%24, %arg1) %extracted_slice = tensor.extract_slice %16#0[%25, %arg1] [%28, %30] [1, 1] : tensor<384x512xf32> to tensor<?x?xf32> %extracted_slice_7 = tensor.extract_slice %17[%arg0, %arg1, 0, 0] [%21, %24, 8, 1] [1, 1, 1, 1] : tensor<48x512x8x1xf32> to tensor<?x?x8x1xf32> %31 = iree_linalg_ext.pack %extracted_slice ... : tensor<?x?xf32> -> tensor<?x?x8x1xf32> } } ``` The input slice sizes of `pack` op is 64x64 in this case. We should propagate the information when tiling the producer. Otherwise, it triggers an undefined behavior. The generic op produces a 64x64xf32 tensor. It is casted to ?x?xf32 when it's used in the tensor.pack op. The ?x?xf32 tensor is casted to 8x64xf32 tensor when storing it into the destination tensor. The cast ops are not folded away because the shapes mismatch. ``` %21:2 = linalg.generic ... } -> (tensor<64x64xf32>, tensor<64x64xf32>) %cast = tensor.cast %21#0 : tensor<64x64xf32> to tensor<?x?xf32> %cast_0 = tensor.cast %21#1 : tensor<64x64xf32> to tensor<?x?xf32> %cast_1 = tensor.cast %cast : tensor<?x?xf32> to tensor<8x64xf32> ... flow.dispatch.tensor.store %cast_1, %7, ... sizes = [8, 64] %cast_2 = tensor.cast %cast_0 : tensor<?x?xf32> to tensor<8x64xf32> flow.dispatch.tensor.store %cast_2, %8, ... sizes = [8, 64] ``` Fixes iree-org#12286
NatashaKnk
pushed a commit
to NatashaKnk/iree
that referenced
this pull request
Jul 6, 2023
…g#12399) The tiling sizes for producers are not always as same as the tiling sizes for the consumers. The information is carried by the extract_slice op. We should use the sizes and offsets from extract_slice op for tiling the producers ops. E.g., ``` %16:2 = linalg.generic { ... } -> (tensor<384x512xf32>, tensor<384x512xf32>) %18 = iree_linalg_ext.pack %16#0 ... : tensor<384x512xf32> -> tensor<48x512x8x1xf32> ``` Say that the tiling sizes are [8, 64], the result after tiled implementation is ``` scf.for ... { scf.for ... { %28 = affine.min affine_map<(d0, d1) -> (d0 * 8, d1 * -8 + 384)>(%21, %arg0) %30 = affine.min affine_map<(d0, d1) -> (d0, -d1 + 512)>(%24, %arg1) %extracted_slice = tensor.extract_slice %16#0[%25, %arg1] [%28, %30] [1, 1] : tensor<384x512xf32> to tensor<?x?xf32> %extracted_slice_7 = tensor.extract_slice %17[%arg0, %arg1, 0, 0] [%21, %24, 8, 1] [1, 1, 1, 1] : tensor<48x512x8x1xf32> to tensor<?x?x8x1xf32> %31 = iree_linalg_ext.pack %extracted_slice ... : tensor<?x?xf32> -> tensor<?x?x8x1xf32> } } ``` The input slice sizes of `pack` op is 64x64 in this case. We should propagate the information when tiling the producer. Otherwise, it triggers an undefined behavior. The generic op produces a 64x64xf32 tensor. It is casted to ?x?xf32 when it's used in the tensor.pack op. The ?x?xf32 tensor is casted to 8x64xf32 tensor when storing it into the destination tensor. The cast ops are not folded away because the shapes mismatch. ``` %21:2 = linalg.generic ... } -> (tensor<64x64xf32>, tensor<64x64xf32>) %cast = tensor.cast %21#0 : tensor<64x64xf32> to tensor<?x?xf32> %cast_0 = tensor.cast %21#1 : tensor<64x64xf32> to tensor<?x?xf32> %cast_1 = tensor.cast %cast : tensor<?x?xf32> to tensor<8x64xf32> ... flow.dispatch.tensor.store %cast_1, %7, ... sizes = [8, 64] %cast_2 = tensor.cast %cast_0 : tensor<?x?xf32> to tensor<8x64xf32> flow.dispatch.tensor.store %cast_2, %8, ... sizes = [8, 64] ``` Fixes iree-org#12286
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.
The tiling sizes for producers are not always as same as the tiling sizes for the consumers. The information is carried by the extract_slice op. We should use the sizes and offsets from extract_slice op for tiling the producers ops. E.g.,
Say that the tiling sizes are [8, 64], the result after tiled implementation is
The input slice sizes of
packop is 64x64 in this case. We should propagate the information when tiling the producer. Otherwise, it triggers an undefined behavior. The generic op produces a 64x64xf32 tensor. It is casted to ?x?xf32 when it's used in the tensor.pack op. The ?x?xf32 tensor is casted to 8x64xf32 tensor when storing it into the destination tensor. The cast ops are not folded away because the shapes mismatch.Fixes #12286