[Mlir-commits] [mlir] [mlir][tosa] Add tosa.argmin lowering to Linalg (PR #233754)
Jack Frankland
llvmlistbot at llvm.org
Tue Oct 20 08:02:29 PDT 2026
================
@@ -1907,6 +1907,111 @@ func.func @argmax_dyn_axis(%arg0 : tensor<3x?xi32>) -> () {
// -----
+// CHECK: #[[$MAP0:.*]] = affine_map<(d0, d1) -> (d0, d1)>
+// CHECK: #[[$MAP1:.*]] = affine_map<(d0, d1) -> (d1)>
+// CHECK: #[[$MAP2:.*]] = affine_map<(d0, d1) -> (d0)>
+// CHECK: #[[$MAP3:.*]] = affine_map<(d0) -> (d0)>
+// CHECK: #[[$MAP4:.*]] = affine_map<(d0) -> ()>
+
+func.func @argmin(%arg0 : tensor<3x2xi32>, %arg1 : tensor<6xf32>) -> () {
+ // CHECK: [[IDX_INIT:%.+]] = tensor.empty()
+ // CHECK: [[IDX_MIN:%.+]] = arith.constant 0 : i32
+ // CHECK: [[IDX_FILL:%.+]] = linalg.fill ins([[IDX_MIN]]{{.*}}outs([[IDX_INIT]]
+ // CHECK: [[VAL_INIT:%.+]] = tensor.empty()
+ // CHECK: [[VAL_MAX:%.+]] = arith.constant 2147483647
+ // CHECK: [[VAL_FILL:%.+]] = linalg.fill ins([[VAL_MAX]]{{.*}}outs([[VAL_INIT]]
+ // 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>)
+ // CHECK: ^bb0(%[[ARG1:[0-9a-zA-Z_]+]]: i32, %[[ARG2:[0-9a-zA-Z_]+]]: i32, %[[ARG3:[0-9a-zA-Z_]+]]: i32
+ // CHECK: [[IDX:%.+]] = linalg.index 0
+ // CHECK: [[CAST:%.+]] = arith.index_cast [[IDX]]
+ // CHECK: [[CMP:%.+]] = arith.cmpi slt, %[[ARG1]], %[[ARG3]]
+ // CHECK: [[SELECT_VAL:%.+]] = arith.select [[CMP]], %[[ARG1]], %[[ARG3]]
+ // CHECK: [[SELECT_IDX:%.+]] = arith.select [[CMP]], [[CAST]], %[[ARG2]]
+ // CHECK: linalg.yield [[SELECT_IDX]], [[SELECT_VAL]]
+ %0 = tosa.argmin %arg0 axis(0) : (tensor<3x2xi32>) -> tensor<2xi32>
+
+ // CHECK: [[IDX_INIT:%.+]] = tensor.empty()
+ // CHECK: [[IDX_MIN:%.+]] = arith.constant 0 : i32
+ // CHECK: [[IDX_FILL:%.+]] = linalg.fill ins([[IDX_MIN]]{{.*}}outs([[IDX_INIT]]
+ // CHECK: [[VAL_INIT:%.+]] = tensor.empty()
+ // CHECK: [[VAL_MAX:%.+]] = arith.constant 2147483647
+ // CHECK: [[VAL_FILL:%.+]] = linalg.fill ins([[VAL_MAX]]{{.*}}outs([[VAL_INIT]]
+ // 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>)
+ // CHECK: ^bb0(%[[ARG1:[0-9a-zA-Z_]+]]: i32, %[[ARG2:[0-9a-zA-Z_]+]]: i32, %[[ARG3:[0-9a-zA-Z_]+]]: i32
+ // CHECK: [[IDX:%.+]] = linalg.index 1
+ // CHECK: [[CAST:%.+]] = arith.index_cast [[IDX]]
+ // CHECK: [[CMP:%.+]] = arith.cmpi slt, %[[ARG1]], %[[ARG3]]
+ // CHECK: [[SELECT_VAL:%.+]] = arith.select [[CMP]], %[[ARG1]], %[[ARG3]]
+ // CHECK: [[SELECT_IDX:%.+]] = arith.select [[CMP]], [[CAST]], %[[ARG2]]
+ // CHECK: linalg.yield [[SELECT_IDX]], [[SELECT_VAL]]
+ %1 = tosa.argmin %arg0 axis(1) : (tensor<3x2xi32>) -> tensor<3xi32>
+
+ // FINITE: arith.constant 3.40282347E+38 : f32
----------------
FranklandJack wrote:
I appreciate it's a pain, but is there a reason these tests doen't capture the various parameteres/values?
https://github.com/llvm/llvm-project/pull/233754
More information about the Mlir-commits
mailing list