Commit 672e1de
[Codegen] Add vector size inference for ukernel operations. (iree-org#22440)
## Summary
This change enables vector size inference for
`iree_codegen.ukernel.generic` operations, allowing downstream
operations like `linalg.unpack` to properly vectorize when consuming
ukernel outputs.
## Problem
The vector size inference mechanism in `inferSizesFromIR` did not handle
`UKernelGenericOp`, causing operations that consume ukernel outputs to
fail vectorization. This resulted in scalar code generation instead of
vectorized operations, leading to suboptimal performance.
Example: An `linalg.unpack` operation following a `iree_uk_mmt4d`
ukernel would use vector sizes of `[1, 1]` instead of the correct `[16,
16]` based on the ukernel's output shape.
## Solution
Added a case in the `inferSizesFromIR` TypeSwitch to handle
`UKernelGenericOp`:
- Infer vector sizes directly from the result tensor type shape
- Handle dynamic dimensions using `ValueBoundsConstraintSet`
- Return `VectorizationTileSizes` with both `vectorSizes` and
`destShape` populated
## Changes
**compiler/src/iree/compiler/Codegen/Utils/Utils.cpp:**
- Added `#include
"iree/compiler/Codegen/Dialect/Codegen/IR/UKernelOps.h"`
- Added standalone `inferSizesFromIR(UKernelGenericOp, OpResult)`
function following the pattern of other operations
- Updated TypeSwitch in `inferSizesFromIR(Value val)` to call the new
function
- Used `llvm::enumerate` with `static_cast<unsigned>` for dimension
indexing
**compiler/src/iree/compiler/Codegen/Utils/Utils.h:**
- Added `#include
"iree/compiler/Codegen/Dialect/Codegen/IR/UKernelOps.h"` in proper
alphabetical order
- Added public function declaration for
`inferSizesFromIR(UKernelGenericOp, OpResult)`
**compiler/src/iree/compiler/Codegen/Common/test/generic_vectorization.mlir:**
- Added test `@ukernel_unpack_infer_vector_sizes` verifying
vectorization of unpack after ukernel
## Testing
The test verifies that:
1. A ukernel operation produces a `tensor<1x1x16x16xf32>`
2. The following unpack operation correctly infers vector sizes and
vectorizes to `vector<16x16xf32>`
3. The vectorization uses `vector.transfer_read`, `vector.shape_cast`,
and `vector.transfer_write` operations
Run test with:
```bash
iree-opt --pass-pipeline="builtin.module(func.func(iree-codegen-generic-vectorization{enable-vector-masking=true}))" test.mlir
```
This change bridges the gap in the vector size inference mechanism,
enabling proper vectorization for any operations that consume ukernel
outputs, not just unpack operations.
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: hanhanW <[email protected]>1 parent c1a373b commit 672e1de
File tree
3 files changed
+73
-0
lines changed- compiler/src/iree/compiler/Codegen
- Common/test
- Utils
3 files changed
+73
-0
lines changedLines changed: 25 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
811 | 811 | | |
812 | 812 | | |
813 | 813 | | |
| 814 | + | |
| 815 | + | |
| 816 | + | |
| 817 | + | |
| 818 | + | |
| 819 | + | |
| 820 | + | |
| 821 | + | |
| 822 | + | |
| 823 | + | |
| 824 | + | |
| 825 | + | |
| 826 | + | |
| 827 | + | |
| 828 | + | |
| 829 | + | |
| 830 | + | |
| 831 | + | |
| 832 | + | |
| 833 | + | |
| 834 | + | |
| 835 | + | |
| 836 | + | |
| 837 | + | |
| 838 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
| |||
1912 | 1913 | | |
1913 | 1914 | | |
1914 | 1915 | | |
| 1916 | + | |
| 1917 | + | |
| 1918 | + | |
| 1919 | + | |
| 1920 | + | |
| 1921 | + | |
| 1922 | + | |
| 1923 | + | |
| 1924 | + | |
| 1925 | + | |
| 1926 | + | |
| 1927 | + | |
| 1928 | + | |
| 1929 | + | |
| 1930 | + | |
| 1931 | + | |
| 1932 | + | |
| 1933 | + | |
| 1934 | + | |
| 1935 | + | |
| 1936 | + | |
| 1937 | + | |
| 1938 | + | |
| 1939 | + | |
| 1940 | + | |
| 1941 | + | |
| 1942 | + | |
| 1943 | + | |
| 1944 | + | |
| 1945 | + | |
| 1946 | + | |
| 1947 | + | |
| 1948 | + | |
| 1949 | + | |
| 1950 | + | |
| 1951 | + | |
| 1952 | + | |
| 1953 | + | |
1915 | 1954 | | |
1916 | 1955 | | |
1917 | 1956 | | |
| |||
1948 | 1987 | | |
1949 | 1988 | | |
1950 | 1989 | | |
| 1990 | + | |
| 1991 | + | |
1951 | 1992 | | |
1952 | 1993 | | |
1953 | 1994 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
| |||
365 | 366 | | |
366 | 367 | | |
367 | 368 | | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
368 | 375 | | |
369 | 376 | | |
370 | 377 | | |
| |||
0 commit comments