Skip to content

Commit 30f7a41

Browse files
authored
Merge pull request #5056 from tingboliao/dev_omatcopy_20250108
Optimize the omatcopy_cn/zomatcopy_cn kernels with RVV 1.0 intrinsic.
2 parents 0b9de3e + 0a5dbf1 commit 30f7a41

File tree

3 files changed

+215
-0
lines changed

3 files changed

+215
-0
lines changed

kernel/riscv64/KERNEL.x280

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,3 +279,9 @@ endif
279279
ifndef ZGEMM_BETA
280280
ZGEMM_BETA = zgemm_beta_rvv.c
281281
endif
282+
283+
ZOMATCOPY_CN = zomatcopy_cn_rvv.c
284+
COMATCOPY_CN = zomatcopy_cn_rvv.c
285+
286+
DOMATCOPY_CN = omatcopy_cn_rvv.c
287+
SOMATCOPY_CN = omatcopy_cn_rvv.c

kernel/riscv64/omatcopy_cn_rvv.c

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
/***************************************************************************
2+
Copyright (c) 2013, The OpenBLAS Project
3+
All rights reserved.
4+
Redistribution and use in source and binary forms, with or without
5+
modification, are permitted provided that the following conditions are
6+
met:
7+
1. Redistributions of source code must retain the above copyright
8+
notice, this list of conditions and the following disclaimer.
9+
2. Redistributions in binary form must reproduce the above copyright
10+
notice, this list of conditions and the following disclaimer in
11+
the documentation and/or other materials provided with the
12+
distribution.
13+
3. Neither the name of the OpenBLAS project nor the names of
14+
its contributors may be used to endorse or promote products
15+
derived from this software without specific prior written permission.
16+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19+
ARE DISCLAIMED. IN NO EVENT SHALL THE OPENBLAS PROJECT OR CONTRIBUTORS BE
20+
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
25+
USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26+
*****************************************************************************/
27+
28+
#include "common.h"
29+
#include <stdio.h>
30+
31+
#if !defined(DOUBLE)
32+
#define VSETVL_MAX __riscv_vsetvlmax_e32m8()
33+
#define VSETVL(n) __riscv_vsetvl_e32m8(n)
34+
#define FLOAT_V_T vfloat32m8_t
35+
#define VLEV_FLOAT __riscv_vle32_v_f32m8
36+
#define VSEV_FLOAT __riscv_vse32_v_f32m8
37+
#define VFMULVF_FLOAT __riscv_vfmul_vf_f32m8
38+
#define VFMVVF_FLOAT __riscv_vfmv_v_f_f32m8
39+
#else
40+
#define VSETVL_MAX __riscv_vsetvlmax_e64m8()
41+
#define VSETVL(n) __riscv_vsetvl_e64m8(n)
42+
#define FLOAT_V_T vfloat64m8_t
43+
#define VLEV_FLOAT __riscv_vle64_v_f64m8
44+
#define VSEV_FLOAT __riscv_vse64_v_f64m8
45+
#define VFMULVF_FLOAT __riscv_vfmul_vf_f64m8
46+
#define VFMVVF_FLOAT __riscv_vfmv_v_f_f64m8
47+
#endif
48+
49+
50+
int CNAME(BLASLONG rows, BLASLONG cols, FLOAT alpha, FLOAT *a, BLASLONG lda, FLOAT *b, BLASLONG ldb)
51+
{
52+
BLASLONG i,j;
53+
FLOAT *aptr,*bptr;
54+
size_t vl;
55+
56+
FLOAT_V_T va, vb;
57+
if ( rows <= 0 ) return(0);
58+
if ( cols <= 0 ) return(0);
59+
60+
aptr = a;
61+
bptr = b;
62+
63+
if ( alpha == 0.0 )
64+
{
65+
vl = VSETVL_MAX;
66+
va = VFMVVF_FLOAT(0, vl);
67+
for ( i=0; i<cols ; i++ )
68+
{
69+
for(j=0; j<rows; j+=vl)
70+
{
71+
vl = VSETVL(rows - j);
72+
VSEV_FLOAT(bptr + j, va, vl);
73+
}
74+
bptr += ldb;
75+
}
76+
return(0);
77+
}
78+
79+
if ( alpha == 1.0 )
80+
{
81+
for ( i=0; i<cols ; i++ )
82+
{
83+
for(j=0; j<rows; j+=vl)
84+
{
85+
vl = VSETVL(rows - j);
86+
va = VLEV_FLOAT(aptr + j, vl);
87+
VSEV_FLOAT(bptr + j, va, vl);
88+
}
89+
aptr += lda;
90+
bptr += ldb;
91+
}
92+
return(0);
93+
}
94+
95+
for ( i=0; i<cols ; i++ )
96+
{
97+
for(j=0; j<rows; j+=vl)
98+
{
99+
vl = VSETVL(rows - j);
100+
va = VLEV_FLOAT(aptr + j, vl);
101+
va = VFMULVF_FLOAT(va, alpha, vl);
102+
VSEV_FLOAT(bptr + j, va, vl);
103+
}
104+
aptr += lda;
105+
bptr += ldb;
106+
}
107+
108+
return(0);
109+
}

kernel/riscv64/zomatcopy_cn_rvv.c

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
/***************************************************************************
2+
Copyright (c) 2013, The OpenBLAS Project
3+
All rights reserved.
4+
Redistribution and use in source and binary forms, with or without
5+
modification, are permitted provided that the following conditions are
6+
met:
7+
1. Redistributions of source code must retain the above copyright
8+
notice, this list of conditions and the following disclaimer.
9+
2. Redistributions in binary form must reproduce the above copyright
10+
notice, this list of conditions and the following disclaimer in
11+
the documentation and/or other materials provided with the
12+
distribution.
13+
3. Neither the name of the OpenBLAS project nor the names of
14+
its contributors may be used to endorse or promote products
15+
derived from this software without specific prior written permission.
16+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19+
ARE DISCLAIMED. IN NO EVENT SHALL THE OPENBLAS PROJECT OR CONTRIBUTORS BE
20+
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
25+
USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26+
*****************************************************************************/
27+
28+
#include "common.h"
29+
#include <stdio.h>
30+
31+
#if defined(DOUBLE)
32+
#define VLSEG2_FLOAT __riscv_vlseg2e64_v_f64m4x2
33+
#define VSSEG2_FLOAT __riscv_vsseg2e64_v_f64m4x2
34+
#define VSETVL __riscv_vsetvl_e64m4
35+
#define FLOAT_VX2_T vfloat64m4x2_t
36+
#define VGET_VX2 __riscv_vget_v_f64m4x2_f64m4
37+
#define VSET_VX2 __riscv_vset_v_f64m4_f64m4x2
38+
#define FLOAT_V vfloat64m4_t
39+
#define VFMULVF_FLOAT __riscv_vfmul_vf_f64m4
40+
#define VFMACCVF_FLOAT __riscv_vfmacc_vf_f64m4
41+
#else
42+
#define VLSEG2_FLOAT __riscv_vlseg2e32_v_f32m4x2
43+
#define VSSEG2_FLOAT __riscv_vsseg2e32_v_f32m4x2
44+
#define VSETVL __riscv_vsetvl_e32m4
45+
#define FLOAT_VX2_T vfloat32m4x2_t
46+
#define VGET_VX2 __riscv_vget_v_f32m4x2_f32m4
47+
#define VSET_VX2 __riscv_vset_v_f32m4_f32m4x2
48+
#define FLOAT_V vfloat32m4_t
49+
#define VFMULVF_FLOAT __riscv_vfmul_vf_f32m4
50+
#define VFMACCVF_FLOAT __riscv_vfmacc_vf_f32m4
51+
#endif
52+
53+
int CNAME(BLASLONG rows, BLASLONG cols, FLOAT alpha_r, FLOAT alpha_i, FLOAT *a, BLASLONG lda, FLOAT *b, BLASLONG ldb)
54+
{
55+
BLASLONG i,j,ia;
56+
FLOAT *aptr,*bptr;
57+
size_t vl;
58+
FLOAT_VX2_T va, vb;
59+
FLOAT_V va0, va1, vb0, vb1, vtemp;
60+
61+
if ( rows <= 0 ) return(0);
62+
if ( cols <= 0 ) return(0);
63+
64+
aptr = a;
65+
bptr = b;
66+
67+
lda *= 2;
68+
ldb *= 2;
69+
70+
for ( i=0; i<cols ; i++ )
71+
{
72+
ia = 0;
73+
74+
for(j=0; j<rows; j+=vl)
75+
{
76+
vl = VSETVL(rows - j);
77+
va = VLSEG2_FLOAT(aptr + ia, vl);
78+
79+
va0 = VGET_VX2(va, 0);
80+
va1 = VGET_VX2(va, 1);
81+
82+
vb0 = VFMULVF_FLOAT(va0, alpha_r, vl);
83+
vb0 = VFMACCVF_FLOAT(vb0, -alpha_i, va1, vl);
84+
85+
vb1 = VFMULVF_FLOAT(va0, alpha_i, vl);
86+
vb1 = VFMACCVF_FLOAT(vb1, alpha_r, va1, vl);
87+
88+
vb = VSET_VX2(vb, 0, vb0);
89+
vb = VSET_VX2(vb, 1, vb1);
90+
91+
VSSEG2_FLOAT(bptr + ia, vb, vl);
92+
93+
ia += vl * 2;
94+
}
95+
aptr += lda;
96+
bptr += ldb;
97+
}
98+
99+
return(0);
100+
}

0 commit comments

Comments
 (0)