[Mlir-commits] [mlir] Add lower-vector-multi-reduction pass (PR #87333)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Mon Apr 8 00:04:02 PDT 2024


================
@@ -0,0 +1,48 @@
+// RUN: mlir-opt -lower-vector-multi-reduction="lowering-strategy=inner-reduction" -split-input-file %s | FileCheck %s --check-prefix=CHECK-RED
+// RUN: mlir-opt -lower-vector-multi-reduction="lowering-strategy=inner-parallel" -split-input-file %s | FileCheck %s --check-prefix=CHECK-PAR
+// RUN: mlir-opt -lower-vector-multi-reduction -split-input-file %s | FileCheck %s --check-prefix=CHECK-PAR
+
+func.func @vector_multi_reduction(%arg0: vector<2x4xf32>, %acc: vector<2xf32>) -> vector<2xf32> {
+    %0 = vector.multi_reduction <mul>, %arg0, %acc [1] : vector<2x4xf32> to vector<2xf32>
+    return %0 : vector<2xf32>
+}
+// CHECK-RED-LABEL: func @vector_multi_reduction
+// CHECK-RED-SAME:   %[[INPUT:.+]]: vector<2x4xf32>, %[[ACC:.*]]: vector<2xf32>)
+//  CHECK-RED-DAG:       %[[RESULT_VEC_0:.+]] = arith.constant dense<{{.*}}> : vector<2xf32>
+//  CHECK-RED-DAG:       %[[C0:.+]] = arith.constant 0 : index
+//  CHECK-RED-DAG:       %[[C1:.+]] = arith.constant 1 : index
+//      CHECK-RED:       %[[V0:.+]] = vector.extract %[[INPUT]][0]
+//      CHECK-RED:       %[[ACC0:.+]] = vector.extract %[[ACC]][0]
+//      CHECK-RED:       %[[RV0:.+]] = vector.reduction <mul>, %[[V0]], %[[ACC0]] : vector<4xf32> into f32
+//      CHECK-RED:       %[[RESULT_VEC_1:.+]] = vector.insertelement %[[RV0:.+]], %[[RESULT_VEC_0]][%[[C0]] : index] : vector<2xf32>
+//      CHECK-RED:       %[[V1:.+]] = vector.extract %[[INPUT]][1]
+//      CHECK-RED:       %[[ACC1:.+]] = vector.extract %[[ACC]][1]
+//      CHECK-RED:       %[[RV1:.+]] = vector.reduction <mul>, %[[V1]], %[[ACC1]] : vector<4xf32> into f32
+//      CHECK-RED:       %[[RESULT_VEC:.+]] = vector.insertelement %[[RV1:.+]], %[[RESULT_VEC_1]][%[[C1]] : index] : vector<2xf32>
+//      CHECK-RED:       return %[[RESULT_VEC]]
+
+// CHECK-PAR-LABEL: func @vector_multi_reduction
+//  CHECK-PAR-SAME:   %[[INPUT:.+]]: vector<2x4xf32>, %[[ACC:.*]]: vector<2xf32>)
+//       CHECK-PAR:   %[[TRANSPOSED:.+]] = vector.transpose %[[INPUT]], [1, 0] : vector<2x4xf32> to vector<4x2xf32>
+//       CHECK-PAR:   %[[V0:.+]] = vector.extract %[[TRANSPOSED]][0] : vector<2xf32> from vector<4x2xf32>
+//       CHECK-PAR:   %[[RV0:.+]] = arith.mulf %[[V0]], %[[ACC]] : vector<2xf32>
+//       CHECK-PAR:   %[[V1:.+]] = vector.extract %[[TRANSPOSED]][1] : vector<2xf32> from vector<4x2xf32>
+//       CHECK-PAR:   %[[RV01:.+]] = arith.mulf %[[V1]], %[[RV0]] : vector<2xf32>
+//       CHECK-PAR:   %[[V2:.+]] = vector.extract %[[TRANSPOSED]][2] : vector<2xf32> from vector<4x2xf32>
+//       CHECK-PAR:   %[[RV012:.+]] = arith.mulf %[[V2]], %[[RV01]] : vector<2xf32>
+//       CHECK-PAR:   %[[V3:.+]] = vector.extract %[[TRANSPOSED]][3] : vector<2xf32> from vector<4x2xf32>
+//       CHECK-PAR:   %[[RESULT_VEC:.+]] = arith.mulf %[[V3]], %[[RV012]] : vector<2xf32>
+//       CHECK-PAR:   return %[[RESULT_VEC]] : vector<2xf32>
+
----------------
xiaoleis-nv wrote:

I've added a CHECK-LABEL to each test case in light of the description provided; therefore, the // ----- is no longer necessary.

> Conceptually, the presence of CHECK-LABEL divides the input stream into separate blocks, each processed independently, which prevents a CHECK: directive in one block from matching a line in another block.

https://github.com/llvm/llvm-project/pull/87333


More information about the Mlir-commits mailing list