Skip to content

Commit 33a7435

Browse files
committed
replacing elemwise_* with named ops
1 parent dbf7930 commit 33a7435

8 files changed

+62
-259
lines changed

mlir/test/Dialect/Linalg/generalize-named-polymorphic-ops.mlir

Lines changed: 0 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -434,117 +434,6 @@ func.func @generalize_const(%min: f64, %max: f64, %seed: i32, %O: tensor<16x32xf
434434

435435
// -----
436436

437-
// Verifies the default value of the fun attribute is an exp op.
438-
func.func @generalize_elemwise_exp(%lhs : tensor<4x8xf32>, %output : tensor<4x8xf32>) -> tensor<4x8xf32> {
439-
%0 = linalg.elemwise_unary ins(%lhs: tensor<4x8xf32>) outs(%output: tensor<4x8xf32>) -> tensor<4x8xf32>
440-
return %0: tensor<4x8xf32>
441-
}
442-
443-
// CHECK-LABEL: @generalize_elemwise_exp
444-
// CHECK: = math.exp
445-
446-
// -----
447-
448-
// Verifies the fun attribute controls the unary function used.
449-
func.func @generalize_elemwise_log(%lhs : tensor<4x8xf32>, %output : tensor<4x8xf32>) -> tensor<4x8xf32> {
450-
%0 = linalg.elemwise_unary {fun = #linalg.unary_fn<log>}
451-
ins(%lhs: tensor<4x8xf32>) outs(%output: tensor<4x8xf32>) -> tensor<4x8xf32>
452-
return %0: tensor<4x8xf32>
453-
}
454-
455-
// CHECK-LABEL: @generalize_elemwise_log
456-
// CHECK: = math.log
457-
458-
// -----
459-
460-
// Verifies the fun attribute controls the unary function used.
461-
func.func @generalize_elemwise_abs(%lhs : tensor<4x8xf32>, %output : tensor<4x8xf32>) -> tensor<4x8xf32> {
462-
%0 = linalg.elemwise_unary {fun = #linalg.unary_fn<abs>}
463-
ins(%lhs: tensor<4x8xf32>) outs(%output: tensor<4x8xf32>) -> tensor<4x8xf32>
464-
return %0: tensor<4x8xf32>
465-
}
466-
467-
// CHECK-LABEL: @generalize_elemwise_abs
468-
// CHECK: = math.absf
469-
470-
// -----
471-
472-
// Verifies the fun attribute controls the unary function used.
473-
func.func @generalize_elemwise_ceil(%lhs : tensor<4x8xf32>, %output : tensor<4x8xf32>) -> tensor<4x8xf32> {
474-
%0 = linalg.elemwise_unary {fun = #linalg.unary_fn<ceil>}
475-
ins(%lhs: tensor<4x8xf32>) outs(%output: tensor<4x8xf32>) -> tensor<4x8xf32>
476-
return %0: tensor<4x8xf32>
477-
}
478-
479-
// CHECK-LABEL: @generalize_elemwise_ceil
480-
// CHECK: = math.ceil
481-
482-
// -----
483-
484-
// Verifies the fun attribute controls the unary function used.
485-
func.func @generalize_elemwise_floor(%lhs : tensor<4x8xf32>, %output : tensor<4x8xf32>) -> tensor<4x8xf32> {
486-
%0 = linalg.elemwise_unary {fun = #linalg.unary_fn<floor>}
487-
ins(%lhs: tensor<4x8xf32>) outs(%output: tensor<4x8xf32>) -> tensor<4x8xf32>
488-
return %0: tensor<4x8xf32>
489-
}
490-
491-
// CHECK-LABEL: @generalize_elemwise_floor
492-
// CHECK: = math.floor
493-
494-
// -----
495-
496-
// Verifies the fun attribute controls the unary function used.
497-
func.func @generalize_elemwise_negf(%lhs : tensor<4x8xf32>, %output : tensor<4x8xf32>) -> tensor<4x8xf32> {
498-
%0 = linalg.elemwise_unary {fun = #linalg.unary_fn<negf>}
499-
ins(%lhs: tensor<4x8xf32>) outs(%output: tensor<4x8xf32>) -> tensor<4x8xf32>
500-
return %0: tensor<4x8xf32>
501-
}
502-
503-
// CHECK-LABEL: @generalize_elemwise_negf
504-
// CHECK: = arith.negf
505-
506-
// -----
507-
508-
// Verifies the default value of the fun attribute is an add op.
509-
func.func @generalize_elemwise_add(%lhs : tensor<4x8xf32>, %rhs : tensor<4x8xf32>, %output : tensor<4x8xf32>) -> tensor<4x8xf32> {
510-
%0 = linalg.elemwise_binary ins(%lhs, %rhs: tensor<4x8xf32>, tensor<4x8xf32>)
511-
outs(%output: tensor<4x8xf32>) -> tensor<4x8xf32>
512-
return %0: tensor<4x8xf32>
513-
}
514-
515-
// CHECK-LABEL: @generalize_elemwise_add
516-
// CHECK: = arith.addf
517-
518-
// -----
519-
520-
// Verifies the fun attribute controls the binary function used.
521-
func.func @generalize_elemwise_mul(%lhs : tensor<4x8xf32>, %rhs : tensor<4x8xf32>, %output : tensor<4x8xf32>) -> tensor<4x8xf32> {
522-
%0 = linalg.elemwise_binary {fun = #linalg.binary_fn<mul>}
523-
ins(%lhs, %rhs: tensor<4x8xf32>, tensor<4x8xf32>)
524-
outs(%output: tensor<4x8xf32>) -> tensor<4x8xf32>
525-
return %0: tensor<4x8xf32>
526-
}
527-
528-
// CHECK-LABEL: @generalize_elemwise_mul
529-
// CHECK: = arith.mulf
530-
531-
// -----
532-
533-
// Verifies pointwise ops support rank zero input tensors
534-
func.func @generalize_elemwise_rank_zero(%lhs : tensor<f32>, %rhs : tensor<f32>, %output : tensor<4x8xf32>) -> tensor<4x8xf32> {
535-
%0 = linalg.elemwise_binary {fun = #linalg.binary_fn<sub>}
536-
ins(%lhs, %rhs: tensor<f32>, tensor<f32>)
537-
outs(%output: tensor<4x8xf32>) -> tensor<4x8xf32>
538-
return %0: tensor<4x8xf32>
539-
}
540-
541-
// CHECK-LABEL: @generalize_elemwise_rank_zero
542-
// CHECK: linalg.generic
543-
// CHECK-SAME: iterator_types = ["parallel", "parallel"]
544-
// CHECK: = arith.subf
545-
546-
// -----
547-
548437
// Verifies the fun attribute controls the binary function used.
549438
func.func @generalize_copy(%lhs : tensor<4x8xf32>, %output : tensor<4x8xf32>) -> tensor<4x8xf32> {
550439
%0 = linalg.copy ins(%lhs: tensor<4x8xf32>) outs(%output: tensor<4x8xf32>) -> tensor<4x8xf32>

mlir/test/Dialect/Linalg/invalid.mlir

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1909,14 +1909,6 @@ module {
19091909

19101910
// -----
19111911

1912-
func.func @elemwise_unary_invalid_mixed_types(%arg0 : tensor<?xi32>) -> tensor<?xi32> {
1913-
// expected-error @below {{unsupported non numeric type}}
1914-
%0 = linalg.elemwise_unary ins(%arg0 : tensor<?xi32>) outs(%arg0 : tensor<?xi32>) -> tensor<?xi32>
1915-
return %0 : tensor<?xi32>
1916-
}
1917-
1918-
// -----
1919-
19201912
func.func @matmul_invalid_mixed_types(%t: tensor<?xf16>, %f: vector<4xf16>)
19211913
-> (tensor<?xf16>, vector<4xf16>)
19221914
{

mlir/test/Dialect/Linalg/library-calls.mlir

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -59,43 +59,3 @@ module {
5959
return
6060
}
6161
}
62-
63-
64-
// -----
65-
66-
// CHECK: func.func private @linalg_elemwise_unary_negf_view16x8xf32_view16x8xf32(memref<16x8xf32, strided<[?, ?], offset: ?>>, memref<16x8xf32, strided<[?, ?], offset: ?>>) attributes {llvm.emit_c_interface}
67-
// CHECK: func.func private @linalg_elemwise_unary_negf_view16xf32_view16xf32(memref<16xf32, strided<[?], offset: ?>>, memref<16xf32, strided<[?], offset: ?>>) attributes {llvm.emit_c_interface}
68-
69-
func.func @test_neg(%A : memref<16x8xf32>, %B: memref<16x8xf32>, %C: memref<16xf32>, %D: memref<16xf32>) {
70-
linalg.elemwise_unary {fun = #linalg.unary_fn<negf>}
71-
ins(%A: memref<16x8xf32>) outs(%B: memref<16x8xf32>)
72-
linalg.elemwise_unary {fun = #linalg.unary_fn<negf>}
73-
ins(%C: memref<16xf32>) outs(%D: memref<16xf32>)
74-
return
75-
}
76-
77-
// -----
78-
79-
// CHECK: func.func private @linalg_elemwise_unary_exp_view16x8xf32_view16x8xf32(memref<16x8xf32, strided<[?, ?], offset: ?>>, memref<16x8xf32, strided<[?, ?], offset: ?>>) attributes {llvm.emit_c_interface}
80-
// CHECK: func.func private @linalg_elemwise_unary_exp_view16xf32_view16xf32(memref<16xf32, strided<[?], offset: ?>>, memref<16xf32, strided<[?], offset: ?>>) attributes {llvm.emit_c_interface}
81-
82-
func.func @test_exp(%A : memref<16x8xf32>, %B: memref<16x8xf32>, %C: memref<16xf32>, %D: memref<16xf32>) {
83-
linalg.elemwise_unary {fun = #linalg.unary_fn<exp>}
84-
ins(%A: memref<16x8xf32>) outs(%B: memref<16x8xf32>)
85-
linalg.elemwise_unary {fun = #linalg.unary_fn<exp>}
86-
ins(%C: memref<16xf32>) outs(%D: memref<16xf32>)
87-
return
88-
}
89-
90-
// -----
91-
92-
// CHECK: func.func private @linalg_elemwise_binary_add_view16x8xf32_view16x8xf32_view16x8xf32(memref<16x8xf32, strided<[?, ?], offset: ?>>, memref<16x8xf32, strided<[?, ?], offset: ?>>, memref<16x8xf32, strided<[?, ?], offset: ?>>) attributes {llvm.emit_c_interface}
93-
// CHECK: func.func private @linalg_elemwise_binary_add_view16xf32_view16xf32_view16xf32(memref<16xf32, strided<[?], offset: ?>>, memref<16xf32, strided<[?], offset: ?>>, memref<16xf32, strided<[?], offset: ?>>) attributes {llvm.emit_c_interface}
94-
95-
func.func @test_add(%A : memref<16x8xf32>, %B: memref<16x8xf32>, %C: memref<16x8xf32>, %D: memref<16xf32>, %E: memref<16xf32>, %F: memref<16xf32>) {
96-
linalg.elemwise_binary {fun = #linalg.binary_fn<add>}
97-
ins(%A, %B: memref<16x8xf32>, memref<16x8xf32>) outs(%C: memref<16x8xf32>)
98-
linalg.elemwise_binary {fun = #linalg.binary_fn<add>}
99-
ins(%D, %E: memref<16xf32>, memref<16xf32>) outs(%F: memref<16xf32>)
100-
return
101-
}

mlir/test/Dialect/Linalg/match-ops-interpreter.mlir

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -842,15 +842,15 @@ module attributes { transform.with_named_sequence } {
842842
// expected-remark @below {{op result}}
843843
// expected-note @below {{value handle points to an op result #0}}
844844
// expected-remark @below {{single user}}
845-
linalg.elemwise_unary {fun = #linalg.unary_fn<negf>} ins(%2 : tensor<42x42xf32>) outs(%0 : tensor<42x42xf32>) -> tensor<42x42xf32>
845+
linalg.negf ins(%2 : tensor<42x42xf32>) outs(%0 : tensor<42x42xf32>) -> tensor<42x42xf32>
846846
// expected-remark @below {{matched result value}}
847847
// expected-remark @below {{op result}}
848848
// expected-note @below {{value handle points to an op result #0}}
849-
linalg.elemwise_unary {fun = #linalg.unary_fn<exp>} ins(%3 : tensor<42x42xf32>) outs(%0 : tensor<42x42xf32>) -> tensor<42x42xf32>
849+
linalg.exp ins(%3 : tensor<42x42xf32>) outs(%0 : tensor<42x42xf32>) -> tensor<42x42xf32>
850850
// expected-remark @below {{matched result value}}
851851
// expected-remark @below {{op result}}
852852
// expected-note @below {{value handle points to an op result #0}}
853-
linalg.elemwise_unary {fun = #linalg.unary_fn<exp>} ins(%3 : tensor<42x42xf32>) outs(%0 : tensor<42x42xf32>) -> tensor<42x42xf32>
853+
linalg.exp ins(%3 : tensor<42x42xf32>) outs(%0 : tensor<42x42xf32>) -> tensor<42x42xf32>
854854
return
855855
}
856856
}

mlir/test/Dialect/Linalg/one-shot-bufferize-analysis.mlir

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,5 @@
11
// RUN: mlir-opt %s -one-shot-bufferize="bufferize-function-boundaries test-analysis-only" -split-input-file | FileCheck %s
22

3-
// CHECK-LABEL: @elementwise_no_conflict
4-
func.func @elementwise_no_conflict(%a: tensor<5xf32>,
5-
%b: tensor<5xf32>) -> tensor<5xf32> {
6-
// CHECK: linalg.elemwise_binary
7-
// CHECK-SAME: {__inplace_operands_attr__ = ["true", "true", "true"], fun = #linalg.binary_fn<add>}
8-
%0 = linalg.elemwise_binary {fun = #linalg.binary_fn<add>}
9-
ins(%a, %b : tensor<5xf32>, tensor<5xf32>)
10-
outs(%a : tensor<5xf32>) -> tensor<5xf32>
11-
return %0 : tensor<5xf32>
12-
}
13-
14-
// -----
15-
16-
// CHECK-LABEL: @elementwise_no_conflict_2
17-
func.func @elementwise_no_conflict_2(%a: tensor<5xf32>) -> tensor<5xf32> {
18-
// CHECK: linalg.elemwise_binary
19-
// CHECK-SAME: {__inplace_operands_attr__ = ["true", "true", "true"], fun = #linalg.binary_fn<add>}
20-
%0 = linalg.elemwise_binary {fun = #linalg.binary_fn<add>}
21-
ins(%a, %a : tensor<5xf32>, tensor<5xf32>)
22-
outs(%a : tensor<5xf32>) -> tensor<5xf32>
23-
return %0 : tensor<5xf32>
24-
}
25-
26-
// -----
27-
28-
// CHECK-LABEL: @elementwise_no_conflict_3
29-
func.func @elementwise_no_conflict_3(%a: tensor<5xf32>) -> tensor<5xf32> {
30-
%c0f = arith.constant 1.0 : f32
31-
// CHECK: linalg.elemwise_binary
32-
// CHECK-SAME: {__inplace_operands_attr__ = ["true", "none", "true"], fun = #linalg.binary_fn<add>}
33-
%0 = linalg.elemwise_binary {fun = #linalg.binary_fn<add>}
34-
ins(%a, %c0f : tensor<5xf32>, f32)
35-
outs(%a : tensor<5xf32>) -> tensor<5xf32>
36-
return %0 : tensor<5xf32>
37-
}
38-
39-
// -----
40-
413
func.func @not_elementwise(%a: tensor<5x6xf32>) -> tensor<5x6xf32> {
424
%cst = arith.constant 5.0 : f32
435
// CHECK: tensor.extract_slice

0 commit comments

Comments
 (0)