Skip to content

Commit 06c09de

Browse files
authored
Merge pull request #5426 from hideaki-motoki/issue5417_axpy_sve
Implementing SVE in `[SD]AXPY` Kernels for `A64FX` and `Graviton3E`
2 parents da7d0f4 + e23f9c6 commit 06c09de

File tree

3 files changed

+93
-0
lines changed

3 files changed

+93
-0
lines changed

kernel/arm64/KERNEL.A64FX

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,6 @@ DGEMVTKERNEL = gemv_t_sve_v4x3.c
77

88
DDOTKERNEL = dot_sve_v8.c
99
SDOTKERNEL = dot_sve_v8.c
10+
11+
SAXPYKERNEL = axpy_sve.c
12+
DAXPYKERNEL = axpy_sve.c

kernel/arm64/KERNEL.NEOVERSEV1

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ SGEMVNKERNEL = gemv_n_sve_v1x3.c
3232
DGEMVNKERNEL = gemv_n_sve_v1x3.c
3333
SGEMVTKERNEL = gemv_t_sve_v1x3.c
3434
DGEMVTKERNEL = gemv_t_sve_v1x3.c
35+
36+
SAXPYKERNEL = axpy_sve.c
37+
DAXPYKERNEL = axpy_sve.c
38+
3539
ifeq ($(BUILD_BFLOAT16), 1)
3640
BGEMM_BETA = bgemm_beta_neon.c
3741
BGEMMKERNEL = bgemm_kernel_2vlx4_neoversev1.c

kernel/arm64/axpy_sve.c

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/***************************************************************************
2+
Copyright (c) 2025, 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+
35+
#include "common.h"
36+
37+
#ifdef DOUBLE
38+
#define SV_TYPE svfloat64_t
39+
#define SV_COUNT svcntd
40+
#define SV_DUP svdup_f64
41+
#define SV_WHILE svwhilelt_b64_s64
42+
#define SV_TRUE svptrue_b64
43+
#else
44+
#define SV_TYPE svfloat32_t
45+
#define SV_COUNT svcntw
46+
#define SV_DUP svdup_f32
47+
#define SV_WHILE svwhilelt_b32_s64
48+
#define SV_TRUE svptrue_b32
49+
#endif
50+
51+
int CNAME(BLASLONG n, BLASLONG dummy0, BLASLONG dummy1, FLOAT da, FLOAT *x, BLASLONG inc_x, FLOAT *y, BLASLONG inc_y, FLOAT *dummy, BLASLONG dummy2) {
52+
BLASLONG i = 0;
53+
BLASLONG ix = 0, iy = 0;
54+
BLASLONG sve_size = SV_COUNT();
55+
56+
if (n < 0) return (0);
57+
if (da == 0.0) return (0);
58+
59+
if (inc_x == 1 && inc_y == 1) {
60+
SV_TYPE da_vec = SV_DUP(da);
61+
for (i = 0; i + sve_size - 1 < n; i += sve_size) {
62+
SV_TYPE x_vec = svld1(SV_TRUE(), &x[i]);
63+
SV_TYPE y_vec = svld1(SV_TRUE(), &y[i]);
64+
y_vec = svmla_x(SV_TRUE(), y_vec, da_vec, x_vec);
65+
svst1(SV_TRUE(), &y[i], y_vec);
66+
}
67+
68+
if (i < n) {
69+
svbool_t pg = SV_WHILE(i, n);
70+
SV_TYPE x_vec = svld1(pg, &x[i]);
71+
SV_TYPE y_vec = svld1(pg, &y[i]);
72+
y_vec = svmla_x(pg, y_vec, da_vec, x_vec);
73+
svst1(pg, &y[i], y_vec);
74+
}
75+
return (0);
76+
}
77+
78+
while (i < n) {
79+
y[iy] += da * x[ix];
80+
ix += inc_x;
81+
iy += inc_y;
82+
i++;
83+
}
84+
85+
return (0);
86+
}

0 commit comments

Comments
 (0)