Repository navigation
[Codegen] Add pass for specializing executable variants - #20771
Merged
qedawkins merged 4 commits intoMay 27, 2025
Merged
Conversation
qedawkins
force-pushed
the
split_dispatch_on_util_assume
branch
from
May 9, 2025 21:19
e9c94c1 to
3e02c28
Compare
Collaborator
|
This is awesome :) |
qedawkins
force-pushed
the
split_dispatch_on_util_assume
branch
from
May 12, 2025 20:26
c25be2d to
4db7b26
Compare
Contributor
Author
|
Depends on #20801 |
qedawkins
force-pushed
the
split_dispatch_on_util_assume
branch
2 times, most recently
from
May 19, 2025 15:46
1c652a6 to
6e73e5d
Compare
qedawkins
marked this pull request as ready for review
May 19, 2025 16:21
qedawkins
requested review from
Groverkss,
MaheshRavishankar,
antiagainst,
benvanik,
hanhanW,
kuhar and
pashu123
as code owners
May 19, 2025 16:21
benvanik
requested changes
May 27, 2025
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.
qedawkins
force-pushed
the
split_dispatch_on_util_assume
branch
from
May 27, 2025 20:50
96f1217 to
8b585f6
Compare
benvanik
approved these changes
May 27, 2025
benvanik
left a comment
Collaborator
There was a problem hiding this comment.
5 or 6 years into the project and we finally have specialization based on dispatch sites - so cool :)
AWoloszyn
pushed a commit
that referenced
this pull request
Dec 1, 2025
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.
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.
This allows for kernel specialization by way of annotating tilable ops with the preferred iteration ranges and divisibilities to specialize for. For example,
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.assumeop. 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.intinformation that this pass refines.