Skip to content

Commit c2f52bc

Browse files
committed
add linalg.elementwise test
1 parent 5280b87 commit c2f52bc

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

mlir/test/Dialect/Linalg/fusion-elementwise.mlir

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ func.func @handle_unused_operands(%arg0: tensor<8xf32>, %arg1: tensor<8xf32>) ->
6565
func.func @map_ops(%in1: tensor<8xf32>, %in2: tensor<8xf32>) -> tensor<8xf32> {
6666
%fill = tensor.empty() : tensor<8xf32>
6767
%add = linalg.map {arith.addf} ins(%in1, %in2: tensor<8xf32>, tensor<8xf32>) outs(%fill: tensor<8xf32>)
68-
%mapped_65 = linalg.map { math.sqrt } ins(%add : tensor<8xf32>) outs(%fill : tensor<8xf32>)
69-
return %mapped_65 : tensor<8xf32>
68+
%sqrt = linalg.map { math.sqrt } ins(%add : tensor<8xf32>) outs(%fill : tensor<8xf32>)
69+
return %sqrt : tensor<8xf32>
7070
}
7171

7272
// CHECK-LABEL: func @map_ops
@@ -113,3 +113,27 @@ func.func @map_ops_mixed_types(%arg0: tensor<8xf32>, %arg1: tensor<8xf32>) -> te
113113
// CHECK-NEXT: linalg.yield %[[RES]]
114114
// CHECK-NOT: linalg.map
115115

116+
// -----
117+
118+
func.func @elementwise_ops(%in1: tensor<8xf32>, %in2: tensor<8xf32>) -> tensor<8xf32> {
119+
%fill = tensor.empty() : tensor<8xf32>
120+
%add = linalg.elementwise
121+
kind=#linalg.elementwise_kind<add>
122+
ins(%in1, %in2: tensor<8xf32>, tensor<8xf32>) outs(%fill: tensor<8xf32>) -> tensor<8xf32>
123+
%wqrt = linalg.elementwise
124+
kind=#linalg.elementwise_kind<sqrt>
125+
ins(%add : tensor<8xf32>) outs(%fill : tensor<8xf32>) -> tensor<8xf32>
126+
return %wqrt : tensor<8xf32>
127+
}
128+
129+
// CHECK-LABEL: func @elementwise_ops
130+
// CHECK-SAME: %[[ARG0:[a-zA-Z0-9]+]]: tensor<8xf32>
131+
// CHECK-SAME: %[[ARG1:[a-zA-Z0-9]+]]: tensor<8xf32>
132+
// CHECK: %[[EMPTY:.+]] = tensor.empty() : tensor<8xf32>
133+
// CHECK: %[[FUSED_OP:.+]] = linalg.generic
134+
// CHECK-SAME: ins(%[[ARG0]], %[[ARG1]] : {{.*}}) outs(%[[EMPTY]] :
135+
// CHECK-NEXT: ^bb0(%[[IN0:.*]]: f32, %[[IN1:.*]]: f32, %[[OUT:.*]]: f32):
136+
// CHECK-NEXT: %[[ADD:.*]] = arith.addf %[[IN0]], %[[IN1]]
137+
// CHECK-NEXT: %[[SQRT:.*]] = math.sqrt %[[ADD]]
138+
// CHECK-NEXT: linalg.yield %[[SQRT]]
139+
// CHECK-NOT: linalg.map

0 commit comments

Comments
 (0)