Skip to content

Commit 69bc1cb

Browse files
[mlir][linalg][transform] Rename {masked_vectorize => vectorize => vectorize_children_and...}. (llvm#66575)
This PR renames the vectorization transform ops as follows: * `structured.masked_vectorize` => `structured.vectorize`. This reflects the fact that since [recently](https://reviews.llvm.org/D157774) the op can also handle the unmasked case. * `structured.vectorize` => `structured.vectorize_children_and_applies_patterns`. This reflects the fact that the op does not just vectorize the given payload op but all vectorizable children contained in it, and applies patterns before and after for preparation and clean-up. This rename was discussed first [here](https://reviews.llvm.org/D157774). The PR also adapts and cleans ups the tablegen description of the `VectorizeChildrenAndApplyPatternsOp` (formerly `VectorizeOp`).
1 parent c00f49c commit 69bc1cb

21 files changed

+2288
-2284
lines changed

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

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1947,37 +1947,39 @@ def TileToForallOp :
19471947
}
19481948

19491949
//===----------------------------------------------------------------------===//
1950-
// VectorizeOp
1950+
// VectorizeChildrenAndApplyPatternsOp
19511951
//===----------------------------------------------------------------------===//
19521952

1953-
def VectorizeOp : Op<Transform_Dialect, "structured.vectorize",
1953+
def VectorizeChildrenAndApplyPatternsOp :
1954+
Op<Transform_Dialect, "structured.vectorize_children_and_apply_patterns",
19541955
[FunctionalStyleTransformOpTrait, MemoryEffectsOpInterface,
19551956
TransformEachOpTrait, TransformOpInterface,
19561957
ReportTrackingListenerFailuresOpTrait]> {
19571958
let description = [{
1958-
Indicates that the given `target` op all the ops it contains should be
1959-
vectorized with the configuration specified by the attributes of this op.
1960-
This vectorization only handles structured ops that operate on shaped types
1961-
and does not vectorize loops or straight-line. Internally, it applies a
1962-
set of rewrite patterns, some of which enable vectorization and some of
1963-
which clean up the results. Therefore, it can only be applied to an op with
1964-
the "isolated from above property". If finer granularity is required, it can
1965-
be achieved by outlining the target part of the payload IR into, e.g., a
1966-
function, performing the transformation, and inlining it back. This
1967-
transformation only fails if the entire pattern rewriting failed, i.e., it
1968-
does **not** fail when no ops were vectorized.
1969-
1970-
Note that this transformation is invalidating the handles to any payload IR
1959+
Vectorizes all children contained in the given `target` using the
1960+
configuration specified by the attributes of this op. This only vectorizes
1961+
structured ops that operate on shaped types and does not vectorize loops or
1962+
straight-line. Internally, it applies a set of rewrite patterns, some of
1963+
which enable vectorization and some of which clean up the results.
1964+
Therefore, it can only be applied to an op with the "isolated from above"
1965+
property. This transformation only fails if the entire pattern rewriting
1966+
failed, i.e., it does **not** fail when no ops were vectorized.
1967+
1968+
Finer granularity can be achieved either with the `VectorizeOp` for
1969+
individual ops or by outlining the target part of the payload IR into, e.g.,
1970+
a function, performing this transformation, and inlining it back.
1971+
1972+
Note that this transformation invalidates the handles to any payload IR
19711973
operation that is contained inside the vectorization target.
19721974

19731975
This transformation supports the following attributes:
1974-
- `vectorize_padding`: a UnitAttr to activate the vectorization of
1976+
- `vectorize_padding`: a `UnitAttr` to activate the vectorization of
19751977
`tensor.pad` ops. Different pipelines may prefer to lower such ops to
19761978
loops.
1977-
- `disable_multi_reduction_to_contract_patterns`: a UnitAttr to deactivate
1979+
- `disable_multi_reduction_to_contract_patterns`: a `UnitAttr` to deactivate
19781980
the rewrite of `vector.multi_reduction` to `vector.contract`. This is
19791981
intended to be used in tests only.
1980-
- `disable_transfer_permutation_map_lowering_patterns`: a UnitAttr to
1982+
- `disable_transfer_permutation_map_lowering_patterns`: a `UnitAttr` to
19811983
deactivate the rewrite of `vector.transfer` with permutation maps into
19821984
explicit `vector.transpose` operations. This is intended to be used in
19831985
tests only but may be promoted to a first class attribute in the future.
@@ -2015,7 +2017,7 @@ def VectorizeOp : Op<Transform_Dialect, "structured.vectorize",
20152017
}];
20162018
}
20172019

2018-
def MaskedVectorizeOp : Op<Transform_Dialect, "structured.masked_vectorize",
2020+
def VectorizeOp : Op<Transform_Dialect, "structured.vectorize",
20192021
[DeclareOpInterfaceMethods<MemoryEffectsOpInterface>,
20202022
TransformOpInterface, ReportTrackingListenerFailuresOpTrait]> {
20212023
let description = [{
@@ -2029,9 +2031,9 @@ def MaskedVectorizeOp : Op<Transform_Dialect, "structured.masked_vectorize",
20292031

20302032
```mlir
20312033
# Masked vectorization - vector sizes are specified explicitly
2032-
transform.structured.masked_vectorize %target vector_sizes [1, 4] : !transform.any_op
2034+
transform.structured.vectorize %target vector_sizes [1, 4] : !transform.any_op
20332035
# Regular vectorization - vector sizes are inferred from the target Op
2034-
transform.structured.masked_vectorize %target : !transform.any_op
2036+
transform.structured.vectorize %target : !transform.any_op
20352037
```
20362038

20372039
The vector sizes can be either static or dynamic (SSA values). In case of

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

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2904,27 +2904,31 @@ LogicalResult TileToForallOp::verify() {
29042904
}
29052905

29062906
//===----------------------------------------------------------------------===//
2907-
// VectorizeOp
2907+
// VectorizeChildrenAndApplyPatternsOp
29082908
//===----------------------------------------------------------------------===//
29092909

2910-
void transform::VectorizeOp::build(OpBuilder &builder, OperationState &result,
2911-
Value target, bool vectorizePadding,
2912-
bool vectorizeExtract) {
2910+
void transform::VectorizeChildrenAndApplyPatternsOp::build(
2911+
OpBuilder &builder, OperationState &result, Value target,
2912+
bool vectorizePadding, bool vectorizeExtract) {
29132913
result.addOperands(target);
29142914
if (vectorizePadding) {
2915-
result.addAttribute(VectorizeOp::getVectorizePaddingAttrName(result.name),
2916-
builder.getUnitAttr());
2915+
result.addAttribute(
2916+
VectorizeChildrenAndApplyPatternsOp::getVectorizePaddingAttrName(
2917+
result.name),
2918+
builder.getUnitAttr());
29172919
}
29182920
if (vectorizeExtract) {
2919-
result.addAttribute(VectorizeOp::getVectorizeNdExtractAttrName(result.name),
2920-
builder.getUnitAttr());
2921+
result.addAttribute(
2922+
VectorizeChildrenAndApplyPatternsOp::getVectorizeNdExtractAttrName(
2923+
result.name),
2924+
builder.getUnitAttr());
29212925
}
29222926
result.addTypes(transform::AnyOpType::get(builder.getContext()));
29232927
}
29242928

29252929
namespace {
29262930
/// This is an helper only to call vectorize via a pattern inside of
2927-
/// VectorizeOp::applyToOne.
2931+
/// VectorizeChildrenAndApplyPatternsOp::applyToOne.
29282932
struct VectorizationPattern : public RewritePattern {
29292933
explicit VectorizationPattern(MLIRContext *context,
29302934
bool vectorizeExtract = false)
@@ -2947,10 +2951,10 @@ struct VectorizationPattern : public RewritePattern {
29472951
} // namespace
29482952

29492953
DiagnosedSilenceableFailure
2950-
transform::VectorizeOp::applyToOne(transform::TransformRewriter &rewriter,
2951-
Operation *target,
2952-
transform::ApplyToEachResultList &results,
2953-
transform::TransformState &state) {
2954+
transform::VectorizeChildrenAndApplyPatternsOp::applyToOne(
2955+
transform::TransformRewriter &rewriter, Operation *target,
2956+
transform::ApplyToEachResultList &results,
2957+
transform::TransformState &state) {
29542958
if (!target->hasTrait<OpTrait::IsIsolatedFromAbove>()) {
29552959
auto diag = this->emitOpError("requires isolated-from-above targets");
29562960
diag.attachNote(target->getLoc()) << "non-isolated target";
@@ -2992,9 +2996,9 @@ transform::VectorizeOp::applyToOne(transform::TransformRewriter &rewriter,
29922996
}
29932997

29942998
//===----------------------------------------------------------------------===//
2995-
// MaskedVectorizeOp
2999+
// VectorizeOp
29963000
//===----------------------------------------------------------------------===//
2997-
DiagnosedSilenceableFailure transform::MaskedVectorizeOp::apply(
3001+
DiagnosedSilenceableFailure transform::VectorizeOp::apply(
29983002
transform::TransformRewriter &rewriter,
29993003
mlir::transform::TransformResults &transformResults,
30003004
mlir::transform::TransformState &state) {
@@ -3058,19 +3062,19 @@ DiagnosedSilenceableFailure transform::MaskedVectorizeOp::apply(
30583062
return DiagnosedSilenceableFailure::success();
30593063
}
30603064

3061-
void transform::MaskedVectorizeOp::getEffects(
3065+
void transform::VectorizeOp::getEffects(
30623066
SmallVectorImpl<MemoryEffects::EffectInstance> &effects) {
30633067
consumesHandle(getTarget(), effects);
30643068
onlyReadsHandle(getVectorSizes(), effects);
30653069
modifiesPayload(effects);
30663070
}
30673071

3068-
SmallVector<OpFoldResult> MaskedVectorizeOp::getMixedVectorSizes() {
3072+
SmallVector<OpFoldResult> VectorizeOp::getMixedVectorSizes() {
30693073
OpBuilder b(getContext());
30703074
return getMixedValues(getStaticVectorSizes(), getVectorSizes(), b);
30713075
}
30723076

3073-
LogicalResult transform::MaskedVectorizeOp::verify() {
3077+
LogicalResult transform::VectorizeOp::verify() {
30743078
if (getStaticVectorSizes().size() != getScalableSizes().size())
30753079
return emitOpError("expected same number of vector sizes (")
30763080
<< getStaticVectorSizes().size() << ") and scalable sizes ("

mlir/python/mlir/dialects/_structured_transform_ops_ext.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -360,8 +360,8 @@ def __init__(
360360
)
361361

362362

363-
class MaskedVectorizeOp:
364-
"""Specialization for MaskedVectorizeOp class."""
363+
class VectorizeOp:
364+
"""Specialization for VectorizeOp class."""
365365

366366
def __init__(
367367
self,
@@ -730,8 +730,8 @@ def __init__(
730730
)
731731

732732

733-
class VectorizeOp:
734-
"""Specialization for VectorizeOp class."""
733+
class VectorizeChildrenAndApplyPatternsOp:
734+
"""Specialization for VectorizeChildrenAndApplyPatternsOp class."""
735735

736736
def __init__(
737737
self,

mlir/test/Dialect/LLVM/transform-e2e.mlir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ transform.sequence failures(propagate) {
1717
%0 = transform.structured.match ops{["linalg.matmul"]} in %module_op : (!transform.any_op) -> !transform.any_op
1818
%1, %loops:3 = transform.structured.tile %0 [2, 2, 2] : (!transform.any_op) -> (!transform.any_op, !transform.any_op, !transform.any_op, !transform.any_op)
1919
%2 = get_parent_op %1 {isolated_from_above} : (!transform.any_op) -> !transform.any_op
20-
transform.structured.vectorize %2 : (!transform.any_op) -> !transform.any_op
20+
transform.structured.vectorize_children_and_apply_patterns %2 : (!transform.any_op) -> !transform.any_op
2121
%b = transform.bufferization.one_shot_bufferize layout{IdentityLayoutMap}
2222
%module_op {bufferize_function_boundaries = true}
2323
: (!transform.any_op) -> !transform.any_op

mlir/test/Dialect/Linalg/matmul-shared-memory-padding.mlir

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ transform.sequence failures(propagate) {
8080
: (!transform.any_op) -> (!transform.any_op, !transform.any_op)
8181

8282
// Apply masked vectorization to padding ops.
83-
transform.structured.masked_vectorize %tiled_pad_op vector_sizes [128, 4]
83+
transform.structured.vectorize %tiled_pad_op vector_sizes [128, 4]
8484
: !transform.any_op
8585

8686
// Assign shared memory buffer to padding.
@@ -105,7 +105,7 @@ transform.sequence failures(propagate) {
105105
: (!transform.any_op) -> !transform.any_op
106106
%bufferized_copy_back = transform.structured.match ops{["linalg.copy"]} in %func_op_2
107107
: (!transform.any_op) -> !transform.any_op
108-
transform.structured.masked_vectorize
108+
transform.structured.vectorize
109109
%bufferized_copy_back vector_sizes [128, 4] : !transform.any_op
110110

111111
// Canonicalize, cleanup and vector lowering. This step also removes buffer
@@ -192,7 +192,7 @@ transform.sequence failures(propagate) {
192192
}
193193

194194
// Apply masked vectorization to padding ops.
195-
transform.structured.masked_vectorize %tiled_pad_op vector_sizes [128, 4]
195+
transform.structured.vectorize %tiled_pad_op vector_sizes [128, 4]
196196
: !transform.any_op
197197

198198
// Assign shared memory buffer to padding.
@@ -217,7 +217,7 @@ transform.sequence failures(propagate) {
217217
: (!transform.any_op) -> !transform.any_op
218218
%bufferized_copy_back = transform.structured.match ops{["linalg.copy"]} in %func_op_2
219219
: (!transform.any_op) -> !transform.any_op
220-
transform.structured.masked_vectorize
220+
transform.structured.vectorize
221221
%bufferized_copy_back vector_sizes [128, 4] : !transform.any_op
222222

223223
// Canonicalize, cleanup and vector lowering. This step also removes buffer

mlir/test/Dialect/Linalg/pad-to-specific-memory-space.mlir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ transform.sequence failures(propagate) {
111111
padding_dimensions=[0, 1, 2],
112112
pack_paddings=[1, 1, 1]
113113
} : (!transform.any_op) -> (!transform.any_op, !transform.any_op, !transform.any_op)
114-
transform.structured.masked_vectorize %pad vector_sizes [10, 12] : !transform.any_op
114+
transform.structured.vectorize %pad vector_sizes [10, 12] : !transform.any_op
115115
%vector_write = transform.structured.match ops{["vector.transfer_write"]} in %arg1 : (!transform.any_op) -> !transform.any_op
116116
%mask_op = transform.get_parent_op %vector_write {op_name = "vector.mask"} : (!transform.any_op) -> !transform.any_op
117117
%buffer, %new_ops = transform.structured.bufferize_to_allocation %mask_op {memory_space = 3, emit_dealloc} : !transform.any_op

mlir/test/Dialect/Linalg/transform-op-compose-masked-vectorize-and-cleanups.mlir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ transform.sequence failures(propagate) {
2626
: (!transform.any_op) -> (!transform.any_op, !transform.any_op, !transform.any_op, !transform.any_op)
2727
%tiled_linalg_op_0, %loops_1:3 = transform.structured.tile %tiled_linalg_op[8, 8, 8]
2828
: (!transform.any_op) -> (!transform.any_op, !transform.any_op, !transform.any_op, !transform.any_op)
29-
transform.structured.masked_vectorize %tiled_linalg_op_0 vector_sizes [8, 8, 8]
29+
transform.structured.vectorize %tiled_linalg_op_0 vector_sizes [8, 8, 8]
3030
: !transform.any_op
3131

3232
%func = transform.structured.match ops{["func.func"]} in %module

mlir/test/Dialect/Linalg/transform-op-matmul-to-outerproduct.mlir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ transform.sequence failures(propagate) {
3131
^bb1(%arg1: !transform.any_op):
3232
%0 = transform.structured.match ops{["linalg.matmul"]} in %arg1 : (!transform.any_op) -> !transform.any_op
3333
%1 = get_parent_op %0 {isolated_from_above} : (!transform.any_op) -> !transform.any_op
34-
%2 = transform.structured.vectorize %1 : (!transform.any_op) -> !transform.any_op
34+
%2 = transform.structured.vectorize_children_and_apply_patterns %1 : (!transform.any_op) -> !transform.any_op
3535
transform.apply_patterns to %2 {
3636
transform.apply_patterns.vector.lower_contraction lowering_strategy = "outerproduct"
3737
} : !transform.any_op

mlir/test/Dialect/Linalg/transform-op-vectorize.mlir

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ transform.sequence failures(propagate) {
2020
^bb1(%arg1: !transform.any_op):
2121
%0 = transform.structured.match ops{["linalg.matmul"]} in %arg1 : (!transform.any_op) -> !transform.any_op
2222
%1 = get_parent_op %0 {isolated_from_above} : (!transform.any_op) -> !transform.any_op
23-
%2 = transform.structured.vectorize %1 : (!transform.any_op) -> !transform.any_op
23+
%2 = transform.structured.vectorize_children_and_apply_patterns %1 : (!transform.any_op) -> !transform.any_op
2424
}
2525

2626
// -----
@@ -45,7 +45,7 @@ transform.sequence failures(propagate) {
4545
^bb1(%arg1: !transform.any_op):
4646
%0 = transform.structured.match ops{["linalg.matmul"]} in %arg1 : (!transform.any_op) -> !transform.any_op
4747
%1 = get_parent_op %0 {isolated_from_above} : (!transform.any_op) -> !transform.any_op
48-
%2 = transform.structured.vectorize %1 : (!transform.any_op) -> !transform.any_op
48+
%2 = transform.structured.vectorize_children_and_apply_patterns %1 : (!transform.any_op) -> !transform.any_op
4949
}
5050

5151
// -----
@@ -65,7 +65,7 @@ transform.sequence failures(propagate) {
6565
^bb1(%arg1: !transform.any_op):
6666
%0 = transform.structured.match ops{["linalg.copy"]} in %arg1 : (!transform.any_op) -> !transform.any_op
6767
%1 = get_parent_op %0 {isolated_from_above} : (!transform.any_op) -> !transform.any_op
68-
%2 = transform.structured.vectorize %1 : (!transform.any_op) -> !transform.any_op
68+
%2 = transform.structured.vectorize_children_and_apply_patterns %1 : (!transform.any_op) -> !transform.any_op
6969
}
7070

7171
// -----
@@ -111,7 +111,7 @@ transform.sequence failures(propagate) {
111111
^bb1(%arg1: !transform.any_op):
112112
%0 = transform.structured.match ops{["linalg.matmul"]} in %arg1 : (!transform.any_op) -> !transform.any_op
113113
%1 = get_parent_op %0 {isolated_from_above} : (!transform.any_op) -> !transform.any_op
114-
%2 = transform.structured.vectorize %1 : (!transform.any_op) -> !transform.any_op
114+
%2 = transform.structured.vectorize_children_and_apply_patterns %1 : (!transform.any_op) -> !transform.any_op
115115
}
116116

117117
// -----
@@ -159,7 +159,7 @@ transform.sequence failures(propagate) {
159159
^bb1(%arg1: !transform.any_op):
160160
%0 = transform.structured.match ops{["linalg.matmul"]} in %arg1 : (!transform.any_op) -> !transform.any_op
161161
%1 = get_parent_op %0 {isolated_from_above} : (!transform.any_op) -> !transform.any_op
162-
%2 = transform.structured.vectorize %1 {vectorize_padding} : (!transform.any_op) -> !transform.any_op
162+
%2 = transform.structured.vectorize_children_and_apply_patterns %1 {vectorize_padding} : (!transform.any_op) -> !transform.any_op
163163
}
164164

165165
// -----
@@ -176,5 +176,5 @@ transform.sequence failures(propagate) {
176176
^bb1(%arg1: !transform.any_op):
177177
%0 = transform.structured.match ops{["linalg.matmul"]} in %arg1 : (!transform.any_op) -> !transform.any_op
178178
// expected-error @below {{op requires isolated-from-above targets}}
179-
%2 = transform.structured.vectorize %0 : (!transform.any_op) -> !transform.any_op
179+
%2 = transform.structured.vectorize_children_and_apply_patterns %0 : (!transform.any_op) -> !transform.any_op
180180
}

0 commit comments

Comments
 (0)