Skip to content

Commit 7a0d0c6

Browse files
committed
[mlir][SVE] Add more e2e test for vector.contract
Adds basic integration tests for `vector.contract` for the dot product and matvec operations. These tests excercise scalable vectors.
1 parent f24c443 commit 7a0d0c6

File tree

1 file changed

+81
-1
lines changed

1 file changed

+81
-1
lines changed

mlir/test/Integration/Dialect/Vector/CPU/ArmSVE/test-contraction.mlir

Lines changed: 81 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,38 @@
1313
// REDEFINE: %{entry} = matmul_f32
1414
// RUN: %{run} | FileCheck %s --check-prefix=F32
1515

16+
// REDEFINE: %{entry} = dot_product_i32
17+
// RUN: %{run} | FileCheck %s --check-prefix=DP
18+
19+
// REDEFINE: %{entry} = matvec_i32
20+
// RUN: %{run} | FileCheck %s --check-prefix=MV
21+
1622
// NOTE: These tests are meant to complement the integration tests from:
1723
// * ../test-contraction.mlir
1824
// (tests with fixed width vectors). Rather than duplicating those tests, this
1925
// file focuses on excercissing scalable vectors in a few most common cases.
2026

21-
// TODO: Masks + matvec + dot product
27+
// TODO: Masks
28+
29+
#dotp_accesses = [
30+
affine_map<(i) -> (i)>,
31+
affine_map<(i) -> (i)>,
32+
affine_map<(i) -> ()>
33+
]
34+
#dotp_trait = {
35+
indexing_maps = #dotp_accesses,
36+
iterator_types = ["reduction"]
37+
}
38+
39+
#matvec_accesses = [
40+
affine_map<(i, j) -> (i, j)>,
41+
affine_map<(i, j) -> (j)>,
42+
affine_map<(i, j) -> (i)>
43+
]
44+
#matvec_trait = {
45+
indexing_maps = #matvec_accesses,
46+
iterator_types = ["parallel", "reduction"]
47+
}
2248

2349
#matmat_accesses = [
2450
affine_map<(i, j, k) -> (i, k)>,
@@ -30,6 +56,60 @@
3056
iterator_types = ["parallel", "parallel", "reduction"]
3157
}
3258

59+
// Contraction: dot-product a x b.
60+
func.func @dot_product_i32() {
61+
%acc = arith.constant 0: i32
62+
63+
%vector_a = arith.constant dense<123> : vector<[4]xi32>
64+
%vector_b = arith.constant dense<314> : vector<[4]xi32>
65+
%vector_c = arith.constant dense<0> : vector<[4]xi32>
66+
67+
// The result of this dot-product will depend
68+
// on the vector length, so we are unable to verify it.
69+
%dp1 = vector.contract #dotp_trait %vector_a, %vector_b, %acc
70+
: vector<[4]xi32>, vector<[4]xi32> into i32
71+
// DP: {{[0-9]*}}
72+
vector.print %dp1 : i32
73+
74+
// The result of this dot-product should be 0.
75+
%dp2 = vector.contract #dotp_trait %vector_a, %vector_c, %acc
76+
: vector<[4]xi32>, vector<[4]xi32> into i32
77+
// DP: 0
78+
vector.print %dp2 : i32
79+
80+
// DP: SVE: END OF TEST OUTPUT
81+
vector.print str "SVE: END OF TEST OUTPUT"
82+
83+
return
84+
}
85+
86+
// Contraction: matrix-vector A x c
87+
func.func @matvec_i32() {
88+
%acc = arith.constant dense<0>: vector<3xi32>
89+
90+
%vector_a = arith.constant dense<123> : vector<3x[4]xi32>
91+
%vector_b = arith.constant dense<314> : vector<[4]xi32>
92+
%vector_c = arith.constant dense<0> : vector<[4]xi32>
93+
94+
// The result of this matvec will depend on the vector length, so we are
95+
// unable to verify it.
96+
%dp1 = vector.contract #matvec_trait %vector_a, %vector_b, %acc
97+
: vector<3x[4]xi32>, vector<[4]xi32> into vector<3xi32>
98+
// MV: {{[0-9]*}}, {{[0-9]*}}, {{[0-9]*}}
99+
vector.print %dp1 : vector<3xi32>
100+
101+
// The result of this matvc should be a vector of 0s.
102+
%dp2 = vector.contract #matvec_trait %vector_a, %vector_c, %acc
103+
: vector<3x[4]xi32>, vector<[4]xi32> into vector<3xi32>
104+
// MV: 0, 0, 0
105+
vector.print %dp2 : vector<3xi32>
106+
107+
// MV: SVE: END OF TEST OUTPUT
108+
vector.print str "SVE: END OF TEST OUTPUT"
109+
110+
return
111+
}
112+
33113
func.func @matmul_i32() {
34114
// Setup vector A:
35115
%vector_a = arith.constant dense<123> : vector<3x5xi32>

0 commit comments

Comments
 (0)