Skip to content

Commit 10fdd67

Browse files
Sameeranjoshinewlingyzhang93
authored
Apply pattern for populateVectorMultiReductionLoweringPatterns from… (#1312)
… mlir-opt in iree-opt For issue #1306, converting vector.multi_reduction to vector.reduction is the first step as `vector.reduction` can be converted to Peano instructions which can vectorize. `mlir-opt` supports it with the flag `lower-vector-multi-reduction` and the `populateVectorMultiReductionLoweringPatterns` pattern, reuse it in IREE, as a last pass to kick in `AMDAIEVectorizationPass` pipeline. --------- Co-authored-by: James Newling <[email protected]> Co-authored-by: Vivian Zhang <[email protected]>
1 parent da927e3 commit 10fdd67

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

compiler/plugins/target/AMD-AIE/iree-amd-aie/Transforms/AMDAIEVectorization.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,9 @@ void AMDAIEVectorizationPass::runOnOperation() {
115115
vector::populateVectorTransferPermutationMapLoweringPatterns(
116116
vectorizationPatterns);
117117

118+
vector::populateVectorMultiReductionLoweringPatterns(
119+
vectorizationPatterns,
120+
vector::VectorMultiReductionLowering::InnerReduction);
118121
(void)applyPatternsGreedily(funcOp, std::move(vectorizationPatterns));
119122
}
120123
} // namespace

compiler/plugins/target/AMD-AIE/iree-amd-aie/Transforms/test/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ iree_lit_test_suite(
7373
"lowering_strategy_objectfifo_npu4.mlir"
7474
"lowering_strategy_softmax.mlir"
7575
"map_forall_to_cores.mlir"
76+
"multi_reduction_to_reduction.mlir"
7677
"none_access_to_temporary_buffer.mlir"
7778
"normalize_loop_bounds.mlir"
7879
"npu_dma_to_half_dma_cpy_nd.mlir"
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// RUN: iree-opt --pass-pipeline='builtin.module(func.func(iree-amdaie-vectorization))' %s | FileCheck %s
2+
3+
// Make sure it's not falling on the InnerParallel pattern
4+
// CHECK-LABEL: func.func @multi_reduction_innerparallel
5+
func.func @multi_reduction_innerparallel(%v : vector<4xf16>, %acc: f16) -> f16 {
6+
// CHECK-NOT: vector.extract %{{.*}}[0] : f16 from vector<4xf16>
7+
// CHECK-NOT: arith.addf %{{.*}}, %{{.*}} : f16
8+
%0 = vector.multi_reduction <add>, %v, %acc[0] : vector<4xf16> to f16
9+
return %0 : f16
10+
}
11+
12+
// CHECK-LABEL: func.func @multi_reduction_2d
13+
func.func @multi_reduction_2d(%v : vector<4x6xf32>, %acc: vector<4xf32>) -> vector<4xf32> {
14+
// CHECK: vector.reduction <add>,
15+
// CHECK: vector.reduction <add>,
16+
// CHECK: vector.reduction <add>,
17+
// CHECK: vector.reduction <add>,
18+
// CHECK-NOT: vector.reduction <add>,
19+
%0 = vector.multi_reduction #vector.kind<add>, %v, %acc [1] : vector<4x6xf32> to vector<4xf32>
20+
return %0 : vector<4xf32>
21+
}
22+
23+
// CHECK-LABEL: func.func @multi_reduction_1d
24+
func.func @multi_reduction_1d(%v : vector<4xf32>, %acc: f32) -> f32 {
25+
// CHECK: vector.reduction <add>, %{{.*}}, %{{.*}} : vector<4xf32> into f32
26+
%0 = vector.multi_reduction <add>, %v, %acc[0] : vector<4xf32> to f32
27+
return %0 : f32
28+
}
29+
30+
// CHECK-LABEL: func.func @multi_reduction_1d_mul
31+
func.func @multi_reduction_1d_mul(%v : vector<4xf32>, %acc: f32) -> f32 {
32+
// CHECK: vector.reduction <mul>, %{{.*}}, %{{.*}} : vector<4xf32> into f32
33+
%0 = vector.multi_reduction <mul>, %v, %acc[0] : vector<4xf32> to f32
34+
return %0 : f32
35+
}
36+
37+
// CHECK-LABEL: func.func @multi_reduction_1d_bf16
38+
func.func @multi_reduction_1d_bf16(%v : vector<32xbf16>, %acc: bf16) -> bf16 {
39+
// CHECK: vector.reduction <add>, %{{.*}}, %{{.*}} : vector<32xbf16> into bf16
40+
%0 = vector.multi_reduction <add>, %v, %acc[0] : vector<32xbf16> to bf16
41+
return %0 : bf16
42+
}

0 commit comments

Comments
 (0)