Skip to content

Commit 3be8dec

Browse files
authored
[Transform][Fusion] Introduce an iterative tiling and fusion pass in forward and backward fashion (#87)
* Matmul fusion with element-wise/reduce/broadcast ops. * Pre-op and post-op fusion(a.k.a. producer and consumer fusion respectively). * Multi-consumer and multi-producer support. * Support multiple level tiling and fusion. * Add flexible options to control the boundary of iterative fusion. * Enable default tiling when no op is tiled before fusion. * Cost-model to determine whether to fuse or not.
1 parent 4f87ec6 commit 3be8dec

File tree

7 files changed

+2168
-1
lines changed

7 files changed

+2168
-1
lines changed

include/gc/Transforms/Passes.td

+32
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,36 @@ def LinalgToXeGPU : Pass<"linalg-to-xegpu", "func::FuncOp"> {
6161
}
6262
#endif
6363

64+
def IterativeTilingAndFusion : Pass<"iterative-tiling-and-fusion",
65+
"func::FuncOp"> {
66+
let summary = "Iterative tiling and fusion for any tilable operation";
67+
let description = [{
68+
The pass tries to fuse any MLIR operation which can be tiled. Moreover, this pass aims to support:
69+
1. Matmul fusion with element-wise/reduce/broadcast ops.
70+
2. Pre-op and post-op fusion.
71+
3. Multi-consumer and multi-producer support.
72+
4. Multiple level of nest loops and candidates.
73+
5. Flexible option to control the boundary of iterative process.
74+
6. Cost-model to determine whether to fuse or not.
75+
76+
It intends to control the granularity of fusion by `fusion-level`, E.g.
77+
* `0`: disable any fusion.
78+
* `1`:[Default] enable both producer and consumer fusion, covering any tilable operation including tensor.pack/tensor.fill/linalg.reduce etc but excluding branches forked by multiple uses.
79+
* `2`: `LEVEL 1` + extend to any topology including branches.
80+
}];
81+
let dependentDialects = ["func::FuncDialect", "linalg::LinalgDialect", "scf::SCFDialect",
82+
"tensor::TensorDialect"];
83+
84+
let options = [
85+
Option<"fusionLevel", "fusion-level", "int64_t",
86+
/*default=*/"1",
87+
"Control the granularity of fusion.">,
88+
Option<"useCostModel", "use-cost-model", "bool",
89+
/*default=*/"false",
90+
"Decide if enable cost model to control iterative fusion.">,
91+
ListOption<"defaultTileSize", "default-tile-size", "std::string",
92+
"Set default TileSize for the certain type of op, saying matmul:{32,32}">,
93+
];
94+
}
95+
6496
#endif // GC_DIALECT_GC_PASSES

lib/gc/Transforms/CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ gc_add_mlir_library(GcPasses
1313
OneDNNGraphToLinalg.cpp
1414
Pipeline.cpp
1515
TileNamed.cpp
16+
IterativeTilingAndFusion.cpp
17+
TilingUsingInterfaceX.cpp
1618

1719
DEPENDS
1820
GraphCompilerPassIncGen

0 commit comments

Comments
 (0)