2631 lines · plain
1// RUN: mlir-opt --split-input-file -pass-pipeline="builtin.module(func.func(tosa-to-linalg))" %s -verify-diagnostics -o -| FileCheck %s2 3// CHECK: #[[$MAP0:.*]] = affine_map<() -> ()>4 5// CHECK-LABEL: @test_abs_scalar6// CHECK-SAME: ([[ARG0:%[0-9a-zA-Z_]*]]7func.func @test_abs_scalar(%arg0: tensor<f32>) -> tensor<f32> {8 // CHECK: [[INIT:%.+]] = tensor.empty() : tensor<f32>9 // CHECK: [[GENERIC:%.+]] = linalg.generic {indexing_maps = [#[[$MAP0]], #[[$MAP0]]], iterator_types = []} ins([[ARG0]] : tensor<f32>) outs([[INIT]] : tensor<f32>) {10 // CHECK: ^bb0([[ARG1:%.*]]: f32, [[ARG2:%.*]]: f32):11 // CHECK: [[ELEMENT:%.*]] = math.absf [[ARG1]] : f3212 // CHECK: linalg.yield [[ELEMENT]] : f3213 // CHECK: } -> tensor<f32>14 %0 = tosa.abs %arg0 : (tensor<f32>) -> tensor<f32>15 16 // CHECK: return [[GENERIC]] : tensor<f32>17 return %0 : tensor<f32>18}19 20// -----21 22// CHECK: #[[$MAP0:.*]] = affine_map<(d0) -> (d0)>23// CHECK-LABEL: @test_abs_1d_cast_static_to_dynamic24// CHECK-SAME: ([[ARG0:%[0-9a-zA-Z_]*]]25func.func @test_abs_1d_cast_static_to_dynamic(%arg0: tensor<5xf32>) -> tensor<?xf32> {26 // CHECK: [[EMPTY:%.+]] = tensor.empty() : tensor<5xf32>27 // CHECK: [[RESULT:%.+]] = linalg.generic {indexing_maps = [#[[$MAP0]], #[[$MAP0]]], iterator_types = ["parallel"]} ins([[ARG0]] : tensor<5xf32>) outs([[EMPTY]] : tensor<5xf32>) {28 // CHECK: ^bb0([[IN0:%.+]]: f32, [[OUT0:%.+]]: f32):29 // CHECK: [[ABS:%.+]] = math.absf [[IN0]] : f3230 // CHECK: linalg.yield [[ABS]] : f3231 // CHECK: } -> tensor<5xf32>32 // CHECK: [[CAST_RESULT:%.+]] = tensor.cast [[RESULT]] : tensor<5xf32> to tensor<?xf32>33 %0 = "tosa.abs"(%arg0) : (tensor<5xf32>) -> tensor<?xf32>34 35 // CHECK: return [[CAST_RESULT]] : tensor<?xf32>36 return %0 : tensor<?xf32>37}38 39// -----40 41// CHECK: #[[$MAP0:.*]] = affine_map<(d0) -> (d0)>42// CHECK-LABEL: @test_abs_1d_cast_dynamic_to_static43// CHECK-SAME: (%[[ARG0:[0-9a-zA-Z_]*]]44func.func @test_abs_1d_cast_dynamic_to_static(%arg0: tensor<?xf32>) -> tensor<5xf32> {45 // CHECK: %[[ZERO:.*]] = arith.constant 0 : index46 // CHECK: %[[DIM_SIZE:.*]] = tensor.dim %[[ARG0]], %[[ZERO]] : tensor<?xf32>47 // CHECK: %[[EMPTY:.*]] = tensor.empty(%[[DIM_SIZE]]) : tensor<?xf32>48 // CHECK: %[[RESULT:.*]] = linalg.generic {indexing_maps = [#[[$MAP0]], #[[$MAP0]]], iterator_types = ["parallel"]} ins(%[[ARG0]] : tensor<?xf32>) outs(%[[EMPTY]] : tensor<?xf32>) {49 // CHECK: ^bb0(%[[VAL_0:.*]]: f32, %[[VAL_1:.*]]: f32):50 // CHECK: %[[VAL_2:.*]] = math.absf %[[VAL_0]] : f3251 // CHECK: linalg.yield %[[VAL_2]] : f3252 // CHECK: } -> tensor<?xf32>53 // CHECK: %[[CAST_RESULT:.*]] = tensor.cast %[[RESULT]] : tensor<?xf32> to tensor<5xf32>54 %0 = "tosa.abs"(%arg0) : (tensor<?xf32>) -> tensor<5xf32>55 56 // CHECK: return %[[CAST_RESULT]] : tensor<5xf32>57 return %0 : tensor<5xf32>58}59 60// -----61 62// CHECK: #[[$MAP0:.*]] = affine_map<(d0) -> (d0)>63// CHECK-LABEL: @test_abs_1d_dynamic64// CHECK-SAME: ([[ARG0:%[0-9a-zA-Z_]*]]65func.func @test_abs_1d_dynamic(%arg0: tensor<?xf32>) -> tensor<?xf32> {66 67 // CHECK: [[ZERO:%.+]] = arith.constant 0 : index68 // CHECK: [[DIM:%.+]] = tensor.dim [[ARG0]], [[ZERO]] : tensor<?xf32>69 // CHECK: [[EMPTY:%.+]] = tensor.empty([[DIM]]) : tensor<?xf32>70 // CHECK: [[RESULT:%.+]] = linalg.generic {indexing_maps = [#map, #map], iterator_types = ["parallel"]} ins(%arg0 : tensor<?xf32>) outs([[EMPTY]] : tensor<?xf32>) {71 // CHECK: ^bb0([[IN0:%.+]]: f32, [[OUT0:%.+]]: f32):72 // CHECK: [[ABSF:%.+]] = math.absf [[IN0]] : f3273 // CHECK: linalg.yield [[ABSF]] : f3274 // CHECK: } -> tensor<?xf32>75 %0 = tosa.abs %arg0 : (tensor<?xf32>) -> tensor<?xf32>76 77 // CHECK: return [[RESULT]] : tensor<?xf32>78 return %0 : tensor<?xf32>79}80 81// -----82 83// CHECK: #[[$MAP0:.*]] = affine_map<() -> ()>84// CHECK-LABEL: @test_add_0d85// CHECK-SAME: [[ARG0:%[0-9a-zA-Z_]*]]:86// CHECK-SAME: [[ARG1:%[0-9a-zA-Z_]*]]:87func.func @test_add_0d(%arg0: tensor<f32>, %arg1: tensor<f32>) -> tensor<f32> {88 89 // CHECK: [[EMPTY:%.+]] = tensor.empty() : tensor<f32>90 // CHECK: [[RESULT:%.+]] = linalg.generic {indexing_maps = [#map, #map, #map], iterator_types = []} ins([[ARG0]], [[ARG1]] : tensor<f32>, tensor<f32>) outs([[EMPTY]] : tensor<f32>) {91 // CHECK: ^bb0([[IN0:%.+]]: f32, [[IN1:%.+]]: f32, [[OUT0:%.+]]: f32):92 // CHECK: [[ADDF:%.+]] = arith.addf [[IN0]], [[IN1]] : f3293 // CHECK: linalg.yield [[ADDF]] : f3294 // CHECK: } -> tensor<f32>95 %0 = tosa.add %arg0, %arg1 : (tensor<f32>, tensor<f32>) -> tensor<f32>96 97 98 // CHECK: return [[RESULT]] : tensor<f32>99 return %0 : tensor<f32>100}101 102// -----103 104// CHECK: #[[$MAP0:.+]] = affine_map<(d0, d1) -> (d0, d1)>105// CHECK: #[[$MAP1:.+]] = affine_map<(d0, d1) -> (0, d1)>106 107// CHECK-LABEL: func.func @test_add_2d_broadcast(108// CHECK-SAME: %[[ARG0:.*]]: tensor<2x1xf32>,109// CHECK-SAME: %[[ARG1:.*]]: tensor<1x1xf32>) -> tensor<2x1xf32> {110// CHECK: %[[EMPTY_TENSOR:.*]] = tensor.empty() : tensor<2x1xf32>111// CHECK: %[[RESULT:.*]] = linalg.generic {indexing_maps = [#[[$MAP0]], #[[$MAP1]], #[[$MAP0]]], iterator_types = ["parallel", "parallel"]} ins(%[[ARG0]], %[[ARG1]] : tensor<2x1xf32>, tensor<1x1xf32>) outs(%[[EMPTY_TENSOR]] : tensor<2x1xf32>) {112// CHECK: ^bb0(%[[IN0:.*]]: f32, %[[IN1:.*]]: f32, %[[OUT:.*]]: f32):113// CHECK: %[[ADD:.*]] = arith.addf %[[IN0]], %[[IN1]] : f32114// CHECK: linalg.yield %[[ADD]] : f32115// CHECK: } -> tensor<2x1xf32>116// CHECK: return %[[RESULT]] : tensor<2x1xf32>117// CHECK: }118func.func @test_add_2d_broadcast(%arg0: tensor<2x1xf32>, %arg1: tensor<1x1xf32>) -> tensor<2x1xf32> {119 // tosa element-wise operators now require operands of equal ranks120 %0 = tosa.add %arg0, %arg1 : (tensor<2x1xf32>, tensor<1x1xf32>) -> tensor<2x1xf32>121 return %0 : tensor<2x1xf32>122}123 124// -----125 126// CHECK: #[[$MAP0:.+]] = affine_map<(d0) -> (0)>127// CHECK: #[[$MAP1:.+]] = affine_map<(d0) -> (d0)>128// CHECK-LABEL: @test_add_1d_all_dynamic129// CHECK-SAME: %[[ARG0:[0-9a-zA-Z_]*]]:130// CHECK-SAME: %[[ARG1:[0-9a-zA-Z_]*]]:131func.func @test_add_1d_all_dynamic(%arg0: tensor<?xf32>, %arg1: tensor<?xf32>) -> tensor<?xf32> {132 133 // CHECK: %[[CONST0:.*]] = arith.constant 0 : index134 // CHECK: %[[ARG0_DIM0:.*]] = tensor.dim %[[ARG0]], %[[CONST0]] : tensor<?xf32>135 // CHECK: %[[ARG1_DIM0:.*]] = tensor.dim %[[ARG1]], %[[CONST0]] : tensor<?xf32>136 // CHECK: %[[ARG0_MAX_DIM:.*]] = arith.maxui %[[ARG0_DIM0]], %[[ARG1_DIM0]] : index137 // CHECK: %[[CONST1:.*]] = arith.constant 1 : index138 // CHECK: %[[VAL_0:.*]] = tensor.dim %[[ARG0]], %[[CONST0]] : tensor<?xf32>139 // CHECK: %[[VAL_1:.*]] = arith.cmpi eq, %[[VAL_0]], %[[CONST1]] : index140 // CHECK: %[[ARG0_DIM0_BROADCAST:.*]] = scf.if %[[VAL_1]] -> (tensor<?xf32>) {141 // CHECK: %[[VAL_2:.*]] = tensor.empty(%[[ARG0_MAX_DIM]]) : tensor<?xf32>142 // CHECK: %[[VAL_3:.*]] = linalg.generic {indexing_maps = [#[[$MAP0]], #[[$MAP1]]], iterator_types = ["parallel"]} ins(%[[ARG0]] : tensor<?xf32>) outs(%[[VAL_2]] : tensor<?xf32>) {143 // CHECK: ^bb0(%[[VAL_4:.*]]: f32, %[[VAL_5:.*]]: f32):144 // CHECK: linalg.yield %[[VAL_4]] : f32145 // CHECK: } -> tensor<?xf32>146 // CHECK: scf.yield %[[VAL_3]] : tensor<?xf32>147 // CHECK: } else {148 // CHECK: scf.yield %[[ARG0]] : tensor<?xf32>149 // CHECK: }150 // CHECK: %[[VAL_6:.*]] = tensor.dim %[[ARG1]], %[[CONST0]] : tensor<?xf32>151 // CHECK: %[[VAL_7:.*]] = arith.cmpi eq, %[[VAL_6]], %[[CONST1]] : index152 // CHECK: %[[ARG0_DIM1_BROADCAST:.*]] = scf.if %[[VAL_7]] -> (tensor<?xf32>) {153 // CHECK: %[[VAL_8:.*]] = tensor.empty(%[[ARG0_MAX_DIM]]) : tensor<?xf32>154 // CHECK: %[[VAL_9:.*]] = linalg.generic {indexing_maps = [#[[$MAP0]], #[[$MAP1]]], iterator_types = ["parallel"]} ins(%[[ARG1]] : tensor<?xf32>) outs(%[[VAL_8]] : tensor<?xf32>) {155 // CHECK: ^bb0(%[[VAL_10:.*]]: f32, %[[VAL_11:.*]]: f32):156 // CHECK: linalg.yield %[[VAL_10]] : f32157 // CHECK: } -> tensor<?xf32>158 // CHECK: scf.yield %[[VAL_9]] : tensor<?xf32>159 // CHECK: } else {160 // CHECK: scf.yield %[[ARG1]] : tensor<?xf32>161 // CHECK: }162 // CHECK: %[[VAL_12:.*]] = tensor.empty(%[[ARG0_MAX_DIM]]) : tensor<?xf32>163 // CHECK: %[[RESULT:.*]] = linalg.generic {indexing_maps = [#[[$MAP1]], #[[$MAP1]], #[[$MAP1]]], iterator_types = ["parallel"]} ins(%[[ARG0_DIM0_BROADCAST]], %[[ARG0_DIM1_BROADCAST]] : tensor<?xf32>, tensor<?xf32>) outs(%[[VAL_12]] : tensor<?xf32>) {164 // CHECK: ^bb0(%[[VAL_13:.*]]: f32, %[[VAL_14:.*]]: f32, %[[VAL_15:.*]]: f32):165 // CHECK: %[[VAL_16:.*]] = arith.addf %[[VAL_13]], %[[VAL_14]] : f32166 // CHECK: linalg.yield %[[VAL_16]] : f32167 // CHECK: } -> tensor<?xf32>168 %0 = tosa.add %arg0, %arg1 : (tensor<?xf32>, tensor<?xf32>) -> tensor<?xf32>169 170 // CHECK: return %[[RESULT]] : tensor<?xf32>171 return %0 : tensor<?xf32>172}173 174// -----175 176// CHECK: #[[$MAP0:.+]] = affine_map<(d0) -> (0)>177// CHECK: #[[$MAP1:.+]] = affine_map<(d0) -> (d0)>178// CHECK-LABEL: @test_add_1d_broadcast_dynamic_to_static179// CHECK-SAME: %[[ARG0:[0-9a-zA-Z_]*]]:180// CHECK-SAME: %[[ARG1:[0-9a-zA-Z_]*]]:181func.func @test_add_1d_broadcast_dynamic_to_static(%arg0: tensor<5xf32>, %arg1: tensor<?xf32>) -> tensor<5xf32> {182 183 // CHECK: %[[CONST1:.*]] = arith.constant 1 : index184 // CHECK: %[[CONST0:.*]] = arith.constant 0 : index185 // CHECK: %[[ARG1_DIM0:.*]] = tensor.dim %[[ARG1]], %[[CONST0]] : tensor<?xf32>186 // CHECK: %[[VAL_0:.*]] = arith.cmpi eq, %[[ARG1_DIM0]], %[[CONST1]] : index187 // CHECK: %[[ARG1_DIM0_BROADCAST:.*]] = scf.if %[[VAL_0]] -> (tensor<?xf32>) {188 // CHECK: %[[VAL_1:.*]] = tensor.empty() : tensor<5xf32>189 // CHECK: %[[VAL_2:.*]] = linalg.generic {indexing_maps = [#[[$MAP0]], #[[$MAP1]]], iterator_types = ["parallel"]} ins(%[[ARG1]] : tensor<?xf32>) outs(%[[VAL_1]] : tensor<5xf32>) {190 // CHECK: ^bb0(%[[VAL_3:.*]]: f32, %[[VAL_4:.*]]: f32):191 // CHECK: linalg.yield %[[VAL_3]] : f32192 // CHECK: } -> tensor<5xf32>193 // CHECK: %[[VAL_5:.*]] = tensor.cast %[[VAL_2]] : tensor<5xf32> to tensor<?xf32>194 // CHECK: scf.yield %[[VAL_5]] : tensor<?xf32>195 // CHECK: } else {196 // CHECK: scf.yield %[[ARG1]] : tensor<?xf32>197 // CHECK: }198 // CHECK: %[[VAL_6:.*]] = tensor.empty() : tensor<5xf32>199 // CHECK: %[[RESULT:.*]] = linalg.generic {indexing_maps = [#[[$MAP1]], #[[$MAP1]], #[[$MAP1]]], iterator_types = ["parallel"]} ins(%[[ARG0]], %[[ARG1_DIM0_BROADCAST]] : tensor<5xf32>, tensor<?xf32>) outs(%[[VAL_6]] : tensor<5xf32>) {200 // CHECK: ^bb0(%[[VAL_7:.*]]: f32, %[[VAL_8:.*]]: f32, %[[VAL_9:.*]]: f32):201 // CHECK: %[[VAL_10:.*]] = arith.addf %[[VAL_7]], %[[VAL_8]] : f32202 // CHECK: linalg.yield %[[VAL_10]] : f32203 // CHECK: } -> tensor<5xf32>204 %0 = tosa.add %arg0, %arg1 : (tensor<5xf32>, tensor<?xf32>) -> tensor<5xf32>205 206 // CHECK: return %[[RESULT]] : tensor<5xf32>207 return %0 : tensor<5xf32>208}209 210// -----211 212// CHECK: #[[$MAP0:.+]] = affine_map<(d0) -> (0)>213// CHECK: #[[$MAP1:.+]] = affine_map<(d0) -> (d0)>214// CHECK-LABEL: @test_add_1d_broadcast_static_to_dynamic215// CHECK-SAME: %[[ARG0:[0-9a-zA-Z_]*]]:216// CHECK-SAME: %[[ARG1:[0-9a-zA-Z_]*]]:217func.func @test_add_1d_broadcast_static_to_dynamic(%arg0: tensor<1xf32>, %arg1: tensor<?xf32>) -> tensor<?xf32> {218 219 // CHECK: %[[CONST0:.*]] = arith.constant 0 : index220 // CHECK: %[[ARG1_DIM0:.*]] = tensor.dim %[[ARG1]], %[[CONST0]] : tensor<?xf32>221 // CHECK: %[[VAL_0:.*]] = tensor.empty(%[[ARG1_DIM0]]) : tensor<?xf32>222 // CHECK: %[[RESULT:.*]] = linalg.generic {indexing_maps = [#[[$MAP0]], #[[$MAP1]], #[[$MAP1]]], iterator_types = ["parallel"]} ins(%[[ARG0]], %[[ARG1]] : tensor<1xf32>, tensor<?xf32>) outs(%[[VAL_0]] : tensor<?xf32>) {223 // CHECK: ^bb0(%[[VAL_1:.*]]: f32, %[[VAL_2:.*]]: f32, %[[VAL_3:.*]]: f32):224 // CHECK: %[[VAL_4:.*]] = arith.addf %[[VAL_1]], %[[VAL_2]] : f32225 // CHECK: linalg.yield %[[VAL_4]] : f32226 // CHECK: } -> tensor<?xf32>227 %0 = tosa.add %arg0, %arg1 : (tensor<1xf32>, tensor<?xf32>) -> tensor<?xf32>228 229 // CHECK: return %[[RESULT]] : tensor<?xf32>230 return %0 : tensor<?xf32>231}232 233// -----234 235// CHECK: #[[$MAP0:.+]] = affine_map<(d0) -> (0)>236// CHECK: #[[$MAP1:.+]] = affine_map<(d0) -> (d0)>237// CHECK-LABEL: @test_add_1d_broadcast_static_to_static238// CHECK-SAME: %[[ARG0:[0-9a-zA-Z_]*]]:239// CHECK-SAME: %[[ARG1:[0-9a-zA-Z_]*]]:240func.func @test_add_1d_broadcast_static_to_static(%arg0: tensor<1xf32>, %arg1: tensor<3xf32>) -> tensor<3xf32> {241 242 // CHECK: %[[VAL_0:.*]] = tensor.empty() : tensor<3xf32>243 // CHECK: %[[RESULT:.*]] = linalg.generic {indexing_maps = [#[[$MAP0]], #[[$MAP1]], #[[$MAP1]]], iterator_types = ["parallel"]} ins(%[[ARG0]], %[[ARG1]] : tensor<1xf32>, tensor<3xf32>) outs(%[[VAL_0]] : tensor<3xf32>) {244 // CHECK: ^bb0(%[[VAL_1:.*]]: f32, %[[VAL_2:.*]]: f32, %[[VAL_3:.*]]: f32):245 // CHECK: %[[VAL_4:.*]] = arith.addf %[[VAL_1]], %[[VAL_2]] : f32246 // CHECK: linalg.yield %[[VAL_4]] : f32247 // CHECK: } -> tensor<3xf32>248 %0 = tosa.add %arg0, %arg1 : (tensor<1xf32>, tensor<3xf32>) -> tensor<3xf32>249 250 // CHECK: return %[[RESULT]] : tensor<3xf32>251 return %0 : tensor<3xf32>252}253 254// -----255 256// CHECK: #[[$MAP:.+]] = affine_map<(d0) -> (d0)>257// CHECK-LABEL: @test_add_1d_matching_no_broadcast258// CHECK-SAME: %[[ARG0:[0-9a-zA-Z_]*]]:259// CHECK-SAME: %[[ARG1:[0-9a-zA-Z_]*]]:260func.func @test_add_1d_matching_no_broadcast(%arg0: tensor<1xf32>, %arg1: tensor<1xf32>) -> tensor<1xf32> {261 262 // CHECK: %[[VAL_0:.*]] = tensor.empty() : tensor<1xf32>263 // CHECK: %[[RESULT:.*]] = linalg.generic {indexing_maps = [#[[$MAP]], #[[$MAP]], #[[$MAP]]], iterator_types = ["parallel"]} ins(%[[ARG0]], %[[ARG1]] : tensor<1xf32>, tensor<1xf32>) outs(%[[VAL_0]] : tensor<1xf32>) {264 // CHECK: ^bb0(%[[VAL_1:.*]]: f32, %[[VAL_2:.*]]: f32, %[[VAL_3:.*]]: f32):265 // CHECK: %[[VAL_4:.*]] = arith.addf %[[VAL_1]], %[[VAL_2]] : f32266 // CHECK: linalg.yield %[[VAL_4]] : f32267 // CHECK: } -> tensor<1xf32>268 %0 = tosa.add %arg0, %arg1 : (tensor<1xf32>, tensor<1xf32>) -> tensor<1xf32>269 270 // CHECK: return %[[RESULT]] : tensor<1xf32>271 return %0 : tensor<1xf32>272}273 274// -----275 276// CHECK: #[[$MAP0:.+]] = affine_map<(d0) -> (d0)>277// CHECK-LABEL: @test_add_1d_matching_static278// CHECK-SAME: %[[ARG0:[0-9a-zA-Z_]*]]:279// CHECK-SAME: %[[ARG1:[0-9a-zA-Z_]*]]:280func.func @test_add_1d_matching_static(%arg0: tensor<3xf32>, %arg1: tensor<3xf32>) -> tensor<3xf32> {281 282 // CHECK: %[[VAL_0:.*]] = tensor.empty() : tensor<3xf32>283 // CHECK: %[[RESULT:.*]] = linalg.generic {indexing_maps = [#[[$MAP0]], #[[$MAP0]], #[[$MAP0]]], iterator_types = ["parallel"]} ins(%[[ARG0]], %[[ARG1]] : tensor<3xf32>, tensor<3xf32>) outs(%[[VAL_0]] : tensor<3xf32>) {284 // CHECK: ^bb0(%[[VAL_1:.*]]: f32, %[[VAL_2:.*]]: f32, %[[VAL_3:.*]]: f32):285 // CHECK: %[[VAL_4:.*]] = arith.addf %[[VAL_1]], %[[VAL_2]] : f32286 // CHECK: linalg.yield %[[VAL_4]] : f32287 // CHECK: } -> tensor<3xf32>288 %0 = tosa.add %arg0, %arg1 : (tensor<3xf32>, tensor<3xf32>) -> tensor<3xf32>289 290 // CHECK: return %[[RESULT]] : tensor<3xf32>291 return %0 : tensor<3xf32>292}293 294// -----295 296// CHECK: #[[$MAP0:.+]] = affine_map<(d0, d1) -> (0, d1)>297// CHECK: #[[$MAP1:.+]] = affine_map<(d0, d1) -> (d0, d1)>298// CHECK: #[[$MAP2:.+]] = affine_map<(d0, d1) -> (d0, 0)>299// CHECK-LABEL: @test_add_2d_all_dynamic300// CHECK-SAME: %[[ARG0:[0-9a-zA-Z_]*]]:301// CHECK-SAME: %[[ARG1:[0-9a-zA-Z_]*]]:302func.func @test_add_2d_all_dynamic(%arg0: tensor<?x?xf32>, %arg1: tensor<?x?xf32>) -> tensor<?x?xf32> {303 304 // CHECK: %[[CONST0:.*]] = arith.constant 0 : index305 // CHECK: %[[ARG0_DIM0:.*]] = tensor.dim %[[ARG0]], %[[CONST0]] : tensor<?x?xf32>306 // CHECK: %[[ARG1_DIM0:.*]] = tensor.dim %[[ARG1]], %[[CONST0]] : tensor<?x?xf32>307 // CHECK: %[[MAX_DIM0:.*]] = arith.maxui %[[ARG0_DIM0]], %[[ARG1_DIM0]] : index308 // CHECK: %[[CONST1:.*]] = arith.constant 1 : index309 // CHECK: %[[ARG0_DIM1:.*]] = tensor.dim %[[ARG0]], %[[CONST1]] : tensor<?x?xf32>310 // CHECK: %[[ARG1_DIM1:.*]] = tensor.dim %[[ARG1]], %[[CONST1]] : tensor<?x?xf32>311 // CHECK: %[[MAX_DIM1:.*]] = arith.maxui %[[ARG0_DIM1]], %[[ARG1_DIM1]] : index312 313 // CHECK: %[[VAL_0:.*]] = tensor.dim %[[ARG0]], %[[CONST0]] : tensor<?x?xf32>314 // CHECK: %[[VAL_1:.*]] = arith.cmpi eq, %[[VAL_0]], %[[CONST1]] : index315 // CHECK: %[[ARG0_DIM0_BROADCAST:.*]] = scf.if %[[VAL_1]] -> (tensor<?x?xf32>) {316 // CHECK: %[[LOCAL_CONST1:.*]] = arith.constant 1 : index317 // CHECK: %[[VAL_2:.*]] = tensor.dim %[[ARG0]], %[[LOCAL_CONST1]] : tensor<?x?xf32>318 // CHECK: %[[VAL_3:.*]] = tensor.empty(%[[MAX_DIM0]], %[[VAL_2]]) : tensor<?x?xf32>319 // CHECK: %[[VAL_4:.*]] = linalg.generic {indexing_maps = [#[[$MAP0]], #[[$MAP1]]], iterator_types = ["parallel", "parallel"]} ins(%[[ARG0]] : tensor<?x?xf32>) outs(%[[VAL_3]] : tensor<?x?xf32>) {320 // CHECK: ^bb0(%[[VAL_5:.*]]: f32, %[[VAL_6:.*]]: f32):321 // CHECK: linalg.yield %[[VAL_5]] : f32322 // CHECK: } -> tensor<?x?xf32>323 // CHECK: scf.yield %[[VAL_4]] : tensor<?x?xf32>324 // CHECK: } else {325 // CHECK: scf.yield %[[ARG0]] : tensor<?x?xf32>326 // CHECK: }327 328 // CHECK: %[[VAL_7:.*]] = tensor.dim %[[ARG0_DIM0_BROADCAST]], %[[CONST1]] : tensor<?x?xf32>329 // CHECK: %[[VAL_8:.*]] = arith.cmpi eq, %[[VAL_7]], %[[CONST1]] : index330 // CHECK: %[[ARG0_DIM1_BROADCAST:.*]] = scf.if %[[VAL_8]] -> (tensor<?x?xf32>) {331 // CHECK: %[[LOCAL_CONST0:.*]] = arith.constant 0 : index332 // CHECK: %[[VAL_9:.*]] = tensor.dim %[[ARG0_DIM0_BROADCAST]], %[[LOCAL_CONST0]] : tensor<?x?xf32>333 // CHECK: %[[VAL_10:.*]] = tensor.empty(%[[VAL_9]], %[[MAX_DIM1]]) : tensor<?x?xf32>334 // CHECK: %[[VAL_11:.*]] = linalg.generic {indexing_maps = [#[[$MAP2]], #[[$MAP1]]], iterator_types = ["parallel", "parallel"]} ins(%[[ARG0_DIM0_BROADCAST]] : tensor<?x?xf32>) outs(%[[VAL_10]] : tensor<?x?xf32>) {335 // CHECK: ^bb0(%[[VAL_12:.*]]: f32, %[[VAL_13:.*]]: f32):336 // CHECK: linalg.yield %[[VAL_12]] : f32337 // CHECK: } -> tensor<?x?xf32>338 // CHECK: scf.yield %[[VAL_11]] : tensor<?x?xf32>339 // CHECK: } else {340 // CHECK: scf.yield %[[ARG0_DIM0_BROADCAST]] : tensor<?x?xf32>341 // CHECK: }342 343 // CHECK: %[[VAL_14:.*]] = tensor.dim %[[ARG1]], %[[CONST0]] : tensor<?x?xf32>344 // CHECK: %[[VAL_15:.*]] = arith.cmpi eq, %[[VAL_14]], %[[CONST1]] : index345 // CHECK: %[[ARG1_DIM0_BROADCAST:.*]] = scf.if %[[VAL_15]] -> (tensor<?x?xf32>) {346 // CHECK: %[[LOCAL_CONST1:.*]] = arith.constant 1 : index347 // CHECK: %[[VAL_16:.*]] = tensor.dim %[[ARG1]], %[[LOCAL_CONST1]] : tensor<?x?xf32>348 // CHECK: %[[VAL_17:.*]] = tensor.empty(%[[MAX_DIM0]], %[[VAL_16]]) : tensor<?x?xf32>349 // CHECK: %[[VAL_18:.*]] = linalg.generic {indexing_maps = [#[[$MAP0]], #[[$MAP1]]], iterator_types = ["parallel", "parallel"]} ins(%[[ARG1]] : tensor<?x?xf32>) outs(%[[VAL_17]] : tensor<?x?xf32>) {350 // CHECK: ^bb0(%[[VAL_19:.*]]: f32, %[[VAL_20:.*]]: f32):351 // CHECK: linalg.yield %[[VAL_19]] : f32352 // CHECK: } -> tensor<?x?xf32>353 // CHECK: scf.yield %[[VAL_18]] : tensor<?x?xf32>354 // CHECK: } else {355 // CHECK: scf.yield %[[ARG1]] : tensor<?x?xf32>356 // CHECK: }357 358 // CHECK: %[[VAL_21:.*]] = tensor.dim %[[ARG1_DIM0_BROADCAST]], %[[CONST1]] : tensor<?x?xf32>359 // CHECK: %[[VAL_22:.*]] = arith.cmpi eq, %[[VAL_21]], %[[CONST1]] : index360 // CHECK: %[[ARG1_DIM1_BROADCAST:.*]] = scf.if %[[VAL_22]] -> (tensor<?x?xf32>) {361 // CHECK: %[[LOCAL_CONST0:.*]] = arith.constant 0 : index362 // CHECK: %[[VAL_23:.*]] = tensor.dim %[[ARG1_DIM0_BROADCAST]], %[[LOCAL_CONST0]] : tensor<?x?xf32>363 // CHECK: %[[VAL_24:.*]] = tensor.empty(%[[VAL_23]], %[[MAX_DIM1]]) : tensor<?x?xf32>364 // CHECK: %[[VAL_25:.*]] = linalg.generic {indexing_maps = [#[[$MAP2]], #[[$MAP1]]], iterator_types = ["parallel", "parallel"]} ins(%[[ARG1_DIM0_BROADCAST]] : tensor<?x?xf32>) outs(%[[VAL_24]] : tensor<?x?xf32>) {365 // CHECK: ^bb0(%[[VAL_26:.*]]: f32, %[[VAL_27:.*]]: f32):366 // CHECK: linalg.yield %[[VAL_26]] : f32367 // CHECK: } -> tensor<?x?xf32>368 // CHECK: scf.yield %[[VAL_25]] : tensor<?x?xf32>369 // CHECK: } else {370 // CHECK: scf.yield %[[ARG1_DIM0_BROADCAST]] : tensor<?x?xf32>371 // CHECK: }372 373 // CHECK: %[[VAL_28:.*]] = tensor.empty(%[[MAX_DIM0]], %[[MAX_DIM1]]) : tensor<?x?xf32>374 // CHECK: %[[RESULT:.*]] = linalg.generic {indexing_maps = [#[[$MAP1]], #[[$MAP1]], #[[$MAP1]]], iterator_types = ["parallel", "parallel"]} ins(%[[ARG0_DIM1_BROADCAST]], %[[ARG1_DIM1_BROADCAST]] : tensor<?x?xf32>, tensor<?x?xf32>) outs(%[[VAL_28]] : tensor<?x?xf32>) {375 // CHECK: ^bb0(%[[VAL_29:.*]]: f32, %[[VAL_30:.*]]: f32, %[[VAL_31:.*]]: f32):376 // CHECK: %[[VAL_32:.*]] = arith.addf %[[VAL_29]], %[[VAL_30]] : f32377 // CHECK: linalg.yield %[[VAL_32]] : f32378 // CHECK: } -> tensor<?x?xf32>379 %0 = tosa.add %arg0, %arg1 : (tensor<?x?xf32>, tensor<?x?xf32>) -> tensor<?x?xf32>380 381 // CHECK: return %[[RESULT]] : tensor<?x?xf32>382 return %0 : tensor<?x?xf32>383}384 385// -----386 387// CHECK: #[[$MAP0:.+]] = affine_map<(d0, d1) -> (d0, 0)>388// CHECK: #[[$MAP1:.+]] = affine_map<(d0, d1) -> (d0, d1)>389// CHECK-LABEL: @test_select_2d_one_dynamic390// CHECK-SAME: %[[ARG0:[0-9a-zA-Z_]*]]:391// CHECK-SAME: %[[ARG1:[0-9a-zA-Z_]*]]:392// CHECK-SAME: %[[ARG2:[0-9a-zA-Z_]*]]:393func.func @test_select_2d_one_dynamic(%arg0: tensor<2x?xi1>, %arg1: tensor<2x?xf32>, %arg2: tensor<2x?xf32>) -> tensor<2x?xf32> {394 395 // CHECK: %[[CONST1:.*]] = arith.constant 1 : index396 // CHECK: %[[ARG0_DIM1:.*]] = tensor.dim %[[ARG0]], %[[CONST1]] : tensor<2x?xi1>397 // CHECK: %[[ARG1_DIM1:.*]] = tensor.dim %[[ARG1]], %[[CONST1]] : tensor<2x?xf32>398 // CHECK: %[[VAL_0:.*]] = arith.maxui %[[ARG0_DIM1]], %[[ARG1_DIM1]] : index399 // CHECK: %[[ARG2_DIM1:.*]] = tensor.dim %[[ARG2]], %[[CONST1]] : tensor<2x?xf32>400 // CHECK: %[[MAX_DIM1:.*]] = arith.maxui %[[VAL_0]], %[[ARG2_DIM1]] : index401 402 // CHECK: %[[VAL_1:.*]] = tensor.dim %[[ARG0]], %[[CONST1]] : tensor<2x?xi1>403 // CHECK: %[[VAL_2:.*]] = arith.cmpi eq, %[[VAL_1]], %[[CONST1]] : index404 // CHECK: %[[ARG0_BROADCAST:.*]] = scf.if %[[VAL_2]] -> (tensor<2x?xi1>) {405 // CHECK: %[[VAL_3:.*]] = tensor.empty(%[[MAX_DIM1]]) : tensor<2x?xi1>406 // CHECK: %[[VAL_4:.*]] = linalg.generic {indexing_maps = [#[[$MAP0]], #[[$MAP1]]], iterator_types = ["parallel", "parallel"]} ins(%[[ARG0]] : tensor<2x?xi1>) outs(%[[VAL_3]] : tensor<2x?xi1>) {407 // CHECK: ^bb0(%[[VAL_5:.*]]: i1, %[[VAL_6:.*]]: i1):408 // CHECK: linalg.yield %[[VAL_5]] : i1409 // CHECK: } -> tensor<2x?xi1>410 // CHECK: scf.yield %[[VAL_4]] : tensor<2x?xi1>411 // CHECK: } else {412 // CHECK: scf.yield %[[ARG0]] : tensor<2x?xi1>413 // CHECK: }414 415 // CHECK: %[[VAL_7:.*]] = tensor.dim %[[ARG1]], %[[CONST1]] : tensor<2x?xf32>416 // CHECK: %[[VAL_8:.*]] = arith.cmpi eq, %[[VAL_7]], %[[CONST1]] : index417 // CHECK: %[[ARG1_BROADCAST:.*]] = scf.if %[[VAL_8]] -> (tensor<2x?xf32>) {418 // CHECK: %[[VAL_9:.*]] = tensor.empty(%[[MAX_DIM1]]) : tensor<2x?xf32>419 // CHECK: %[[VAL_10:.*]] = linalg.generic {indexing_maps = [#[[$MAP0]], #[[$MAP1]]], iterator_types = ["parallel", "parallel"]} ins(%[[ARG1]] : tensor<2x?xf32>) outs(%[[VAL_9]] : tensor<2x?xf32>) {420 // CHECK: ^bb0(%[[VAL_11:.*]]: f32, %[[VAL_12:.*]]: f32):421 // CHECK: linalg.yield %[[VAL_11]] : f32422 // CHECK: } -> tensor<2x?xf32>423 // CHECK: scf.yield %[[VAL_10]] : tensor<2x?xf32>424 // CHECK: } else {425 // CHECK: scf.yield %[[ARG1]] : tensor<2x?xf32>426 // CHECK: }427 428 // CHECK: %[[VAL_13:.*]] = tensor.dim %[[ARG2]], %[[CONST1]] : tensor<2x?xf32>429 // CHECK: %[[VAL_14:.*]] = arith.cmpi eq, %[[VAL_13]], %[[CONST1]] : index430 // CHECK: %[[ARG2_BROADCAST:.*]] = scf.if %[[VAL_14]] -> (tensor<2x?xf32>) {431 // CHECK: %[[VAL_15:.*]] = tensor.empty(%[[MAX_DIM1]]) : tensor<2x?xf32>432 // CHECK: %[[VAL_16:.*]] = linalg.generic {indexing_maps = [#[[$MAP0]], #[[$MAP1]]], iterator_types = ["parallel", "parallel"]} ins(%[[ARG2]] : tensor<2x?xf32>) outs(%[[VAL_15]] : tensor<2x?xf32>) {433 // CHECK: ^bb0(%[[VAL_17:.*]]: f32, %[[VAL_18:.*]]: f32):434 // CHECK: linalg.yield %[[VAL_17]] : f32435 // CHECK: } -> tensor<2x?xf32>436 // CHECK: scf.yield %[[VAL_16]] : tensor<2x?xf32>437 // CHECK: } else {438 // CHECK: scf.yield %[[ARG2]] : tensor<2x?xf32>439 // CHECK: }440 441 // CHECK: %[[VAL_19:.*]] = tensor.empty(%[[MAX_DIM1]]) : tensor<2x?xf32>442 // CHECK: %[[RESULT:.*]] = linalg.generic {indexing_maps = [#[[$MAP1]], #[[$MAP1]], #[[$MAP1]], #[[$MAP1]]], iterator_types = ["parallel", "parallel"]} ins(%[[ARG0_BROADCAST]], %[[ARG1_BROADCAST]], %[[ARG2_BROADCAST]] : tensor<2x?xi1>, tensor<2x?xf32>, tensor<2x?xf32>) outs(%[[VAL_19]] : tensor<2x?xf32>) {443 // CHECK: ^bb0(%[[VAL_20:.*]]: i1, %[[VAL_21:.*]]: f32, %[[VAL_22:.*]]: f32, %[[VAL_23:.*]]: f32):444 // CHECK: %[[VAL_24:.*]] = arith.select %[[VAL_20]], %[[VAL_21]], %[[VAL_22]] : f32445 // CHECK: linalg.yield %[[VAL_24]] : f32446 // CHECK: } -> tensor<2x?xf32>447 %0 = tosa.select %arg0, %arg1, %arg2 : (tensor<2x?xi1>, tensor<2x?xf32>, tensor<2x?xf32>) -> tensor<2x?xf32>448 449 // CHECK: return %[[RESULT]] : tensor<2x?xf32>450 return %0 : tensor<2x?xf32>451}452 453// -----454 455// CHECK-LABEL: @test_simple_f32456func.func @test_simple_f32(%arg0: tensor<1xf32>) -> () {457 // CHECK: linalg.generic458 // CHECK: tanh459 %0 = tosa.tanh %arg0 : (tensor<1xf32>) -> tensor<1xf32>460 461 // CHECK: linalg.generic462 // CHECK: math.absf463 %1 = tosa.abs %arg0 : (tensor<1xf32>) -> tensor<1xf32>464 465 // CHECK: linalg.generic466 // CHECK: arith.addf467 %2 = tosa.add %0, %0 : (tensor<1xf32>, tensor<1xf32>) -> tensor<1xf32>468 469 // CHECK: linalg.generic470 // CHECK: arith.subf471 %3 = tosa.sub %0, %1 : (tensor<1xf32>, tensor<1xf32>) -> tensor<1xf32>472 473 // CHECK: linalg.generic474 // CHECK: arith.mulf475 %shift = "tosa.const"() <{values = dense<0> : tensor<1xi8>}> : () -> tensor<1xi8>476 %4 = tosa.mul %0, %1, %shift : (tensor<1xf32>, tensor<1xf32>, tensor<1xi8>) -> tensor<1xf32>477 478 // CHECK: linalg.generic479 // CHECK: arith.negf480 %in_zp = "tosa.const"() <{values = dense<0.0> : tensor<1xf32>}> : () -> tensor<1xf32>481 %out_zp = "tosa.const"() <{values = dense<0.0> : tensor<1xf32>}> : () -> tensor<1xf32>482 %5 = tosa.negate %0, %in_zp, %out_zp : (tensor<1xf32>, tensor<1xf32>, tensor<1xf32>) -> tensor<1xf32>483 484 // CHECK: linalg.generic485 // CHECK: pow486 %6 = tosa.pow %1, %2 : (tensor<1xf32>, tensor<1xf32>) -> tensor<1xf32>487 488 // CHECK: linalg.generic489 // CHECK: rsqrt490 %7 = tosa.rsqrt %1 : (tensor<1xf32>) -> tensor<1xf32>491 492 // CHECK: linalg.generic493 // CHECK: log494 %8 = tosa.log %arg0 : (tensor<1xf32>) -> tensor<1xf32>495 496 // CHECK: linalg.generic497 // CHECK: exp498 %9 = tosa.exp %arg0 : (tensor<1xf32>) -> tensor<1xf32>499 500 // CHECK: linalg.generic501 // CHECK: arith.cmpf502 %10 = tosa.greater %0, %1 : (tensor<1xf32>, tensor<1xf32>) -> tensor<1xi1>503 504 // CHECK: linalg.generic505 // CHECK: arith.cmpf506 %11 = tosa.greater_equal %0, %1 : (tensor<1xf32>, tensor<1xf32>) -> tensor<1xi1>507 508 // CHECK: linalg.generic509 // CHECK: arith.cmpf510 %12 = tosa.equal %0, %1 : (tensor<1xf32>, tensor<1xf32>) -> tensor<1xi1>511 512 // CHECK: linalg.generic513 // CHECK: select514 %13 = tosa.select %10, %0, %1 : (tensor<1xi1>, tensor<1xf32>, tensor<1xf32>) -> tensor<1xf32>515 516 // CHECK: linalg.generic517 // CHECK: arith.maximumf518 %14 = tosa.maximum %0, %1 : (tensor<1xf32>, tensor<1xf32>) -> tensor<1xf32>519 520 // CHECK: linalg.generic521 // CHECK: arith.minimumf522 %15 = tosa.minimum %0, %1 : (tensor<1xf32>, tensor<1xf32>) -> tensor<1xf32>523 524 // CHECK: linalg.generic525 // CHECK: ceil526 %16 = tosa.ceil %0 : (tensor<1xf32>) -> tensor<1xf32>527 528 // CHECK: linalg.generic529 // CHECK: floor530 %17 = tosa.floor %0 : (tensor<1xf32>) -> tensor<1xf32>531 532 // CHECK: linalg.generic533 // CHECK: arith.minimumf534 // CHECK: arith.maximumf535 %18 = tosa.clamp %0 {min_val = 1.0 : f32, max_val = 5.0 : f32} : (tensor<1xf32>) -> tensor<1xf32>536 537 // CHECK: linalg.generic538 // CHECK: arith.negf539 // CHECK: exp540 // CHECK: arith.addf541 // CHECK: arith.divf542 %19 = tosa.sigmoid %0 : (tensor<1xf32>) -> tensor<1xf32>543 544 // CHECK: linalg.generic545 // CHECK: [[ROUND:%.+]] = math.roundeven {{%.+}} : f32546 // CHECK: [[CSTMIN:%.+]] = arith.constant -2.14748365E+9 : f32547 // CHECK: [[CSTMAXP1:%.+]] = arith.constant 2.14748365E+9 : f32548 // CHECK: [[CSTMAX:%.+]] = arith.constant 2147483647 : i32549 // CHECK: [[MAX:%.+]] = arith.maximumf [[ROUND]], [[CSTMIN]] : f32550 // CHECK: [[CONV:%.+]] = arith.fptosi [[MAX]] : f32 to i32551 // CHECK: [[CMP:%.+]] = arith.cmpf uge, [[ROUND]], [[CSTMAXP1]] : f32552 // CHECK: arith.select [[CMP]], [[CSTMAX]], [[CONV]] : i32553 %20 = tosa.cast %0 : (tensor<1xf32>) -> tensor<1xi32>554 555 // CHECK: linalg.generic556 // CHECK: arith.constant 0557 // CHECK: arith.cmpf558 %21 = tosa.cast %0 : (tensor<1xf32>) -> tensor<1xi1>559 560 // CHECK: linalg.generic561 // CHECK: arith.truncf562 %22 = tosa.cast %0 : (tensor<1xf32>) -> tensor<1xf16>563 564 // CHECK: linalg.generic565 // CHECK: arith.divf566 %23 = tosa.reciprocal %0 : (tensor<1xf32>) -> tensor<1xf32>567 568 // CHECK: linalg.generic569 // CHECK: math.erf570 %24 = tosa.erf %0 : (tensor<1xf32>) -> tensor<1xf32>571 572 // CHECK: linalg.generic573 // CHECK: math.sin574 %25 = tosa.sin %arg0 : (tensor<1xf32>) -> tensor<1xf32>575 576 // CHECK: linalg.generic577 // CHECK: math.cos578 %26 = tosa.cos %arg0 : (tensor<1xf32>) -> tensor<1xf32>579 580 return581}582 583// -----584 585// CHECK-LABEL: @test_simple_f16586func.func @test_simple_f16(%arg0: tensor<1xf16>) -> () {587 588 // CHECK: linalg.generic589 // CHECK: arith.extf590 %0 = tosa.cast %arg0 : (tensor<1xf16>) -> tensor<1xf32>591 592 // CHECK: linalg.generic593 // CHECK: [[ROUND:%.+]] = math.roundeven {{%.+}} : f16594 // CHECK: [[CSTMIN:%.+]] = arith.constant -1.280000e+02 : f16595 // CHECK: [[CSTMAX:%.+]] = arith.constant 1.270000e+02 : f16596 // CHECK: [[MIN:%.+]] = arith.minimumf [[ROUND]], [[CSTMAX]] : f16597 // CHECK: [[CLAMP:%.+]] = arith.maximumf [[MIN]], [[CSTMIN]] : f16598 // CHECK: arith.fptosi [[CLAMP]] : f16 to i8599 %1 = "tosa.cast"(%arg0) : (tensor<1xf16>) -> tensor<1xi8>600 601 // CHECK: linalg.generic602 // CHECK: [[ROUND:%.+]] = math.roundeven {{%[a-z0-9_]+}} : f16603 // CHECK: [[CONV:%.+]] = arith.fptosi [[ROUND]] : f16 to i32604 // CHECK: [[POSINF:%.+]] = arith.constant 0x7C00 : f16605 // CHECK: [[NEGINF:%.+]] = arith.constant 0xFC00 : f16606 // CHECK: [[OVERFLOW:%.+]] = arith.cmpf ueq, [[ROUND]], [[POSINF]] : f16607 // CHECK: [[UNDERFLOW:%.+]] = arith.cmpf ueq, [[ROUND]], [[NEGINF]] : f16608 // CHECK: [[MININT:%.+]] = arith.constant -2147483648 : i32609 // CHECK: [[MAXINT:%.+]] = arith.constant 2147483647 : i32610 // CHECK: [[CLAMPPOSINF:%.+]] = arith.select [[OVERFLOW]], [[MAXINT]], [[CONV]] : i32611 // CHECK: arith.select [[UNDERFLOW]], [[MININT]], [[CLAMPPOSINF]] : i32612 %2 = "tosa.cast"(%arg0) : (tensor<1xf16>) -> tensor<1xi32>613 return614}615 616// -----617 618// CHECK-LABEL: @test_simple_i16619func.func @test_simple_i16(%arg0: tensor<1xi16>) -> () {620 // CHECK: linalg.generic621 // CHECK: arith.extsi622 // CHECK: arith.extsi623 // CHECK: arith.muli624 %shift = "tosa.const"() <{values = dense<0> : tensor<1xi8>}> : () -> tensor<1xi8>625 %0 = tosa.mul %arg0, %arg0, %shift : (tensor<1xi16>, tensor<1xi16>, tensor<1xi8>) -> tensor<1xi32>626 627 return628}629 630// -----631 632// CHECK-LABEL: @test_simple_ui8633func.func @test_simple_ui8(%arg0: tensor<1xui8>) -> () {634 // CHECK: arith.uitofp635 %0 = tosa.cast %arg0 : (tensor<1xui8>) -> tensor<1xf32>636 return637}638 639// -----640 641// CHECK-LABEL: @test_simple_i32642func.func @test_simple_i32(%arg0: tensor<1xi32>, %unsigned: tensor<1xui32>, %unsigned64: tensor<1xui64>) -> () {643 // CHECK: linalg.generic644 // CHECK: arith.addi645 %0 = tosa.add %arg0, %arg0 : (tensor<1xi32>, tensor<1xi32>) -> tensor<1xi32>646 647 // CHECK: linalg.generic648 // CHECK: arith.subi649 %1 = tosa.sub %arg0, %arg0 : (tensor<1xi32>, tensor<1xi32>) -> tensor<1xi32>650 651 // CHECK: linalg.generic652 // CHECK: arith.muli653 %shift1 = "tosa.const"() <{values = dense<0> : tensor<1xi8>}> : () -> tensor<1xi8>654 %2 = tosa.mul %arg0, %arg0, %shift1 : (tensor<1xi32>, tensor<1xi32>, tensor<1xi8>) -> tensor<1xi32>655 656 // CHECK: linalg.generic657 // CHECK: arith.constant 2658 // CHECK: apply_scale659 %shift2 = "tosa.const"() <{values = dense<2> : tensor<1xi8>}> : () -> tensor<1xi8>660 %3 = tosa.mul %arg0, %arg0, %shift2: (tensor<1xi32>, tensor<1xi32>, tensor<1xi8>) -> tensor<1xi32>661 662 // CHECK: linalg.generic663 // CHECK: arith.divsi664 %4 = tosa.intdiv %arg0, %arg0 : (tensor<1xi32>, tensor<1xi32>) -> tensor<1xi32>665 666 // CHECK: linalg.generic667 // CHECK: ^bb0(%[[ARG1:.*]]: i32, %[[ARG2:.*]]: i32):668 // CHECK: [[ZERO:%.+]] = arith.constant 0669 // CHECK: arith.subi [[ZERO]], %[[ARG1]]670 %in_zp = "tosa.const"() <{values = dense<0> : tensor<1xi32>}> : () -> tensor<1xi32>671 %out_zp = "tosa.const"() <{values = dense<0> : tensor<1xi32>}> : () -> tensor<1xi32>672 %5 = tosa.negate %arg0, %in_zp, %out_zp : (tensor<1xi32>, tensor<1xi32>, tensor<1xi32>) -> tensor<1xi32>673 674 // CHECK: linalg.generic675 // CHECK: and676 %6 = tosa.bitwise_and %arg0, %arg0 : (tensor<1xi32>, tensor<1xi32>) -> tensor<1xi32>677 678 // CHECK: linalg.generic679 // CHECK: or680 %7 = tosa.bitwise_or %arg0, %arg0 : (tensor<1xi32>, tensor<1xi32>) -> tensor<1xi32>681 682 // CHECK: linalg.generic683 // CHECK: arith.xori684 %8 = tosa.bitwise_xor %arg0, %arg0 : (tensor<1xi32>, tensor<1xi32>) -> tensor<1xi32>685 686 // CHECK: linalg.generic687 // CHECK: arith.shli688 %9 = tosa.logical_left_shift %arg0, %arg0 : (tensor<1xi32>, tensor<1xi32>) -> tensor<1xi32>689 690 // CHECK: linalg.generic691 // CHECK: arith.shrui692 %10 = tosa.logical_right_shift %arg0, %arg0 : (tensor<1xi32>, tensor<1xi32>) -> tensor<1xi32>693 694 // CHECK: linalg.generic695 // CHECK: arith.shrsi696 %11 = tosa.arithmetic_right_shift %arg0, %arg0 {round = 0 : i1} : (tensor<1xi32>, tensor<1xi32>) -> tensor<1xi32>697 698 // CHECK: linalg.generic699 // CHECK: arith.constant 1700 // CHECK: arith.constant 0701 // CHECK: arith.constant false702 // CHECK: arith.constant true703 // CHECK: arith.cmpi704 // CHECK: arith.subi705 // CHECK: arith.shrsi706 // CHECK: arith.trunci707 // CHECK: and708 // CHECK: arith.select709 // CHECK: arith.extui710 // CHECK: arith.addi711 %12 = tosa.arithmetic_right_shift %arg0, %arg0 {round = 1 : i1} : (tensor<1xi32>, tensor<1xi32>) -> tensor<1xi32>712 713 // CHECK: math.ctlz714 %13 = tosa.clz %arg0 : (tensor<1xi32>) -> tensor<1xi32>715 716 // CHECK: linalg.generic717 // CHECK: arith.cmpi718 %14 = tosa.greater %0, %1 : (tensor<1xi32>, tensor<1xi32>) -> tensor<1xi1>719 720 // CHECK: linalg.generic721 // CHECK: arith.cmpi722 %15 = tosa.greater_equal %0, %1 : (tensor<1xi32>, tensor<1xi32>) -> tensor<1xi1>723 724 // CHECK: linalg.generic725 // CHECK: select726 %16 = tosa.select %14, %0, %1 : (tensor<1xi1>, tensor<1xi32>, tensor<1xi32>) -> tensor<1xi32>727 728 // CHECK: linalg.generic729 // CHECK: arith.maxsi730 %17 = tosa.maximum %0, %1 : (tensor<1xi32>, tensor<1xi32>) -> tensor<1xi32>731 732 // CHECK: linalg.generic733 // CHECK: arith.minsi734 %18 = tosa.minimum %0, %1 : (tensor<1xi32>, tensor<1xi32>) -> tensor<1xi32>735 736 // CHECK: linalg.generic737 // CHECK-DAG: arith.maxsi738 // CHECK-DAG: arith.minsi739 %19 = tosa.clamp %0 {min_val = 1 : i32, max_val = 5 : i32} : (tensor<1xi32>) -> tensor<1xi32>740 741 // CHECK: linalg.generic742 // CHECK-DAG: %[[LB:.*]] = arith.constant 4 : i32743 // CHECK-DAG: %[[UB:.*]] = arith.constant 32 : i32744 // CHECK-DAG: arith.maxui %[[LB]],745 // CHECK-DAG: arith.minui %[[UB]],746 %u0 = tosa.clamp %unsigned {min_val = 4 : ui32, max_val = 32 : ui32} : (tensor<1xui32>) -> tensor<1xui32>747 748 // CHECK: linalg.generic749 // CHECK: arith.trunci750 %20 = tosa.cast %0 : (tensor<1xi32>) -> tensor<1xi16>751 752 // CHECK: linalg.generic753 // CHECK: arith.extsi754 %21 = tosa.cast %0 : (tensor<1xi32>) -> tensor<1xi64>755 756 // CHECK: linalg.generic757 // CHECK: arith.constant 0758 // CHECK: arith.cmpi759 %22 = tosa.cast %0 : (tensor<1xi32>) -> tensor<1xi1>760 761 // CHECK: linalg.generic762 // CHECK: arith.sitofp763 %23 = tosa.cast %0 : (tensor<1xi32>) -> tensor<1xf32>764 765 // CHECK: linalg.generic766 // CHECK: arith.constant 0767 // CHECK: arith.subi768 // CHECK: arith.maxsi769 %24 = tosa.abs %arg0 : (tensor<1xi32>) -> tensor<1xi32>770 771 return772}773 774// -----775 776// CHECK-LABEL: @test_simple_ui8777func.func @test_simple_ui8(%arg0: tensor<1xi8>) -> () {778 779 // CHECK: linalg.generic780 // CHECK: sitofp781 %0 = tosa.cast %arg0 : (tensor<1xi8>) -> tensor<1xf32>782 783 return784}785 786// -----787 788// CHECK-LABEL: @test_i8789func.func @test_i8(%arg0: tensor<1xi8>) -> () {790 // CHECK: linalg.generic791 // CHECK: ^bb0(%[[ARG1:.+]]: i8,792 // CHECK-DAG: %[[C127:.+]] = arith.constant -127793 // CHECK-DAG: %[[C126:.+]] = arith.constant 126794 // CHECK-DAG: %[[LOWER:.+]] = arith.maxsi %[[C127]], %[[ARG1]]795 // CHECK-DAG: %[[CLAMPED:.+]] = arith.minsi %[[C126]], %[[LOWER]]796 %0 = tosa.clamp %arg0 {min_val = -127 : i8, max_val = 126 : i8} : (tensor<1xi8>) -> tensor<1xi8>797 798 return799}800 801// -----802 803// CHECK-LABEL: @test_i64804func.func @test_i64(%arg0: tensor<1xi64>) -> () {805 // CHECK: linalg.generic806 // CHECK: ^bb0(%[[ARG1:.+]]: i64,807 // CHECK-DAG: %[[C127:.+]] = arith.constant -9223372036854775808808 // CHECK-DAG: %[[C126:.+]] = arith.constant 9223372036854775807809 // CHECK-DAG: %[[LOWER:.+]] = arith.maxsi %[[C127]], %[[ARG1]]810 // CHECK-DAG: %[[CLAMPED:.+]] = arith.minsi %[[C126]], %[[LOWER]]811 %0 = tosa.clamp %arg0 {min_val = -9223372036854775808 : i64, max_val = 9223372036854775807 : i64} : (tensor<1xi64>) -> tensor<1xi64>812 813 return814}815 816// -----817 818// CHECK-LABEL: @test_clamp_f16819func.func @test_clamp_f16(%arg0: tensor<1xf16>) -> () {820 // CHECK: linalg.generic821 // CHECK: ^bb0(%[[ARG1:.+]]: f16,822 // CHECK-DAG: %[[C0:.+]] = arith.constant 0.0823 // CHECK-DAG: %[[C6:.+]] = arith.constant 6.0824 // CHECK-DAG: %[[MIN:.+]] = arith.minimumf %[[ARG1]], %[[C6]]825 // CHECK-DAG: %[[MAX:.+]] = arith.maximumf %[[MIN]], %[[C0]]826 %0 = tosa.clamp %arg0 {min_val = 0.0 : f16, max_val = 6.0 : f16} : (tensor<1xf16>) -> tensor<1xf16>827 828 return829}830 831// -----832 833// CHECK-LABEL: @test_bool834func.func @test_bool(%arg0: tensor<1xi1>, %arg1: tensor<1xi1>) -> () {835 // CHECK: linalg.generic836 // CHECK: and837 %0 = tosa.logical_and %arg0, %arg1 : (tensor<1xi1>, tensor<1xi1>) -> tensor<1xi1>838 839 // CHECK: linalg.generic840 // CHECK: or841 %1 = tosa.logical_or %arg0, %arg1 : (tensor<1xi1>, tensor<1xi1>) -> tensor<1xi1>842 843 // CHECK: linalg.generic844 // CHECK: arith.xori845 %2 = tosa.logical_xor %arg0, %arg1 : (tensor<1xi1>, tensor<1xi1>) -> tensor<1xi1>846 847 // CHECK: linalg.generic848 // CHECK: arith.constant true849 // CHECK: arith.xori850 %3 = tosa.logical_not %arg0 : (tensor<1xi1>) -> tensor<1xi1>851 852 return853}854 855// -----856 857// CHECK-LABEL: @test_negate_quantized858func.func @test_negate_quantized(%arg0: tensor<1xi8>) -> () {859 // CHECK: linalg.generic860 // CHECK: ^bb0(%[[BBARG0:.+]]: i8, %[[BBARG1:.+]]: i8861 // CHECK: [[CNST:%.+]] = arith.constant 7862 // CHECK: [[EXT:%.+]] = arith.extsi %[[BBARG0]] : i8 to i16863 // CHECK: [[SUB:%.+]] = arith.subi [[CNST]], [[EXT]]864 // CHECK: [[MIN:%.+]] = arith.constant -128865 // CHECK: [[MAX:%.+]] = arith.constant 127866 // CHECK: [[LBOUND:%.+]] = arith.maxsi [[MIN]], [[SUB]]867 // CHECK: [[UBOUND:%.+]] = arith.minsi [[MAX]], [[LBOUND]]868 // CHECK: [[TRUNC:%.+]] = arith.trunci [[UBOUND]]869 // CHECK: linalg.yield [[TRUNC]]870 %in_zp0 = "tosa.const"() <{values = dense<0> : tensor<1xi8>}> : () -> tensor<1xi8>871 %out_zp0 = "tosa.const"() <{values = dense<7> : tensor<1xi8>}> : () -> tensor<1xi8>872 %0 = tosa.negate %arg0, %in_zp0, %out_zp0 : (tensor<1xi8>, tensor<1xi8>, tensor<1xi8>) -> tensor<1xi8>873 874 // CHECK: linalg.generic875 // CHECK: ^bb0(%[[BBARG0:.+]]: i8, %[[BBARG1:.+]]: i8876 // CHECK: [[C_128:%.+]] = arith.constant -128877 // CHECK: [[EXT:%.+]] = arith.extsi %[[BBARG0]] : i8 to i16878 // CHECK: [[SUB:%.+]] = arith.subi [[C_128]], [[EXT]]879 // CHECK: [[MIN:%.+]] = arith.constant -128880 // CHECK: [[MAX:%.+]] = arith.constant 127881 // CHECK: [[LBOUND:%.+]] = arith.maxsi [[MIN]], [[SUB]]882 // CHECK: [[UBOUND:%.+]] = arith.minsi [[MAX]], [[LBOUND]]883 // CHECK: [[TRUNC:%.+]] = arith.trunci [[UBOUND]]884 // CHECK: linalg.yield [[TRUNC]]885 %in_zp3 = "tosa.const"() <{values = dense<-128> : tensor<1xi8>}> : () -> tensor<1xi8>886 %out_zp3 = "tosa.const"() <{values = dense<0> : tensor<1xi8>}> : () -> tensor<1xi8>887 %3 = tosa.negate %arg0, %in_zp3, %out_zp3 : (tensor<1xi8>, tensor<1xi8>, tensor<1xi8>) -> tensor<1xi8>888 889 // CHECK: linalg.generic890 // CHECK: ^bb0(%[[BBARG0:.+]]: i8,891 // CHECK: [[ZERO:%.+]] = arith.constant 0892 // CHECK: [[SUB:%.+]] = arith.subi [[ZERO]],893 // CHECK: linalg.yield [[SUB]]894 %in_zp4 = "tosa.const"() <{values = dense<0> : tensor<1xi8>}> : () -> tensor<1xi8>895 %out_zp4 = "tosa.const"() <{values = dense<0> : tensor<1xi8>}> : () -> tensor<1xi8>896 %4 = tosa.negate %arg0, %in_zp4, %out_zp4 : (tensor<1xi8>, tensor<1xi8>, tensor<1xi8>) -> tensor<1xi8>897 898 return899}900 901// -----902 903// CHECK-LABEL: @test_negate_no_const_1904func.func @test_negate_no_const_1(%arg0: tensor<50x42xf16> ,%arg1: tensor<1xf16> , %arg2: tensor<1xf16> ) -> tensor<*xf16> {905 // CHECK: %[[GENERIC:.+]] = linalg.generic 906 // CHECK: ^bb0([[ARG0:%.*]]: f16, [[ARG1:%.*]]: f16, [[ARG2:%.*]]: f16, [[OUT:%.*]]: f16)907 // CHECK: [[ELEMENT:%.*]] = arith.negf [[ARG0]] : f16908 %0 = tosa.negate %arg0, %arg1, %arg2 : (tensor<50x42xf16>, tensor<1xf16>, tensor<1xf16>) -> tensor<50x42xf16>909 %cast = tensor.cast %0 : tensor<50x42xf16> to tensor<*xf16>910 return %cast : tensor<*xf16>911}912 913// -----914 915// CHECK-LABEL: @test_negate_no_const_2916func.func @test_negate_no_const_2(%arg0: tensor<50x42xi16> ,%arg1: tensor<1xi16> , %arg2: tensor<1xi16> ) -> tensor<*xi16> {917 // CHECK: %[[GENERIC:.+]] = linalg.generic 918 // CHECK: ^bb0([[ARG0:%.*]]: i16, [[ARG1:%.*]]: i16, [[ARG2:%.*]]: i16, [[OUT:%.*]]: i16)919 // CHECK: [[EXTSI1:%.*]] = arith.extsi [[ARG1]] : i16 to i64920 // CHECK: [[EXTSI2:%.*]] = arith.extsi [[ARG2]] : i16 to i64921 // CHECK: [[SUM:%.*]] = arith.addi [[EXTSI1]], [[EXTSI2]] : i64922 // CHECK: [[EXTSI0:%.*]] = arith.extsi [[ARG0]] : i16 to i64923 // CHECK: [[SUB:%.*]] = arith.subi [[SUM]], [[EXTSI0]] : i64924 // CHECK: [[C_32768:%.*]] = arith.constant -32768 : i64925 // CHECK: [[C32767:%.*]] = arith.constant 32767 : i64926 // CHECK: [[MAX:%.*]] = arith.maxsi [[C_32768]], [[SUB]] : i64927 // CHECK: [[MIN:%.*]] = arith.minsi [[C32767]], [[MAX]] : i64928 // CHECK: [[TRUNC:%.*]] = arith.trunci [[MIN]] : i64 to i16929 %0 = tosa.negate %arg0, %arg1, %arg2 : (tensor<50x42xi16>, tensor<1xi16>, tensor<1xi16>) -> tensor<50x42xi16>930 %cast = tensor.cast %0 : tensor<50x42xi16> to tensor<*xi16>931 return %cast : tensor<*xi16>932}933 934// -----935 936// CHECK-LABEL: @test_identity937// CHECK-SAME: %[[ARG0:[0-9a-zA-Z_]*]]: tensor<1xf32>,938// CHECK-SAME: %[[ARG1:[0-9a-zA-Z_]*]]: tensor<1xi32>939func.func @test_identity(%arg0: tensor<1xf32>, %arg1: tensor<1xi32>) -> (tensor<1xf32>, tensor<1xi32>) {940 %0 = tosa.identity %arg0 : (tensor<1xf32>) -> tensor<1xf32>941 %1 = tosa.identity %arg1 : (tensor<1xi32>) -> tensor<1xi32>942 943 // CHECK: return %[[ARG0]], %[[ARG1]]944 return %0, %1 : tensor<1xf32>, tensor<1xi32>945}946 947// -----948 949// CHECK: #[[$MAP0:.*]] = affine_map<(d0) -> (d0)>950// CHECK-LABEL: @reduce_bf16951// CHECK-SAME: [[ARG0:%.+]]: tensor<5x4xbf16>952func.func @reduce_bf16(%arg0: tensor<5x4xbf16>) -> () {953 // CHECK: [[INIT:%.+]] = tensor.empty() : tensor<4xf32>954 // CHECK: [[CST0:%.+]] = arith.constant 0.0955 // CHECK: [[FILL:%.+]] = linalg.fill ins([[CST0]]{{.*}}outs([[INIT]]956 // CHECK: [[REDUCE:%.+]] = linalg.reduce ins([[ARG0]] : tensor<5x4xbf16>) outs([[FILL]] : tensor<4xf32>) dimensions = [0]957 // CHECK: (%[[ARG1:.*]]: bf16, %[[ARG2:.*]]: f32) {958 // CHECK: [[EXTF:%.+]] = arith.extf %[[ARG1]] : bf16 to f32959 // CHECK: [[ACC:%.+]] = arith.addf [[EXTF]], %[[ARG2]] : f32960 // CHECK: linalg.yield [[ACC]] : f32961 // CHECK: }962 // CHECK: [[INIT_RES:%.+]] = tensor.empty() : tensor<4xbf16>963 // CHECK: [[RES:%.+]] = linalg.generic {indexing_maps = [#[[$MAP0]], #[[$MAP0]]], iterator_types = ["parallel"]} ins([[REDUCE]] : tensor<4xf32>) outs([[INIT_RES]] : tensor<4xbf16>)964 // CHECK: ^bb0(%[[IN:.*]]: f32, %[[OUT:.*]]: bf16):965 // CHECK: [[TRUNCF:%.+]] = arith.truncf %[[IN]] : f32 to bf16966 // CHECK: linalg.yield [[TRUNCF]] : bf16967 // CHECK: }968 // CHECK: tensor.expand_shape [[RES]] {{\[}}[0, 1]] output_shape [1, 4] : tensor<4xbf16> into tensor<1x4xbf16>969 %0 = tosa.reduce_sum %arg0 {axis = 0 : i32} : (tensor<5x4xbf16>) -> tensor<1x4xbf16>970 return971}972 973// -----974 975// CHECK-LABEL: @reduce_float976// CHECK-SAME: [[ARG0:%.+]]: tensor<5x4xf32>977func.func @reduce_float(%arg0: tensor<5x4xf32>) -> () {978 // CHECK: [[INIT:%.+]] = tensor.empty() : tensor<4xf32>979 // CHECK: [[CST0:%.+]] = arith.constant 0.0980 // CHECK: [[FILL:%.+]] = linalg.fill ins([[CST0]]{{.*}}outs([[INIT]]981 // CHECK: [[REDUCE:%.+]] = linalg.reduce ins([[ARG0]] : tensor<5x4xf32>) outs([[FILL]] : tensor<4xf32>) dimensions = [0]982 // CHECK: (%[[ARG1:.*]]: f32, %[[ARG2:.*]]: f32) {983 // CHECK: [[RES:%.+]] = arith.addf %[[ARG1]], %[[ARG2]] : f32984 // CHECK: linalg.yield [[RES]] : f32985 // CHECK: }986 // CHECK: tensor.expand_shape [[REDUCE]] {{\[}}[0, 1]] output_shape [1, 4] : tensor<4xf32> into tensor<1x4xf32>987 %0 = tosa.reduce_sum %arg0 {axis = 0 : i32} : (tensor<5x4xf32>) -> tensor<1x4xf32>988 989 // CHECK: [[INIT:%.+]] = tensor.empty() : tensor<5xf32>990 // CHECK: [[CST0:%.+]] = arith.constant 0.0991 // CHECK: [[FILL:%.+]] = linalg.fill ins([[CST0]]{{.*}}outs([[INIT]]992 // CHECK: [[REDUCE:%.+]] = linalg.reduce ins([[ARG0]] : tensor<5x4xf32>) outs([[FILL]] : tensor<5xf32>) dimensions = [1]993 // CHECK: (%[[ARG1:.*]]: f32, %[[ARG2:.*]]: f32) {994 // CHECK: [[RES:%.+]] = arith.addf %[[ARG1]], %[[ARG2]] : f32995 // CHECK: linalg.yield [[RES]] : f32996 // CHECK: }997 // CHECK: tensor.expand_shape [[REDUCE]] {{\[}}[0, 1]] output_shape [5, 1] : tensor<5xf32> into tensor<5x1xf32>998 %1 = tosa.reduce_sum %arg0 {axis = 1 : i32} : (tensor<5x4xf32>) -> tensor<5x1xf32>999 1000 // CHECK: arith.constant 1.01001 // CHECK: linalg.fill1002 // CHECK: linalg.reduce1003 // CHECK: arith.mulf1004 %2 = tosa.reduce_product %arg0 {axis = 0 : i32} : (tensor<5x4xf32>) -> tensor<1x4xf32>1005 1006 // CHECK: arith.constant 3.40282347E+38 : f321007 // CHECK: linalg.fill1008 // CHECK: linalg.reduce1009 // CHECK: arith.minimumf1010 %3 = tosa.reduce_min %arg0 {axis = 0 : i32} : (tensor<5x4xf32>) -> tensor<1x4xf32>1011 1012 // CHECK: arith.constant -3.40282347E+38 : f321013 // CHECK: linalg.fill1014 // CHECK: linalg.reduce1015 // CHECK: arith.maximumf1016 %4 = tosa.reduce_max %arg0 {axis = 0 : i32} : (tensor<5x4xf32>) -> tensor<1x4xf32>1017 return1018}1019 1020// -----1021 1022// CHECK-LABEL: @reduce_float_dyn1023// CHECK-SAME: %[[ARG0:[0-9a-zA-Z_]*]]: tensor<?x5x4xf32>1024func.func @reduce_float_dyn(%arg0: tensor<?x5x4xf32>) -> () {1025 // CHECK: %[[C0:.+]] = arith.constant 01026 // CHECK: %[[DYN:.+]] = tensor.dim %[[ARG0]], %[[C0]]1027 // CHECK: %[[INIT:.+]] = tensor.empty(%[[DYN]]) : tensor<?x4xf32>1028 // CHECK: %[[CST0:.+]] = arith.constant 0.01029 // CHECK: %[[FILL:.+]] = linalg.fill ins(%[[CST0]]{{.*}}outs(%[[INIT]]1030 // CHECK: %[[REDUCE:.+]] = linalg.reduce ins(%[[ARG0]] : tensor<?x5x4xf32>) outs(%[[FILL]] : tensor<?x4xf32>) dimensions = [1]1031 // CHECK: (%[[ARG1:.*]]: f32, %[[ARG2:.*]]: f32) {1032 // CHECK: %[[RES:.+]] = arith.addf %[[ARG1]], %[[ARG2]] : f321033 // CHECK: linalg.yield %[[RES]] : f321034 // CHECK: }1035 // CHECK: %[[C0_0:.+]] = arith.constant 0 : index1036 // CHECK: %[[DIM_1:.+]] = tensor.dim %[[REDUCE]], %[[C0_0]] : tensor<?x4xf32>1037 // CHECK: %[[C1:.+]] = arith.constant 1 : index1038 // CHECK: tensor.expand_shape %[[REDUCE]] {{\[}}[0], [1, 2]] output_shape [%[[DIM_1]], 1, 4] : tensor<?x4xf32> into tensor<?x1x4xf32>1039 %0 = tosa.reduce_sum %arg0 {axis = 1 : i32} : (tensor<?x5x4xf32>) -> tensor<?x1x4xf32>1040 return1041}1042 1043// -----1044 1045// CHECK-LABEL: @reduce_float_dyn_rank_11046// CHECK-SAME: %[[ARG0:[0-9a-zA-Z_]*]]: tensor<?xf32>1047func.func @reduce_float_dyn_rank_1(%arg0: tensor<?xf32>) -> () {1048 // CHECK-DAG: %[[INIT:.+]] = tensor.empty() : tensor<f32>1049 // CHECK-DAG: %[[CST0:.+]] = arith.constant 0.01050 // CHECK: %[[FILL:.+]] = linalg.fill ins(%[[CST0]]{{.*}}outs(%[[INIT]]1051 // CHECK: %[[REDUCE:.+]] = linalg.reduce ins(%[[ARG0]] : tensor<?xf32>) outs(%[[FILL]] : tensor<f32>) dimensions = [0]1052 // CHECK: (%[[ARG1:.*]]: f32, %[[ARG2:.*]]: f32) {1053 // CHECK: %[[RES:.+]] = arith.addf %[[ARG1]], %[[ARG2]] : f321054 // CHECK: linalg.yield %[[RES]] : f321055 // CHECK: }1056 // CHECK: tensor.expand_shape %[[REDUCE]] {{\[}}] output_shape [1] : tensor<f32> into tensor<1xf32>1057 %0 = tosa.reduce_sum %arg0 {axis = 0 : i32} : (tensor<?xf32>) -> tensor<1xf32>1058 return1059}1060 1061// -----1062 1063// CHECK-LABEL: @reduce_float_dyn_nonzero_batch1064// CHECK-SAME: (%[[ARG0:[0-9a-zA-Z_]*]]:1065func.func @reduce_float_dyn_nonzero_batch(%arg0: tensor<5x?x4xf32>) -> () {1066 // CHECK: %[[C1:.+]] = arith.constant 11067 // CHECK: %[[DYN:.+]] = tensor.dim %[[ARG0]], %[[C1]]1068 // CHECK: %[[INIT:.+]] = tensor.empty(%[[DYN]]) : tensor<5x?xf32>1069 // CHECK: %[[CST1:.+]] = arith.constant 1.01070 // CHECK: %[[FILL:.+]] = linalg.fill ins(%[[CST1]]{{.*}}outs(%[[INIT]]1071 // CHECK: %[[REDUCE:.+]] = linalg.reduce ins(%[[ARG0]] : tensor<5x?x4xf32>) outs(%[[FILL]] : tensor<5x?xf32>) dimensions = [2]1072 // CHECK: (%[[ARG1:.*]]: f32, %[[ARG2:.*]]: f32) {1073 // CHECK: %[[RES:.+]] = arith.mulf %[[ARG1]], %[[ARG2]] : f321074 // CHECK: linalg.yield %[[RES]] : f321075 // CHECK: }1076 // CHECK: %[[C1_0:.+]] = arith.constant 1 : index1077 // CHECK: %[[DIM_1:.+]] = tensor.dim %[[REDUCE]], %[[C1_0]] : tensor<5x?xf32>1078 // CHECK: %[[C1_2:.+]] = arith.constant 1 : index1079 // CHECK: tensor.expand_shape %[[REDUCE]] {{\[}}[0], [1, 2]] output_shape [5, %[[DIM_1]], 1] : tensor<5x?xf32> into tensor<5x?x1xf32>1080 %0 = tosa.reduce_product %arg0 {axis = 2 : i32} : (tensor<5x?x4xf32>) -> tensor<5x?x1xf32>1081 return1082}1083 1084// -----1085 1086// CHECK-LABEL: @reduce_float_dyn_multiple1087// CHECK-SAME: (%[[ARG0:[0-9a-zA-Z_]*]]:1088func.func @reduce_float_dyn_multiple(%arg0: tensor<?x?xf32>) -> () {1089 // CHECK: %[[C0:.+]] = arith.constant 01090 // CHECK: %[[DYN:.+]] = tensor.dim %[[ARG0]], %[[C0]]1091 // CHECK: %[[INIT:.+]] = tensor.empty(%[[DYN]])1092 // CHECK: %[[CMIN:.+]] = arith.constant -3.40282347E+381093 // CHECK: %[[FILL:.+]] = linalg.fill ins(%[[CMIN]]{{.*}}outs(%[[INIT]]1094 // CHECK: %[[REDUCE:.+]] = linalg.reduce ins(%[[ARG0]] : tensor<?x?xf32>) outs(%[[FILL]] : tensor<?xf32>) dimensions = [1]1095 // CHECK: (%[[ARG1:.*]]: f32, %[[ARG2:.*]]: f32) {1096 // CHECK: %[[MAX:.+]] = arith.maximumf %[[ARG1]], %[[ARG2]] : f321097 // CHECK: linalg.yield %[[MAX]] : f321098 // CHECK: }1099 // CHECK: %[[C0_0:.+]] = arith.constant 0 : index1100 // CHECK: %[[DIM_1:.+]] = tensor.dim %[[REDUCE]], %[[C0_0]] : tensor<?xf32>1101 // CHECK: %[[C1_2:.+]] = arith.constant 1 : index1102 // CHECK: tensor.expand_shape %[[REDUCE]] {{\[}}[0, 1]] output_shape [%[[DIM_1]], 1] : tensor<?xf32> into tensor<?x1xf32>1103 %0 = tosa.reduce_max %arg0 {axis = 1 : i32} : (tensor<?x?xf32>) -> tensor<?x1xf32>1104 return1105}1106 1107// -----1108 1109// CHECK-LABEL: @reduce_int1110// CHECK-SAME: [[ARG0:%.+]]: tensor<5x4xi32>1111func.func @reduce_int(%arg0: tensor<5x4xi32>) -> () {1112 // CHECK: [[INIT:%.+]] = tensor.empty()1113 // CHECK: [[CST0:%.+]] = arith.constant 01114 // CHECK: [[FILL:%.+]] = linalg.fill ins([[CST0]]{{.*}}outs([[INIT]]1115 // CHECK: [[REDUCE:%.+]] = linalg.reduce ins([[ARG0]] : tensor<5x4xi32>) outs([[FILL]] : tensor<4xi32>) dimensions = [0]1116 // CHECK: (%[[ARG1:.*]]: i32, %[[ARG2:.*]]: i32) {1117 // CHECK: [[RES:%.+]] = arith.addi %[[ARG1]], %[[ARG2]] : i321118 // CHECK: linalg.yield [[RES]] : i321119 // CHECK: }1120 // CHECK: tensor.expand_shape [[REDUCE]] {{\[}}[0, 1]] output_shape [1, 4] : tensor<4xi32> into tensor<1x4xi32>1121 %0 = tosa.reduce_sum %arg0 {axis = 0 : i32} : (tensor<5x4xi32>) -> tensor<1x4xi32>1122 1123 // CHECK: [[INIT:%.+]] = tensor.empty()1124 // CHECK: [[CST0:%.+]] = arith.constant 01125 // CHECK: [[FILL:%.+]] = linalg.fill ins([[CST0]]{{.*}}outs([[INIT]]1126 // CHECK: [[REDUCE:%.+]] = linalg.reduce ins([[ARG0]] : tensor<5x4xi32>) outs([[FILL]] : tensor<5xi32>) dimensions = [1]1127 // CHECK: (%[[ARG1:.*]]: i32, %[[ARG2:.*]]: i32) {1128 // CHECK: [[RES:%.+]] = arith.addi %[[ARG1]], %[[ARG2]] : i321129 // CHECK: linalg.yield [[RES]] : i321130 // CHECK: }1131 // CHECK: tensor.expand_shape [[REDUCE]] {{\[}}[0, 1]] output_shape [5, 1] : tensor<5xi32> into tensor<5x1xi32>1132 %1 = tosa.reduce_sum %arg0 {axis = 1 : i32} : (tensor<5x4xi32>) -> tensor<5x1xi32>1133 1134 // CHECK: arith.constant 11135 // CHECK: linalg.fill1136 // CHECK: linalg.reduce1137 // CHECK: arith.muli1138 %2 = tosa.reduce_product %arg0 {axis = 0 : i32} : (tensor<5x4xi32>) -> tensor<1x4xi32>1139 1140 // CHECK: arith.constant 2147483647 : i321141 // CHECK: linalg.fill1142 // CHECK: linalg.reduce1143 // CHECK: arith.minsi1144 %3 = tosa.reduce_min %arg0 {axis = 0 : i32} : (tensor<5x4xi32>) -> tensor<1x4xi32>1145 1146 // CHECK: arith.constant -2147483648 : i321147 // CHECK: linalg.fill1148 // CHECK: linalg.reduce1149 // CHECK: arith.maxsi1150 %4 = tosa.reduce_max %arg0 {axis = 0 : i32} : (tensor<5x4xi32>) -> tensor<1x4xi32>1151 return1152}1153 1154// -----1155 1156// CHECK-LABEL: @reduce_bool1157// CHECK-SAME: [[ARG0:%.+]]: tensor<5x4xi1>1158func.func @reduce_bool(%arg0: tensor<5x4xi1>) -> () {1159 // CHECK: [[INIT:%.+]] = tensor.empty()1160 // CHECK: [[CST0:%.+]] = arith.constant true1161 // CHECK: [[FILL:%.+]] = linalg.fill ins([[CST0]]{{.*}}outs([[INIT]]1162 // CHECK: [[REDUCE:%.+]] = linalg.reduce ins([[ARG0]] : tensor<5x4xi1>) outs([[FILL]] : tensor<4xi1>) dimensions = [0]1163 // CHECK: (%[[ARG1:[0-9a-zA-Z_]+]]: i1, %[[ARG2:[0-9a-zA-Z_]+]]: i1) {1164 // CHECK: [[RES:%.+]] = arith.andi %[[ARG1]], %[[ARG2]] : i11165 // CHECK: linalg.yield [[RES]] : i11166 // CHECK: }1167 // CHECK: tensor.expand_shape [[REDUCE]] {{\[}}[0, 1]] output_shape [1, 4] : tensor<4xi1> into tensor<1x4xi1>1168 %0 = tosa.reduce_all %arg0 {axis = 0 : i32} : (tensor<5x4xi1>) -> tensor<1x4xi1>1169 1170 // CHECK: arith.constant false1171 // CHECK: linalg.fill1172 // CHECK: linalg.reduce1173 // CHECK: or1174 %1 = tosa.reduce_any %arg0 {axis = 0 : i32} : (tensor<5x4xi1>) -> tensor<1x4xi1>1175 1176 return1177}1178 1179// -----1180// CHECK: #[[$MAP0:.*]] = affine_map<(d0) -> (d0)>1181 1182// CHECK-LABEL: @rescale_i81183// CHECK-SAME: (%[[ARG0:[0-9a-zA-Z_]*]]:1184func.func @rescale_i8(%arg0 : tensor<2xi8>) -> () {1185 // CHECK: [[C0:%.+]] = arith.constant 196891186 // CHECK: [[C1:%.+]] = arith.constant 151187 // CHECK: [[INIT:%.+]] = tensor.empty()1188 // CHECK: [[GENERIC:%.+]] = linalg.generic {indexing_maps = [#[[$MAP0]], #[[$MAP0]]], iterator_types = ["parallel"]} ins(%[[ARG0]] : tensor<2xi8>) outs([[INIT]] : tensor<2xi8>)1189 // CHECK: ^bb0([[IN:%.+]]: i8, [[UNUSED:%.+]]: i8):1190 // CHECK: [[C17:%.+]] = arith.constant 171191 // CHECK: [[C22:%.+]] = arith.constant 221192 // CHECK-DAG: [[IN32:%.+]] = arith.extsi [[IN]]1193 // CHECK-DAG: [[IN_ZEROED:%.+]] = arith.subi [[IN32]], [[C17]]1194 // CHECK-DAG: [[SCALED:%.+]] = tosa.apply_scale [[IN_ZEROED]], [[C0]], [[C1]] {rounding_mode = SINGLE_ROUND}1195 // CHECK-DAG: [[SCALED_ZEROED:%.+]] = arith.addi [[SCALED]], [[C22]]1196 // CHECK-DAG: [[CMIN:%.+]] = arith.constant -1281197 // CHECK-DAG: [[CMAX:%.+]] = arith.constant 1271198 // CHECK-DAG: [[LOWER:%.+]] = arith.maxsi [[CMIN]], [[SCALED_ZEROED]]1199 // CHECK-DAG: [[BOUNDED:%.+]] = arith.minsi [[CMAX]], [[LOWER]]1200 // CHECK-DAG: [[TRUNC:%.+]] = arith.trunci [[BOUNDED]]1201 // CHECK-DAG: linalg.yield [[TRUNC]]1202 %multiplier = "tosa.const"() {values = dense<19689> : tensor<1xi16>} : () -> tensor<1xi16>1203 %shift = "tosa.const"() {values = dense<15> : tensor<1xi8>} : () -> tensor<1xi8>1204 %input_zp = "tosa.const"() {values = dense<17> : tensor<1xi8>} : () -> tensor<1xi8>1205 %output_zp = "tosa.const"() {values = dense<22> : tensor<1xi8>} : () -> tensor<1xi8>1206 %0 = tosa.rescale %arg0, %multiplier, %shift, %input_zp, %output_zp {scale32 = false, rounding_mode = SINGLE_ROUND, per_channel = false, input_unsigned = false, output_unsigned = false} : (tensor<2xi8>, tensor<1xi16>, tensor<1xi8>, tensor<1xi8>, tensor<1xi8>) -> tensor<2xi8>1207 1208 // CHECK: return1209 return1210}1211 1212// -----1213// CHECK: #[[$MAP0:.*]] = affine_map<(d0) -> (d0)>1214 1215// CHECK-LABEL: @rescale_i8_unsigned_output_explicit1216// CHECK-SAME: (%[[ARG0:[0-9a-zA-Z_]*]]:1217func.func @rescale_i8_unsigned_output_explicit(%arg0 : tensor<2xi8>) -> () {1218 // CHECK: [[C0:%.+]] = arith.constant 196891219 // CHECK: [[C1:%.+]] = arith.constant 151220 // CHECK: [[INIT:%.+]] = tensor.empty()1221 // CHECK: [[GENERIC:%.+]] = linalg.generic {indexing_maps = [#[[$MAP0]], #[[$MAP0]]], iterator_types = ["parallel"]} ins(%[[ARG0]] : tensor<2xi8>) outs([[INIT]] : tensor<2xui8>)1222 // CHECK: ^bb0([[IN:%.+]]: i8, [[UNUSED:%.+]]: ui8):1223 // CHECK-DAG: [[C17:%.+]] = arith.constant 171224 // CHECK-DAG: [[C234:%.+]] = arith.constant 2341225 // CHECK-DAG: [[IN32:%.+]] = arith.extsi [[IN]]1226 // CHECK-DAG: [[IN_ZEROED:%.+]] = arith.subi [[IN32]], [[C17]]1227 // CHECK-DAG: [[SCALED:%.+]] = tosa.apply_scale [[IN_ZEROED]], [[C0]], [[C1]] {rounding_mode = SINGLE_ROUND}1228 // CHECK-DAG: [[SCALED_ZEROED:%.+]] = arith.addi [[SCALED]], [[C234]]1229 // CHECK-DAG: [[CMIN:%.+]] = arith.constant 01230 // CHECK-DAG: [[CMAX:%.+]] = arith.constant 2551231 // CHECK-DAG: [[LOWER:%.+]] = arith.maxsi [[CMIN]], [[SCALED_ZEROED]]1232 // CHECK: [[BOUNDED:%.+]] = arith.minsi [[CMAX]], [[LOWER]]1233 // CHECK: [[TRUNC:%.+]] = arith.trunci [[BOUNDED]]1234 // CHECK: [[TRUNC_ITOU:%.+]] = builtin.unrealized_conversion_cast [[TRUNC]] : i8 to ui81235 // CHECK: linalg.yield [[TRUNC_ITOU]]1236 %multiplier = "tosa.const"() {values = dense<19689> : tensor<1xi16> } : () -> tensor<1xi16>1237 %shift = "tosa.const"() {values = dense<15> : tensor<1xi8> } : () -> tensor<1xi8>1238 %input_zp = "tosa.const"() {values = dense<17> : tensor<1xi8>} : () -> tensor<1xi8>1239 %output_zp = "tosa.const"() {values = dense<-22> : tensor<1xi8>} : () -> tensor<1xi8>1240 %1 = tosa.rescale %arg0, %multiplier, %shift, %input_zp, %output_zp {scale32 = false, rounding_mode = SINGLE_ROUND, per_channel = false, input_unsigned = false, output_unsigned = true} : (tensor<2xi8>, tensor<1xi16>, tensor<1xi8>, tensor<1xi8>, tensor<1xi8>) -> tensor<2xui8>1241 1242 // CHECK: return1243 return1244}1245 1246// -----1247// CHECK: #[[$MAP0:.*]] = affine_map<(d0) -> (d0)>1248 1249// CHECK-LABEL: @rescale_i8_unsigned_output_implicit1250// CHECK-SAME: (%[[ARG0:[0-9a-zA-Z_]*]]:1251func.func @rescale_i8_unsigned_output_implicit(%arg0 : tensor<2xi8>) -> () {1252 // CHECK: [[C0:%.+]] = arith.constant 196891253 // CHECK: [[C1:%.+]] = arith.constant 151254 // CHECK: [[INIT:%.+]] = tensor.empty()1255 // CHECK: [[GENERIC:%.+]] = linalg.generic {indexing_maps = [#[[$MAP0]], #[[$MAP0]]], iterator_types = ["parallel"]} ins(%[[ARG0]] : tensor<2xi8>) outs([[INIT]] : tensor<2xi8>)1256 // CHECK: ^bb0([[IN:%.+]]: i8, [[UNUSED:%.+]]: i8):1257 // CHECK-DAG: [[C17:%.+]] = arith.constant 171258 // CHECK-DAG: [[C234:%.+]] = arith.constant 2341259 // CHECK-DAG: [[IN32:%.+]] = arith.extsi [[IN]]1260 // CHECK-DAG: [[IN_ZEROED:%.+]] = arith.subi [[IN32]], [[C17]]1261 // CHECK-DAG: [[SCALED:%.+]] = tosa.apply_scale [[IN_ZEROED]], [[C0]], [[C1]] {rounding_mode = SINGLE_ROUND}1262 // CHECK-DAG: [[SCALED_ZEROED:%.+]] = arith.addi [[SCALED]], [[C234]]1263 // CHECK-DAG: [[CMIN:%.+]] = arith.constant 01264 // CHECK-DAG: [[CMAX:%.+]] = arith.constant 2551265 // CHECK-DAG: [[LOWER:%.+]] = arith.maxsi [[CMIN]], [[SCALED_ZEROED]]1266 // CHECK: [[BOUNDED:%.+]] = arith.minsi [[CMAX]], [[LOWER]]1267 // CHECK: [[TRUNC:%.+]] = arith.trunci [[BOUNDED]]1268 // CHECK-NOT: builtin.unrealized_conversion_cast [[TRUNC]]1269 // CHECK: linalg.yield [[TRUNC]]1270 %multiplier = "tosa.const"() {values = dense<19689> : tensor<1xi16> } : () -> tensor<1xi16>1271 %shift = "tosa.const"() {values = dense<15> : tensor<1xi8> } : () -> tensor<1xi8>1272 %input_zp = "tosa.const"() {values = dense<17> : tensor<1xi8>} : () -> tensor<1xi8>1273 %output_zp = "tosa.const"() {values = dense<-22> : tensor<1xi8>} : () -> tensor<1xi8>1274 %1 = tosa.rescale %arg0, %multiplier, %shift, %input_zp, %output_zp {scale32 = false, rounding_mode = SINGLE_ROUND, per_channel = false, input_unsigned = false, output_unsigned = true} : (tensor<2xi8>, tensor<1xi16>, tensor<1xi8>, tensor<1xi8>, tensor<1xi8>) -> tensor<2xi8>1275 1276 // CHECK: return1277 return1278}1279 1280// -----1281// CHECK: #[[$MAP0:.*]] = affine_map<(d0) -> (d0)>1282 1283// CHECK-LABEL: @rescale_i48_unsigned_output_implicit1284// CHECK-SAME: (%[[ARG0:[0-9a-zA-Z_]*]]:1285func.func @rescale_i48_unsigned_output_implicit(%arg0 : tensor<2xi48>) -> () {1286 // CHECK: [[C19689:%.+]] = arith.constant 196891287 // CHECK: [[C15:%.+]] = arith.constant 151288 // CHECK: [[INIT:%.+]] = tensor.empty()1289 // CHECK: [[GENERIC:%.+]] = linalg.generic {indexing_maps = [#[[$MAP0]], #[[$MAP0]]], iterator_types = ["parallel"]} ins(%[[ARG0]] : tensor<2xi48>) outs([[INIT]] : tensor<2xi8>)1290 // CHECK: ^bb0([[IN:%.+]]: i48, [[UNUSED:%.+]]: i8):1291 // CHECK-NOT: builtin.unrealized_conversion_cast [[IN]]1292 // CHECK-DAG: [[C0:%.+]] = arith.constant 01293 // CHECK-DAG: [[C234:%.+]] = arith.constant 2341294 // CHECK-DAG: [[IN_ZEROED:%.+]] = arith.subi [[IN]], [[C0]]1295 // CHECK-DAG: [[SCALED:%.+]] = tosa.apply_scale [[IN_ZEROED]], [[C19689]], [[C15]] {rounding_mode = SINGLE_ROUND}1296 // CHECK-DAG: [[SCALED_ZEROED:%.+]] = arith.addi [[SCALED]], [[C234]]1297 // CHECK-DAG: [[CMIN:%.+]] = arith.constant 01298 // CHECK-DAG: [[CMAX:%.+]] = arith.constant 2551299 // CHECK-DAG: [[LOWER:%.+]] = arith.maxsi [[CMIN]], [[SCALED_ZEROED]]1300 // CHECK-DAG: [[BOUNDED:%.+]] = arith.minsi [[CMAX]], [[LOWER]]1301 // CHECK-DAG: [[TRUNC:%.+]] = arith.trunci [[BOUNDED]]1302 // CHECK: linalg.yield [[TRUNC]]1303 %multiplier = "tosa.const"() {values = dense<19689> : tensor<1xi16> } : () -> tensor<1xi16>1304 %shift = "tosa.const"() {values = dense<15> : tensor<1xi8> } : () -> tensor<1xi8>1305 %input_zp = "tosa.const"() {values = dense<0> : tensor<1xi48>} : () -> tensor<1xi48>1306 %output_zp = "tosa.const"() {values = dense<-22> : tensor<1xi8>} : () -> tensor<1xi8>1307 %1 = tosa.rescale %arg0, %multiplier, %shift, %input_zp, %output_zp {scale32 = false, rounding_mode = SINGLE_ROUND, per_channel = false, input_unsigned = false, output_unsigned = true} : (tensor<2xi48>, tensor<1xi16>, tensor<1xi8>, tensor<1xi48>, tensor<1xi8>) -> tensor<2xi8>1308 1309 // CHECK: return1310 return1311}1312 1313// -----1314 1315// CHECK: #[[$MAP0:.*]] = affine_map<(d0, d1) -> (d0, d1)>1316 1317// CHECK-LABEL: @rescale_i8_dyn_batch1318// CHECK-SAME: (%[[ARG0:[0-9a-zA-Z_]*]]:1319func.func @rescale_i8_dyn_batch(%arg0 : tensor<?x2xi8>) -> () {1320 %multiplier = "tosa.const"() {values = dense<19689> : tensor<1xi16>} : () -> tensor<1xi16>1321 %shift = "tosa.const"() {values = dense<15> : tensor<1xi8>} : () -> tensor<1xi8>1322 %input_zp = "tosa.const"() {values = dense<17> : tensor<1xi8>} : () -> tensor<1xi8>1323 %output_zp = "tosa.const"() {values = dense<22> : tensor<1xi8>} : () -> tensor<1xi8>1324 // CHECK: %[[C0:.+]] = arith.constant 01325 // CHECK: %[[BATCH:.+]] = tensor.dim %[[ARG0]], %[[C0]]1326 // CHECK: %[[INIT:.+]] = tensor.empty(%[[BATCH]]) : tensor<?x2xi8>1327 // CHECK: [[GENERIC:%.+]] = linalg.generic {indexing_maps = [#[[$MAP0]], #[[$MAP0]]], iterator_types = ["parallel", "parallel"]} ins(%[[ARG0]] : tensor<?x2xi8>) outs(%[[INIT]] : tensor<?x2xi8>)1328 %0 = tosa.rescale %arg0, %multiplier, %shift, %input_zp, %output_zp {scale32 = false, rounding_mode = SINGLE_ROUND, per_channel = false, input_unsigned = false, output_unsigned = false} : (tensor<?x2xi8>, tensor<1xi16>, tensor<1xi8>, tensor<1xi8>, tensor<1xi8>) -> tensor<?x2xi8>1329 1330 // CHECK: %[[C0:.+]] = arith.constant 01331 // CHECK: %[[BATCH:.+]] = tensor.dim %[[ARG0]], %[[C0]]1332 // CHECK: %[[INIT:.+]] = tensor.empty(%[[BATCH]]) : tensor<?x2xi8>1333 // CHECK: [[GENERIC:%.+]] = linalg.generic {indexing_maps = [#[[$MAP0]], #[[$MAP0]]], iterator_types = ["parallel", "parallel"]} ins(%[[ARG0]] : tensor<?x2xi8>) outs(%[[INIT]] : tensor<?x2xi8>)1334 %1 = tosa.rescale %arg0, %multiplier, %shift, %input_zp, %output_zp {scale32 = false, rounding_mode = SINGLE_ROUND, per_channel = false, input_unsigned = false, output_unsigned = true} : (tensor<?x2xi8>, tensor<1xi16>, tensor<1xi8>, tensor<1xi8>, tensor<1xi8>) -> tensor<?x2xi8>1335 1336 return1337}1338 1339// -----1340 1341// CHECK: #[[$MAP1:.*]] = affine_map<(d0, d1, d2, d3) -> (d0, d1, d2, d3)>1342 1343// CHECK-LABEL: @rescale_dyn1344// CHECK-SAME: (%[[ARG0:[0-9a-zA-Z_]*]]:1345func.func @rescale_dyn(%arg0 : tensor<1x?x?x32xi32>) -> () {1346 %input_zp = "tosa.const"() {values = dense<0> : tensor<1xi32>} : () -> tensor<1xi32>1347 %output_zp = "tosa.const"() {values = dense<0> : tensor<1xi8>} : () -> tensor<1xi8>1348 // CHECK: %[[C1:.+]] = arith.constant 11349 // CHECK: %[[DIM1:.+]] = tensor.dim %[[ARG0]], %[[C1]]1350 // CHECK: %[[C2:.+]] = arith.constant 21351 // CHECK: %[[DIM2:.+]] = tensor.dim %[[ARG0]], %[[C2]]1352 // CHECK: %[[INIT:.+]] = tensor.empty(%[[DIM1]], %[[DIM2]])1353 // CHECK: [[GENERIC:%.+]] = linalg.generic {indexing_maps = [#[[$MAP1]], #[[$MAP1]]], iterator_types = ["parallel", "parallel", "parallel", "parallel"]} ins(%[[ARG0]] : tensor<1x?x?x32xi32>) outs(%[[INIT]] : tensor<1x?x?x32xi8>)1354 %multiplier = "tosa.const"() {values = dense<1376784203> : tensor<1xi32> } : () -> tensor<1xi32>1355 %shift = "tosa.const"() {values = dense<38> : tensor<1xi8> } : () -> tensor<1xi8>1356 %0 = tosa.rescale %arg0, %multiplier, %shift, %input_zp, %output_zp {rounding_mode = DOUBLE_ROUND, per_channel = false, scale32 = true, input_unsigned = false, output_unsigned = false} : (tensor<1x?x?x32xi32>, tensor<1xi32>, tensor<1xi8>, tensor<1xi32>, tensor<1xi8>) -> tensor<1x?x?x32xi8>1357 return1358}1359 1360// -----1361// CHECK: #[[$MAP0:.*]] = affine_map<(d0) -> (d0)>1362 1363// CHECK-LABEL: @rescale_i8_unsigned_input_explicit1364// CHECK-SAME: (%[[ARG0:[0-9a-zA-Z_]*]]:1365func.func @rescale_i8_unsigned_input_explicit(%arg0 : tensor<2xui8>) -> () {1366 // CHECK: [[C0:%.+]] = arith.constant 196891367 // CHECK: [[C1:%.+]] = arith.constant 151368 // CHECK: [[INIT:%.+]] = tensor.empty()1369 // CHECK: [[GENERIC:%.+]] = linalg.generic {indexing_maps = [#[[$MAP0]], #[[$MAP0]]], iterator_types = ["parallel"]} ins(%[[ARG0]] : tensor<2xui8>) outs([[INIT]] : tensor<2xi8>)1370 // CHECK: ^bb0([[IN:%.+]]: ui8, [[UNUSED:%.+]]: i8):1371 // CHECK-DAG: [[C17:%.+]] = arith.constant 171372 // CHECK-DAG: [[C22:%.+]] = arith.constant 221373 // CHECK-DAG: [[IN_UTOI:%.+]] = builtin.unrealized_conversion_cast [[IN]] : ui8 to i81374 // CHECK-DAG: [[IN32:%.+]] = arith.extui [[IN_UTOI]]1375 // CHECK-DAG: [[IN_ZEROED:%.+]] = arith.subi [[IN32]], [[C17]]1376 // CHECK-DAG: [[SCALED:%.+]] = tosa.apply_scale [[IN_ZEROED]], [[C0]], [[C1]] {rounding_mode = SINGLE_ROUND}1377 // CHECK-DAG: [[SCALED_ZEROED:%.+]] = arith.addi [[SCALED]], [[C22]]1378 // CHECK-DAG: [[CMIN:%.+]] = arith.constant -1281379 // CHECK-DAG: [[CMAX:%.+]] = arith.constant 1271380 // CHECK-DAG: [[LOWER:%.+]] = arith.maxsi [[CMIN]], [[SCALED_ZEROED]]1381 // CHECK: [[BOUNDED:%.+]] = arith.minsi [[CMAX]], [[LOWER]]1382 // CHECK: [[TRUNC:%.+]] = arith.trunci [[BOUNDED]]1383 // CHECK: linalg.yield [[TRUNC]]1384 %multiplier = "tosa.const"() {values = dense<19689> : tensor<1xi16> } : () -> tensor<1xi16>1385 %shift = "tosa.const"() {values = dense<15> : tensor<1xi8> } : () -> tensor<1xi8>1386 %input_zp = "tosa.const"() {values = dense<17> : tensor<1xi8>} : () -> tensor<1xi8>1387 %output_zp = "tosa.const"() {values = dense<22> : tensor<1xi8>} : () -> tensor<1xi8>1388 %0 = tosa.rescale %arg0, %multiplier, %shift, %input_zp, %output_zp {scale32 = false, rounding_mode = SINGLE_ROUND, per_channel = false, input_unsigned = true, output_unsigned = false} : (tensor<2xui8>, tensor<1xi16>, tensor<1xi8>, tensor<1xi8>, tensor<1xi8>) -> tensor<2xi8>1389 1390 return1391}1392 1393// -----1394// CHECK: #[[$MAP0:.*]] = affine_map<(d0) -> (d0)>1395 1396// CHECK-LABEL: @rescale_i8_unsigned_input_implicit1397// CHECK-SAME: (%[[ARG0:[0-9a-zA-Z_]*]]:1398func.func @rescale_i8_unsigned_input_implicit(%arg0 : tensor<2xi8>) -> () {1399 // CHECK: [[C0:%.+]] = arith.constant 196891400 // CHECK: [[C1:%.+]] = arith.constant 151401 // CHECK: [[INIT:%.+]] = tensor.empty()1402 // CHECK: [[GENERIC:%.+]] = linalg.generic {indexing_maps = [#[[$MAP0]], #[[$MAP0]]], iterator_types = ["parallel"]} ins(%[[ARG0]] : tensor<2xi8>) outs([[INIT]] : tensor<2xi8>)1403 // CHECK: ^bb0([[IN:%.+]]: i8, [[UNUSED:%.+]]: i8):1404 // CHECK-NOT: builtin.unrealized_conversion_cast [[IN]]1405 // CHECK-DAG: [[C128:%.+]] = arith.constant 1281406 // CHECK-DAG: [[C22:%.+]] = arith.constant 221407 // CHECK-DAG: [[IN32:%.+]] = arith.extui [[IN]]1408 // CHECK-DAG: [[IN_ZEROED:%.+]] = arith.subi [[IN32]], [[C128]]1409 // CHECK-DAG: [[SCALED:%.+]] = tosa.apply_scale [[IN_ZEROED]], [[C0]], [[C1]] {rounding_mode = SINGLE_ROUND}1410 // CHECK-DAG: [[SCALED_ZEROED:%.+]] = arith.addi [[SCALED]], [[C22]]1411 // CHECK-DAG: [[CMIN:%.+]] = arith.constant -1281412 // CHECK-DAG: [[CMAX:%.+]] = arith.constant 1271413 // CHECK-DAG: [[LOWER:%.+]] = arith.maxsi [[CMIN]], [[SCALED_ZEROED]]1414 // CHECK-DAG: [[BOUNDED:%.+]] = arith.minsi [[CMAX]], [[LOWER]]1415 // CHECK-DAG: [[TRUNC:%.+]] = arith.trunci [[BOUNDED]]1416 // CHECK: linalg.yield [[TRUNC]]1417 %multiplier = "tosa.const"() {values = dense<19689> : tensor<1xi16> } : () -> tensor<1xi16>1418 %shift = "tosa.const"() {values = dense<15> : tensor<1xi8> } : () -> tensor<1xi8>1419 %input_zp = "tosa.const"() {values = dense<-128> : tensor<1xi8>} : () -> tensor<1xi8>1420 %output_zp = "tosa.const"() {values = dense<22> : tensor<1xi8>} : () -> tensor<1xi8>1421 %0 = tosa.rescale %arg0, %multiplier, %shift, %input_zp, %output_zp {scale32 = false, rounding_mode = SINGLE_ROUND, per_channel = false, input_unsigned = true, output_unsigned = false} : (tensor<2xi8>, tensor<1xi16>, tensor<1xi8>, tensor<1xi8>, tensor<1xi8>) -> tensor<2xi8>1422 1423 return1424}1425 1426// -----1427// CHECK: #[[$MAP0:.*]] = affine_map<(d0) -> (d0)>1428 1429// CHECK-LABEL: @rescale_i8_unsigned_input_output_explicit1430// CHECK-SAME: (%[[ARG0:[0-9a-zA-Z_]*]]:1431func.func @rescale_i8_unsigned_input_output_explicit(%arg0 : tensor<2xui8>) -> () {1432 // CHECK: [[C0:%.+]] = arith.constant 196891433 // CHECK: [[C1:%.+]] = arith.constant 151434 // CHECK: [[INIT:%.+]] = tensor.empty()1435 // CHECK: [[GENERIC:%.+]] = linalg.generic {indexing_maps = [#[[$MAP0]], #[[$MAP0]]], iterator_types = ["parallel"]} ins(%[[ARG0]] : tensor<2xui8>) outs([[INIT]] : tensor<2xui8>)1436 // CHECK: ^bb0([[IN:%.+]]: ui8, [[UNUSED:%.+]]: ui8):1437 // CHECK-DAG: [[C17:%.+]] = arith.constant 171438 // CHECK-DAG: [[C22:%.+]] = arith.constant 221439 // CHECK-DAG: [[IN_UTOI:%.+]] = builtin.unrealized_conversion_cast [[IN]] : ui8 to i81440 // CHECK-DAG: [[IN32:%.+]] = arith.extui [[IN_UTOI]]1441 // CHECK-DAG: [[IN_ZEROED:%.+]] = arith.subi [[IN32]], [[C17]]1442 // CHECK-DAG: [[SCALED:%.+]] = tosa.apply_scale [[IN_ZEROED]], [[C0]], [[C1]] {rounding_mode = SINGLE_ROUND}1443 // CHECK-DAG: [[SCALED_ZEROED:%.+]] = arith.addi [[SCALED]], [[C22]]1444 // CHECK-DAG: [[CMIN:%.+]] = arith.constant -1281445 // CHECK-DAG: [[CMAX:%.+]] = arith.constant 1271446 // CHECK-DAG: [[LOWER:%.+]] = arith.maxsi [[CMIN]], [[SCALED_ZEROED]]1447 // CHECK: [[BOUNDED:%.+]] = arith.minsi [[CMAX]], [[LOWER]]1448 // CHECK: [[TRUNC:%.+]] = arith.trunci [[BOUNDED]]1449 // CHECK: [[TRUNC_ITOU:%.+]] = builtin.unrealized_conversion_cast [[TRUNC]] : i8 to ui81450 // CHECK: linalg.yield [[TRUNC_ITOU]]1451 %multiplier = "tosa.const"() {values = dense<19689> : tensor<1xi16> } : () -> tensor<1xi16>1452 %shift = "tosa.const"() {values = dense<15> : tensor<1xi8> } : () -> tensor<1xi8>1453 %input_zp = "tosa.const"() {values = dense<17> : tensor<1xi8>} : () -> tensor<1xi8>1454 %output_zp = "tosa.const"() {values = dense<22> : tensor<1xi8>} : () -> tensor<1xi8>1455 %0 = tosa.rescale %arg0, %multiplier, %shift, %input_zp, %output_zp {scale32 = false, rounding_mode = SINGLE_ROUND, per_channel = false, input_unsigned = true, output_unsigned = false} : (tensor<2xui8>, tensor<1xi16>, tensor<1xi8>, tensor<1xi8>, tensor<1xi8>) -> tensor<2xui8>1456 1457 return1458}1459 1460// -----1461 1462// CHECK: #[[$MAP0:.*]] = affine_map<(d0) -> (d0)>1463 1464// CHECK-LABEL: @rescale_per_channel1465// CHECK-SAME: (%[[ARG0:[0-9a-zA-Z_]*]]:1466func.func @rescale_per_channel(%arg0 : tensor<3xi8>) -> (tensor<3xi8>) {1467 // CHECK: [[MULTIPLIERS:%.+]] = arith.constant dense<[42, 43, 0]>1468 // CHECK: [[SHIFTS:%.+]] = arith.constant dense<[14, 15, 0]>1469 // CHECK: [[INIT:%.+]] = tensor.empty()1470 // CHECK: [[GENERIC:%.+]] = linalg.generic {indexing_maps = [#[[$MAP0]], #[[$MAP0]], #[[$MAP0]], #[[$MAP0]]], iterator_types = ["parallel"]} ins(%[[ARG0]], [[MULTIPLIERS]], [[SHIFTS]] : tensor<3xi8>, tensor<3xi32>, tensor<3xi8>) outs([[INIT]] : tensor<3xi8>)1471 // CHECK: ^bb0([[IN:%.+]]: i8, [[MULTIPLIER:%.+]]: i32, [[SHIFT:%.+]]: i8, [[UNUSED:%.+]]: i8):1472 // CHECK: [[C243:%.+]] = arith.constant 431473 // CHECK: [[C252:%.+]] = arith.constant 521474 1475 // CHECK-DAG: [[IN32:%.+]] = arith.extsi [[IN]]1476 // CHECK-DAG: [[IN_ZEROED:%.+]] = arith.subi [[IN32]], [[C243]]1477 // CHECK-DAG: [[SCALED:%.+]] = tosa.apply_scale [[IN_ZEROED]], [[MULTIPLIER]], [[SHIFT]] {rounding_mode = SINGLE_ROUND}1478 // CHECK-DAG: [[SCALED_ZEROED:%.+]] = arith.addi [[SCALED]], [[C252]]1479 // CHECK-DAG: [[CMIN:%.+]] = arith.constant -1281480 // CHECK-DAG: [[CMAX:%.+]] = arith.constant 1271481 // CHECK-DAG: [[LOWER:%.+]] = arith.maxsi [[CMIN]], [[SCALED_ZEROED]]1482 // CHECK-DAG: [[BOUNDED:%.+]] = arith.minsi [[CMAX]], [[LOWER]]1483 // CHECK-DAG: [[TRUNC:%.+]] = arith.trunci [[BOUNDED]]1484 // CHECK-DAG: linalg.yield [[TRUNC]]1485 %multiplier = "tosa.const"() {values = dense<[42, 43, 44]> : tensor<3xi16>} : () -> tensor<3xi16>1486 %shift = "tosa.const"() {values = dense<[14, 15, 64]> : tensor<3xi8>} : () -> tensor<3xi8>1487 %input_zp = "tosa.const"() {values = dense<43> : tensor<1xi8>} : () -> tensor<1xi8>1488 %output_zp = "tosa.const"() {values = dense<52> : tensor<1xi8>} : () -> tensor<1xi8>1489 %0 = tosa.rescale %arg0, %multiplier, %shift, %input_zp, %output_zp {scale32 = false, rounding_mode = SINGLE_ROUND, per_channel = true, input_unsigned = false, output_unsigned = false} : (tensor<3xi8>, tensor<3xi16>, tensor<3xi8>, tensor<1xi8>, tensor<1xi8>) -> tensor<3xi8>1490 1491 // CHECK: return [[GENERIC]]1492 return %0 : tensor<3xi8>1493}1494 1495// -----1496 1497// CHECK-LABEL: @rescaleDoubleRound1498func.func @rescaleDoubleRound(%arg0 : tensor<2xi8>) -> (tensor<2xi8>) {1499 %multiplier = "tosa.const"() {values = dense<19689> : tensor<1xi32>} : () -> tensor<1xi32>1500 %shift = "tosa.const"() {values = dense<33> : tensor<1xi8>} : () -> tensor<1xi8>1501 %input_zp = "tosa.const"() {values = dense<43> : tensor<1xi8>} : () -> tensor<1xi8>1502 %output_zp = "tosa.const"() {values = dense<52> : tensor<1xi8>} : () -> tensor<1xi8>1503 1504 // CHECK: linalg.generic1505 // CHECK: tosa.apply_scale1506 // CHECK-SAME: {rounding_mode = DOUBLE_ROUND}1507 %0 = tosa.rescale %arg0, %multiplier, %shift, %input_zp, %output_zp {scale32 = true, rounding_mode = DOUBLE_ROUND, per_channel = false, input_unsigned = false, output_unsigned = false} : (tensor<2xi8>, tensor<1xi32>, tensor<1xi8>, tensor<1xi8>, tensor<1xi8>) -> tensor<2xi8>1508 return %0 : tensor<2xi8>1509}1510 1511// -----1512 1513// CHECK-LABEL: @rescaleUnnecessaryDoubleRound1514func.func @rescaleUnnecessaryDoubleRound(%arg0 : tensor<2xi8>) -> (tensor<2xi8>) {1515 %multiplier = "tosa.const"() {values = dense<19689> : tensor<1xi32>} : () -> tensor<1xi32>1516 %shift = "tosa.const"() {values = dense<15> : tensor<1xi8>} : () -> tensor<1xi8>1517 %input_zp = "tosa.const"() {values = dense<43> : tensor<1xi8>} : () -> tensor<1xi8>1518 %output_zp = "tosa.const"() {values = dense<52> : tensor<1xi8>} : () -> tensor<1xi8>1519 1520 // CHECK: linalg.generic1521 // CHECK: tosa.apply_scale1522 // CHECK-SAME: {rounding_mode = SINGLE_ROUND}1523 %0 = tosa.rescale %arg0, %multiplier, %shift, %input_zp, %output_zp {scale32 = true, rounding_mode = DOUBLE_ROUND, per_channel = false, input_unsigned = false, output_unsigned = false} : (tensor<2xi8>, tensor<1xi32>, tensor<1xi8>, tensor<1xi8>, tensor<1xi8>) -> tensor<2xi8>1524 return %0 : tensor<2xi8>1525}1526 1527// -----1528 1529func.func @unsupportedRescaleInexactRound(%arg0 : tensor<2xi8>) -> (tensor<2xi8>) {1530 %multiplier = "tosa.const"() {values = dense<19689> : tensor<1xi32> } : () -> tensor<1xi32>1531 %shift = "tosa.const"() {values = dense<33> : tensor<1xi8> } : () -> tensor<1xi8>1532 %input_zp = "tosa.const"() {values = dense<0> : tensor<1xi8>} : () -> tensor<1xi8>1533 %output_zp = "tosa.const"() {values = dense<0> : tensor<1xi8>} : () -> tensor<1xi8>1534 // expected-error@+1 {{failed to legalize operation 'tosa.rescale'}}1535 %0 = tosa.rescale %arg0, %multiplier, %shift, %input_zp, %output_zp {scale32 = true, rounding_mode = INEXACT_ROUND, per_channel = false, input_unsigned = false, output_unsigned = false} : (tensor<2xi8>, tensor<1xi32>, tensor<1xi8>, tensor<1xi8>, tensor<1xi8>) -> tensor<2xi8>1536 return %0 : tensor<2xi8>1537}1538 1539// -----1540 1541// CHECK: #[[$MAP0:.+]] = affine_map<(d0) -> (d0)>1542// CHECK: #[[$MAP1:.+]] = affine_map<(d0) -> ()>1543// CHECK-LABEL: @rescale_no_const1544// CHECK-SAME: ([[ARG0:%[0-9a-zA-Z_]*]]1545func.func @rescale_no_const(%arg0 : tensor<2xi8>, %multiplier : tensor<1xi32>, %shift : tensor<1xi8>, %input_zp : tensor<1xi8>, %output_zp : tensor<1xi8>) -> (tensor<2xi8>) {1546 // CHECK: [[MULTIPLIER:%.+]] = tensor.collapse_shape %arg1 [] : tensor<1xi32> into tensor<i32>1547 // CHECK: [[SHIFT:%.+]] = tensor.collapse_shape %arg2 [] : tensor<1xi8> into tensor<i8>1548 // CHECK: [[INPUT_ZP:%.+]] = tensor.collapse_shape %arg3 [] : tensor<1xi8> into tensor<i8>1549 // CHECK: [[OUTPUT_ZP:%.+]] = tensor.collapse_shape %arg4 [] : tensor<1xi8> into tensor<i8>1550 // CHECK: [[INIT:%.+]] = tensor.empty() : tensor<2xi8>1551 // CHECK: [[GENERIC:%.+]] = linalg.generic {indexing_maps = [#[[$MAP0]], #[[$MAP1]], #[[$MAP1]], #[[$MAP1]], #[[$MAP1]], #[[$MAP0]]], iterator_types = ["parallel"]} ins([[ARG0]], [[MULTIPLIER]], [[SHIFT]], [[INPUT_ZP]], [[OUTPUT_ZP]] : tensor<2xi8>, tensor<i32>, tensor<i8>, tensor<i8>, tensor<i8>) outs([[INIT]] : tensor<2xi8>) {1552 // CHECK: ^bb0([[ARG0:%.*]]: i8, [[ARG1:%.*]]: i32, [[ARG2:%.*]]: i8, [[ARG3:%.*]]: i8, [[ARG4:%.*]]: i8, [[OUT:%.*]]: i8):1553 // CHECK: [[INPUT_ZP_I32:%.+]] = arith.extsi [[ARG3]] : i8 to i321554 // CHECK: [[OUTPUT_ZP_I32:%.+]] = arith.extsi [[ARG4]] : i8 to i321555 // CHECK: [[ARG0_I32:%.+]] = arith.extsi [[ARG0]] : i8 to i321556 // CHECK: [[TMP1:%.+]] = arith.subi [[ARG0_I32]], [[INPUT_ZP_I32]] : i321557 // CHECK: [[TMP2:%.+]] = tosa.apply_scale [[TMP1]], [[ARG1]], [[ARG2]] {rounding_mode = DOUBLE_ROUND} : (i32, i32, i8) -> i321558 // CHECK: [[TMP3:%.+]] = arith.addi [[TMP2]], [[OUTPUT_ZP_I32]] : i321559 // CHECK: %c-128_i32 = arith.constant -128 : i321560 // CHECK: %c127_i32 = arith.constant 127 : i321561 // CHECK: [[MAX:%.+]] = arith.maxsi %c-128_i32, [[TMP3]] : i321562 // CHECK: [[MIN:%.+]] = arith.minsi %c127_i32, [[MAX]] : i321563 %0 = tosa.rescale %arg0, %multiplier, %shift, %input_zp, %output_zp {scale32 = true, rounding_mode = DOUBLE_ROUND, per_channel = false, input_unsigned = false, output_unsigned = false} : (tensor<2xi8>, tensor<1xi32>, tensor<1xi8>, tensor<1xi8>, tensor<1xi8>) -> tensor<2xi8>1564 return %0 : tensor<2xi8>1565}1566 1567// -----1568 1569// CHECK: #[[$MAP0:.+]] = affine_map<(d0) -> (d0)>1570// CHECK: #[[$MAP1:.+]] = affine_map<(d0) -> ()>1571// CHECK-LABEL: @rescale_no_const_per_channel1572// CHECK-SAME: ([[ARG0:%[0-9a-zA-Z_]*]]1573// CHECK-SAME: [[ARG1:%[0-9a-zA-Z_]*]]1574// CHECK-SAME: [[ARG2:%[0-9a-zA-Z_]*]]1575func.func @rescale_no_const_per_channel(%arg0 : tensor<2xi8>, %arg1 : tensor<2xi32>, %arg2 : tensor<2xi8>, %input_zp : tensor<1xi8>, %output_zp : tensor<1xi8>) -> (tensor<2xi8>) {1576 // CHECK: [[INPUT_ZP:%.+]] = tensor.collapse_shape %arg3 [] : tensor<1xi8> into tensor<i8>1577 // CHECK: [[OUTPUT_ZP:%.+]] = tensor.collapse_shape %arg4 [] : tensor<1xi8> into tensor<i8>1578 // CHECK: [[INIT:%.+]] = tensor.empty() : tensor<2xi8>1579 // CHECK: [[GENERIC:%.+]] = linalg.generic {indexing_maps = [#[[$MAP0]], #[[$MAP0]], #[[$MAP0]], #[[$MAP1]], #[[$MAP1]], #[[$MAP0]]], iterator_types = ["parallel"]} ins([[ARG0]], [[ARG1]], [[ARG2]], [[INPUT_ZP]], [[OUTPUT_ZP]] : tensor<2xi8>, tensor<2xi32>, tensor<2xi8>, tensor<i8>, tensor<i8>) outs([[INIT]] : tensor<2xi8>) {1580 // CHECK: ^bb0([[ARG0:%.*]]: i8, [[ARG1:%.*]]: i32, [[ARG2:%.*]]: i8, [[ARG3:%.*]]: i8, [[ARG4:%.*]]: i8, [[OUT:%.*]]: i8):1581 // CHECK: [[INPUT_ZP_I32:%.+]] = arith.extsi [[ARG3]] : i8 to i321582 // CHECK: [[OUTPUT_ZP_I32:%.+]] = arith.extsi [[ARG4]] : i8 to i321583 // CHECK: [[ARG0_I32:%.+]] = arith.extsi [[ARG0]] : i8 to i321584 // CHECK: [[TMP1:%.+]] = arith.subi [[ARG0_I32]], [[INPUT_ZP_I32]] : i321585 // CHECK: [[TMP2:%.+]] = tosa.apply_scale [[TMP1]], [[ARG1]], [[ARG2]] {rounding_mode = DOUBLE_ROUND} : (i32, i32, i8) -> i321586 // CHECK: [[TMP3:%.+]] = arith.addi [[TMP2]], [[OUTPUT_ZP_I32]] : i321587 // CHECK: %c-128_i32 = arith.constant -128 : i321588 // CHECK: %c127_i32 = arith.constant 127 : i321589 // CHECK: [[MAX:%.+]] = arith.maxsi %c-128_i32, [[TMP3]] : i321590 // CHECK: [[MIN:%.+]] = arith.minsi %c127_i32, [[MAX]] : i321591 %0 = tosa.rescale %arg0, %arg1, %arg2, %input_zp, %output_zp {scale32 = true, rounding_mode = DOUBLE_ROUND, per_channel = true, input_unsigned = false, output_unsigned = false} : (tensor<2xi8>, tensor<2xi32>, tensor<2xi8>, tensor<1xi8>, tensor<1xi8>) -> tensor<2xi8>1592 return %0 : tensor<2xi8>1593}1594 1595// -----1596 1597// CHECK: #[[$MAP0:.+]] = affine_map<(d0) -> (d0)>1598// CHECK: #[[$MAP1:.+]] = affine_map<(d0) -> ()>1599// CHECK-LABEL: @rescale_no_const_per_channel_input_output_zp_ui81600// CHECK-SAME: ([[ARG0:%[0-9a-zA-Z_]*]]1601// CHECK-SAME: [[ARG1:%[0-9a-zA-Z_]*]]1602// CHECK-SAME: [[ARG2:%[0-9a-zA-Z_]*]]1603func.func @rescale_no_const_per_channel_input_output_zp_ui8(%arg0 : tensor<2xi8>, %arg1 : tensor<2xi32>, %arg2 : tensor<2xi8>, %input_zp : tensor<1xui8>, %output_zp : tensor<1xui8>) -> (tensor<2xui8>) {1604 // CHECK: [[INPUT_ZP:%.+]] = tensor.collapse_shape %arg3 [] : tensor<1xui8> into tensor<ui8>1605 // CHECK: [[OUTPUT_ZP:%.+]] = tensor.collapse_shape %arg4 [] : tensor<1xui8> into tensor<ui8>1606 // CHECK: [[INIT:%.+]] = tensor.empty() : tensor<2xui8>1607 // CHECK: [[GENERIC:%.+]] = linalg.generic {indexing_maps = [#[[$MAP0]], #[[$MAP0]], #[[$MAP0]], #[[$MAP1]], #[[$MAP1]], #[[$MAP0]]], iterator_types = ["parallel"]} ins([[ARG0]], [[ARG1]], [[ARG2]], [[INPUT_ZP]], [[OUTPUT_ZP]] : tensor<2xi8>, tensor<2xi32>, tensor<2xi8>, tensor<ui8>, tensor<ui8>) outs([[INIT]] : tensor<2xui8>) {1608 // CHECK: ^bb0([[ARG0:%.*]]: i8, [[ARG1:%.*]]: i32, [[ARG2:%.*]]: i8, [[ARG3:%.*]]: ui8, [[ARG4:%.*]]: ui8, [[OUT:%.*]]: ui8):1609 // CHECK: [[INPUT_ZP_I8:%.+]] = builtin.unrealized_conversion_cast [[ARG3]] : ui8 to i81610 // CHECK: [[INPUT_ZP_I32:%.+]] = arith.extui [[INPUT_ZP_I8]] : i8 to i321611 // CHECK: [[OUTPUT_ZP_I8:%.+]] = builtin.unrealized_conversion_cast [[ARG4]] : ui8 to i81612 // CHECK: [[OUTPUT_ZP_I32:%.+]] = arith.extui [[OUTPUT_ZP_I8]] : i8 to i321613 // CHECK: [[ARG0_I32:%.+]] = arith.extsi [[ARG0]] : i8 to i321614 // CHECK: [[TMP1:%.+]] = arith.subi [[ARG0_I32]], [[INPUT_ZP_I32]] : i321615 // CHECK: [[TMP2:%.+]] = tosa.apply_scale [[TMP1]], [[ARG1]], [[ARG2]] {rounding_mode = DOUBLE_ROUND} : (i32, i32, i8) -> i321616 // CHECK: [[TMP3:%.+]] = arith.addi [[TMP2]], [[OUTPUT_ZP_I32]] : i321617 // CHECK: %c0_i32 = arith.constant 0 : i321618 // CHECK: %c255_i32 = arith.constant 255 : i321619 // CHECK: [[MAX:%.+]] = arith.maxsi %c0_i32, [[TMP3]] : i321620 // CHECK: [[MIN:%.+]] = arith.minsi %c255_i32, [[MAX]] : i321621 %0 = tosa.rescale %arg0, %arg1, %arg2, %input_zp, %output_zp {scale32 = true, rounding_mode = DOUBLE_ROUND, per_channel = true, input_unsigned = false, output_unsigned = true} : (tensor<2xi8>, tensor<2xi32>, tensor<2xi8>, tensor<1xui8>, tensor<1xui8>) -> tensor<2xui8>1622 return %0 : tensor<2xui8>1623}1624 1625// -----1626 1627// CHECK: #[[$MAP0:.*]] = affine_map<(d0, d1) -> (d0, d1)>1628 1629// CHECK-LABEL: @reverse1630// CHECK-SAME: (%[[ARG0:[0-9a-zA-Z_]*]]:1631func.func @reverse(%arg0: tensor<5x4xi32>) -> () {1632 // CHECK: %[[C0:.+]] = arith.constant 01633 // CHECK: %[[RDIM:.+]] = tensor.dim %[[ARG0]], %[[C0]]1634 // CHECK: %[[INIT:.+]] = tensor.empty()1635 // CHECK: %[[GENERIC:.+]] = linalg.generic {indexing_maps = [#[[$MAP0]]], iterator_types = ["parallel", "parallel"]} outs(%[[INIT]] : tensor<5x4xi32>)1636 // CHECK-DAG: %[[I0:.+]] = linalg.index 01637 // CHECK-DAG: %[[I1:.+]] = linalg.index 11638 // CHECK-DAG: %[[SUB1:.+]] = arith.constant 11639 // CHECK-DAG: %[[RDIM_MINUS_C1:.+]] = arith.subi %[[RDIM]], %[[SUB1]]1640 // CHECK-DAG: %[[READ_DIM:.+]] = arith.subi %[[RDIM_MINUS_C1]], %[[I0]]1641 // CHECK-DAG: %[[EXTRACT:.+]] = tensor.extract %arg0[%[[READ_DIM]], %[[I1]]] : tensor<5x4xi32>1642 // CHECK: linalg.yield %[[EXTRACT]]1643 %0 = tosa.reverse %arg0 {axis = 0 : i32} : (tensor<5x4xi32>) -> tensor<5x4xi32>1644 1645 // CHECK: %[[C1:.+]] = arith.constant 11646 // CHECK: %[[RDIM:.+]] = tensor.dim %[[ARG0]], %[[C1]]1647 // CHECK: %[[INIT:.+]] = tensor.empty()1648 // CHECK: %[[GENERIC:.+]] = linalg.generic {indexing_maps = [#[[$MAP0]]], iterator_types = ["parallel", "parallel"]} outs(%[[INIT]] : tensor<5x4xi32>)1649 // CHECK-DAG: %[[I0:.+]] = linalg.index 01650 // CHECK-DAG: %[[I1:.+]] = linalg.index 11651 // CHECK-DAG: %[[SUB1:.+]] = arith.constant 11652 // CHECK-DAG: %[[RDIM_MINUS_C1:.+]] = arith.subi %[[RDIM]], %[[SUB1]]1653 // CHECK-DAG: %[[READ_DIM:.+]] = arith.subi %[[RDIM_MINUS_C1]], %[[I1]]1654 // CHECK-DAG: %[[EXTRACT:.+]] = tensor.extract %arg0[%[[I0]], %[[READ_DIM]]] : tensor<5x4xi32>1655 // CHECK: linalg.yield %[[EXTRACT]]1656 %1 = tosa.reverse %arg0 {axis = 1 : i32} : (tensor<5x4xi32>) -> tensor<5x4xi32>1657 return1658}1659 1660// -----1661 1662// CHECK: #[[$MAP0:.*]] = affine_map<(d0) -> (d0)>1663 1664// CHECK-LABEL: @reverse_dyn1665// CHECK-SAME: (%[[ARG0:[0-9a-zA-Z_]*]]:1666func.func @reverse_dyn(%arg0: tensor<?xi32>) -> () {1667 // CHECK: %[[C0_1:.+]] = arith.constant 01668 // CHECK: %[[D0_1:.+]] = tensor.dim %[[ARG0]], %[[C0_1]]1669 // CHECK: %[[C0_2:.+]] = arith.constant 01670 // CHECK: %[[D0_2:.+]] = tensor.dim %[[ARG0]], %[[C0_2]]1671 // CHECK: %[[INIT:.+]] = tensor.empty(%[[D0_1]])1672 // CHECK: %[[GENERIC:.+]] = linalg.generic {indexing_maps = [#[[$MAP0]]], iterator_types = ["parallel"]} outs(%[[INIT]] : tensor<?xi32>)1673 // CHECK-DAG: %[[I0:.+]] = linalg.index 01674 // CHECK-DAG: %[[SUB1:.+]] = arith.constant 11675 // CHECK-DAG: %[[RDIM_MINUS_C1:.+]] = arith.subi %[[D0_2]], %[[SUB1]]1676 // CHECK-DAG: %[[READ_DIM:.+]] = arith.subi %[[RDIM_MINUS_C1]], %[[I0]]1677 // CHECK-DAG: %[[EXTRACT:.+]] = tensor.extract %arg0[%[[READ_DIM]]] : tensor<?xi32>1678 // CHECK: linalg.yield %[[EXTRACT]]1679 %0 = tosa.reverse %arg0 {axis = 0 : i32} : (tensor<?xi32>) -> tensor<?xi32>1680 return1681}1682 1683// -----1684 1685// CHECK-DAG: #[[$MAP0:.*]] = affine_map<(d0, d1, d2, d3) -> (d1, d3)>1686// CHECK-DAG: #[[$MAP1:.*]] = affine_map<(d0, d1, d2, d3) -> (d0, d1, d2, d3)>1687 1688// CHECK-LABEL: @tile1689// CHECK-SAME: %[[ARG0:.+]]: tensor<2x3xi8>1690func.func @tile(%arg0 : tensor<2x3xi8>) -> () {1691 // CHECK: [[INIT:%.+]] = tensor.empty()1692 // CHECK: [[GENERIC:%.+]] = linalg.generic {indexing_maps = [#[[$MAP0]], #[[$MAP1]]], iterator_types = ["parallel", "parallel", "parallel", "parallel"]} ins(%[[ARG0]] : tensor<2x3xi8>) outs([[INIT]] : tensor<2x2x1x3xi8>)1693 // CHECK: ^bb0(%[[ARG1:[0-9a-zA-Z_]+]]: i81694 // CHECK: linalg.yield %[[ARG1]] : i81695 // CHECK: [[CONST3:%.+]] = tosa.const_shape {values = dense<[4, 3]> : tensor<2xindex>} : () -> !tosa.shape<2>1696 // CHECK: tosa.reshape [[GENERIC]], [[CONST3]]1697 %cst21 = tosa.const_shape { values = dense<[2, 1]> : tensor<2xindex> } : () -> !tosa.shape<2>1698 %0 = tosa.tile %arg0, %cst21: (tensor<2x3xi8>, !tosa.shape<2>) -> tensor<4x3xi8>1699 1700 // CHECK: [[INIT:%.+]] = tensor.empty()1701 // CHECK: [[GENERIC:%.+]] = linalg.generic {indexing_maps = [#[[$MAP0]], #[[$MAP1]]], iterator_types = ["parallel", "parallel", "parallel", "parallel"]} ins(%[[ARG0]] : tensor<2x3xi8>) outs([[INIT]] : tensor<1x2x2x3xi8>)1702 // CHECK: ^bb0(%[[ARG1:[0-9a-zA-Z_]+]]: i81703 // CHECK: linalg.yield %[[ARG1]] : i81704 // CHECK: [[CONST8:%.+]] = tosa.const_shape {values = dense<[2, 6]> : tensor<2xindex>} : () -> !tosa.shape<2>1705 // tosa.reshape [[GENERIC]], [[CONST8]]1706 %cst12 = tosa.const_shape { values = dense<[1, 2]> : tensor<2xindex> } : () -> !tosa.shape<2>1707 %1 = tosa.tile %arg0, %cst12: (tensor<2x3xi8>, !tosa.shape<2>) -> tensor<2x6xi8>1708 1709 // CHECK: [[INIT:%.+]] = tensor.empty()1710 // CHECK: [[GENERIC:%.+]] = linalg.generic {indexing_maps = [#[[$MAP0]], #[[$MAP1]]], iterator_types = ["parallel", "parallel", "parallel", "parallel"]} ins(%[[ARG0]] : tensor<2x3xi8>) outs([[INIT]] : tensor<5x2x7x3xi8>)1711 // CHECK: ^bb0(%[[ARG1:[0-9a-zA-Z_]+]]: i81712 // CHECK: linalg.yield %[[ARG1]] : i81713 %cst57 = tosa.const_shape { values = dense<[5, 7]> : tensor<2xindex> } : () -> !tosa.shape<2>1714 // CHECK: [[CONST13:%.+]] = tosa.const_shape {values = dense<[10, 21]> : tensor<2xindex>} : () -> !tosa.shape<2>1715 // CHECK: tosa.reshape [[GENERIC]], [[CONST13]]1716 %2 = tosa.tile %arg0, %cst57: (tensor<2x3xi8>, !tosa.shape<2>) -> tensor<10x21xi8>1717 1718 return1719}1720 1721// -----1722 1723// CHECK-DAG: #[[$MAP0:.*]] = affine_map<(d0, d1, d2, d3) -> (d1, d3)>1724// CHECK-DAG: #[[$MAP1:.*]] = affine_map<(d0, d1, d2, d3) -> (d0, d1, d2, d3)>1725 1726// CHECK-LABEL: @tile_dyn_input1727// CHECK-SAME: (%[[ARG0:[0-9a-zA-Z_]*]]:1728func.func @tile_dyn_input(%arg0 : tensor<?x3xi8>) -> () {1729 // CHECK: %[[CST0:.+]] = arith.constant 01730 // CHECK: %[[DYN:.+]] = tensor.dim %[[ARG0]], %[[CST0]] : tensor<?x3xi8>1731 // CHECK: %[[INIT:.+]] = tensor.empty(%[[DYN]])1732 // CHECK: %[[GENERIC:.+]] = linalg.generic {indexing_maps = [#[[$MAP0]], #[[$MAP1]]], iterator_types = ["parallel", "parallel", "parallel", "parallel"]} ins(%[[ARG0]] : tensor<?x3xi8>) outs(%[[INIT]] : tensor<2x?x1x3xi8>)1733 // CHECK: ^bb0(%[[ARG1:.+]]: i8,1734 // CHECK: linalg.yield %[[ARG1]] : i81735 // CHECK: %[[CONST3:.+]] = tosa.const_shape {values = dense<[-1, 3]> : tensor<2xindex>} : () -> !tosa.shape<2>1736 // CHECK: tosa.reshape %[[GENERIC]], %[[CONST3]]1737 %cst21 = tosa.const_shape { values = dense<[2, 1]> : tensor<2xindex> } : () -> !tosa.shape<2>1738 %0 = tosa.tile %arg0, %cst21: (tensor<?x3xi8>, !tosa.shape<2>) -> tensor<?x3xi8>1739 1740 return1741}1742 1743// -----1744 1745// CHECK-DAG: #[[$MAP0:.*]] = affine_map<(d0, d1, d2, d3) -> (d1, d3)>1746// CHECK-DAG: #[[$MAP1:.*]] = affine_map<(d0, d1, d2, d3) -> (d0, d1, d2, d3)>1747 1748// CHECK-LABEL: @tile_dyn_multiples1749// CHECK-SAME: (%[[ARG0:[0-9a-zA-Z_]*]]:1750func.func @tile_dyn_multiples(%arg0 : tensor<2x3xi8>) -> () {1751 // CHECK: %[[CST1:.+]] = arith.constant 11752 // CHECK: %[[DYN:.+]] = tensor.dim %[[ARG0]], %[[CST1]] : tensor<2x3xi8>1753 // CHECK: %[[INIT:.+]] = tensor.empty(%[[DYN]])1754 // CHECK: %[[GENERIC:.+]] = linalg.generic {indexing_maps = [#[[$MAP0]], #[[$MAP1]]], iterator_types = ["parallel", "parallel", "parallel", "parallel"]} ins(%[[ARG0]] : tensor<2x3xi8>) outs(%[[INIT]] : tensor<2x2x?x3xi8>)1755 // CHECK: ^bb0(%[[ARG1:.+]]: i8,1756 // CHECK: linalg.yield %[[ARG1]] : i81757 // CHECK: %[[CONST2:.+]] = tosa.const_shape {values = dense<[2, -1]> : tensor<2xindex>} : () -> !tosa.shape<2>1758 // CHECK: tosa.reshape %[[GENERIC]], %[[CONST2]]1759 %cst = tosa.const_shape { values = dense<[2, -1]> : tensor<2xindex> } : () -> !tosa.shape<2>1760 %0 = tosa.tile %arg0, %cst: (tensor<2x3xi8>, !tosa.shape<2>) -> tensor<2x?xi8>1761 1762 return1763}1764 1765// -----1766 1767// CHECK: #[[$MAP0:.*]] = affine_map<(d0, d1) -> (d0, d1)>1768// CHECK: #[[$MAP1:.*]] = affine_map<(d0, d1) -> (d1)>1769// CHECK: #[[$MAP2:.*]] = affine_map<(d0, d1) -> (d0)>1770// CHECK: #[[$MAP3:.*]] = affine_map<(d0) -> (d0)>1771// CHECK: #[[$MAP4:.*]] = affine_map<(d0) -> ()>1772 1773func.func @argmax(%arg0 : tensor<3x2xi32>, %arg1 : tensor<6xf32>) -> () {1774 // CHECK: [[IDX_INIT:%.+]] = tensor.empty()1775 // CHECK: [[IDX_MIN:%.+]] = arith.constant 0 : i321776 // CHECK: [[IDX_FILL:%.+]] = linalg.fill ins([[IDX_MIN]]{{.*}}outs([[IDX_INIT]]1777 // CHECK: [[VAL_INIT:%.+]] = tensor.empty()1778 // CHECK: [[VAL_MIN:%.+]] = arith.constant -21474836481779 // CHECK: [[VAL_FILL:%.+]] = linalg.fill ins([[VAL_MIN]]{{.*}}outs([[VAL_INIT]]1780 // CHECK: linalg.generic {indexing_maps = [#[[$MAP0]], #[[$MAP1]], #[[$MAP1]]], iterator_types = ["reduction", "parallel"]} ins(%[[ARG0]] : tensor<3x2xi32>) outs([[IDX_FILL]], [[VAL_FILL]] : tensor<2xi32>, tensor<2xi32>)1781 // CHECK: ^bb0(%[[ARG1:[0-9a-zA-Z_]+]]: i32, %[[ARG2:[0-9a-zA-Z_]+]]: i32, %[[ARG3:[0-9a-zA-Z_]+]]: i321782 // CHECK: [[IDX:%.+]] = linalg.index 01783 // CHECK: [[CAST:%.+]] = arith.index_cast [[IDX]]1784 // CHECK: [[CMP:%.+]] = arith.cmpi sgt, %[[ARG1]], %[[ARG3]]1785 // CHECK: [[SELECT_VAL:%.+]] = arith.select [[CMP]], %[[ARG1]], %[[ARG3]]1786 // CHECK: [[SELECT_IDX:%.+]] = arith.select [[CMP]], [[CAST]], %[[ARG2]]1787 // CHECK: linalg.yield [[SELECT_IDX]], [[SELECT_VAL]]1788 %0 = tosa.argmax %arg0 { axis = 0 : i32} : (tensor<3x2xi32>) -> tensor<2xi32>1789 1790 // CHECK: [[IDX_INIT:%.+]] = tensor.empty()1791 // CHECK: [[IDX_MIN:%.+]] = arith.constant 0 : i321792 // CHECK: [[IDX_FILL:%.+]] = linalg.fill ins([[IDX_MIN]]{{.*}}outs([[IDX_INIT]]1793 // CHECK: [[VAL_INIT:%.+]] = tensor.empty()1794 // CHECK: [[VAL_MIN:%.+]] = arith.constant -21474836481795 // CHECK: [[VAL_FILL:%.+]] = linalg.fill ins([[VAL_MIN]]{{.*}}outs([[VAL_INIT]]1796 // CHECK: linalg.generic {indexing_maps = [#map, #map2, #map2], iterator_types = ["parallel", "reduction"]} ins(%[[ARG0]] : tensor<3x2xi32>) outs([[IDX_FILL]], [[VAL_FILL]] : tensor<3xi32>, tensor<3xi32>)1797 // CHECK: ^bb0(%[[ARG1:[0-9a-zA-Z_]+]]: i32, %[[ARG2:[0-9a-zA-Z_]+]]: i32, %[[ARG3:[0-9a-zA-Z_]+]]: i321798 // CHECK: [[IDX:%.+]] = linalg.index 11799 // CHECK: [[CAST:%.+]] = arith.index_cast [[IDX]]1800 // CHECK: [[CMP:%.+]] = arith.cmpi sgt, %[[ARG1]], %[[ARG3]]1801 // CHECK: [[SELECT_VAL:%.+]] = arith.select [[CMP]], %[[ARG1]], %[[ARG3]]1802 // CHECK: [[SELECT_IDX:%.+]] = arith.select [[CMP]], [[CAST]], %[[ARG2]]1803 // CHECK: linalg.yield [[SELECT_IDX]], [[SELECT_VAL]]1804 %1 = tosa.argmax %arg0 { axis = 1 : i32} : (tensor<3x2xi32>) -> tensor<3xi32>1805 1806 // CHECK: arith.constant -3.40282347E+38 : f321807 // CHECK: linalg.index1808 // CHECK: arith.index_cast1809 // CHECK: arith.cmpf ugt1810 // CHECK: arith.cmpf ord1811 // CHECK: andi1812 // CHECK: select1813 // CHECK: select1814 // CHECK: linalg.yield1815 %2 = tosa.argmax %arg1 { axis = 0 : i32} : (tensor<6xf32>) -> tensor<i32>1816 1817 return1818}1819 1820// -----1821 1822// CHECK: #[[$MAP0:.*]] = affine_map<(d0, d1) -> (d0, d1)>1823// CHECK: #[[$MAP1:.*]] = affine_map<(d0, d1) -> (d1)>1824 1825func.func @argmax_dyn_non_axis(%arg0 : tensor<3x?xi32>) -> () {1826 // CHECK: %[[CST1:.+]] = arith.constant 11827 // CHECK: %[[DYN:.+]] = tensor.dim %[[ARG0]], %[[CST1]]1828 // CHECK: %[[IDX_INIT:.+]] = tensor.empty(%[[DYN]])1829 // CHECK: %[[IDX_MIN:.+]] = arith.constant 0 : i321830 // CHECK: %[[IDX_FILL:.+]] = linalg.fill ins(%[[IDX_MIN]]{{.*}}outs(%[[IDX_INIT]]1831 // CHECK: %[[VAL_INIT:.+]] = tensor.empty(%[[DYN]])1832 // CHECK: %[[VAL_MIN:.+]] = arith.constant -21474836481833 // CHECK: %[[VAL_FILL:.+]] = linalg.fill ins(%[[VAL_MIN]]{{.*}}outs(%[[VAL_INIT]]1834 // CHECK: linalg.generic {indexing_maps = [#[[$MAP0]], #[[$MAP1]], #[[$MAP1]]], iterator_types = ["reduction", "parallel"]} ins(%[[ARG0]] : tensor<3x?xi32>) outs(%[[IDX_FILL]], %[[VAL_FILL]] : tensor<?xi32>, tensor<?xi32>)1835 // CHECK: ^bb0(%[[ARG1:[0-9a-zA-Z_]+]]: i32, %[[ARG2:[0-9a-zA-Z_]+]]: i32, %[[ARG3:[0-9a-zA-Z_]+]]: i321836 // CHECK: %[[IDX:.+]] = linalg.index 01837 // CHECK: %[[CAST:.+]] = arith.index_cast %[[IDX]]1838 // CHECK: %[[CMP:.+]] = arith.cmpi sgt, %[[ARG1]], %[[ARG3]]1839 // CHECK: %[[SELECT_VAL:.+]] = arith.select %[[CMP]], %[[ARG1]], %[[ARG3]]1840 // CHECK: %[[SELECT_IDX:.+]] = arith.select %[[CMP]], %[[CAST]], %[[ARG2]]1841 // CHECK: linalg.yield %[[SELECT_IDX]], %[[SELECT_VAL]]1842 %0 = tosa.argmax %arg0 { axis = 0 : i32} : (tensor<3x?xi32>) -> tensor<?xi32>1843 return1844}1845 1846// -----1847 1848// CHECK: #[[$MAP0:.*]] = affine_map<(d0, d1) -> (d0, d1)>1849// CHECK: #[[$MAP1:.*]] = affine_map<(d0, d1) -> (d0)>1850 1851func.func @argmax_dyn_axis(%arg0 : tensor<3x?xi32>) -> () {1852 // CHECK: %[[IDX_INIT:.+]] = tensor.empty()1853 // CHECK: %[[IDX_MIN:.+]] = arith.constant 0 : i321854 // CHECK: %[[IDX_FILL:.+]] = linalg.fill ins(%[[IDX_MIN]]{{.*}}outs(%[[IDX_INIT]]1855 // CHECK: %[[VAL_INIT:.+]] = tensor.empty()1856 // CHECK: %[[VAL_MIN:.+]] = arith.constant -21474836481857 // CHECK: %[[VAL_FILL:.+]] = linalg.fill ins(%[[VAL_MIN]]{{.*}}outs(%[[VAL_INIT]]1858 // CHECK: linalg.generic {indexing_maps = [#[[$MAP0]], #[[$MAP1]], #[[$MAP1]]], iterator_types = ["parallel", "reduction"]} ins(%[[ARG0]] : tensor<3x?xi32>) outs(%[[IDX_FILL]], %[[VAL_FILL]] : tensor<3xi32>, tensor<3xi32>)1859 // CHECK: %[[IDX:.+]] = linalg.index 11860 // CHECK: %[[CAST:.+]] = arith.index_cast %[[IDX]]1861 // CHECK: %[[CMP:.+]] = arith.cmpi sgt, %[[ARG1]], %[[ARG3]]1862 // CHECK: %[[SELECT_VAL:.+]] = arith.select %[[CMP]], %[[ARG1]], %[[ARG3]]1863 // CHECK: %[[SELECT_IDX:.+]] = arith.select %[[CMP]], %[[CAST]], %[[ARG2]]1864 // CHECK: linalg.yield %[[SELECT_IDX]], %[[SELECT_VAL]]1865 %0 = tosa.argmax %arg0 { axis = 1 : i32} : (tensor<3x?xi32>) -> tensor<3xi32>1866 return1867}1868 1869// -----1870 1871// CHECK-LABEL: @gather_float1872// CHECK-SAME: (%[[ARG0:[0-9a-zA-Z_]*]]1873// CHECK-SAME: %[[ARG1:[0-9a-zA-Z_]*]]1874func.func @gather_float(%arg0: tensor<2x3x2xf32>, %arg1: tensor<2x3xi32>) -> () {1875 // CHECK: %[[INIT:.+]] = tensor.empty()1876 // CHECK: %[[GENERIC:.+]] = linalg.generic {indexing_maps = [#map, #map1], iterator_types = ["parallel", "parallel", "parallel"]} ins(%[[ARG1]] : tensor<2x3xi32>) outs(%[[INIT]] : tensor<2x3x2xf32>)1877 // CHECK: ^bb0(%[[BBARG0:.+]]: i32, %[[BBARG1:.+]]: f32)1878 // CHECK: %[[IDX0:.+]] = linalg.index 01879 // CHECK: %[[CAST:.+]] = arith.index_cast %[[BBARG0]]1880 // CHECK: %[[IDX2:.+]] = linalg.index 21881 // CHECK: %[[EXTRACT:.+]] = tensor.extract %[[ARG0]][%[[IDX0]], %[[CAST]], %[[IDX2]]] : tensor<2x3x2xf32>1882 // CHECK: linalg.yield %[[EXTRACT]]1883 %0 = tosa.gather %arg0, %arg1 : (tensor<2x3x2xf32>, tensor<2x3xi32>) -> tensor<2x3x2xf32>1884 return1885}1886 1887// -----1888 1889// CHECK-LABEL: @gather_float_dyn1890// CHECK-SAME: (%[[ARG0:[0-9a-zA-Z_]*]]1891// CHECK-SAME: %[[ARG1:[0-9a-zA-Z_]*]]1892func.func @gather_float_dyn(%arg0: tensor<?x3x2xf32>, %arg1: tensor<?x3xi32>) -> () {1893 // CHECK: %[[C0:.+]] = arith.constant 01894 // CHECK: %[[BATCH:.+]] = tensor.dim %[[ARG0]], %[[C0]]1895 // CHECK: %[[INIT:.+]] = tensor.empty(%[[BATCH]])1896 // CHECK: %[[GENERIC:.+]] = linalg.generic {indexing_maps = [#map, #map1], iterator_types = ["parallel", "parallel", "parallel"]} ins(%[[ARG1]] : tensor<?x3xi32>) outs(%[[INIT]] : tensor<?x3x2xf32>)1897 // CHECK: ^bb0(%[[BBARG0:.+]]: i32, %[[BBARG1:.+]]: f32)1898 // CHECK: %[[IDX0:.+]] = linalg.index 01899 // CHECK: %[[CAST:.+]] = arith.index_cast %[[BBARG0]]1900 // CHECK: %[[IDX2:.+]] = linalg.index 21901 // CHECK: %[[EXTRACT:.+]] = tensor.extract %[[ARG0]][%[[IDX0]], %[[CAST]], %[[IDX2]]] : tensor<?x3x2xf32>1902 // CHECK: linalg.yield %[[EXTRACT]]1903 %0 = tosa.gather %arg0, %arg1 : (tensor<?x3x2xf32>, tensor<?x3xi32>) -> tensor<?x3x2xf32>1904 return1905}1906 1907// -----1908 1909// CHECK-LABEL: @gather_float_all_dynamic1910// CHECK-SAME: (%[[ARG0:[0-9a-zA-Z_]*]]1911// CHECK-SAME: %[[ARG1:[0-9a-zA-Z_]*]]1912func.func @gather_float_all_dynamic(%arg0: tensor<?x?x?xf32>, %arg1: tensor<?x?xi32>) -> () {1913 // CHECK: %[[C0:.+]] = arith.constant 01914 // CHECK: %[[BATCH:.+]] = tensor.dim %[[ARG0]], %[[C0]]1915 // CHECK: %[[C1:.+]] = arith.constant 11916 // CHECK: %[[INDEX:.+]] = tensor.dim %[[ARG1]], %[[C1]]1917 // CHECK: %[[C2:.+]] = arith.constant 21918 // CHECK: %[[CHANNEL:.+]] = tensor.dim %[[ARG0]], %[[C2]]1919 // CHECK: %[[INIT:.+]] = tensor.empty(%[[BATCH]], %[[INDEX]], %[[CHANNEL]])1920 // CHECK: %[[GENERIC:.+]] = linalg.generic {indexing_maps = [#map, #map1], iterator_types = ["parallel", "parallel", "parallel"]} ins(%[[ARG1]] : tensor<?x?xi32>) outs(%[[INIT]] : tensor<?x?x?xf32>)1921 // CHECK: ^bb0(%[[BBARG0:.+]]: i32, %[[BBARG1:.+]]: f32)1922 // CHECK: %[[IDX0:.+]] = linalg.index 01923 // CHECK: %[[CAST:.+]] = arith.index_cast %[[BBARG0]]1924 // CHECK: %[[IDX2:.+]] = linalg.index 21925 // CHECK: %[[EXTRACT:.+]] = tensor.extract %[[ARG0]][%[[IDX0]], %[[CAST]], %[[IDX2]]] : tensor<?x?x?xf32>1926 // CHECK: linalg.yield %[[EXTRACT]]1927 %0 = tosa.gather %arg0, %arg1 : (tensor<?x?x?xf32>, tensor<?x?xi32>) -> tensor<?x?x?xf32>1928 return1929}1930 1931// -----1932 1933// CHECK-LABEL: @gather_int1934// CHECK-SAME: (%[[ARG0:[0-9a-zA-Z_]*]]1935// CHECK-SAME: %[[ARG1:[0-9a-zA-Z_]*]]1936func.func @gather_int(%arg0: tensor<2x3x2xi32>, %arg1: tensor<2x3xi32>) -> () {1937 // CHECK: %[[INIT:.+]] = tensor.empty()1938 // CHECK: %[[GENERIC:.+]] = linalg.generic {indexing_maps = [#map, #map1], iterator_types = ["parallel", "parallel", "parallel"]} ins(%[[ARG1]] : tensor<2x3xi32>) outs(%[[INIT]] : tensor<2x3x2xi32>)1939 // CHECK: ^bb0(%[[BBARG0:.+]]: i32, %[[BBARG1:.+]]: i32)1940 // CHECK: %[[IDX0:.+]] = linalg.index 01941 // CHECK: %[[CAST:.+]] = arith.index_cast %[[BBARG0]]1942 // CHECK: %[[IDX2:.+]] = linalg.index 21943 // CHECK: %[[EXTRACT:.+]] = tensor.extract %[[ARG0]][%[[IDX0]], %[[CAST]], %[[IDX2]]] : tensor<2x3x2xi32>1944 // CHECK: linalg.yield %[[EXTRACT]]1945 %0 = tosa.gather %arg0, %arg1 : (tensor<2x3x2xi32>, tensor<2x3xi32>) -> tensor<2x3x2xi32>1946 return1947}1948 1949// -----1950 1951// CHECK-LABEL: @table81952// CHECK-SAME: (%[[ARG0:[0-9a-zA-Z_]*]]:1953// CHECK-SAME: %[[ARG1:[0-9a-zA-Z_]*]]:1954func.func @table8(%arg0: tensor<6xi8>, %arg1: tensor<512xi8>) -> () {1955 // CHECK: %[[INIT:.+]] = tensor.empty()1956 // CHECK: %[[GENERIC:.+]] = linalg.generic {indexing_maps = [#map, #map], iterator_types = ["parallel"]} ins(%[[ARG0]] : tensor<6xi8>) outs(%[[INIT]] : tensor<6xi8>)1957 // CHECK: ^bb0(%[[ARG_IN:.+]]: i8, %[[ARG_INIT:.+]]: i8)1958 // CHECK: %[[CAST:.+]] = arith.index_cast %[[ARG_IN]]1959 // CHECK: %[[OFFSET:.+]] = arith.constant 1281960 // CHECK: %[[ADD:.+]] = arith.addi %[[CAST]], %[[OFFSET]]1961 // CHECK: %[[EXTRACT:.+]] = tensor.extract %[[ARG1]][%[[ADD]]]1962 // CHECK: linalg.yield %[[EXTRACT]]1963 %0 = tosa.table %arg0, %arg1 : (tensor<6xi8>, tensor<512xi8>) -> tensor<6xi8>1964 return1965}1966 1967// -----1968 1969// CHECK-LABEL: @table161970// CHECK-SAME: (%[[ARG0:[0-9a-zA-Z_]*]]:1971// CHECK-SAME: %[[ARG1:[0-9a-zA-Z_]*]]:1972func.func @table16(%arg0: tensor<6xi16>, %arg1: tensor<513xi16>) -> () {1973 // CHECK: %[[INIT:.+]] = tensor.empty()1974 // CHECK: %[[GENERIC:.+]] = linalg.generic {indexing_maps = [#map, #map], iterator_types = ["parallel"]} ins(%[[ARG0]] : tensor<6xi16>) outs(%[[INIT]] : tensor<6xi32>)1975 // CHECK: ^bb0(%[[ARG2:.*]]: i16, %[[ARG3:.*]]: i32)1976 // CHECK: %[[EXT_IN:.+]] = arith.extsi %[[ARG2]]1977 // CHECK: %[[C32768:.+]] = arith.constant 327681978 // CHECK: %[[C7:.+]] = arith.constant 71979 // CHECK: %[[C1:.+]] = arith.constant 11980 // CHECK: %[[C127:.+]] = arith.constant 1271981 // CHECK: %[[INADD:.+]] = arith.addi %[[EXT_IN]], %[[C32768]]1982 // CHECK: %[[IDX:.+]] = arith.shrui %[[INADD]], %[[C7]]1983 // CHECK: %[[FRACTION:.+]] = arith.andi %[[INADD]], %[[C127]]1984 // CHECK: %[[IDXPLUS1:.+]] = arith.addi %[[IDX]], %[[C1]]1985 // CHECK: %[[IDX_CAST:.+]] = arith.index_cast %[[IDX]]1986 // CHECK: %[[IDXPLUS1_CAST:.+]] = arith.index_cast %[[IDXPLUS1]]1987 // CHECK: %[[BASE:.+]] = tensor.extract %[[ARG1]][%[[IDX_CAST]]]1988 // CHECK: %[[NEXT:.+]] = tensor.extract %[[ARG1]][%[[IDXPLUS1_CAST]]]1989 // CHECK: %[[BASE_EXT:.+]] = arith.extsi %[[BASE]]1990 // CHECK: %[[NEXT_EXT:.+]] = arith.extsi %[[NEXT]]1991 // CHECK: %[[BASE_MUL:.+]] = arith.shli %[[BASE_EXT]], %[[C7]]1992 // CHECK: %[[DIFF:.+]] = arith.subi %[[NEXT_EXT]], %[[BASE_EXT]]1993 // CHECK: %[[DIFF_MUL:.+]] = arith.muli %[[DIFF]], %[[FRACTION]]1994 // CHECK: %[[RESULT:.+]] = arith.addi %[[BASE_MUL]], %[[DIFF_MUL]]1995 // CHECK: linalg.yield %[[RESULT]]1996 %0 = tosa.table %arg0, %arg1 : (tensor<6xi16>, tensor<513xi16>) -> tensor<6xi32>1997 return1998}1999 2000// -----2001 2002// CHECK-LABEL: @table8_dyn2003// CHECK-SAME: (%[[ARG0:[0-9a-zA-Z_]*]]:2004// CHECK-SAME: %[[ARG1:[0-9a-zA-Z_]*]]:2005func.func @table8_dyn(%arg0: tensor<?xi8>, %arg1: tensor<512xi8>) -> () {2006 // CHECK: %[[CST0:.+]] = arith.constant 02007 // CHECK: %[[DYN:.+]] = tensor.dim %[[ARG0]], %[[CST0]]2008 // CHECK: %[[INIT:.+]] = tensor.empty(%[[DYN]])2009 // CHECK: %[[GENERIC:.+]] = linalg.generic {indexing_maps = [#map, #map], iterator_types = ["parallel"]} ins(%[[ARG0]] : tensor<?xi8>) outs(%[[INIT]] : tensor<?xi8>)2010 // CHECK: ^bb0(%[[ARG_IN:.+]]: i8, %[[ARG_INIT:.+]]: i8)2011 // CHECK: %[[CAST:.+]] = arith.index_cast %[[ARG_IN]]2012 // CHECK: %[[OFFSET:.+]] = arith.constant 1282013 // CHECK: %[[ADD:.+]] = arith.addi %[[CAST]], %[[OFFSET]]2014 // CHECK: %[[EXTRACT:.+]] = tensor.extract %[[ARG1]][%[[ADD]]]2015 // CHECK: linalg.yield %[[EXTRACT]]2016 %0 = tosa.table %arg0, %arg1 : (tensor<?xi8>, tensor<512xi8>) -> tensor<?xi8>2017 return2018}2019 2020// -----2021 2022// CHECK-LABEL: @table8_dyn_table2023// CHECK-SAME: (%[[ARG0:[0-9a-zA-Z_]*]]:2024// CHECK-SAME: %[[ARG1:[0-9a-zA-Z_]*]]:2025func.func @table8_dyn_table(%arg0: tensor<6xi8>, %arg1: tensor<?xi8>) -> () {2026 // CHECK: %[[INIT:.+]] = tensor.empty()2027 // CHECK: %[[GENERIC:.+]] = linalg.generic {indexing_maps = [#map, #map], iterator_types = ["parallel"]} ins(%[[ARG0]] : tensor<6xi8>) outs(%[[INIT]] : tensor<6xi8>)2028 // CHECK: ^bb0(%[[ARG_IN:.+]]: i8, %[[ARG_INIT:.+]]: i8)2029 // CHECK: %[[CAST:.+]] = arith.index_cast %[[ARG_IN]]2030 // CHECK: %[[OFFSET:.+]] = arith.constant 1282031 // CHECK: %[[ADD:.+]] = arith.addi %[[CAST]], %[[OFFSET]]2032 // CHECK: %[[EXTRACT:.+]] = tensor.extract %[[ARG1]][%[[ADD]]]2033 // CHECK: linalg.yield %[[EXTRACT]]2034 %0 = tosa.table %arg0, %arg1 : (tensor<6xi8>, tensor<?xi8>) -> tensor<6xi8>2035 return2036}2037 2038// -----2039// NOTE: Assertions have been autogenerated by utils/generate-test-checks.py2040// CHECK: #[[$ATTR_0:.+]] = affine_map<(d0, d1, d2, d3, d4) -> (d0, d3, d4)>2041// CHECK: #[[$ATTR_1:.+]] = affine_map<(d0, d1, d2, d3, d4) -> (d0, d1, d2)>2042 2043// CHECK-LABEL: func.func @test_static_rfft2d(2044// CHECK-SAME: %[[VAL_0:.*]]: tensor<5x4x8xf32>) -> (tensor<5x4x5xf32>, tensor<5x4x5xf32>) {2045// CHECK: %[[VAL_1:.*]] = arith.constant 1 : index2046// CHECK: %[[VAL_2:.*]] = arith.constant 2 : index2047// CHECK: %[[VAL_3:.*]] = arith.constant 8 : index2048// CHECK: %[[VAL_4:.*]] = arith.constant 4 : index2049// CHECK: %[[VAL_5:.*]] = arith.constant 5 : index2050// CHECK: %[[VAL_6:.*]] = tensor.empty() : tensor<5x4x5xf32>2051// CHECK: %[[VAL_7:.*]] = arith.constant 0.000000e+00 : f322052// CHECK: %[[VAL_8:.*]] = linalg.fill ins(%[[VAL_7]] : f32) outs(%[[VAL_6]] : tensor<5x4x5xf32>) -> tensor<5x4x5xf32>2053// CHECK: %[[VAL_9:.*]] = tensor.empty() : tensor<5x4x5xf32>2054// CHECK: %[[VAL_10:.*]] = arith.constant 0.000000e+00 : f322055// CHECK: %[[VAL_11:.*]] = linalg.fill ins(%[[VAL_10]] : f32) outs(%[[VAL_9]] : tensor<5x4x5xf32>) -> tensor<5x4x5xf32>2056// CHECK: %[[VAL_12:.*]] = arith.constant 1 : index2057// CHECK: %[[VAL_13:.*]] = arith.constant 4 : index2058// CHECK: %[[VAL_14:.*]] = arith.constant 2 : index2059// CHECK: %[[VAL_15:.*]] = arith.constant 8 : index2060// CHECK: %[[VAL_16:.*]] = arith.constant 6.28318548 : f322061// CHECK: %[[VAL_17:.*]] = arith.index_castui %[[VAL_13]] : index to i322062// CHECK: %[[VAL_18:.*]] = arith.uitofp %[[VAL_17]] : i32 to f322063// CHECK: %[[VAL_19:.*]] = arith.index_castui %[[VAL_15]] : index to i322064// CHECK: %[[VAL_20:.*]] = arith.uitofp %[[VAL_19]] : i32 to f322065// CHECK: %[[VAL_21:.*]]:2 = linalg.generic {indexing_maps = [#[[$ATTR_0]], #[[$ATTR_1]], #[[$ATTR_1]]], iterator_types = ["parallel", "parallel", "parallel", "reduction", "reduction"]} ins(%[[VAL_0]] : tensor<5x4x8xf32>) outs(%[[VAL_8]], %[[VAL_11]] : tensor<5x4x5xf32>, tensor<5x4x5xf32>) {2066// CHECK: ^bb0(%[[VAL_22:.*]]: f32, %[[VAL_23:.*]]: f32, %[[VAL_24:.*]]: f32):2067// CHECK: %[[VAL_25:.*]] = linalg.index 1 : index2068// CHECK: %[[VAL_26:.*]] = linalg.index 2 : index2069// CHECK: %[[VAL_27:.*]] = linalg.index 3 : index2070// CHECK: %[[VAL_28:.*]] = linalg.index 4 : index2071// CHECK: %[[VAL_29:.*]] = index.mul %[[VAL_27]], %[[VAL_25]]2072// CHECK: %[[VAL_30:.*]] = index.mul %[[VAL_28]], %[[VAL_26]]2073// CHECK: %[[VAL_31:.*]] = index.remu %[[VAL_29]], %[[VAL_13]]2074// CHECK: %[[VAL_32:.*]] = index.remu %[[VAL_30]], %[[VAL_15]]2075// CHECK: %[[VAL_33:.*]] = arith.index_castui %[[VAL_31]] : index to i322076// CHECK: %[[VAL_34:.*]] = arith.uitofp %[[VAL_33]] : i32 to f322077// CHECK: %[[VAL_35:.*]] = arith.index_castui %[[VAL_32]] : index to i322078// CHECK: %[[VAL_36:.*]] = arith.uitofp %[[VAL_35]] : i32 to f322079// CHECK: %[[VAL_37:.*]] = arith.divf %[[VAL_34]], %[[VAL_18]] : f322080// CHECK: %[[VAL_38:.*]] = arith.divf %[[VAL_36]], %[[VAL_20]] : f322081// CHECK: %[[VAL_39:.*]] = arith.addf %[[VAL_37]], %[[VAL_38]] : f322082// CHECK: %[[VAL_40:.*]] = arith.mulf %[[VAL_16]], %[[VAL_39]] : f322083// CHECK: %[[VAL_41:.*]] = math.cos %[[VAL_40]] : f322084// CHECK: %[[VAL_42:.*]] = math.sin %[[VAL_40]] : f322085// CHECK: %[[VAL_43:.*]] = arith.mulf %[[VAL_22]], %[[VAL_41]] : f322086// CHECK: %[[VAL_44:.*]] = arith.mulf %[[VAL_22]], %[[VAL_42]] : f322087// CHECK: %[[VAL_45:.*]] = arith.addf %[[VAL_23]], %[[VAL_43]] : f322088// CHECK: %[[VAL_46:.*]] = arith.subf %[[VAL_24]], %[[VAL_44]] : f322089// CHECK: linalg.yield %[[VAL_45]], %[[VAL_46]] : f32, f322090// CHECK: } -> (tensor<5x4x5xf32>, tensor<5x4x5xf32>)2091// CHECK: return %[[VAL_47:.*]]#0, %[[VAL_47]]#1 : tensor<5x4x5xf32>, tensor<5x4x5xf32>2092// CHECK: }2093func.func @test_static_rfft2d(%arg0: tensor<5x4x8xf32>) -> (tensor<5x4x5xf32>, tensor<5x4x5xf32>) {2094 %output_real, %output_imag = "tosa.rfft2d"(%arg0) {} : (tensor<5x4x8xf32>) -> (tensor<5x4x5xf32>, tensor<5x4x5xf32>)2095 return %output_real, %output_imag : tensor<5x4x5xf32>, tensor<5x4x5xf32>2096}2097 2098// -----2099// NOTE: Assertions have been autogenerated by utils/generate-test-checks.py2100// CHECK: #[[$ATTR_0:.+]] = affine_map<(d0, d1, d2, d3, d4) -> (d0, d3, d4)>2101// CHECK: #[[$ATTR_1:.+]] = affine_map<(d0, d1, d2, d3, d4) -> (d0, d1, d2)>2102 2103// CHECK-LABEL: func.func @test_dynamic_rfft2d(2104// CHECK-SAME: %[[VAL_0:.*]]: tensor<?x?x?xf32>) -> (tensor<?x?x?xf32>, tensor<?x?x?xf32>) {2105// CHECK: %[[VAL_1:.*]] = arith.constant 0 : index2106// CHECK: %[[VAL_2:.*]] = tensor.dim %[[VAL_0]], %[[VAL_1]] : tensor<?x?x?xf32>2107// CHECK: %[[VAL_3:.*]] = arith.constant 1 : index2108// CHECK: %[[VAL_4:.*]] = tensor.dim %[[VAL_0]], %[[VAL_3]] : tensor<?x?x?xf32>2109// CHECK: %[[VAL_5:.*]] = arith.constant 2 : index2110// CHECK: %[[VAL_6:.*]] = tensor.dim %[[VAL_0]], %[[VAL_5]] : tensor<?x?x?xf32>2111// CHECK: %[[VAL_7:.*]] = arith.constant 1 : index2112// CHECK: %[[VAL_8:.*]] = arith.constant 2 : index2113// CHECK: %[[VAL_9:.*]] = arith.divui %[[VAL_6]], %[[VAL_8]] : index2114// CHECK: %[[VAL_10:.*]] = arith.addi %[[VAL_9]], %[[VAL_7]] : index2115// CHECK: %[[VAL_11:.*]] = tensor.empty(%[[VAL_2]], %[[VAL_4]], %[[VAL_10]]) : tensor<?x?x?xf32>2116// CHECK: %[[VAL_12:.*]] = arith.constant 0.000000e+00 : f322117// CHECK: %[[VAL_13:.*]] = linalg.fill ins(%[[VAL_12]] : f32) outs(%[[VAL_11]] : tensor<?x?x?xf32>) -> tensor<?x?x?xf32>2118// CHECK: %[[VAL_14:.*]] = tensor.empty(%[[VAL_2]], %[[VAL_4]], %[[VAL_10]]) : tensor<?x?x?xf32>2119// CHECK: %[[VAL_15:.*]] = arith.constant 0.000000e+00 : f322120// CHECK: %[[VAL_16:.*]] = linalg.fill ins(%[[VAL_15]] : f32) outs(%[[VAL_14]] : tensor<?x?x?xf32>) -> tensor<?x?x?xf32>2121// CHECK: %[[VAL_17:.*]] = arith.constant 1 : index2122// CHECK: %[[VAL_18:.*]] = tensor.dim %[[VAL_0]], %[[VAL_17]] : tensor<?x?x?xf32>2123// CHECK: %[[VAL_19:.*]] = arith.constant 2 : index2124// CHECK: %[[VAL_20:.*]] = tensor.dim %[[VAL_0]], %[[VAL_19]] : tensor<?x?x?xf32>2125// CHECK: %[[VAL_21:.*]] = arith.constant 6.28318548 : f322126// CHECK: %[[VAL_22:.*]] = arith.index_castui %[[VAL_18]] : index to i322127// CHECK: %[[VAL_23:.*]] = arith.uitofp %[[VAL_22]] : i32 to f322128// CHECK: %[[VAL_24:.*]] = arith.index_castui %[[VAL_20]] : index to i322129// CHECK: %[[VAL_25:.*]] = arith.uitofp %[[VAL_24]] : i32 to f322130// CHECK: %[[VAL_26:.*]]:2 = linalg.generic {indexing_maps = [#[[$ATTR_0]], #[[$ATTR_1]], #[[$ATTR_1]]], iterator_types = ["parallel", "parallel", "parallel", "reduction", "reduction"]} ins(%[[VAL_0]] : tensor<?x?x?xf32>) outs(%[[VAL_13]], %[[VAL_16]] : tensor<?x?x?xf32>, tensor<?x?x?xf32>) {2131// CHECK: ^bb0(%[[VAL_27:.*]]: f32, %[[VAL_28:.*]]: f32, %[[VAL_29:.*]]: f32):2132// CHECK: %[[VAL_30:.*]] = linalg.index 1 : index2133// CHECK: %[[VAL_31:.*]] = linalg.index 2 : index2134// CHECK: %[[VAL_32:.*]] = linalg.index 3 : index2135// CHECK: %[[VAL_33:.*]] = linalg.index 4 : index2136// CHECK: %[[VAL_34:.*]] = index.mul %[[VAL_32]], %[[VAL_30]]2137// CHECK: %[[VAL_35:.*]] = index.mul %[[VAL_33]], %[[VAL_31]]2138// CHECK: %[[VAL_36:.*]] = index.remu %[[VAL_34]], %[[VAL_18]]2139// CHECK: %[[VAL_37:.*]] = index.remu %[[VAL_35]], %[[VAL_20]]2140// CHECK: %[[VAL_38:.*]] = arith.index_castui %[[VAL_36]] : index to i322141// CHECK: %[[VAL_39:.*]] = arith.uitofp %[[VAL_38]] : i32 to f322142// CHECK: %[[VAL_40:.*]] = arith.index_castui %[[VAL_37]] : index to i322143// CHECK: %[[VAL_41:.*]] = arith.uitofp %[[VAL_40]] : i32 to f322144// CHECK: %[[VAL_42:.*]] = arith.divf %[[VAL_39]], %[[VAL_23]] : f322145// CHECK: %[[VAL_43:.*]] = arith.divf %[[VAL_41]], %[[VAL_25]] : f322146// CHECK: %[[VAL_44:.*]] = arith.addf %[[VAL_42]], %[[VAL_43]] : f322147// CHECK: %[[VAL_45:.*]] = arith.mulf %[[VAL_21]], %[[VAL_44]] : f322148// CHECK: %[[VAL_46:.*]] = math.cos %[[VAL_45]] : f322149// CHECK: %[[VAL_47:.*]] = math.sin %[[VAL_45]] : f322150// CHECK: %[[VAL_48:.*]] = arith.mulf %[[VAL_27]], %[[VAL_46]] : f322151// CHECK: %[[VAL_49:.*]] = arith.mulf %[[VAL_27]], %[[VAL_47]] : f322152// CHECK: %[[VAL_50:.*]] = arith.addf %[[VAL_28]], %[[VAL_48]] : f322153// CHECK: %[[VAL_51:.*]] = arith.subf %[[VAL_29]], %[[VAL_49]] : f322154// CHECK: linalg.yield %[[VAL_50]], %[[VAL_51]] : f32, f322155// CHECK: } -> (tensor<?x?x?xf32>, tensor<?x?x?xf32>)2156// CHECK: return %[[VAL_52:.*]]#0, %[[VAL_52]]#1 : tensor<?x?x?xf32>, tensor<?x?x?xf32>2157// CHECK: }2158func.func @test_dynamic_rfft2d(%arg0: tensor<?x?x?xf32>) -> (tensor<?x?x?xf32>, tensor<?x?x?xf32>) {2159 %output_real, %output_imag = "tosa.rfft2d"(%arg0) {} : (tensor<?x?x?xf32>) -> (tensor<?x?x?xf32>, tensor<?x?x?xf32>)2160 return %output_real, %output_imag : tensor<?x?x?xf32>, tensor<?x?x?xf32>2161}2162 2163// -----2164// NOTE: Assertions have been autogenerated by utils/generate-test-checks.py2165// CHECK: #[[$ATTR_0:.+]] = affine_map<(d0, d1, d2, d3, d4) -> (d0, d3, d4)>2166// CHECK: #[[$ATTR_1:.+]] = affine_map<(d0, d1, d2, d3, d4) -> (d0, d1, d2)>2167 2168// CHECK-LABEL: func.func @test_static_fft2d(2169// CHECK-SAME: %[[VAL_0:.*]]: tensor<8x8x8xf32>,2170// CHECK-SAME: %[[VAL_1:.*]]: tensor<8x8x8xf32>) -> (tensor<8x8x8xf32>, tensor<8x8x8xf32>) {2171// CHECK: %[[VAL_2:.*]] = tensor.empty() : tensor<8x8x8xf32>2172// CHECK: %[[VAL_3:.*]] = arith.constant 0.000000e+00 : f322173// CHECK: %[[VAL_4:.*]] = linalg.fill ins(%[[VAL_3]] : f32) outs(%[[VAL_2]] : tensor<8x8x8xf32>) -> tensor<8x8x8xf32>2174// CHECK: %[[VAL_5:.*]] = tensor.empty() : tensor<8x8x8xf32>2175// CHECK: %[[VAL_6:.*]] = arith.constant 0.000000e+00 : f322176// CHECK: %[[VAL_7:.*]] = linalg.fill ins(%[[VAL_6]] : f32) outs(%[[VAL_5]] : tensor<8x8x8xf32>) -> tensor<8x8x8xf32>2177// CHECK: %[[VAL_8:.*]] = arith.constant 1 : index2178// CHECK: %[[VAL_9:.*]] = arith.constant 8 : index2179// CHECK: %[[VAL_10:.*]] = arith.constant 2 : index2180// CHECK: %[[VAL_11:.*]] = arith.constant 8 : index2181// CHECK: %[[VAL_12:.*]] = arith.constant 6.28318548 : f322182// CHECK: %[[VAL_13:.*]] = arith.index_castui %[[VAL_9]] : index to i322183// CHECK: %[[VAL_14:.*]] = arith.uitofp %[[VAL_13]] : i32 to f322184// CHECK: %[[VAL_15:.*]] = arith.index_castui %[[VAL_11]] : index to i322185// CHECK: %[[VAL_16:.*]] = arith.uitofp %[[VAL_15]] : i32 to f322186// CHECK: %[[VAL_17:.*]]:2 = linalg.generic {indexing_maps = [#[[$ATTR_0]], #[[$ATTR_0]], #[[$ATTR_1]], #[[$ATTR_1]]], iterator_types = ["parallel", "parallel", "parallel", "reduction", "reduction"]} ins(%[[VAL_0]], %[[VAL_1]] : tensor<8x8x8xf32>, tensor<8x8x8xf32>) outs(%[[VAL_4]], %[[VAL_7]] : tensor<8x8x8xf32>, tensor<8x8x8xf32>) {2187// CHECK: ^bb0(%[[VAL_18:.*]]: f32, %[[VAL_19:.*]]: f32, %[[VAL_20:.*]]: f32, %[[VAL_21:.*]]: f32):2188// CHECK: %[[VAL_22:.*]] = linalg.index 1 : index2189// CHECK: %[[VAL_23:.*]] = linalg.index 2 : index2190// CHECK: %[[VAL_24:.*]] = linalg.index 3 : index2191// CHECK: %[[VAL_25:.*]] = linalg.index 4 : index2192// CHECK: %[[VAL_26:.*]] = index.mul %[[VAL_24]], %[[VAL_22]]2193// CHECK: %[[VAL_27:.*]] = index.mul %[[VAL_25]], %[[VAL_23]]2194// CHECK: %[[VAL_28:.*]] = index.remu %[[VAL_26]], %[[VAL_9]]2195// CHECK: %[[VAL_29:.*]] = index.remu %[[VAL_27]], %[[VAL_11]]2196// CHECK: %[[VAL_30:.*]] = arith.index_castui %[[VAL_28]] : index to i322197// CHECK: %[[VAL_31:.*]] = arith.uitofp %[[VAL_30]] : i32 to f322198// CHECK: %[[VAL_32:.*]] = arith.index_castui %[[VAL_29]] : index to i322199// CHECK: %[[VAL_33:.*]] = arith.uitofp %[[VAL_32]] : i32 to f322200// CHECK: %[[VAL_34:.*]] = arith.divf %[[VAL_31]], %[[VAL_14]] : f322201// CHECK: %[[VAL_35:.*]] = arith.divf %[[VAL_33]], %[[VAL_16]] : f322202// CHECK: %[[VAL_36:.*]] = arith.addf %[[VAL_34]], %[[VAL_35]] : f322203// CHECK: %[[VAL_37:.*]] = arith.mulf %[[VAL_12]], %[[VAL_36]] : f322204// CHECK: %[[VAL_38:.*]] = math.cos %[[VAL_37]] : f322205// CHECK: %[[VAL_39:.*]] = math.sin %[[VAL_37]] : f322206// CHECK: %[[VAL_40:.*]] = arith.mulf %[[VAL_18]], %[[VAL_38]] : f322207// CHECK: %[[VAL_41:.*]] = arith.mulf %[[VAL_19]], %[[VAL_39]] : f322208// CHECK: %[[VAL_42:.*]] = arith.addf %[[VAL_40]], %[[VAL_41]] : f322209// CHECK: %[[VAL_43:.*]] = arith.mulf %[[VAL_19]], %[[VAL_38]] : f322210// CHECK: %[[VAL_44:.*]] = arith.mulf %[[VAL_18]], %[[VAL_39]] : f322211// CHECK: %[[VAL_45:.*]] = arith.subf %[[VAL_43]], %[[VAL_44]] : f322212// CHECK: %[[VAL_46:.*]] = arith.addf %[[VAL_20]], %[[VAL_42]] : f322213// CHECK: %[[VAL_47:.*]] = arith.addf %[[VAL_21]], %[[VAL_45]] : f322214// CHECK: linalg.yield %[[VAL_46]], %[[VAL_47]] : f32, f322215// CHECK: } -> (tensor<8x8x8xf32>, tensor<8x8x8xf32>)2216// CHECK: return %[[VAL_48:.*]]#0, %[[VAL_48]]#1 : tensor<8x8x8xf32>, tensor<8x8x8xf32>2217// CHECK: }2218func.func @test_static_fft2d(%arg0: tensor<8x8x8xf32>, %arg1: tensor<8x8x8xf32>) -> (tensor<8x8x8xf32>, tensor<8x8x8xf32>) {2219 %output_real, %output_imag = "tosa.fft2d"(%arg0, %arg1) {inverse=false} : (tensor<8x8x8xf32>, tensor<8x8x8xf32>) -> (tensor<8x8x8xf32>, tensor<8x8x8xf32>)2220 return %output_real, %output_imag : tensor<8x8x8xf32>, tensor<8x8x8xf32>2221}2222 2223// -----2224// NOTE: Assertions have been autogenerated by utils/generate-test-checks.py2225// CHECK: #[[$ATTR_0:.+]] = affine_map<(d0, d1, d2, d3, d4) -> (d0, d3, d4)>2226// CHECK: #[[$ATTR_1:.+]] = affine_map<(d0, d1, d2, d3, d4) -> (d0, d1, d2)>2227 2228// CHECK-LABEL: func.func @test_dynamic_fft2d(2229// CHECK-SAME: %[[VAL_0:.*]]: tensor<?x?x?xf32>,2230// CHECK-SAME: %[[VAL_1:.*]]: tensor<?x?x?xf32>) -> (tensor<?x?x?xf32>, tensor<?x?x?xf32>) {2231// CHECK: %[[VAL_2:.*]] = arith.constant 0 : index2232// CHECK: %[[VAL_3:.*]] = tensor.dim %[[VAL_0]], %[[VAL_2]] : tensor<?x?x?xf32>2233// CHECK: %[[VAL_4:.*]] = arith.constant 1 : index2234// CHECK: %[[VAL_5:.*]] = tensor.dim %[[VAL_0]], %[[VAL_4]] : tensor<?x?x?xf32>2235// CHECK: %[[VAL_6:.*]] = arith.constant 2 : index2236// CHECK: %[[VAL_7:.*]] = tensor.dim %[[VAL_0]], %[[VAL_6]] : tensor<?x?x?xf32>2237// CHECK: %[[VAL_8:.*]] = tensor.empty(%[[VAL_3]], %[[VAL_5]], %[[VAL_7]]) : tensor<?x?x?xf32>2238// CHECK: %[[VAL_9:.*]] = arith.constant 0.000000e+00 : f322239// CHECK: %[[VAL_10:.*]] = linalg.fill ins(%[[VAL_9]] : f32) outs(%[[VAL_8]] : tensor<?x?x?xf32>) -> tensor<?x?x?xf32>2240// CHECK: %[[VAL_11:.*]] = tensor.empty(%[[VAL_3]], %[[VAL_5]], %[[VAL_7]]) : tensor<?x?x?xf32>2241// CHECK: %[[VAL_12:.*]] = arith.constant 0.000000e+00 : f322242// CHECK: %[[VAL_13:.*]] = linalg.fill ins(%[[VAL_12]] : f32) outs(%[[VAL_11]] : tensor<?x?x?xf32>) -> tensor<?x?x?xf32>2243// CHECK: %[[VAL_14:.*]] = arith.constant 1 : index2244// CHECK: %[[VAL_15:.*]] = tensor.dim %[[VAL_0]], %[[VAL_14]] : tensor<?x?x?xf32>2245// CHECK: %[[VAL_16:.*]] = arith.constant 2 : index2246// CHECK: %[[VAL_17:.*]] = tensor.dim %[[VAL_0]], %[[VAL_16]] : tensor<?x?x?xf32>2247// CHECK: %[[VAL_18:.*]] = arith.constant 6.28318548 : f322248// CHECK: %[[VAL_19:.*]] = arith.index_castui %[[VAL_15]] : index to i322249// CHECK: %[[VAL_20:.*]] = arith.uitofp %[[VAL_19]] : i32 to f322250// CHECK: %[[VAL_21:.*]] = arith.index_castui %[[VAL_17]] : index to i322251// CHECK: %[[VAL_22:.*]] = arith.uitofp %[[VAL_21]] : i32 to f322252// CHECK: %[[VAL_23:.*]]:2 = linalg.generic {indexing_maps = [#[[$ATTR_0]], #[[$ATTR_0]], #[[$ATTR_1]], #[[$ATTR_1]]], iterator_types = ["parallel", "parallel", "parallel", "reduction", "reduction"]} ins(%[[VAL_0]], %[[VAL_1]] : tensor<?x?x?xf32>, tensor<?x?x?xf32>) outs(%[[VAL_10]], %[[VAL_13]] : tensor<?x?x?xf32>, tensor<?x?x?xf32>) {2253// CHECK: ^bb0(%[[VAL_24:.*]]: f32, %[[VAL_25:.*]]: f32, %[[VAL_26:.*]]: f32, %[[VAL_27:.*]]: f32):2254// CHECK: %[[VAL_28:.*]] = linalg.index 1 : index2255// CHECK: %[[VAL_29:.*]] = linalg.index 2 : index2256// CHECK: %[[VAL_30:.*]] = linalg.index 3 : index2257// CHECK: %[[VAL_31:.*]] = linalg.index 4 : index2258// CHECK: %[[VAL_32:.*]] = index.mul %[[VAL_30]], %[[VAL_28]]2259// CHECK: %[[VAL_33:.*]] = index.mul %[[VAL_31]], %[[VAL_29]]2260// CHECK: %[[VAL_34:.*]] = index.remu %[[VAL_32]], %[[VAL_15]]2261// CHECK: %[[VAL_35:.*]] = index.remu %[[VAL_33]], %[[VAL_17]]2262// CHECK: %[[VAL_36:.*]] = arith.index_castui %[[VAL_34]] : index to i322263// CHECK: %[[VAL_37:.*]] = arith.uitofp %[[VAL_36]] : i32 to f322264// CHECK: %[[VAL_38:.*]] = arith.index_castui %[[VAL_35]] : index to i322265// CHECK: %[[VAL_39:.*]] = arith.uitofp %[[VAL_38]] : i32 to f322266// CHECK: %[[VAL_40:.*]] = arith.divf %[[VAL_37]], %[[VAL_20]] : f322267// CHECK: %[[VAL_41:.*]] = arith.divf %[[VAL_39]], %[[VAL_22]] : f322268// CHECK: %[[VAL_42:.*]] = arith.addf %[[VAL_40]], %[[VAL_41]] : f322269// CHECK: %[[VAL_43:.*]] = arith.mulf %[[VAL_18]], %[[VAL_42]] : f322270// CHECK: %[[VAL_44:.*]] = arith.constant -1.000000e+00 : f322271// CHECK: %[[VAL_45:.*]] = arith.mulf %[[VAL_43]], %[[VAL_44]] : f322272// CHECK: %[[VAL_46:.*]] = math.cos %[[VAL_45]] : f322273// CHECK: %[[VAL_47:.*]] = math.sin %[[VAL_45]] : f322274// CHECK: %[[VAL_48:.*]] = arith.mulf %[[VAL_24]], %[[VAL_46]] : f322275// CHECK: %[[VAL_49:.*]] = arith.mulf %[[VAL_25]], %[[VAL_47]] : f322276// CHECK: %[[VAL_50:.*]] = arith.addf %[[VAL_48]], %[[VAL_49]] : f322277// CHECK: %[[VAL_51:.*]] = arith.mulf %[[VAL_25]], %[[VAL_46]] : f322278// CHECK: %[[VAL_52:.*]] = arith.mulf %[[VAL_24]], %[[VAL_47]] : f322279// CHECK: %[[VAL_53:.*]] = arith.subf %[[VAL_51]], %[[VAL_52]] : f322280// CHECK: %[[VAL_54:.*]] = arith.addf %[[VAL_26]], %[[VAL_50]] : f322281// CHECK: %[[VAL_55:.*]] = arith.addf %[[VAL_27]], %[[VAL_53]] : f322282// CHECK: linalg.yield %[[VAL_54]], %[[VAL_55]] : f32, f322283// CHECK: } -> (tensor<?x?x?xf32>, tensor<?x?x?xf32>)2284// CHECK: return %[[VAL_56:.*]]#0, %[[VAL_56]]#1 : tensor<?x?x?xf32>, tensor<?x?x?xf32>2285// CHECK: }2286func.func @test_dynamic_fft2d(%arg0: tensor<?x?x?xf32>, %arg1: tensor<?x?x?xf32>) -> (tensor<?x?x?xf32>, tensor<?x?x?xf32>) {2287 %output_real, %output_imag = "tosa.fft2d"(%arg0, %arg1) {inverse = true} : (tensor<?x?x?xf32>, tensor<?x?x?xf32>) -> (tensor<?x?x?xf32>, tensor<?x?x?xf32>)2288 return %output_real, %output_imag : tensor<?x?x?xf32>, tensor<?x?x?xf32>2289}2290 2291 2292// -----2293 2294// CHECK: #[[$MAP0:.+]] = affine_map<(d0) -> (d0)>2295 2296// CHECK-LABEL: func.func @test_cast_fp32_i64(2297// CHECK-SAME: %[[ARG0:.*]]: tensor<1xf32>) -> tensor<1xi64> {2298// CHECK: %[[EMPTY_TENSOR:.*]] = tensor.empty() : tensor<1xi64>2299// CHECK: %[[RESULT:.*]] = linalg.generic {indexing_maps = [#[[$MAP0]], #[[$MAP0]]], iterator_types = ["parallel"]} ins(%[[ARG0]] : tensor<1xf32>) outs(%[[EMPTY_TENSOR]] : tensor<1xi64>) {2300// CHECK: ^bb0(%[[IN:.*]]: f32, %[[OUT:.*]]: i64):2301// CHECK: %[[ROUND_EVEN:.*]] = math.roundeven %[[IN]] : f322302// CHECK: %[[FP_INT_MIN:.*]] = arith.constant -9.22337203E+18 : f322303// CHECK: %[[FP_INT_MAX_PLUS_ONE:.*]] = arith.constant 9.22337203E+18 : f322304// CHECK: %[[INT_MAX:.*]] = arith.constant 9223372036854775807 : i642305// CHECK: %[[MAX:.*]] = arith.maximumf %[[ROUND_EVEN]], %[[FP_INT_MIN]] : f322306// CHECK: %[[FPTOSI:.*]] = arith.fptosi %[[MAX]] : f32 to i642307// CHECK: %[[CMPF:.*]] = arith.cmpf uge, %[[ROUND_EVEN]], %[[FP_INT_MAX_PLUS_ONE]] : f322308// CHECK: %[[SELECT:.*]] = arith.select %[[CMPF]], %[[INT_MAX]], %[[FPTOSI]] : i642309// CHECK: linalg.yield %[[SELECT]] : i642310// CHECK: } -> tensor<1xi64>2311// CHECK: return %[[RESULT]] : tensor<1xi64>2312func.func @test_cast_fp32_i64(%arg0: tensor<1xf32>) -> (tensor<1xi64>) {2313 %0 = tosa.cast %arg0 : (tensor<1xf32>) -> tensor<1xi64>2314 return %0: tensor<1xi64>2315}2316 2317// -----2318 2319// CHECK-LABEL: @reduce_min_nan_propagate2320func.func @reduce_min_nan_propagate(%arg0: tensor<5x4xf32>, %arg1: tensor<5x4xf32>) -> () {2321 // CHECK: linalg.reduce2322 // CHECK: arith.minimumf2323 // CHECK-NOT: arith.cmpf uno2324 // CHECK-NOT: arith.select2325 // CHECK: linalg.yield2326 // CHECK-NOT: arith.constant 0x7FC000002327 // CHECK-NOT: tensor.empty()2328 // CHECK-NOT: linalg.fill2329 // CHECK-NOT: tensor.empty()2330 // CHECK-NOT: select2331 // CHECK: return2332 %3 = tosa.reduce_min %arg0 {axis = 0 : i32, nan_mode = PROPAGATE} : (tensor<5x4xf32>) -> tensor<1x4xf32>2333 return2334}2335 2336// -----2337 2338// CHECK-LABEL: @reduce_max_nan_propagate2339func.func @reduce_max_nan_propagate(%arg0: tensor<5x4xf32>, %arg1: tensor<5x4xf32>) -> () {2340 // CHECK: linalg.reduce2341 // CHECK: arith.maximumf2342 // CHECK-NOT: arith.cmpf uno2343 // CHECK-NOT: arith.select2344 // CHECK: linalg.yield2345 // CHECK-NOT: arith.constant 0x7FC000002346 // CHECK-NOT: tensor.empty()2347 // CHECK-NOT: linalg.fill2348 // CHECK-NOT: tensor.empty()2349 // CHECK-NOT: select2350 // CHECK: return2351 %4 = tosa.reduce_max %arg0 {axis = 0 : i32, nan_mode = PROPAGATE} : (tensor<5x4xf32>) -> tensor<1x4xf32>2352 return2353}2354 2355// -----2356 2357// CHECK-LABEL: @reduce_min_nan_ignore_int2358func.func @reduce_min_nan_ignore_int(%arg0: tensor<5x4xi8>, %arg1: tensor<5x4xi8>) -> () {2359 // CHECK: linalg.reduce2360 // CHECK: arith.minsi2361 // CHECK-NOT: arith.cmpf uno2362 // CHECK-NOT: arith.select2363 // CHECK: linalg.yield2364 // CHECK-NOT: arith.constant 0x7FC000002365 // CHECK-NOT: tensor.empty()2366 // CHECK-NOT: linalg.fill2367 // CHECK-NOT: tensor.empty()2368 // CHECK-NOT: select2369 // CHECK: return2370 %5 = tosa.reduce_min %arg0 {axis = 0 : i32, nan_mode = IGNORE} : (tensor<5x4xi8>) -> tensor<1x4xi8>2371 return2372}2373 2374// -----2375 2376// CHECK-LABEL: @reduce_max_nan_ignore_int2377func.func @reduce_max_nan_ignore_int(%arg0: tensor<5x4xi8>, %arg1: tensor<5x4xi8>) -> () {2378 // CHECK: linalg.reduce2379 // CHECK: arith.maxsi2380 // CHECK-NOT: arith.cmpf uno2381 // CHECK-NOT: arith.select2382 // CHECK: linalg.yield2383 // CHECK-NOT: arith.constant 0x7FC000002384 // CHECK-NOT: tensor.empty()2385 // CHECK-NOT: linalg.fill2386 // CHECK-NOT: tensor.empty()2387 // CHECK-NOT: select2388 // CHECK: return2389 %6 = tosa.reduce_max %arg0 {axis = 0 : i32, nan_mode = IGNORE} : (tensor<5x4xi8>) -> tensor<1x4xi8>2390 return2391}2392 2393// -----2394 2395// CHECK-LABEL: @reduce_min_nan_ignore2396func.func @reduce_min_nan_ignore(%arg0: tensor<5x4xf32>, %arg1: tensor<5x4xf32>) -> () {2397 // CHECK: linalg.reduce2398 // CHECK: arith.minimumf2399 // CHECK: arith.cmpf uno2400 // CHECK: arith.select2401 // CHECK: linalg.yield2402 // CHECK: arith.constant 0x7FC000002403 // CHECK: tensor.empty()2404 // CHECK: linalg.fill2405 // CHECK: tensor.empty()2406 // CHECK: select2407 %5 = tosa.reduce_min %arg0 {axis = 0 : i32, nan_mode = IGNORE} : (tensor<5x4xf32>) -> tensor<1x4xf32>2408 return2409}2410 2411// -----2412 2413// CHECK-LABEL: @reduce_max_nan_ignore2414func.func @reduce_max_nan_ignore(%arg0: tensor<5x4xf32>, %arg1: tensor<5x4xf32>) -> () {2415 // CHECK: linalg.reduce2416 // CHECK: arith.maximumf2417 // CHECK: arith.cmpf uno2418 // CHECK: arith.select2419 // CHECK: linalg.yield2420 // CHECK: arith.constant 0x7FC000002421 // CHECK: tensor.empty()2422 // CHECK: linalg.fill2423 // CHECK: tensor.empty()2424 // CHECK: select2425 %6 = tosa.reduce_max %arg0 {axis = 0 : i32, nan_mode = IGNORE} : (tensor<5x4xf32>) -> tensor<1x4xf32>2426 return2427}2428 2429// -----2430 2431// CHECK-LABEL: @minimum_nan_propagate2432func.func @minimum_nan_propagate(%arg0: tensor<5x4xf32>, %arg1: tensor<5x4xf32>) -> () {2433 // CHECK: linalg.generic2434 // CHECK: arith.minimumf2435 // CHECK-NOT: arith.cmpf uno2436 // CHECK-NOT: arith.select2437 // CHECK: linalg.yield2438 %7 = tosa.minimum %arg0, %arg1 {nan_mode = PROPAGATE} : (tensor<5x4xf32>, tensor<5x4xf32>) -> tensor<5x4xf32>2439 return2440}2441 2442// -----2443 2444// CHECK-LABEL: @maximum_nan_propagate2445func.func @maximum_nan_propagate(%arg0: tensor<5x4xf32>, %arg1: tensor<5x4xf32>) -> () {2446 // CHECK: linalg.generic2447 // CHECK: arith.maximumf2448 // CHECK-NOT: arith.cmpf uno2449 // CHECK-NOT: arith.select2450 // CHECK: linalg.yield2451 %8 = tosa.maximum %arg0, %arg1 {nan_mode = PROPAGATE} : (tensor<5x4xf32>, tensor<5x4xf32>) -> tensor<5x4xf32>2452 return2453}2454 2455// -----2456 2457// CHECK-LABEL: @minimum_nan_ignore_int2458func.func @minimum_nan_ignore_int(%arg0: tensor<5x4xi8>, %arg1: tensor<5x4xi8>) -> () {2459 // CHECK: linalg.generic2460 // CHECK: arith.minsi2461 // CHECK-NOT: arith.cmpf uno2462 // CHECK-NOT: arith.select2463 // CHECK: linalg.yield2464 %9 = tosa.minimum %arg0, %arg1 {nan_mode = IGNORE} : (tensor<5x4xi8>, tensor<5x4xi8>) -> tensor<5x4xi8>2465 return2466}2467 2468// -----2469 2470// CHECK-LABEL: @maximum_nan_ignore_int2471func.func @maximum_nan_ignore_int(%arg0: tensor<5x4xi8>, %arg1: tensor<5x4xi8>) -> () {2472 // CHECK: linalg.generic2473 // CHECK: arith.maxsi2474 // CHECK-NOT: arith.cmpf uno2475 // CHECK-NOT: arith.select2476 // CHECK: linalg.yield2477 %10 = tosa.maximum %arg0, %arg1 {nan_mode = IGNORE} : (tensor<5x4xi8>, tensor<5x4xi8>) -> tensor<5x4xi8>2478 return2479}2480 2481// -----2482 2483// CHECK-LABEL: @minimum_nan_ignore2484func.func @minimum_nan_ignore(%arg0: tensor<5x4xf32>, %arg1: tensor<5x4xf32>) -> () {2485 // CHECK: linalg.generic2486 // CHECK: arith.minimumf2487 // CHECK: arith.cmpf uno2488 // CHECK: arith.cmpf uno2489 // CHECK: arith.select2490 // CHECK: arith.select2491 // CHECK: linalg.yield2492 %9 = tosa.minimum %arg0, %arg1 {nan_mode = IGNORE} : (tensor<5x4xf32>, tensor<5x4xf32>) -> tensor<5x4xf32>2493 return2494}2495 2496// -----2497 2498// CHECK-LABEL: @maximum_nan_ignore2499func.func @maximum_nan_ignore(%arg0: tensor<5x4xf32>, %arg1: tensor<5x4xf32>) -> () {2500 // CHECK: linalg.generic2501 // CHECK: arith.maximumf2502 // CHECK: arith.cmpf uno2503 // CHECK: arith.cmpf uno2504 // CHECK: arith.select2505 // CHECK: arith.select2506 // CHECK: linalg.yield2507 %10 = tosa.maximum %arg0, %arg1 {nan_mode = IGNORE} : (tensor<5x4xf32>, tensor<5x4xf32>) -> tensor<5x4xf32>2508 return2509}2510 2511// -----2512 2513// CHECK-LABEL: @argmax_nan_propagate2514func.func @argmax_nan_propagate(%arg0: tensor<5x4xf32>, %arg1: tensor<5x4xf32>) -> () {2515 // CHECK: linalg.generic2516 // CHECK: arith.cmpf ugt2517 // CHECK: arith.cmpf ord2518 // CHECK: andi2519 // CHECK: arith.select2520 // CHECK: arith.select2521 // CHECK-NOT: arith.cmpf uno2522 // CHECK-NOT: arith.select2523 // CHECK: linalg.yield2524 %11 = tosa.argmax %arg0 {axis = 0 : i32, nan_mode = PROPAGATE} : (tensor<5x4xf32>) -> tensor<4xi32>2525 return2526}2527 2528// -----2529 2530// CHECK-LABEL: @argmax_nan_ignore_int2531func.func @argmax_nan_ignore_int(%arg0: tensor<5x4xi8>, %arg1: tensor<5x4xi8>) -> () {2532 // CHECK: linalg.generic2533 // CHECK: arith.cmpi sgt2534 // CHECK: arith.select2535 // CHECK: arith.select2536 // CHECK-NOT: arith.cmpf uno2537 // CHECK-NOT: arith.cmpf uno2538 // CHECK-NOT: arith.select2539 // CHECK-NOT: arith.select2540 // CHECK: linalg.yield2541 %12 = tosa.argmax %arg0 {axis = 0 : i32, nan_mode = IGNORE} : (tensor<5x4xi8>) -> tensor<4xi32>2542 return2543}2544 2545// -----2546 2547// CHECK-LABEL: @argmax_nan_ignore2548func.func @argmax_nan_ignore(%arg0: tensor<5x4xf32>, %arg1: tensor<5x4xf32>) -> () {2549 // CHECK: linalg.generic2550 // CHECK: arith.cmpf ogt2551 // CHECK: arith.select2552 // CHECK: arith.select2553 // CHECK: linalg.yield2554 %12 = tosa.argmax %arg0 {axis = 0 : i32, nan_mode = IGNORE} : (tensor<5x4xf32>) -> tensor<4xi32>2555 return2556}2557 2558// -----2559 2560// CHECK-LABEL: @clamp_nan_propagate2561func.func @clamp_nan_propagate(%arg0: tensor<5x4xf32>, %arg1: tensor<5x4xf32>) -> () {2562 // CHECK: linalg.generic2563 // CHECK: arith.minimumf2564 // CHECK: arith.maximumf2565 // CHECK-NOT: arith.cmpf uno2566 // CHECK-NOT: arith.select2567 // CHECK: linalg.yield2568 %13 = tosa.clamp %arg0 {min_val = 1.0 : f32, max_val = 5.0 : f32, nan_mode = PROPAGATE} : (tensor<5x4xf32>) -> tensor<5x4xf32>2569 return2570}2571 2572// -----2573 2574// CHECK-LABEL: @clamp_nan_ignore_int2575func.func @clamp_nan_ignore_int(%arg0: tensor<5x4xi8>, %arg1: tensor<5x4xi8>) -> () {2576 // CHECK: linalg.generic2577 // CHECK: arith.maxsi2578 // CHECK: arith.minsi2579 // CHECK-NOT: arith.cmpf uno2580 // CHECK-NOT: arith.select2581 // CHECK: linalg.yield2582 %14 = tosa.clamp %arg0 {min_val = 1 : i8, max_val = 5 : i8, nan_mode = IGNORE} : (tensor<5x4xi8>) -> tensor<5x4xi8>2583 return2584}2585 2586// -----2587 2588// CHECK-LABEL: @clamp_nan_ignore2589func.func @clamp_nan_ignore(%arg0: tensor<5x4xf32>, %arg1: tensor<5x4xf32>) -> () {2590 // CHECK: linalg.generic2591 // CHECK: arith.minimumf2592 // CHECK: arith.maximumf2593 // CHECK: arith.cmpf uno2594 // CHECK: arith.select2595 // CHECK: linalg.yield2596 %14 = tosa.clamp %arg0 {min_val = 1.0 : f32, max_val = 5.0 : f32, nan_mode = IGNORE} : (tensor<5x4xf32>) -> tensor<5x4xf32>2597 2598 return2599}2600 2601// -----2602 2603// CHECK-LABEL: @test_0d_input2604func.func @test_0d_input(%arg0: tensor<i32>) -> () {2605 // CHECK: linalg.generic2606 // CHECK: arith.muli2607 %shift1 = "tosa.const"() <{values = dense<0> : tensor<1xi8>}> : () -> tensor<1xi8>2608 %0 = tosa.mul %arg0, %arg0, %shift1 : (tensor<i32>, tensor<i32>, tensor<1xi8>) -> tensor<i32>2609 2610 // CHECK: linalg.generic2611 // CHECK: ^bb0(%[[ARG1:.*]]: i32, %[[ARG2:.*]]: i32):2612 // CHECK: [[ZERO:%.+]] = arith.constant 02613 // CHECK: arith.subi [[ZERO]], %[[ARG1]]2614 %in_zp = "tosa.const"() <{values = dense<0> : tensor<1xi32>}> : () -> tensor<1xi32>2615 %out_zp = "tosa.const"() <{values = dense<0> : tensor<1xi32>}> : () -> tensor<1xi32>2616 %5 = tosa.negate %arg0, %in_zp, %out_zp : (tensor<i32>, tensor<1xi32>, tensor<1xi32>) -> tensor<i32>2617 2618 return2619}2620 2621// -----2622 2623// CHECK-LABEL: @mul_no_const_shift2624func.func @mul_no_const_shift(%arg0: tensor<2x3xi32>, %arg1: tensor<2x3xi32>, %arg2: tensor<1xi8>) -> tensor<2x3xi32> {2625 // CHECK: linalg.generic2626 // CHECK: ^bb0(%[[ARG0:.*]]: i32, %[[ARG1:.*]]: i32, %[[ARG2:.*]]: i8, %[[OUT:.*]]: i32):2627 // CHECK: tosa.apply_scale %[[ARG0]], %[[ARG1]], %[[ARG2]]2628 %0 = tosa.mul %arg0, %arg1, %arg2 : (tensor<2x3xi32>, tensor<2x3xi32>, tensor<1xi8>) -> tensor<2x3xi32>2629 return %0 : tensor<2x3xi32>2630}2631