Debian Codegraph @

src/qd8-f32-qc8w-gemm/gen/qd8-f32-qc8w-gemm-8x4v-minmax-rvv.c

raw
1 // Auto-generated file. Do not edit!
2 // Template: src/qs8-gemm/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/gemm.h"
15 #include "xnnpack/math.h"
16
17 void xnn_qd8_f32_qc8w_gemm_minmax_ukernel_8x4v__rvv(
18 size_t mr,
19 size_t nc,
20 size_t kc,
21 const int8_t* restrict a,
22 size_t a_stride,
23 const void* restrict w,
24 float* restrict c,
25 size_t cm_stride,
26 size_t cn_stride,
27 const union xnn_f32_minmax_params params[restrict XNN_MIN_ELEMENTS(1)],
28 const struct xnn_qd8_quantization_params quantization_params[restrict XNN_MIN_ELEMENTS(1)])
29 {
30 assert(mr != 0);
31 assert(mr <= 8);
32 assert(nc != 0);
33 assert(kc != 0);
34
35 const int8_t* a0 = a;
36 float* c0 = c;
37 const int8_t* a1 = (const int8_t*) ((uintptr_t) a0 + a_stride);
38 float* c1 = (float*) ((uintptr_t) c0 + cm_stride);
39 if XNN_UNPREDICTABLE(mr < 2) {
40 a1 = a0;
41 c1 = c0;
42 }
43 const int8_t* a2 = (const int8_t*) ((uintptr_t) a1 + a_stride);
44 float* c2 = (float*) ((uintptr_t) c1 + cm_stride);
45 if XNN_UNPREDICTABLE(mr <= 2) {
46 a2 = a1;
47 c2 = c1;
48 }
49 const int8_t* a3 = (const int8_t*) ((uintptr_t) a2 + a_stride);
50 float* c3 = (float*) ((uintptr_t) c2 + cm_stride);
51 if XNN_UNPREDICTABLE(mr < 4) {
52 a3 = a2;
53 c3 = c2;
54 }
55 const int8_t* a4 = (const int8_t*) ((uintptr_t) a3 + a_stride);
56 float* c4 = (float*) ((uintptr_t) c3 + cm_stride);
57 if XNN_UNPREDICTABLE(mr <= 4) {
58 a4 = a3;
59 c4 = c3;
60 }
61 const int8_t* a5 = (const int8_t*) ((uintptr_t) a4 + a_stride);
62 float* c5 = (float*) ((uintptr_t) c4 + cm_stride);
63 if XNN_UNPREDICTABLE(mr < 6) {
64 a5 = a4;
65 c5 = c4;
66 }
67 const int8_t* a6 = (const int8_t*) ((uintptr_t) a5 + a_stride);
68 float* c6 = (float*) ((uintptr_t) c5 + cm_stride);
69 if XNN_UNPREDICTABLE(mr <= 6) {
70 a6 = a5;
71 c6 = c5;
72 }
73 const int8_t* a7 = (const int8_t*) ((uintptr_t) a6 + a_stride);
74 float* c7 = (float*) ((uintptr_t) c6 + cm_stride);
75 if XNN_UNPREDICTABLE(mr != 8) {
76 a7 = a6;
77 c7 = c6;
78 }
79
80 const size_t nr = __riscv_vsetvlmax_e32m4();
81 size_t vl = nr;
82 do {
83 if XNN_UNLIKELY(nc < nr) {
84 vl = __riscv_vsetvl_e32m4(nc);
85 }
86 nc = nc - vl;
87
88 vint32m4_t vksum = __riscv_vle32_v_i32m4((const int32_t*)w, vl);
89 w = (const int32_t*) w + nr;
90 const int32_t vinput_zero_point0 = quantization_params[0].zero_point;
91 const int32_t vinput_zero_point1 = quantization_params[1].zero_point;
92 const int32_t vinput_zero_point2 = quantization_params[2].zero_point;
93 const int32_t vinput_zero_point3 = quantization_params[3].zero_point;
94 const int32_t vinput_zero_point4 = quantization_params[4].zero_point;
95 const int32_t vinput_zero_point5 = quantization_params[5].zero_point;
96 const int32_t vinput_zero_point6 = quantization_params[6].zero_point;
97 const int32_t vinput_zero_point7 = quantization_params[7].zero_point;
98 vint32m4_t vacc0 = __riscv_vmul_vx_i32m4(vksum, vinput_zero_point0, vl);
99 vint32m4_t vacc1 = __riscv_vmul_vx_i32m4(vksum, vinput_zero_point1, vl);
100 vint32m4_t vacc2 = __riscv_vmul_vx_i32m4(vksum, vinput_zero_point2, vl);
101 vint32m4_t vacc3 = __riscv_vmul_vx_i32m4(vksum, vinput_zero_point3, vl);
102 vint32m4_t vacc4 = __riscv_vmul_vx_i32m4(vksum, vinput_zero_point4, vl);
103 vint32m4_t vacc5 = __riscv_vmul_vx_i32m4(vksum, vinput_zero_point5, vl);
104 vint32m4_t vacc6 = __riscv_vmul_vx_i32m4(vksum, vinput_zero_point6, vl);
105 vint32m4_t vacc7 = __riscv_vmul_vx_i32m4(vksum, vinput_zero_point7, vl);
106
107 size_t k = kc;
108 do {
109 const int8_t va0 = *a0++;
110 const int8_t va1 = *a1++;
111 const int8_t va2 = *a2++;
112 const int8_t va3 = *a3++;
113 const int8_t va4 = *a4++;
114 const int8_t va5 = *a5++;
115 const int8_t va6 = *a6++;
116 const int8_t va7 = *a7++;
117 const vint8m1_t vb = __riscv_vle8_v_i8m1((const int8_t*) w, vl);
118 w = (const int8_t*) w + nr;
119
120 vint16m2_t va0b = __riscv_vwmul_vx_i16m2(vb, va0, vl);
121 vacc0 = __riscv_vwadd_wv_i32m4(vacc0, va0b, vl);
122 vint16m2_t va1b = __riscv_vwmul_vx_i16m2(vb, va1, vl);
123 vacc1 = __riscv_vwadd_wv_i32m4(vacc1, va1b, vl);
124 vint16m2_t va2b = __riscv_vwmul_vx_i16m2(vb, va2, vl);
125 vacc2 = __riscv_vwadd_wv_i32m4(vacc2, va2b, vl);
126 vint16m2_t va3b = __riscv_vwmul_vx_i16m2(vb, va3, vl);
127 vacc3 = __riscv_vwadd_wv_i32m4(vacc3, va3b, vl);
128 vint16m2_t va4b = __riscv_vwmul_vx_i16m2(vb, va4, vl);
129 vacc4 = __riscv_vwadd_wv_i32m4(vacc4, va4b, vl);
130 vint16m2_t va5b = __riscv_vwmul_vx_i16m2(vb, va5, vl);
131 vacc5 = __riscv_vwadd_wv_i32m4(vacc5, va5b, vl);
132 vint16m2_t va6b = __riscv_vwmul_vx_i16m2(vb, va6, vl);
133 vacc6 = __riscv_vwadd_wv_i32m4(vacc6, va6b, vl);
134 vint16m2_t va7b = __riscv_vwmul_vx_i16m2(vb, va7, vl);
135 vacc7 = __riscv_vwadd_wv_i32m4(vacc7, va7b, vl);
136
137 k -= sizeof(int8_t);
138 } while (k != 0);
139 // i32 -> f32
140 vfloat32m4_t vout0 = __riscv_vfcvt_f_x_v_f32m4(vacc0, vl);
141 vfloat32m4_t vout1 = __riscv_vfcvt_f_x_v_f32m4(vacc1, vl);
142 vfloat32m4_t vout2 = __riscv_vfcvt_f_x_v_f32m4(vacc2, vl);
143 vfloat32m4_t vout3 = __riscv_vfcvt_f_x_v_f32m4(vacc3, vl);
144 vfloat32m4_t vout4 = __riscv_vfcvt_f_x_v_f32m4(vacc4, vl);
145 vfloat32m4_t vout5 = __riscv_vfcvt_f_x_v_f32m4(vacc5, vl);
146 vfloat32m4_t vout6 = __riscv_vfcvt_f_x_v_f32m4(vacc6, vl);
147 vfloat32m4_t vout7 = __riscv_vfcvt_f_x_v_f32m4(vacc7, vl);
148
149 // vout * input_scale
150 const float vinput_scale0 = quantization_params[0].inv_scale;
151 const float vinput_scale1 = quantization_params[1].inv_scale;
152 const float vinput_scale2 = quantization_params[2].inv_scale;
153 const float vinput_scale3 = quantization_params[3].inv_scale;
154 const float vinput_scale4 = quantization_params[4].inv_scale;
155 const float vinput_scale5 = quantization_params[5].inv_scale;
156 const float vinput_scale6 = quantization_params[6].inv_scale;
157 const float vinput_scale7 = quantization_params[7].inv_scale;
158 vout0 = __riscv_vfmul_vf_f32m4(vout0, vinput_scale0, vl);
159 vout1 = __riscv_vfmul_vf_f32m4(vout1, vinput_scale1, vl);
160 vout2 = __riscv_vfmul_vf_f32m4(vout2, vinput_scale2, vl);
161 vout3 = __riscv_vfmul_vf_f32m4(vout3, vinput_scale3, vl);
162 vout4 = __riscv_vfmul_vf_f32m4(vout4, vinput_scale4, vl);
163 vout5 = __riscv_vfmul_vf_f32m4(vout5, vinput_scale5, vl);
164 vout6 = __riscv_vfmul_vf_f32m4(vout6, vinput_scale6, vl);
165 vout7 = __riscv_vfmul_vf_f32m4(vout7, vinput_scale7, vl);
166
167 const vfloat32m4_t vfilter_output_scale = __riscv_vle32_v_f32m4((const float*) w, vl);
168 w = (const float*) w + nr;
169 vout0 = __riscv_vfmul_vv_f32m4(vout0, vfilter_output_scale, vl);
170 vout1 = __riscv_vfmul_vv_f32m4(vout1, vfilter_output_scale, vl);
171 vout2 = __riscv_vfmul_vv_f32m4(vout2, vfilter_output_scale, vl);
172 vout3 = __riscv_vfmul_vv_f32m4(vout3, vfilter_output_scale, vl);
173 vout4 = __riscv_vfmul_vv_f32m4(vout4, vfilter_output_scale, vl);
174 vout5 = __riscv_vfmul_vv_f32m4(vout5, vfilter_output_scale, vl);
175 vout6 = __riscv_vfmul_vv_f32m4(vout6, vfilter_output_scale, vl);
176 vout7 = __riscv_vfmul_vv_f32m4(vout7, vfilter_output_scale, vl);
177
178 const vfloat32m4_t vbias = __riscv_vle32_v_f32m4((const float*) w, vl);
179 w = (const float*) w + nr;
180 vout0 = __riscv_vfadd_vv_f32m4(vout0, vbias, vl);
181 vout1 = __riscv_vfadd_vv_f32m4(vout1, vbias, vl);
182 vout2 = __riscv_vfadd_vv_f32m4(vout2, vbias, vl);
183 vout3 = __riscv_vfadd_vv_f32m4(vout3, vbias, vl);
184 vout4 = __riscv_vfadd_vv_f32m4(vout4, vbias, vl);
185 vout5 = __riscv_vfadd_vv_f32m4(vout5, vbias, vl);
186 vout6 = __riscv_vfadd_vv_f32m4(vout6, vbias, vl);
187 vout7 = __riscv_vfadd_vv_f32m4(vout7, vbias, vl);
188
189 const float vmin = params->scalar.min;
190 vout0 = __riscv_vfmax_vf_f32m4(vout0, vmin, vl);
191 vout1 = __riscv_vfmax_vf_f32m4(vout1, vmin, vl);
192 vout2 = __riscv_vfmax_vf_f32m4(vout2, vmin, vl);
193 vout3 = __riscv_vfmax_vf_f32m4(vout3, vmin, vl);
194 vout4 = __riscv_vfmax_vf_f32m4(vout4, vmin, vl);
195 vout5 = __riscv_vfmax_vf_f32m4(vout5, vmin, vl);
196 vout6 = __riscv_vfmax_vf_f32m4(vout6, vmin, vl);
197 vout7 = __riscv_vfmax_vf_f32m4(vout7, vmin, vl);
198 const float vmax = params->scalar.max;
199 vout0 = __riscv_vfmin_vf_f32m4(vout0, vmax, vl);
200 vout1 = __riscv_vfmin_vf_f32m4(vout1, vmax, vl);
201 vout2 = __riscv_vfmin_vf_f32m4(vout2, vmax, vl);
202 vout3 = __riscv_vfmin_vf_f32m4(vout3, vmax, vl);
203 vout4 = __riscv_vfmin_vf_f32m4(vout4, vmax, vl);
204 vout5 = __riscv_vfmin_vf_f32m4(vout5, vmax, vl);
205 vout6 = __riscv_vfmin_vf_f32m4(vout6, vmax, vl);
206 vout7 = __riscv_vfmin_vf_f32m4(vout7, vmax, vl);
207
208 // store 8 x vl results to c
209 __riscv_vse32_v_f32m4(c0, vout0, vl);
210 c0 = (float*) ((uintptr_t) c0 + cn_stride);
211 __riscv_vse32_v_f32m4(c1, vout1, vl);
212 c1 = (float*) ((uintptr_t) c1 + cn_stride);
213 __riscv_vse32_v_f32m4(c2, vout2, vl);
214 c2 = (float*) ((uintptr_t) c2 + cn_stride);
215 __riscv_vse32_v_f32m4(c3, vout3, vl);
216 c3 = (float*) ((uintptr_t) c3 + cn_stride);
217 __riscv_vse32_v_f32m4(c4, vout4, vl);
218 c4 = (float*) ((uintptr_t) c4 + cn_stride);
219 __riscv_vse32_v_f32m4(c5, vout5, vl);
220 c5 = (float*) ((uintptr_t) c5 + cn_stride);
221 __riscv_vse32_v_f32m4(c6, vout6, vl);
222 c6 = (float*) ((uintptr_t) c6 + cn_stride);
223 __riscv_vse32_v_f32m4(c7, vout7, vl);
224 c7 = (float*) ((uintptr_t) c7 + cn_stride);
225
226 a0 = (const int8_t*) ((uintptr_t) a0 - kc);
227 a1 = (const int8_t*) ((uintptr_t) a1 - kc);
228 a2 = (const int8_t*) ((uintptr_t) a2 - kc);
229 a3 = (const int8_t*) ((uintptr_t) a3 - kc);
230 a4 = (const int8_t*) ((uintptr_t) a4 - kc);
231 a5 = (const int8_t*) ((uintptr_t) a5 - kc);
232 a6 = (const int8_t*) ((uintptr_t) a6 - kc);
233 a7 = (const int8_t*) ((uintptr_t) a7 - kc);
234 } while (nc != 0);
235 }