[Mlir-commits] [mlir] [MLIR][Linalg] Scalable Vectorization of Reduction (PR #97788)
Zhaoshi Zheng
llvmlistbot at llvm.org
Thu Jul 11 10:38:38 PDT 2024
================
@@ -1947,13 +1956,30 @@ vectorizeScalableVectorPrecondition(Operation *op,
if (inputVectorSizes.empty())
return success();
+ auto linalgOp = dyn_cast<LinalgOp>(op);
+ if (linalgOp && isLinalgReduction(linalgOp)) {
+ LDBG("Checking reduce op dims for scalable vectorization\n");
+ auto iteratorTypes = linalgOp.getIteratorTypesArray();
+ assert(iteratorTypes.size() == inputScalableVecDims.size() &&
+ "Number of iterator types and input scalable dims mismatch");
+ // For now, only support scalable vectorization of a reduction on the
+ // trailing dim.
+ for (size_t i = 0; i < inputScalableVecDims.size() - 1; ++i) {
+ if (inputScalableVecDims[i] && isReductionIterator(iteratorTypes[i])) {
+ LDBG("Non-trailing reduction dim requested for scalable "
+ "vectorization\n");
+ return failure();
+ }
+ }
+ return success();
+ }
----------------
zhaoshiz wrote:
this would work for linalg.reduce ops but prevent vectorizing dimensions with parallel iterators of linalg.generics ops, e.g.: requested vector sizes are [4, [4], 1] for the op below:
```
%result = linalg.generic {
indexing_maps = [affine_map<(i, j, k) -> (i, k)>,
affine_map<(i, j, k) -> (k, j)>,
affine_map<(i, j, k) -> (i, j)>],
iterator_types = ["parallel", "parallel", "reduction"]
} ins(%lhs, %rhs : tensor<8x10xf32>,tensor<10x16xf32>)
outs(%init :tensor<8x16xf32>) {
^bb0(%lhs_one: f32, %rhs_one: f32, %init_one: f32):
%0 = arith.mulf %lhs_one, %rhs_one : f32
%1 = arith.addf %init_one, %0 : f32
linalg.yield %1 : f32
} -> tensor<8x16xf32>
```
https://github.com/llvm/llvm-project/pull/97788
More information about the Mlir-commits
mailing list