Skip to content

Commit fab2366

Browse files
committed
address review comments
Mostly renaming and restructuring of code and tests.
1 parent 975a4f6 commit fab2366

File tree

6 files changed

+45
-41
lines changed

6 files changed

+45
-41
lines changed

mlir/include/mlir/Dialect/Linalg/Passes.td

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,29 +100,30 @@ def LinalgMorphOpsPass : Pass<"linalg-morph-ops"> {
100100

101101
named-op <--> category_op (elementwise, contraction, ..) <--> generic
102102

103-
Generic is a bigger set than named and category ops and so not all generics
104-
can be converted to single category-op or named-op. Similarly, category
105-
ops are bigger set than named ops.
103+
Note that the set of `linalg.generic` subsumes named and category ops
104+
and therefore not all `linalg.genric` can be converted to named or
105+
category op. Similarly, catgory ops subsume named ops.
106106

107107
Note:
108-
Legacy converters (will be deprecated):
108+
Legacy converters:
109109
`--linalg-generalize-named-ops` is the path `named-op --> generic-op`
110110
`--linalg-specialize-generic-ops` is the path `named-op <-- generic-op`
111111
}];
112112
let dependentDialects = ["linalg::LinalgDialect"];
113113

114114
let options = [
115115
// named-op <--> category <--> generic
116+
117+
// Lowering options
116118
Option<"namedToCategory", "named-to-category", "bool", /*default=*/"false",
117119
"convert named ops to category op e.g. `linalg.elementwise`">,
118120
Option<"categoryToGeneric", "category-to-generic", "bool", /*default=*/"false",
119121
"convert category ops e.g. `linalg.elementwise` to `linalg.generic`">,
120122
Option<"namedToGeneric", "named-to-generic", "bool", /*default=*/"false",
121123
"convert named ops e.g. `linalg.add` to `linalg.generic`">,
122-
Option<"genericToCategory", "generic-to-category", "bool", /*default=*/"false",
123-
"convert generic ops to category op e.g. `linalg.contraction`">,
124-
Option<"categoryToNamed", "category-to-named", "bool", /*default=*/"false",
125-
"convert category ops to equivalent named ops">,
124+
125+
// Lifting options
126+
// TODOs: `generic-to-category`, `category-to-named`
126127
Option<"genericToNamed", "generic-to-named", "bool", /*default=*/"false",
127128
"convert linalg.generic to equivalent named ops"> ];
128129
}

mlir/lib/Dialect/Linalg/Transforms/MorphOps.cpp

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,8 @@
66
//
77
//===----------------------------------------------------------------------===//
88
//
9-
// This file implements conversions between:
10-
// named <--> category (elementwise, contraction, ..) <--> generic ops.
11-
//
12-
// For example, a named op such `linalg.add` can also be re-written as an
13-
// equivalent category op `linalg.elementwise` and also as a `linalg.generic`.
14-
//
15-
// Generic is a bigger set than named ops and so not all generics can be
16-
// converted to single category-op or named-op. Similarly, category-ops
17-
// are bigger in representational possiblities than named ops e.g.
18-
// `linalg.add` has no affine maps attached, but `linalg.elementwise` does.
19-
//
20-
// Note:
21-
// Legacy converters (will be deprecated):
22-
// `--linalg-generalize-named-ops` is the path `named-op --> generic-op`
23-
// `--linalg-specialize-generic-ops` is the path `named-op <-- generic-op`
9+
// This file implements conversions between linalg ops:
10+
// named <--> category (elementwise, contraction, ..) <--> generic.
2411
//===----------------------------------------------------------------------===//
2512

2613
#include "mlir/Dialect/Complex/IR/Complex.h"
@@ -58,20 +45,13 @@ void LinalgMorphOpsPass::runOnOperation() {
5845

5946
// Lowering paths (named -> category -> generic)
6047
if (namedToCategory) {
61-
// TODO: named -> contraction-op
6248
populateLinalgNamedToElementwisePatterns(patterns);
6349
}
6450
if (namedToGeneric || categoryToGeneric) {
6551
populateLinalgNamedOpsGeneralizationPatterns(patterns);
6652
}
6753

6854
// Lifting paths (named <- category <- generic)
69-
if (genericToCategory) {
70-
// TODO.
71-
}
72-
if (categoryToNamed) {
73-
// TODO: if there is a case for this.
74-
}
7555
if (genericToNamed) {
7656
populateLinalgGenericOpsSpecializationPatterns(patterns);
7757
}

mlir/lib/Dialect/Linalg/Transforms/NamedToElementwise.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ struct NamedToElementwisePattern : public OpRewritePattern<NamedOpTy> {
7575

7676
void mlir::linalg::populateLinalgNamedToElementwisePatterns(
7777
RewritePatternSet &patterns) {
78+
patterns.add<NamedToElementwisePattern<SelectOp>>(patterns.getContext());
7879
patterns.add<NamedToElementwisePattern<AddOp>>(patterns.getContext());
7980
patterns.add<NamedToElementwisePattern<SubOp>>(patterns.getContext());
8081
patterns.add<NamedToElementwisePattern<MulOp>>(patterns.getContext());

mlir/test/Dialect/Linalg/elementwise/named_to_elementwise.mlir renamed to mlir/test/Dialect/Linalg/elementwise/named-to-elementwise.mlir

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,21 @@ func.func @sub(%A : memref<16x8xf32>, %B: memref<16x8xf32>, %C : memref<16x8xf32
3636
linalg.sub ins(%A, %B : memref<16x8xf32>, memref<16x8xf32>) outs(%C : memref<16x8xf32>)
3737
return
3838
}
39+
40+
// ----
41+
42+
// CHECK: @ternary_select(%[[A:.+]]: tensor<4x8x16xi1>, %[[B:.+]]: tensor<4x8x16xf32>, %[[C:.+]]: tensor<4x8x16xf32>)
43+
// CHECK: %[[E:.+]] = tensor.empty() : tensor<4x8x16xf32>
44+
// CHECK: {{.*}} = linalg.elementwise
45+
// CHECK-SAME: kind=#linalg.elementwise_kind<select>
46+
// CHECK-SAME: ins(%[[A]], %[[B]], %[[C]] : tensor<4x8x16xi1>, tensor<4x8x16xf32>, tensor<4x8x16xf32>)
47+
// CHECK-SAME: outs(%[[E]] : tensor<4x8x16xf32>) -> tensor<4x8x16xf32>
48+
//
49+
func.func @ternary_select(%A: tensor<4x8x16xi1>, %B: tensor<4x8x16xf32>, %C: tensor<4x8x16xf32>)
50+
-> tensor<4x8x16xf32> {
51+
%empty = tensor.empty() : tensor<4x8x16xf32>
52+
%select = linalg.select
53+
ins(%A, %B, %C : tensor<4x8x16xi1>, tensor<4x8x16xf32>, tensor<4x8x16xf32>)
54+
outs(%empty: tensor<4x8x16xf32>) -> tensor<4x8x16xf32>
55+
return %select : tensor<4x8x16xf32>
56+
}
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
// Forward path `named -> category -> generic`
22
// RUN: mlir-opt %s -linalg-morph-ops=named-to-category | FileCheck %s --check-prefix=NAMED_TO_CATEGORY
3-
// RUN: mlir-opt %s -linalg-morph-ops=named-to-generic | FileCheck %s --check-prefix=NAMED_TO_GENERIC
3+
44
// RUN: mlir-opt %s -linalg-morph-ops=named-to-category | \
55
// RUN: mlir-opt %s -linalg-morph-ops=category-to-generic | FileCheck %s --check-prefix=CATEGORY_TO_GENERIC
6-
//
7-
// Backward path `named <- category <- generic`
8-
// RUN: mlir-opt %s -linalg-morph-ops=named-to-generic | mlir-opt %s -linalg-morph-ops=generic-to-named | \
9-
// RUN: FileCheck %s --check-prefix=GENERIC_TO_NAMED
106

117
func.func @exp(%A : tensor<16x8xf32>, %B : tensor<16x8xf32>) -> tensor<16x8xf32> {
128
%exp = linalg.exp ins(%A : tensor<16x8xf32>) outs(%B : tensor<16x8xf32>) -> tensor<16x8xf32>
@@ -15,11 +11,5 @@ func.func @exp(%A : tensor<16x8xf32>, %B : tensor<16x8xf32>) -> tensor<16x8xf32
1511
// NAMED_TO_CATEGORY: linalg.elementwise
1612
// NAMED_TO_CATEGORY-NOT: linalg.exp
1713

18-
// NAMED_TO_GENERIC: linalg.generic
19-
// NAMED_TO_GENERIC-NOT: linalg.exp
20-
2114
// CATEGORY_TO_GENERIC: linalg.generic
2215
// CATEGORY_TO_GENERIC-NOT: linalg.elementwise
23-
24-
// GENERIC_TO_NAMED: linalg.exp
25-
// GENERIC_TO_NAMED-NOT: linalg.generic
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// RUN: mlir-opt %s -linalg-morph-ops=named-to-generic | FileCheck %s --check-prefix=NAMED_TO_GENERIC
2+
// RUN: mlir-opt %s -linalg-morph-ops=named-to-generic | mlir-opt %s -linalg-morph-ops=generic-to-named | \
3+
// RUN: FileCheck %s --check-prefix=GENERIC_TO_NAMED
4+
5+
func.func @exp(%A : tensor<16x8xf32>, %B : tensor<16x8xf32>) -> tensor<16x8xf32> {
6+
%exp = linalg.exp ins(%A : tensor<16x8xf32>) outs(%B : tensor<16x8xf32>) -> tensor<16x8xf32>
7+
return %exp : tensor<16x8xf32>
8+
}
9+
10+
// NAMED_TO_GENERIC: linalg.generic
11+
// NAMED_TO_GENERIC-NOT: linalg.exp
12+
13+
// GENERIC_TO_NAMED: linalg.exp
14+
// GENERIC_TO_NAMED-NOT: linalg.generic

0 commit comments

Comments
 (0)