Skip to content

Commit 7171244

Browse files
committed
[mlir] Add vectorize_nd_extract attribute to the masked_vectorize Op
This patch simply adds `vectorize_nd_extract` (that's currently only used for the `vectorize` Op) to `masked_vectorize`. A test is added to verify that it works as expected - it prevents the masked vectorisation of `tensor.extract`, which is currently not supported. Differential Revision: https://reviews.llvm.org/D142634
1 parent 86a63b2 commit 7171244

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

mlir/include/mlir/Dialect/Linalg/TransformOps/LinalgTransformOps.td

+1
Original file line numberDiff line numberDiff line change
@@ -1594,6 +1594,7 @@ def MaskedVectorizeOp : Op<Transform_Dialect, "structured.masked_vectorize",
15941594

15951595
let arguments = (ins PDL_Operation:$target,
15961596
Variadic<PDL_Operation>:$vector_sizes,
1597+
UnitAttr:$vectorize_nd_extract,
15971598
DefaultValuedOptionalAttr<DenseI64ArrayAttr, "{}">:
15981599
$static_vector_sizes);
15991600
let results = (outs);

mlir/lib/Dialect/Linalg/TransformOps/LinalgTransformOps.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -2986,7 +2986,8 @@ DiagnosedSilenceableFailure transform::MaskedVectorizeOp::apply(
29862986
<< "cannot vectorize non-Linalg op";
29872987
}
29882988

2989-
if (failed(linalg::vectorize(rewriter, linalgOp, vectorSizes))) {
2989+
if (failed(linalg::vectorize(rewriter, linalgOp, vectorSizes,
2990+
getVectorizeNdExtract()))) {
29902991
return mlir::emitSilenceableFailure(target->getLoc())
29912992
<< "failed to vectorize op";
29922993
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// RUN: mlir-opt %s -test-transform-dialect-interpreter -split-input-file -verify-diagnostics
2+
3+
// Masked vectorisation of `tensor.extract`:
4+
// * requires the `{ vectorize_nd_extract }` attribute,
5+
// * has not been implemented yet (hence the attribute is absent).
6+
// TOOD: Implement masked vectorization for `tensor.extract`
7+
8+
#map1 = affine_map<(d0, d1) -> (d0, d1)>
9+
func.func @extract_masked_vectorize(%arg0: tensor<?x?xf32>, %arg1: tensor<?x?xf32>) -> tensor<?x?xf32> {
10+
%c0 = arith.constant 1 : index
11+
%c1 = arith.constant 2 : index
12+
// expected-error@+1 {{failed to vectorize op}}
13+
%2 = linalg.generic {
14+
indexing_maps = [#map1],
15+
iterator_types = ["parallel", "parallel"]
16+
} outs(%arg1 : tensor<?x?xf32>) {
17+
^bb0(%arg3: f32):
18+
%7 = tensor.extract %arg0[%c0, %c1] : tensor<?x?xf32>
19+
linalg.yield %7 : f32
20+
} -> tensor<?x?xf32>
21+
return %2 : tensor<?x?xf32>
22+
}
23+
24+
25+
transform.sequence failures(propagate) {
26+
^bb1(%arg1: !pdl.operation):
27+
%0 = transform.structured.match ops{["linalg.generic"]} in %arg1 : (!pdl.operation) -> !pdl.operation
28+
transform.structured.masked_vectorize %0 vector_sizes [3, 3]
29+
}

0 commit comments

Comments
 (0)