Skip to content

Commit 8e2b322

Browse files
authored
[DispatchCreation] Do not collapse dimensions if there are encoded operands (#20621)
Signed-off-by: hanhanW <[email protected]>
1 parent da1f88b commit 8e2b322

File tree

4 files changed

+30
-2
lines changed

4 files changed

+30
-2
lines changed

compiler/src/iree/compiler/DispatchCreation/CollapseDimensions.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,14 @@ static bool isEligibleForCollapse(Operation *op) {
177177
return false;
178178
}
179179

180+
auto hasEncoding = [](Type type) -> bool {
181+
auto rankedTensorType = dyn_cast<RankedTensorType>(type);
182+
return rankedTensorType && rankedTensorType.getEncoding();
183+
};
184+
if (llvm::any_of(op->getOperandTypes(), hasEncoding)) {
185+
return false;
186+
}
187+
180188
// TODO(guray) Currently we can only collapse when result of all the
181189
// AffineMaps are dimensions. Possible to collapse cases like
182190
// affine_map<d0, d1+d2> with affine_map<d0, d1+d2>, however, this is not

compiler/src/iree/compiler/DispatchCreation/test/collapse_dimensions.mlir

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,26 @@ util.func public @quantized_matmul(%arg0: tensor<4096x32x128xi8>, %arg1: tensor<
213213

214214
// -----
215215

216+
#map = affine_map<(d0, d1, d2, d3) -> (d0, d1, d2, d3)>
217+
#encoding = #iree_encoding.testing_encoding<>
218+
util.func public @do_not_collapse_ops_with_encoding(%arg0: tensor<2x320x128x128xf32, #encoding>) -> tensor<2x320x128x128xf32, #encoding> {
219+
%0 = flow.dispatch.region -> (tensor<2x320x128x128xf32, #encoding>) {
220+
%empty = tensor.empty() : tensor<2x320x128x128xf32, #encoding>
221+
%cst = arith.constant 3.14 : f32
222+
%elementwise = linalg.generic {indexing_maps = [#map, #map], iterator_types = ["parallel", "parallel", "parallel", "parallel"]} ins(%arg0 : tensor<2x320x128x128xf32, #encoding>) outs(%empty : tensor<2x320x128x128xf32, #encoding>) {
223+
^bb0(%in : f32, %out : f32):
224+
%22 = arith.mulf %cst, %in : f32
225+
linalg.yield %22 : f32
226+
} -> tensor<2x320x128x128xf32, #encoding>
227+
flow.return %elementwise : tensor<2x320x128x128xf32, #encoding>
228+
}
229+
util.return %0 : tensor<2x320x128x128xf32, #encoding>
230+
}
231+
// CHECK-LABEL: @do_not_collapse_ops_with_encoding(
232+
// CHECK-NOT: tensor.collapse_shape
233+
234+
// -----
235+
216236
#map = affine_map<(d0, d1, d2, d3) -> (d0, d1, d2, d3)>
217237
util.func public @elementwise_chain(%arg0: tensor<2x320x128x128xf32>) -> tensor<2x320x128x128xf32> {
218238
%0 = flow.dispatch.region -> (tensor<2x320x128x128xf32>) {

tests/e2e/encoding/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ iree_check_single_backend_test_suite(
1717
name = "check_rocm_hip",
1818
srcs = ["encoding.mlir"],
1919
compiler_flags = [
20-
"--iree-global-opt-experimental-rocm-data-tiling",
20+
"--iree-global-opt-enable-early-materialization=false",
2121
"--iree-hip-encoding-layout-resolver=data-tiling",
2222
],
2323
driver = "hip",

tests/e2e/encoding/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ iree_check_single_backend_test_suite(
2020
DRIVER
2121
"hip"
2222
COMPILER_FLAGS
23-
"--iree-global-opt-experimental-rocm-data-tiling"
23+
"--iree-global-opt-enable-early-materialization=false"
2424
"--iree-hip-encoding-layout-resolver=data-tiling"
2525
)
2626

0 commit comments

Comments
 (0)