@@ -45,7 +45,7 @@ def ApplyDecomposeTensorPackUnpackPatternsOp
45
45
: Op<Transform_Dialect, "apply_patterns.linalg.decompose_pack_unpack",
46
46
[DeclareOpInterfaceMethods<PatternDescriptorOpInterface>]> {
47
47
let description = [{
48
- Collect patterns to decompose tensor .pack and tensor .unpack into e.g.
48
+ Collect patterns to decompose linalg .pack and linalg .unpack into e.g.
49
49
tensor::PadOp, linalg::transposeOp Ops. Requires all outer dims to be unit.
50
50
}];
51
51
@@ -126,6 +126,28 @@ def ApplyPadVectorizationPatternsOp : Op<Transform_Dialect,
126
126
let assemblyFormat = "attr-dict";
127
127
}
128
128
129
+ def ApplyFoldIntoPackAndUnpackPatternsOp : Op<Transform_Dialect,
130
+ "apply_patterns.tensor.fold_into_pack_and_unpack",
131
+ [DeclareOpInterfaceMethods<PatternDescriptorOpInterface>]> {
132
+ let description = [{
133
+ Indicates that operations like tensor.pad and tensor.extract_slice should
134
+ be folded into tensor.pack and tensor.unpack operations, respectively.
135
+ }];
136
+
137
+ let assemblyFormat = "attr-dict";
138
+ }
139
+
140
+ def ApplyFoldPackUnpackIntoEmptyPatternsOp : Op<Transform_Dialect,
141
+ "apply_patterns.linalg.fold_pack_unpack_into_empty",
142
+ [DeclareOpInterfaceMethods<PatternDescriptorOpInterface>]> {
143
+ let description = [{
144
+ // TODO:
145
+ }];
146
+
147
+ let arguments = (ins DefaultValuedAttr<BoolAttr, "false">:$fold_single_use_only);
148
+ let assemblyFormat = "attr-dict";
149
+ }
150
+
129
151
//===----------------------------------------------------------------------===//
130
152
// BufferizeToAllocationOp
131
153
//===----------------------------------------------------------------------===//
@@ -547,19 +569,18 @@ def LowerPackOp : Op<Transform_Dialect, "structured.lower_pack", [
547
569
TransformOpInterface,
548
570
ReportTrackingListenerFailuresOpTrait]> {
549
571
let description = [{
550
- Rewrite a tensor .pack into tensor.pad + tensor.expand_shape + linalg.transpose.
572
+ Rewrite a linalg .pack into tensor.pad + tensor.expand_shape + linalg.transpose.
551
573
552
574
#### Return modes
553
575
554
- This operation ignores non-pack ops and drops them in the return.
555
- This operation produces a silenceable failure if the rewrite fails for any
556
- reason.
557
- If all the operations referred to by the `target` are rewritten, the
558
- transform succeeds.
559
- Return handles to the newly produced pad, expand_shape and transpose ops.
576
+ This operation ignores non-pack ops and drops them in the return. This
577
+ operation produces a silenceable failure if the rewrite fails for any
578
+ reason. If all the operations referred to by the `target` are rewritten,
579
+ the transform succeeds. Return handles to the newly produced pad,
580
+ expand_shape and transpose ops.
560
581
}];
561
582
562
- let arguments = (ins Transform_ConcreteOpType<"tensor .pack">:$target,
583
+ let arguments = (ins Transform_ConcreteOpType<"linalg .pack">:$target,
563
584
DefaultValuedAttr<BoolAttr, "true">:$lowerPadLikeWithInsertSlice);
564
585
let results = (outs Transform_ConcreteOpType<"tensor.pad">:$pad_op,
565
586
Transform_ConcreteOpType<"tensor.expand_shape">:$expand_shape_op,
@@ -571,7 +592,7 @@ def LowerPackOp : Op<Transform_Dialect, "structured.lower_pack", [
571
592
let extraClassDeclaration = [{
572
593
::mlir::DiagnosedSilenceableFailure applyToOne(
573
594
::mlir::transform::TransformRewriter &rewriter,
574
- ::mlir::tensor ::PackOp target,
595
+ ::mlir::linalg ::PackOp target,
575
596
::mlir::transform::ApplyToEachResultList &transformResults,
576
597
::mlir::transform::TransformState &state);
577
598
}];
@@ -587,20 +608,19 @@ def LowerUnPackOp : Op<Transform_Dialect, "structured.lower_unpack", [
587
608
TransformOpInterface,
588
609
ReportTrackingListenerFailuresOpTrait]> {
589
610
let description = [{
590
- Lower a tensor .unpack into empty + linalg.transpose + tensor.collapse_shape +
611
+ Lower a linalg .unpack into empty + linalg.transpose + tensor.collapse_shape +
591
612
tensor.extract_slice.
592
613
593
614
#### Return modes
594
615
595
- This operation ignores non-unpack ops and drops them in the return.
596
- This operation produces a silenceable failure if the rewrite fails for any
597
- reason.
598
- If all the operations referred to by the `target` are rewritten, the
599
- transform succeeds.
600
- Return handles to the newly produced empty, transpose, collapse_shape and extract_slice ops.
616
+ This operation ignores non-unpack ops and drops them in the return. This
617
+ operation produces a silenceable failure if the rewrite fails for any
618
+ reason. If all the operations referred to by the `target` are rewritten,
619
+ the transform succeeds. Return handles to the newly produced empty,
620
+ transpose, collapse_shape and extract_slice ops.
601
621
}];
602
622
603
- let arguments = (ins Transform_ConcreteOpType<"tensor .unpack">:$target,
623
+ let arguments = (ins Transform_ConcreteOpType<"linalg .unpack">:$target,
604
624
DefaultValuedAttr<BoolAttr, "true">:$lowerUnpadLikeWithExtractSlice);
605
625
let results = (outs Transform_ConcreteOpType<"tensor.empty">:$empty_op,
606
626
Transform_ConcreteOpType<"linalg.transpose">:$transpose_op,
@@ -613,7 +633,7 @@ def LowerUnPackOp : Op<Transform_Dialect, "structured.lower_unpack", [
613
633
let extraClassDeclaration = [{
614
634
::mlir::DiagnosedSilenceableFailure applyToOne(
615
635
::mlir::transform::TransformRewriter &rewriter,
616
- ::mlir::tensor ::UnPackOp target,
636
+ ::mlir::linalg ::UnPackOp target,
617
637
::mlir::transform::ApplyToEachResultList &transformResults,
618
638
::mlir::transform::TransformState &state);
619
639
}];
@@ -791,7 +811,7 @@ def PackOp : Op<Transform_Dialect, "structured.pack", [
791
811
Specifying a packed size of 0 for an iterator removes it from consideration
792
812
for packing.
793
813
794
- `tensor .pack` (resp. `tensor .unpack`) operations are inserted for the operands
814
+ `linalg .pack` (resp. `linalg .unpack`) operations are inserted for the operands
795
815
(resp. results) that need to be packed (resp. unpacked) according to the
796
816
`packed_sizes` specification.
797
817
@@ -980,7 +1000,7 @@ def PackTransposeOp : Op<Transform_Dialect, "structured.pack_transpose", [
980
1000
DeclareOpInterfaceMethods<TransformOpInterface>,
981
1001
ReportTrackingListenerFailuresOpTrait]> {
982
1002
let description = [{
983
- Apply a transposition to a single `tensor .pack` (resp. `tensor .unpack`) and
1003
+ Apply a transposition to a single `linalg .pack` (resp. `linalg .unpack`) and
984
1004
update the `linalg.generic` op that consumes (resp. produces) the operation.
985
1005
986
1006
This transform allows composing a simple `structured.pack` with additional
@@ -989,19 +1009,19 @@ def PackTransposeOp : Op<Transform_Dialect, "structured.pack_transpose", [
989
1009
990
1010
The transpose spec must specify at least one of `outer_perm` or `inner_perm`
991
1011
attributes, which will act upon the `outer_dims_perm` or `inner_dims_pos` of
992
- the specified `tensor .pack` or `tensor .unpack` op.
1012
+ the specified `linalg .pack` or `linalg .unpack` op.
993
1013
994
- If the `target` of this op is a `tensor .pack` then a new `tensor.empty` will
995
- be created along with transposed versions of the `tensor .pack` and the
1014
+ If the `target` of this op is a `linalg .pack` then a new `tensor.empty` will
1015
+ be created along with transposed versions of the `linalg .pack` and the
996
1016
consuming `linalg.generic`, which is expected to be the sole consumer.
997
1017
998
- If the `target` of this op is a `tensor .unpack` then the whole pack / compute
999
- / unpack chain will be transposed and transposed clones of `tensor .pack`,
1000
- the consuming `linalg.generic` and the tail `tensor .pack` will be created.
1018
+ If the `target` of this op is a `linalg .unpack` then the whole pack / compute
1019
+ / unpack chain will be transposed and transposed clones of `linalg .pack`,
1020
+ the consuming `linalg.generic` and the tail `linalg .pack` will be created.
1001
1021
1002
1022
#### Return modes
1003
1023
1004
- This operation targets a single `tensor .pack` / `tensor .unpack` op and a
1024
+ This operation targets a single `linalg .pack` / `linalg .unpack` op and a
1005
1025
single matching `linalg.generic` that consumes / produces the op. Otherwise,
1006
1026
it produces a silenceableFailure.
1007
1027
@@ -1011,9 +1031,9 @@ def PackTransposeOp : Op<Transform_Dialect, "structured.pack_transpose", [
1011
1031
reason.
1012
1032
1013
1033
This operation returns 3 handles, one to the transformed LinalgOp, one to
1014
- the transformed `tensor .pack` and one to the transformed `tensor .unpack`.
1015
- The last handle for `tensor .unpack` is empty if `target_pack_or_unpack_op`
1016
- was not itself a `tensor .unpack`.
1034
+ the transformed `linalg .pack` and one to the transformed `linalg .unpack`.
1035
+ The last handle for `linalg .unpack` is empty if `target_pack_or_unpack_op`
1036
+ was not itself a `linalg .unpack`.
1017
1037
}];
1018
1038
1019
1039
let arguments = (ins TransformHandleTypeInterface:$target_pack_or_un_pack_op,
@@ -1143,7 +1163,7 @@ def HoistPadBuildPackingLoopNestOp :
1143
1163
creates the packing loop nest required by the hoist_pad operation and makes
1144
1164
that functionality available independently.
1145
1165
1146
- TODO: In the future, we should consider rewriting as a tensor .pack after
1166
+ TODO: In the future, we should consider rewriting as a linalg .pack after
1147
1167
hoisting since this abstraction is now available.
1148
1168
1149
1169
#### Return modes
@@ -1182,7 +1202,7 @@ def HoistPadOp : Op<Transform_Dialect, "structured.hoist_pad",
1182
1202
Hoist the tensor.pad target operation by at most the given number of loops.
1183
1203
Optionally apply the transpose attribute to the inner dimensions.
1184
1204
1185
- TODO: In the future, we should consider rewriting as a tensor .pack after
1205
+ TODO: In the future, we should consider rewriting as a linalg .pack after
1186
1206
hoisting since this abstraction is now available.
1187
1207
TODO: Maybe also return the linalg.generic transpose created at some point.
1188
1208
0 commit comments