|
| 1 | +// RUN: tf-opt --split-input-file --tf-to-tosa-pipeline --verify-each %s | FileCheck %s |
| 2 | + |
| 3 | +// Test tf legalization that produce TOSA ResultsBroadcastableShape operators with unequal ranks |
| 4 | + |
| 5 | +// ----- |
| 6 | + |
| 7 | +// CHECK-LABEL: test_add |
| 8 | +func.func @test_add(%arg0: tensor<13x21x1xf32>, %arg1: tensor<1x13x21x3xf32>) -> tensor<*xf32> { |
| 9 | + // CHECK: tosa.add |
| 10 | + %2 = "tf.Add"(%arg0, %arg1) : (tensor<13x21x1xf32>, tensor<1x13x21x3xf32>) -> tensor<*xf32> |
| 11 | + func.return %2 : tensor<*xf32> |
| 12 | +} |
| 13 | + |
| 14 | +// ----- |
| 15 | + |
| 16 | +// CHECK-LABEL: test_add |
| 17 | +func.func @test_addn(%arg0: tensor<13x21x1xf32>, %arg1: tensor<1x13x21x3xf32>, %arg2: tensor<21x3xf32>, %arg3: tensor<3xf32>) -> tensor<*xf32> { |
| 18 | + // CHECK: tosa.add |
| 19 | + // CHECK: tosa.add |
| 20 | + // CHECK: tosa.add |
| 21 | + %2 = "tf.AddN"(%arg0, %arg1, %arg2, %arg3) : (tensor<13x21x1xf32>, tensor<1x13x21x3xf32>, tensor<21x3xf32>, tensor<3xf32>) -> tensor<*xf32> |
| 22 | + func.return %2 : tensor<*xf32> |
| 23 | +} |
| 24 | + |
| 25 | +// ----- |
| 26 | + |
| 27 | +// CHECK-LABEL: test_bitwise_and |
| 28 | +func.func @test_bitwise_and(%arg0: tensor<8x13x21x3xi32>, %arg1: tensor<13x21x1xi32>) -> tensor<8x13x21x3xi32> { |
| 29 | + // CHECK: tosa.bitwise_and |
| 30 | + %2 = "tf.BitwiseAnd"(%arg0, %arg1) : (tensor<8x13x21x3xi32>, tensor<13x21x1xi32>) -> tensor<8x13x21x3xi32> |
| 31 | + func.return %2 : tensor<8x13x21x3xi32> |
| 32 | +} |
| 33 | + |
| 34 | +// ----- |
| 35 | + |
| 36 | +// CHECK-LABEL: test_sub |
| 37 | +func.func @test_sub(%arg0: tensor<13x21x1xf32>, %arg1: tensor<1x13x21x3xf32>) -> tensor<*xf32> { |
| 38 | + // CHECK: tosa.sub |
| 39 | + %2 = "tf.Sub"(%arg0, %arg1) : (tensor<13x21x1xf32>, tensor<1x13x21x3xf32>) -> tensor<*xf32> |
| 40 | + func.return %2 : tensor<*xf32> |
| 41 | +} |
| 42 | + |
| 43 | +// ----- |
| 44 | + |
| 45 | +// CHECK-LABEL: test_bitwise_or |
| 46 | +func.func @test_bitwise_or(%arg0: tensor<8x13x21x3xi32>, %arg1: tensor<13x21x1xi32>) -> tensor<8x13x21x3xi32> { |
| 47 | + // CHECK: tosa.bitwise_or |
| 48 | + %2 = "tf.BitwiseOr"(%arg0, %arg1) : (tensor<8x13x21x3xi32>, tensor<13x21x1xi32>) -> tensor<8x13x21x3xi32> |
| 49 | + func.return %2 : tensor<8x13x21x3xi32> |
| 50 | +} |
| 51 | + |
| 52 | +// ----- |
| 53 | + |
| 54 | +// CHECK-LABEL: test_bitwise_xor |
| 55 | +func.func @test_bitwise_xor(%arg0: tensor<8x13x21x3xi32>, %arg1: tensor<13x21x1xi32>) -> tensor<8x13x21x3xi32> { |
| 56 | + // CHECK: tosa.bitwise_xor |
| 57 | + %2 = "tf.BitwiseXor"(%arg0, %arg1) : (tensor<8x13x21x3xi32>, tensor<13x21x1xi32>) -> tensor<8x13x21x3xi32> |
| 58 | + func.return %2 : tensor<8x13x21x3xi32> |
| 59 | +} |
| 60 | + |
| 61 | +// ----- |
| 62 | + |
| 63 | +// CHECK-LABEL: test_logical_and |
| 64 | +func.func @test_logical_and(%arg0: tensor<8x13x21x3xi1>, %arg1: tensor<13x21x1xi1>) -> tensor<8x13x21x3xi1> { |
| 65 | + // CHECK: tosa.logical_and |
| 66 | + %2 = "tf.LogicalAnd"(%arg0, %arg1) : (tensor<8x13x21x3xi1>, tensor<13x21x1xi1>) -> tensor<8x13x21x3xi1> |
| 67 | + func.return %2 : tensor<8x13x21x3xi1> |
| 68 | +} |
| 69 | + |
| 70 | +// ----- |
| 71 | + |
| 72 | +// CHECK-LABEL: test_logical_or |
| 73 | +func.func @test_logical_or(%arg0: tensor<8x13x21x3xi1>, %arg1: tensor<13x21x1xi1>) -> tensor<8x13x21x3xi1> { |
| 74 | + // CHECK: tosa.logical_or |
| 75 | + %2 = "tf.LogicalOr"(%arg0, %arg1) : (tensor<8x13x21x3xi1>, tensor<13x21x1xi1>) -> tensor<8x13x21x3xi1> |
| 76 | + func.return %2 : tensor<8x13x21x3xi1> |
| 77 | +} |
| 78 | + |
| 79 | +// ----- |
| 80 | + |
| 81 | +// CHECK-LABEL: test_floor_div |
| 82 | +func.func @test_floor_div(%arg0: tensor<13x21x3xi32>, %arg1: tensor<1x13x1x3xi32>) -> tensor<1x13x21x3xi32> { |
| 83 | + // CHECK: tosa.int_div |
| 84 | + %2 = "tf.FloorDiv"(%arg0, %arg1) : (tensor<13x21x3xi32>, tensor<1x13x1x3xi32>) -> tensor<1x13x21x3xi32> |
| 85 | + func.return %2 : tensor<1x13x21x3xi32> |
| 86 | +} |
| 87 | + |
| 88 | +// ----- |
| 89 | + |
| 90 | +// CHECK-LABEL: test_real_div |
| 91 | +// CHECK: tosa.int_div |
| 92 | +func.func @test_real_div(%arg0: tensor<13x21x3xi32>, %arg1: tensor<1x13x1x3xi32>) -> tensor<1x13x21x3xi32> { |
| 93 | + %2 = "tf.RealDiv"(%arg0, %arg1) : (tensor<13x21x3xi32>, tensor<1x13x1x3xi32>) -> tensor<1x13x21x3xi32> |
| 94 | + func.return %2 : tensor<1x13x21x3xi32> |
| 95 | +} |
| 96 | + |
| 97 | +// ----- |
| 98 | + |
| 99 | +// CHECK-LABEL: test_left_shift |
| 100 | +func.func @test_left_shift(%arg0: tensor<4x4xi32>, %arg1: tensor<1x1x1xi32>) -> tensor<1x4x4xi32> { |
| 101 | + // CHECK: tosa.logical_left_shift |
| 102 | + %0 = "tf.LeftShift"(%arg0, %arg1) : (tensor<4x4xi32>, tensor<1x1x1xi32>) -> tensor<1x4x4xi32> |
| 103 | + func.return %0 : tensor<1x4x4xi32> |
| 104 | +} |
| 105 | + |
| 106 | +// ----- |
| 107 | + |
| 108 | +// CHECK-LABEL: test_right_shift |
| 109 | +func.func @test_right_shift(%arg0: tensor<4x4xi32>, %arg1: tensor<1x1x1xi32>) -> tensor<1x4x4xi32> { |
| 110 | + // CHECK: tosa.arithmetic_right_shift |
| 111 | + %0 = "tf.RightShift"(%arg0, %arg1) : (tensor<4x4xi32>, tensor<1x1x1xi32>) -> tensor<1x4x4xi32> |
| 112 | + func.return %0 : tensor<1x4x4xi32> |
| 113 | +} |
| 114 | + |
| 115 | +// ----- |
| 116 | + |
| 117 | +// CHECK-LABEL: test_max |
| 118 | +func.func @test_max(%arg0: tensor<13x21x3xf32>, %arg1: tensor<1x13x21x1xf32>) -> tensor<1x13x21x3xf32> { |
| 119 | + // CHECK: tosa.maximum |
| 120 | + %2 = "tf.Maximum"(%arg0, %arg1) : (tensor<13x21x3xf32>, tensor<1x13x21x1xf32>) -> tensor<1x13x21x3xf32> |
| 121 | + func.return %2 : tensor<1x13x21x3xf32> |
| 122 | +} |
| 123 | + |
| 124 | +// ----- |
| 125 | + |
| 126 | +// CHECK-LABEL: test_min |
| 127 | +func.func @test_min(%arg0: tensor<13x21x3xf32>, %arg1: tensor<1x13x21x1xf32>) -> tensor<1x13x21x3xf32> { |
| 128 | + // CHECK: tosa.minimum |
| 129 | + %2 = "tf.Minimum"(%arg0, %arg1) : (tensor<13x21x3xf32>, tensor<1x13x21x1xf32>) -> tensor<1x13x21x3xf32> |
| 130 | + func.return %2 : tensor<1x13x21x3xf32> |
| 131 | +} |
| 132 | + |
| 133 | +// ----- |
| 134 | + |
| 135 | +// CHECK-LABEL: test_power |
| 136 | +func.func @test_power(%arg0: tensor<8x13x21x3xi32>, %arg1: tensor<13x21x1xi32>) -> tensor<8x13x21x3xi32> { |
| 137 | + // CHECK: tosa.pow |
| 138 | + %2 = "tf.Pow"(%arg0, %arg1) : (tensor<8x13x21x3xi32>, tensor<13x21x1xi32>) -> tensor<8x13x21x3xi32> |
| 139 | + func.return %2 : tensor<8x13x21x3xi32> |
| 140 | +} |
| 141 | + |
| 142 | +// ----- |
| 143 | + |
| 144 | +// CHECK-LABEL: test_equal |
| 145 | +// CHECK: tosa.equal |
| 146 | +func.func @test_equal(%arg0: tensor<13x21x3xf32>, %arg1: tensor<1x13x1x3xf32>) -> tensor<1x13x21x3xi1> { |
| 147 | + %2 = "tf.Equal"(%arg0, %arg1) {incompatible_shape_error = true} : (tensor<13x21x3xf32>, tensor<1x13x1x3xf32>) -> tensor<1x13x21x3xi1> |
| 148 | + func.return %2 : tensor<1x13x21x3xi1> |
| 149 | +} |
| 150 | + |
| 151 | +// ----- |
| 152 | + |
| 153 | +// CHECK-LABEL: test_greater_equal |
| 154 | +// CHECK: tosa.greater_equal |
| 155 | +func.func @test_greater_equal(%arg0: tensor<13x1x3xf32>, %arg1: tensor<1x13x21x3xf32>) -> tensor<1x13x21x3xi1> { |
| 156 | + %2 = "tf.GreaterEqual"(%arg0, %arg1) : (tensor<13x1x3xf32>, tensor<1x13x21x3xf32>) -> tensor<1x13x21x3xi1> |
| 157 | + func.return %2 : tensor<1x13x21x3xi1> |
| 158 | +} |
| 159 | + |
| 160 | +// ----- |
| 161 | + |
| 162 | +// CHECK-LABEL: test_greater |
| 163 | +// CHECK: tosa.greater |
| 164 | +func.func @test_greater(%arg0: tensor<13x21x1xf32>, %arg1: tensor<1x13x21x3xf32>) -> tensor<1x13x21x3xi1> { |
| 165 | + %2 = "tf.Greater"(%arg0, %arg1) : (tensor<13x21x1xf32>, tensor<1x13x21x3xf32>) -> tensor<1x13x21x3xi1> |
| 166 | + func.return %2 : tensor<1x13x21x3xi1> |
| 167 | +} |
| 168 | + |
| 169 | +// ----- |
| 170 | + |
| 171 | +// CHECK-LABEL: test_less |
| 172 | +// CHECK: tosa.greater_equal |
| 173 | +// CHECK: tosa.logical_not |
| 174 | +func.func @test_less(%arg0: tensor<13x21x1xf32>, %arg1: tensor<1x13x21x3xf32>) -> tensor<1x13x21x3xi1> { |
| 175 | + %2 = "tf.Less"(%arg0, %arg1) : (tensor<13x21x1xf32>, tensor<1x13x21x3xf32>) -> tensor<1x13x21x3xi1> |
| 176 | + func.return %2 : tensor<1x13x21x3xi1> |
| 177 | +} |
| 178 | + |
| 179 | +// ----- |
| 180 | +// CHECK-LABEL: test_select |
| 181 | +// CHECK: tosa.select |
| 182 | +func.func @test_select(%arg0: tensor<13x21x3xf32>, %arg1: tensor<1x13x21x3xf32>, %arg2: tensor<1xi1>) -> tensor<1x13x21x3xf32> { |
| 183 | + %2 = "tf.SelectV2"(%arg2, %arg0, %arg1) : (tensor<1xi1>, tensor<13x21x3xf32>, tensor<1x13x21x3xf32>) -> tensor<1x13x21x3xf32> |
| 184 | + func.return %2 : tensor<1x13x21x3xf32> |
| 185 | +} |
0 commit comments