Skip to content

Commit bb906c1

Browse files
authored
[Codegen] Add pass for specializing executable variants (#20771)
This allows for kernel specialization by way of annotating tilable ops with the preferred iteration ranges and divisibilities to specialize for. For example, ``` %35 = linalg.matmul ins(%30, %31 : tensor<?x?xf16>, tensor<?x?xf16>) outs(%34 : tensor<?x?xf32>) {iree_codegen.specialization_ranges = #util<int.assumption.multi_array[ [<umin = 128, umax = 4096, udiv = 128>, <umin = 128, umax = 4096, udiv = 128>, <umin = 64, udiv = 64>], [<umin = 4096, udiv = 256>, <umin = 4096, udiv = 256>, <udiv = 64>] ]>} -> tensor<?x?xf32> ``` This matmul will be specialized into up to 3 variants, one default, and two for each list of ranges. More details can be found in the code documentation. To specialize a dispatch, the pass queries the iteration domain of the tilable op and looks for a producer `util.int.assume` op. The function is then cloned and the assume is updated to match the requested ranges. This is just one way to implement kernel specialization, in the future we can implement many more options (e.g. based on estimated TOPs or smallest individual dimension) and that's without considering what device we're targeting. The implementation here supports many common cases of minimum/maximum sizes and alignments. Learnings here will translate to future improvements for other strategies. This pass runs first thing in the configuration pipelines because it needs to apply to the variant, and should run before passes like BlockDynamicDims which takes advantage of `util.assume.int` information that this pass refines.
1 parent b3128ba commit bb906c1

File tree

17 files changed

+916
-0
lines changed

17 files changed

+916
-0
lines changed

compiler/src/iree/compiler/Codegen/Common/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ iree_compiler_cc_library(
156156
"RemoveSingleIterationLoop.cpp",
157157
"ReplaceSlowMinMaxOps.cpp",
158158
"ResolveSwizzleHints.cpp",
159+
"SpecializeExports.cpp",
159160
"SplitFullPartialTransferPass.cpp",
160161
"StripCompilationInfoPass.cpp",
161162
"TensorDynamicDimAnalysis.cpp",

compiler/src/iree/compiler/Codegen/Common/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ iree_cc_library(
145145
"RemoveSingleIterationLoop.cpp"
146146
"ReplaceSlowMinMaxOps.cpp"
147147
"ResolveSwizzleHints.cpp"
148+
"SpecializeExports.cpp"
148149
"SplitFullPartialTransferPass.cpp"
149150
"StripCompilationInfoPass.cpp"
150151
"TensorDynamicDimAnalysis.cpp"

compiler/src/iree/compiler/Codegen/Common/Passes.td

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,11 @@ def ResolveSwizzleHintsPass :
658658
];
659659
}
660660

661+
def SpecializeExportsPass :
662+
Pass<"iree-codegen-specialize-exports", "IREE::HAL::ExecutableVariantOp">{
663+
let summary = "Specializes exported functions based on annotated ranges";
664+
}
665+
661666
def StripCompilationInfoPass :
662667
Pass<"iree-codegen-strip-compilation-info", "">{
663668
let summary = "Remove all the the lowering configuration and translation info attributes.";

0 commit comments

Comments
 (0)