Skip to content

Commit cc0e843

Browse files
hanhanWkeshavvinayak01
authored andcommitted
[CPU] Propagate cache tiling sizes in lowering config propagation. (iree-org#21410)
Signed-off-by: hanhanW <[email protected]> Signed-off-by: keshavvinayak01 <[email protected]>
1 parent 880ef00 commit cc0e843

File tree

6 files changed

+31
-7
lines changed

6 files changed

+31
-7
lines changed

compiler/src/iree/compiler/Codegen/Common/TileSizeSelection.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,11 @@ TilingConfig::getTilingLevelInfo() {
113113
return result;
114114
}
115115

116+
bool TilingConfig::isValidLevel(IREE::CPU::TilingLevel level) {
117+
return tilingLevelToActualLevelMap[static_cast<int64_t>(level)] !=
118+
IREE::CPU::TilingLevel::InvalidLevel;
119+
}
120+
116121
/// Returns the tiling level that contains the vector dim at `dimPos` (which is
117122
/// an index into the result of `getVectorTileSizes()`).
118123
std::optional<unsigned>

compiler/src/iree/compiler/Codegen/Common/TileSizeSelection.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,9 @@ class TilingConfig {
112112
return result;
113113
}
114114

115+
/// Returns true if the `level` is available in TilingConfig.
116+
bool isValidLevel(TilingLevel level);
117+
115118
/// Returns the tiling level for cache parallel dimensions.
116119
unsigned getDistributionLevel() {
117120
return getActualLevel(TilingLevel::DistributionTiles);
@@ -151,6 +154,10 @@ class TilingConfig {
151154
return getTileSizesForLevel(getActualLevel(TilingLevel::DistributionTiles));
152155
}
153156

157+
SmallVector<int64_t> getCacheParallelSizes() {
158+
return getTileSizesForLevel(getCacheParallelLevel());
159+
}
160+
154161
SmallVector<int64_t> getCacheReductionSizes() {
155162
return getTileSizesForLevel(getCacheReductionLevel());
156163
}

compiler/src/iree/compiler/Codegen/LLVMCPU/KernelDispatch.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3154,6 +3154,18 @@ setLoweringConfigForComputeOps(mlir::FunctionOpInterface entryPointFn,
31543154
SmallVector<bool> falseVec(numLoops, 0);
31553155
updateOrAddTilingLevelInfo(newTilingInfo, IREE::CPU::DistributionTiles,
31563156
distTileSizes, falseVec);
3157+
// The cache level tiling sizes are not adjusted, so we use the
3158+
// config from the rootOp directly.
3159+
if (tilingConfig->isValidLevel(IREE::CPU::CacheParallelTiles)) {
3160+
updateOrAddTilingLevelInfo(newTilingInfo, IREE::CPU::CacheParallelTiles,
3161+
tilingConfig->getCacheParallelSizes(),
3162+
falseVec);
3163+
}
3164+
if (tilingConfig->isValidLevel(IREE::CPU::CacheReductionTiles)) {
3165+
updateOrAddTilingLevelInfo(
3166+
newTilingInfo, IREE::CPU::CacheReductionTiles,
3167+
tilingConfig->getCacheReductionSizes(), falseVec);
3168+
}
31573169
updateOrAddTilingLevelInfo(
31583170
newTilingInfo, IREE::CPU::VectorCommonParallelTiles,
31593171
commonVecTileSizes, commonVecScalableTileFlags);

compiler/src/iree/compiler/Codegen/LLVMCPU/test/select_lowering_strategy_without_distribution.mlir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ func.func @matmul_static() attributes {hal.executable.target = #executable_targe
2020
return
2121
}
2222

23-
// CHECK-DAG: #[[CONFIG:.+]] = #iree_codegen.lowering_config<tile_sizes = {{\[}}[0, 0], [1, 1], [0, 0], [0, 0]]>
23+
// CHECK-DAG: #[[CONFIG:.+]] = #iree_codegen.lowering_config<tile_sizes = {{\[}}[0, 0], [0, 0], [0, 0], [1, 1], [0, 0], [0, 0]]>
2424
// CHECK-DAG: #[[CONFIG:.+]] = #iree_codegen.lowering_config<tile_sizes = {{\[}}[0, 0, 0], [0, 0, 0], [0, 0, 0], [1, 1, 0], [0, 0, 4], [0, 0, 0]]>
2525
// CHECK-DAG: #[[TRANSLATION:.+]] = #iree_codegen.translation_info<pipeline = CPUDoubleTilingExpert, {{\{}}enable_loop_peeling}>
2626
// CHECK: func.func @matmul_static()

compiler/src/iree/compiler/Codegen/LLVMCPU/test/select_riscv_lowering_strategy.mlir

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ func.func @matmul_riscv(%lhs: tensor<384x512xf32>, %rhs: tensor<512x128xf32>) ->
1111
%2 = linalg.matmul ins(%lhs, %rhs : tensor<384x512xf32>, tensor<512x128xf32>) outs(%1 : tensor<384x128xf32>) -> tensor<384x128xf32>
1212
return %2 : tensor<384x128xf32>
1313
}
14-
// CHECK-DAG: #[[CONFIG:.+]] = #iree_codegen.lowering_config<tile_sizes = {{\[}}[48, 64], [8, 32], [0, 0], [0, 0]]>
14+
// CHECK-DAG: #[[CONFIG:.+]] = #iree_codegen.lowering_config<tile_sizes = {{\[}}[48, 64], [48, 64], [0, 0], [8, 32], [0, 0], [0, 0]]>
1515
// CHECK-DAG: #[[CONFIG2:.+]] = #iree_codegen.lowering_config<tile_sizes = {{\[}}[48, 64, 0], [48, 64, 0], [0, 0, 0], [8, 32, 0], [0, 0, 1], [0, 0, 0]]>
1616
// CHECK-DAG: #[[TRANSLATION:.+]] = #iree_codegen.translation_info<pipeline = CPUDoubleTilingExpert, {{\{}}enable_loop_peeling}>
1717
// CHECK: func.func @matmul_riscv(
@@ -31,7 +31,7 @@ func.func @matmul_gemm_riscv_vl512(%lhs: tensor<384x512xf32>, %rhs: tensor<512x1
3131
%res = linalg.matmul ins(%lhs, %rhs : tensor<384x512xf32>, tensor<512x128xf32>) outs(%fill : tensor<384x128xf32>) -> tensor<384x128xf32>
3232
return %res : tensor<384x128xf32>
3333
}
34-
// CHECK-DAG: #[[CONFIG:.+]] = #iree_codegen.lowering_config<tile_sizes = {{\[}}[64, 64], [7, 64], [0, 0], [0, 0]]>
34+
// CHECK-DAG: #[[CONFIG:.+]] = #iree_codegen.lowering_config<tile_sizes = {{\[}}[64, 64], [64, 64], [0, 0], [7, 64], [0, 0], [0, 0]]>
3535
// CHECK-DAG: #[[CONFIG2:.+]] = #iree_codegen.lowering_config<tile_sizes = {{\[}}[64, 64, 0], [64, 64, 0], [0, 0, 0], [7, 64, 0], [0, 0, 1], [0, 0, 0]]>
3636
// CHECK-DAG: #[[TRANSLATION:.+]] = #iree_codegen.translation_info<pipeline = CPUDoubleTilingExpert, {{\{}}enable_loop_peeling}>
3737
// CHECK: func.func @matmul_gemm_riscv_vl512(
@@ -51,15 +51,15 @@ func.func @matmul_gemm_riscv_vl1024(%lhs: tensor<384x512xf32>, %rhs: tensor<512x
5151
%res = linalg.matmul ins(%lhs, %rhs : tensor<384x512xf32>, tensor<512x256xf32>) outs(%fill : tensor<384x256xf32>) -> tensor<384x256xf32>
5252
return %res : tensor<384x256xf32>
5353
}
54-
// CHECK-DAG: #[[CONFIG:.+]] = #iree_codegen.lowering_config<tile_sizes = {{\[}}[64, 128], [7, 128], [0, 0], [0, 0]]>
54+
// CHECK-DAG: #[[CONFIG:.+]] = #iree_codegen.lowering_config<tile_sizes = {{\[}}[64, 128], [64, 128], [0, 0], [7, 128], [0, 0], [0, 0]]>
5555
// CHECK-DAG: #[[CONFIG2:.+]] = #iree_codegen.lowering_config<tile_sizes = {{\[}}[64, 128, 0], [64, 128, 0], [0, 0, 0], [7, 128, 0], [0, 0, 1], [0, 0, 0]]>
5656
// CHECK-DAG: #[[TRANSLATION:.+]] = #iree_codegen.translation_info<pipeline = CPUDoubleTilingExpert, {{\{}}enable_loop_peeling}>
5757
// CHECK: func.func @matmul_gemm_riscv_vl1024(
5858
// CHECK-SAME: translation_info = #[[TRANSLATION]]
5959
// CHECK: linalg.matmul
6060
// CHECK-SAME: lowering_config = #[[CONFIG2]]
6161

62-
// CHECK-AGGRESSIVE-DAG: #[[CONFIG:.+]] = #iree_codegen.lowering_config<tile_sizes = {{\[}}[32, 256], [7, 128], [0, 0], [0, 0]]>
62+
// CHECK-AGGRESSIVE-DAG: #[[CONFIG:.+]] = #iree_codegen.lowering_config<tile_sizes = {{\[}}[32, 256], [32, 256], [0, 0], [7, 128], [0, 0], [0, 0]]>
6363
// CHECK-AGGRESSIVE-DAG: #[[CONFIG2:.+]] = #iree_codegen.lowering_config<tile_sizes = {{\[}}[32, 256, 0], [32, 256, 0], [0, 0, 0], [7, 128, 0], [0, 0, 1], [0, 0, 0]]>
6464
// CHECK-AGGRESSIVE-DAG: #[[TRANSLATION:.+]] = #iree_codegen.translation_info<pipeline = CPUDoubleTilingExpert, {{\{}}enable_loop_peeling}>
6565
// CHECK-AGGRESSIVE: func.func @matmul_gemm_riscv_vl1024(
@@ -79,7 +79,7 @@ func.func @matmul_gemv_riscv_vl512(%lhs: tensor<1x512xf32>, %rhs: tensor<512x128
7979
%res = linalg.matmul ins(%lhs, %rhs : tensor<1x512xf32>, tensor<512x128xf32>) outs(%fill : tensor<1x128xf32>) -> tensor<1x128xf32>
8080
return %res : tensor<1x128xf32>
8181
}
82-
// CHECK-DAG: #[[CONFIG:.+]] = #iree_codegen.lowering_config<tile_sizes = {{\[}}[0, 128], [1, 128], [0, 0], [0, 0]]>
82+
// CHECK-DAG: #[[CONFIG:.+]] = #iree_codegen.lowering_config<tile_sizes = {{\[}}[0, 128], [0, 128], [0, 0], [1, 128], [0, 0], [0, 0]]>
8383
// CHECK-DAG: #[[CONFIG2:.+]] = #iree_codegen.lowering_config<tile_sizes = {{\[}}[0, 128, 0], [0, 128, 0], [0, 0, 0], [1, 128, 0], [0, 0, 1], [0, 0, 0]]>
8484
// CHECK-DAG: #[[TRANSLATION:.+]] = #iree_codegen.translation_info<pipeline = CPUDoubleTilingExpert, {{\{}}enable_loop_peeling}>
8585
// CHECK: func.func @matmul_gemv_riscv_vl512(

compiler/src/iree/compiler/Codegen/LLVMCPU/test/select_x86_64_lowering_strategy.mlir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1941,7 +1941,7 @@ func.func @custom_op(%arg0 : tensor<384x512xf32>, %arg1 : tensor<512x128xf32>,
19411941
return %1 : tensor<384x128xf32>
19421942
}
19431943
// CHECK-DAG: #[[CONFIG0:.+]] = #iree_codegen.lowering_config<tile_sizes = {{\[}}[48, 64]]>
1944-
// CHECK-DAG: #[[CONFIG1:.+]] = #iree_codegen.lowering_config<tile_sizes = {{\[}}[48, 64], [8, 32], [0, 0], [0, 0]]>
1944+
// CHECK-DAG: #[[CONFIG1:.+]] = #iree_codegen.lowering_config<tile_sizes = {{\[}}[48, 64], [48, 64], [0, 0], [8, 32], [0, 0], [0, 0]]>
19451945
// CHECK-DAG: #[[CONFIG2:.+]] = #iree_codegen.lowering_config<tile_sizes = {{\[}}[48, 64, 0], [48, 64, 0], [0, 0, 0], [8, 32, 0], [0, 0, 16], [0, 0, 0]]>
19461946
// CHECK-DAG: #[[TRANSLATION_INFO:.+]] = #iree_codegen.translation_info<pipeline = CPUDoubleTilingExpert, {enable_loop_peeling}>
19471947
// CHECK: func @custom_op(

0 commit comments

Comments
 (0)