Debian Codegraph @

src/f32-igemm/gen/f32-igemm-7x4v-relu-rvv.c

raw
1 // Auto-generated file. Do not edit!
2 // Template: src/f32-igemm/MRxNRv-rvv.c.in
3 // Generator: tools/xngen
4 //
5 // Copyright 2024 SiFive, Inc.
6 //
7 // This source code is licensed under the BSD-style license found in the
8 // LICENSE file in the root directory of this source tree.
9
10 #include <assert.h>
11
12 #include <riscv_vector.h>
13
14 #include "xnnpack/igemm.h"
15
16
17 void xnn_f32_igemm_relu_ukernel_7x4v__rvv(
18 size_t mr,
19 size_t nc,
20 size_t kc,
21 size_t ks,
22 const float** restrict a,
23 const float* restrict w,
24 float* restrict c,
25 size_t cm_stride,
26 size_t cn_stride,
27 size_t a_offset,
28 const float* zero,
29 const struct xnn_f32_relu_params params[restrict XNN_MIN_ELEMENTS(1)])
30 {
31 assert(mr != 0);
32 assert(mr <= 7);
33 assert(nc != 0);
34 assert(kc != 0);
35 assert(kc % sizeof(float) == 0);
36 assert(ks != 0);
37 assert(ks % (7 * sizeof(void*)) == 0);
38 assert(a_offset % sizeof(float) == 0);
39 assert(a != NULL);
40 assert(w != NULL);
41 assert(c != NULL);
42
43 const float vmin = 0.0f;
44 float* c0 = c;
45 float* c1 = (float*) ((uintptr_t) c0 + cm_stride);
46 if XNN_UNPREDICTABLE(mr < 2) {
47 c1 = c0;
48 }
49 float* c2 = (float*) ((uintptr_t) c1 + cm_stride);
50 if XNN_UNPREDICTABLE(mr <= 2) {
51 c2 = c1;
52 }
53 float* c3 = (float*) ((uintptr_t) c2 + cm_stride);
54 if XNN_UNPREDICTABLE(mr < 4) {
55 c3 = c2;
56 }
57 float* c4 = (float*) ((uintptr_t) c3 + cm_stride);
58 if XNN_UNPREDICTABLE(mr <= 4) {
59 c4 = c3;
60 }
61 float* c5 = (float*) ((uintptr_t) c4 + cm_stride);
62 if XNN_UNPREDICTABLE(mr < 6) {
63 c5 = c4;
64 }
65 float* c6 = (float*) ((uintptr_t) c5 + cm_stride);
66 if XNN_UNPREDICTABLE(mr <= 6) {
67 c6 = c5;
68 }
69
70 const size_t nr = __riscv_vsetvlmax_e32m4();
71 size_t vl = nr;
72 do {
73 if XNN_UNLIKELY(nc < nr) {
74 vl = __riscv_vsetvl_e32m4(nc);
75 }
76 nc = nc - vl;
77 vfloat32m4_t vacc0 = __riscv_vle32_v_f32m4(w, vl);
78 w = w + nr;
79 vfloat32m4_t vacc1 = __riscv_vmv_v_v_f32m4(vacc0, vl);
80 vfloat32m4_t vacc2 = __riscv_vmv_v_v_f32m4(vacc0, vl);
81 vfloat32m4_t vacc3 = __riscv_vmv_v_v_f32m4(vacc0, vl);
82 vfloat32m4_t vacc4 = __riscv_vmv_v_v_f32m4(vacc0, vl);
83 vfloat32m4_t vacc5 = __riscv_vmv_v_v_f32m4(vacc0, vl);
84 vfloat32m4_t vacc6 = __riscv_vmv_v_v_f32m4(vacc0, vl);
85
86 size_t p = ks;
87 do {
88 const float* restrict a0 = a[0];
89 assert(a0 != NULL);
90 if XNN_UNPREDICTABLE(a0 != zero) {
91 a0 = (const float*) ((uintptr_t) a0 + a_offset);
92 }
93 const float* restrict a1 = a[1];
94 assert(a1 != NULL);
95 if XNN_UNPREDICTABLE(a1 != zero) {
96 a1 = (const float*) ((uintptr_t) a1 + a_offset);
97 }
98 const float* restrict a2 = a[2];
99 assert(a2 != NULL);
100 if XNN_UNPREDICTABLE(a2 != zero) {
101 a2 = (const float*) ((uintptr_t) a2 + a_offset);
102 }
103 const float* restrict a3 = a[3];
104 assert(a3 != NULL);
105 if XNN_UNPREDICTABLE(a3 != zero) {
106 a3 = (const float*) ((uintptr_t) a3 + a_offset);
107 }
108 const float* restrict a4 = a[4];
109 assert(a4 != NULL);
110 if XNN_UNPREDICTABLE(a4 != zero) {
111 a4 = (const float*) ((uintptr_t) a4 + a_offset);
112 }
113 const float* restrict a5 = a[5];
114 assert(a5 != NULL);
115 if XNN_UNPREDICTABLE(a5 != zero) {
116 a5 = (const float*) ((uintptr_t) a5 + a_offset);
117 }
118 const float* restrict a6 = a[6];
119 assert(a6 != NULL);
120 if XNN_UNPREDICTABLE(a6 != zero) {
121 a6 = (const float*) ((uintptr_t) a6 + a_offset);
122 }
123 a += 7;
124
125 size_t k = kc;
126 do {
127 const float va0 = *a0++;
128 const float va1 = *a1++;
129 const float va2 = *a2++;
130 const float va3 = *a3++;
131 const float va4 = *a4++;
132 const float va5 = *a5++;
133 const float va6 = *a6++;
134 vfloat32m4_t vb = __riscv_vle32_v_f32m4(w, vl);
135 w = w + nr;
136 vacc0 = __riscv_vfmacc_vf_f32m4(vacc0, va0, vb, vl);
137 vacc1 = __riscv_vfmacc_vf_f32m4(vacc1, va1, vb, vl);
138 vacc2 = __riscv_vfmacc_vf_f32m4(vacc2, va2, vb, vl);
139 vacc3 = __riscv_vfmacc_vf_f32m4(vacc3, va3, vb, vl);
140 vacc4 = __riscv_vfmacc_vf_f32m4(vacc4, va4, vb, vl);
141 vacc5 = __riscv_vfmacc_vf_f32m4(vacc5, va5, vb, vl);
142 vacc6 = __riscv_vfmacc_vf_f32m4(vacc6, va6, vb, vl);
143
144 k -= sizeof(float);
145 } while (k != 0);
146 p -= 7 * sizeof(void*);
147 } while (p != 0);
148 // apply ReLU to results
149 vacc0 = __riscv_vfmax_vf_f32m4(vacc0, vmin, vl);
150 vacc1 = __riscv_vfmax_vf_f32m4(vacc1, vmin, vl);
151 vacc2 = __riscv_vfmax_vf_f32m4(vacc2, vmin, vl);
152 vacc3 = __riscv_vfmax_vf_f32m4(vacc3, vmin, vl);
153 vacc4 = __riscv_vfmax_vf_f32m4(vacc4, vmin, vl);
154 vacc5 = __riscv_vfmax_vf_f32m4(vacc5, vmin, vl);
155 vacc6 = __riscv_vfmax_vf_f32m4(vacc6, vmin, vl);
156 // store 7 x vl results to c
157 __riscv_vse32_v_f32m4(c6, vacc6, vl);
158 c6 = (float*) ((uintptr_t) c6 + cn_stride);
159 __riscv_vse32_v_f32m4(c5, vacc5, vl);
160 c5 = (float*) ((uintptr_t) c5 + cn_stride);
161 __riscv_vse32_v_f32m4(c4, vacc4, vl);
162 c4 = (float*) ((uintptr_t) c4 + cn_stride);
163 __riscv_vse32_v_f32m4(c3, vacc3, vl);
164 c3 = (float*) ((uintptr_t) c3 + cn_stride);
165 __riscv_vse32_v_f32m4(c2, vacc2, vl);
166 c2 = (float*) ((uintptr_t) c2 + cn_stride);
167 __riscv_vse32_v_f32m4(c1, vacc1, vl);
168 c1 = (float*) ((uintptr_t) c1 + cn_stride);
169 __riscv_vse32_v_f32m4(c0, vacc0, vl);
170 c0 = (float*) ((uintptr_t) c0 + cn_stride);
171
172 a = (const float**restrict) ((uintptr_t) a - ks);
173 } while (nc != 0);
174 }