Skip to content

Commit 0985fdc

Browse files
author
iha fujitsu
committed
A64FX: Add support for SVE to SGEMV/DGEMV kernels.
1 parent e1eef56 commit 0985fdc

File tree

3 files changed

+191
-0
lines changed

3 files changed

+191
-0
lines changed

kernel/arm64/KERNEL.A64FX

+5
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
11
include $(KERNELDIR)/KERNEL.ARMV8SVE
2+
3+
SGEMVNKERNEL = gemv_n_sve.c
4+
DGEMVNKERNEL = gemv_n_sve.c
5+
SGEMVTKERNEL = gemv_t_sve.c
6+
DGEMVTKERNEL = gemv_t_sve.c

kernel/arm64/gemv_n_sve.c

+92
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
/***************************************************************************
2+
Copyright (c) 2024, The OpenBLAS Project
3+
All rights reserved.
4+
5+
Redistribution and use in source and binary forms, with or without
6+
modification, are permitted provided that the following conditions are
7+
met:
8+
9+
1. Redistributions of source code must retain the above copyright
10+
notice, this list of conditions and the following disclaimer.
11+
12+
2. Redistributions in binary form must reproduce the above copyright
13+
notice, this list of conditions and the following disclaimer in
14+
the documentation and/or other materials provided with the
15+
distribution.
16+
3. Neither the name of the OpenBLAS project nor the names of
17+
its contributors may be used to endorse or promote products
18+
derived from this software without specific prior written
19+
permission.
20+
21+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24+
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
25+
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
30+
USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31+
*****************************************************************************/
32+
33+
#include <arm_sve.h>
34+
#include "common.h"
35+
36+
#ifdef DOUBLE
37+
#define SV_COUNT svcntd
38+
#define SV_TYPE svfloat64_t
39+
#define SV_TRUE svptrue_b64
40+
#define SV_WHILE svwhilelt_b64
41+
#define SV_DUP svdup_f64
42+
#else
43+
#define SV_COUNT svcntw
44+
#define SV_TYPE svfloat32_t
45+
#define SV_TRUE svptrue_b32
46+
#define SV_WHILE svwhilelt_b32
47+
#define SV_DUP svdup_f32
48+
#endif
49+
50+
int CNAME(BLASLONG m, BLASLONG n, BLASLONG dummy1, FLOAT alpha, FLOAT *a, BLASLONG lda, FLOAT *x, BLASLONG inc_x, FLOAT *y, BLASLONG inc_y, FLOAT *buffer)
51+
{
52+
BLASLONG i;
53+
BLASLONG ix,iy;
54+
BLASLONG j;
55+
FLOAT *a_ptr;
56+
FLOAT temp;
57+
58+
ix = 0;
59+
a_ptr = a;
60+
61+
if (inc_y == 1) {
62+
uint64_t sve_size = SV_COUNT();
63+
for (j = 0; j < n; j++) {
64+
SV_TYPE temp_vec = SV_DUP(alpha * x[ix]);
65+
i = 0;
66+
svbool_t pg = SV_WHILE(i, m);
67+
while (svptest_any(SV_TRUE(), pg)) {
68+
SV_TYPE a_vec = svld1(pg, a_ptr + i);
69+
SV_TYPE y_vec = svld1(pg, y + i);
70+
y_vec = svmla_x(pg, y_vec, temp_vec, a_vec);
71+
svst1(pg, y + i, y_vec);
72+
i += sve_size;
73+
pg = SV_WHILE(i, m);
74+
}
75+
a_ptr += lda;
76+
ix += inc_x;
77+
}
78+
return(0);
79+
}
80+
81+
for (j = 0; j < n; j++) {
82+
temp = alpha * x[ix];
83+
iy = 0;
84+
for (i = 0; i < m; i++) {
85+
y[iy] += temp * a_ptr[i];
86+
iy += inc_y;
87+
}
88+
a_ptr += lda;
89+
ix += inc_x;
90+
}
91+
return (0);
92+
}

kernel/arm64/gemv_t_sve.c

+94
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/***************************************************************************
2+
Copyright (c) 2024, The OpenBLAS Project
3+
All rights reserved.
4+
5+
Redistribution and use in source and binary forms, with or without
6+
modification, are permitted provided that the following conditions are
7+
met:
8+
9+
1. Redistributions of source code must retain the above copyright
10+
notice, this list of conditions and the following disclaimer.
11+
12+
2. Redistributions in binary form must reproduce the above copyright
13+
notice, this list of conditions and the following disclaimer in
14+
the documentation and/or other materials provided with the
15+
distribution.
16+
3. Neither the name of the OpenBLAS project nor the names of
17+
its contributors may be used to endorse or promote products
18+
derived from this software without specific prior written
19+
permission.
20+
21+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24+
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
25+
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
30+
USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31+
*****************************************************************************/
32+
33+
#include <arm_sve.h>
34+
#include "common.h"
35+
36+
#ifdef DOUBLE
37+
#define SV_COUNT svcntd
38+
#define SV_TYPE svfloat64_t
39+
#define SV_TRUE svptrue_b64
40+
#define SV_WHILE svwhilelt_b64
41+
#define SV_DUP svdup_f64
42+
#else
43+
#define SV_COUNT svcntw
44+
#define SV_TYPE svfloat32_t
45+
#define SV_TRUE svptrue_b32
46+
#define SV_WHILE svwhilelt_b32
47+
#define SV_DUP svdup_f32
48+
#endif
49+
50+
int CNAME(BLASLONG m, BLASLONG n, BLASLONG dummy1, FLOAT alpha, FLOAT *a, BLASLONG lda, FLOAT *x, BLASLONG inc_x, FLOAT *y, BLASLONG inc_y, FLOAT *buffer)
51+
{
52+
BLASLONG i;
53+
BLASLONG ix,iy;
54+
BLASLONG j;
55+
FLOAT *a_ptr;
56+
FLOAT temp;
57+
58+
iy = 0;
59+
a_ptr = a;
60+
61+
if (inc_x == 1) {
62+
uint64_t sve_size = SV_COUNT();
63+
for (j = 0; j < n; j++) {
64+
SV_TYPE temp_vec = SV_DUP(0.0);
65+
i = 0;
66+
svbool_t pg = SV_WHILE(i, m);
67+
while (svptest_any(SV_TRUE(), pg)) {
68+
SV_TYPE a_vec = svld1(pg, a_ptr + i);
69+
SV_TYPE x_vec = svld1(pg, x + i);
70+
temp_vec = svmla_m(pg, temp_vec, a_vec, x_vec);
71+
i += sve_size;
72+
pg = SV_WHILE(i, m);
73+
}
74+
temp = svaddv(SV_TRUE(), temp_vec);
75+
y[iy] += alpha * temp;
76+
iy += inc_y;
77+
a_ptr += lda;
78+
}
79+
return(0);
80+
}
81+
82+
for (j = 0; j < n; j++) {
83+
temp = 0.0;
84+
ix = 0;
85+
for (i = 0; i < m; i++) {
86+
temp += a_ptr[i] * x[ix];
87+
ix += inc_x;
88+
}
89+
y[iy] += alpha * temp;
90+
iy += inc_y;
91+
a_ptr += lda;
92+
}
93+
return (0);
94+
}

0 commit comments

Comments
 (0)