Debian Codegraph @

src/qd8-f32-qc8w-gemm/gen/qd8-f32-qc8w-gemm-5x8c4-minmax-neondot.c

raw
1 // Auto-generated file. Do not edit!
2 // Template: src/qs8-gemm/c4-neondot.c.in
3 // Generator: tools/xngen
4 //
5 // Copyright 2020 Google LLC
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 <arm_neon.h>
13
14 #include "xnnpack/gemm.h"
15 #include "xnnpack/math.h"
16
17
18 void xnn_qd8_f32_qc8w_gemm_minmax_ukernel_5x8c4__neondot(
19 size_t mr,
20 size_t nc,
21 size_t kc,
22 const int8_t* restrict a,
23 size_t a_stride,
24 const void* restrict w,
25 float* restrict c,
26 size_t cm_stride,
27 size_t cn_stride,
28 const union xnn_f32_minmax_params params[restrict XNN_MIN_ELEMENTS(1)],
29 const struct xnn_qd8_quantization_params quantization_params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS
30 {
31 assert(mr != 0);
32 assert(mr <= 5);
33 assert(nc != 0);
34 assert(kc != 0);
35 assert(kc % sizeof(int8_t) == 0);
36 assert(a != NULL);
37 assert(w != NULL);
38 assert(c != NULL);
39
40 kc = round_up_po2(kc, 4 * sizeof(int8_t));
41 const int8_t* a0 = a;
42 float* c0 = c;
43 const int8_t* a1 = (const int8_t*) ((uintptr_t) a0 + a_stride);
44 float* c1 = (float*) ((uintptr_t) c0 + cm_stride);
45 if XNN_UNPREDICTABLE(mr < 2) {
46 a1 = a0;
47 c1 = c0;
48 }
49 const int8_t* a2 = (const int8_t*) ((uintptr_t) a1 + a_stride);
50 float* c2 = (float*) ((uintptr_t) c1 + cm_stride);
51 if XNN_UNPREDICTABLE(mr <= 2) {
52 a2 = a1;
53 c2 = c1;
54 }
55 const int8_t* a3 = (const int8_t*) ((uintptr_t) a2 + a_stride);
56 float* c3 = (float*) ((uintptr_t) c2 + cm_stride);
57 if XNN_UNPREDICTABLE(mr < 4) {
58 a3 = a2;
59 c3 = c2;
60 }
61 const int8_t* a4 = (const int8_t*) ((uintptr_t) a3 + a_stride);
62 float* c4 = (float*) ((uintptr_t) c3 + cm_stride);
63 if XNN_UNPREDICTABLE(mr <= 4) {
64 a4 = a3;
65 c4 = c3;
66 }
67
68 // Loop over groups of 8 columns.
69 do {
70 // Initialize accumulators with bias. 8 bias values are loaded from the
71 // weight matrix, at the start of the group of 8 columns.
72 const int32x4_t vinput_zero_point01 = vld1q_s32(&quantization_params[0].zero_point);
73 const int32x4_t vksum0123 = vld1q_s32(w); w = (const int32_t*) w + 4;
74 int32x4_t vacc0x0123 = vmulq_lane_s32(vksum0123, vget_low_s32(vinput_zero_point01), 0);
75 int32x4_t vacc1x0123 = vmulq_lane_s32(vksum0123, vget_high_s32(vinput_zero_point01), 0);
76 const int32x4_t vksum4567 = vld1q_s32(w); w = (const int32_t*) w + 4;
77 int32x4_t vacc0x4567 = vmulq_lane_s32(vksum4567, vget_low_s32(vinput_zero_point01), 0);
78 int32x4_t vacc1x4567 = vmulq_lane_s32(vksum4567, vget_high_s32(vinput_zero_point01), 0);
79 const int32x4_t vinput_zero_point23 = vld1q_s32(&quantization_params[2].zero_point);
80 int32x4_t vacc2x0123 = vmulq_lane_s32(vksum0123, vget_low_s32(vinput_zero_point23), 0);
81 int32x4_t vacc3x0123 = vmulq_lane_s32(vksum0123, vget_high_s32(vinput_zero_point23), 0);
82 int32x4_t vacc2x4567 = vmulq_lane_s32(vksum4567, vget_low_s32(vinput_zero_point23), 0);
83 int32x4_t vacc3x4567 = vmulq_lane_s32(vksum4567, vget_high_s32(vinput_zero_point23), 0);
84 const int32x4_t vinput_zero_point4 = vld1q_dup_s32(&quantization_params[4].zero_point);
85 int32x4_t vacc4x0123 = vmulq_s32(vksum0123, vinput_zero_point4);
86 int32x4_t vacc4x4567 = vmulq_s32(vksum4567, vinput_zero_point4);
87
88 // Inner accumulation loop along the 8 columns.
89 size_t k = kc;
90 // 2x partial unrolled loop to load 8 bytes at a time.
91 while (k >= 8 * sizeof(int8_t)) {
92 // Load a 5x8 block of activations.
93 const int8x8_t va0x01234567 = vld1_s8(a0); a0 += 8;
94 const int8x8_t va1x01234567 = vld1_s8(a1); a1 += 8;
95 const int8x8_t va2x01234567 = vld1_s8(a2); a2 += 8;
96 const int8x8_t va3x01234567 = vld1_s8(a3); a3 += 8;
97 const int8x8_t va4x01234567 = vld1_s8(a4); a4 += 8;
98
99 // Load a 8x8 block of weights.
100 const int8x16_t vb0123x0123 = vld1q_s8(w); w = (const int8_t*) w + 16;
101 const int8x16_t vb0123x4567 = vld1q_s8(w); w = (const int8_t*) w + 16;
102 const int8x16_t vb4567x0123 = vld1q_s8(w); w = (const int8_t*) w + 16;
103 const int8x16_t vb4567x4567 = vld1q_s8(w); w = (const int8_t*) w + 16;
104
105 // Multiply-accumulate: 5x8 * 8x8 --> 5x8.
106 vacc0x0123 = vdotq_lane_s32(vacc0x0123, vb0123x0123, va0x01234567, 0);
107 vacc0x4567 = vdotq_lane_s32(vacc0x4567, vb0123x4567, va0x01234567, 0);
108 vacc1x0123 = vdotq_lane_s32(vacc1x0123, vb0123x0123, va1x01234567, 0);
109 vacc1x4567 = vdotq_lane_s32(vacc1x4567, vb0123x4567, va1x01234567, 0);
110 vacc2x0123 = vdotq_lane_s32(vacc2x0123, vb0123x0123, va2x01234567, 0);
111 vacc2x4567 = vdotq_lane_s32(vacc2x4567, vb0123x4567, va2x01234567, 0);
112 vacc3x0123 = vdotq_lane_s32(vacc3x0123, vb0123x0123, va3x01234567, 0);
113 vacc3x4567 = vdotq_lane_s32(vacc3x4567, vb0123x4567, va3x01234567, 0);
114 vacc4x0123 = vdotq_lane_s32(vacc4x0123, vb0123x0123, va4x01234567, 0);
115 vacc4x4567 = vdotq_lane_s32(vacc4x4567, vb0123x4567, va4x01234567, 0);
116 vacc0x0123 = vdotq_lane_s32(vacc0x0123, vb4567x0123, va0x01234567, 1);
117 vacc0x4567 = vdotq_lane_s32(vacc0x4567, vb4567x4567, va0x01234567, 1);
118 vacc1x0123 = vdotq_lane_s32(vacc1x0123, vb4567x0123, va1x01234567, 1);
119 vacc1x4567 = vdotq_lane_s32(vacc1x4567, vb4567x4567, va1x01234567, 1);
120 vacc2x0123 = vdotq_lane_s32(vacc2x0123, vb4567x0123, va2x01234567, 1);
121 vacc2x4567 = vdotq_lane_s32(vacc2x4567, vb4567x4567, va2x01234567, 1);
122 vacc3x0123 = vdotq_lane_s32(vacc3x0123, vb4567x0123, va3x01234567, 1);
123 vacc3x4567 = vdotq_lane_s32(vacc3x4567, vb4567x4567, va3x01234567, 1);
124 vacc4x0123 = vdotq_lane_s32(vacc4x0123, vb4567x0123, va4x01234567, 1);
125 vacc4x4567 = vdotq_lane_s32(vacc4x4567, vb4567x4567, va4x01234567, 1);
126
127 k -= 8 * sizeof(int8_t);
128 }
129 // Handle up to 4 final positions of `k`
130 if XNN_UNLIKELY(k != 0) {
131 // Load a 5x4 block of activations.
132 const int8x8_t va0x01234567 = vld1_s8(a0); a0 += 4;
133 const int8x8_t va1x01234567 = vld1_s8(a1); a1 += 4;
134 const int8x8_t va2x01234567 = vld1_s8(a2); a2 += 4;
135 const int8x8_t va3x01234567 = vld1_s8(a3); a3 += 4;
136 const int8x8_t va4x01234567 = vld1_s8(a4); a4 += 4;
137
138 // Load a 4x8 block of weights.
139 const int8x16_t vb0123x0123 = vld1q_s8(w); w = (const int8_t*) w + 16;
140 const int8x16_t vb0123x4567 = vld1q_s8(w); w = (const int8_t*) w + 16;
141
142 // Multiply-accumulate: 5x4 * 4x8 --> 5x8.
143 vacc0x0123 = vdotq_lane_s32(vacc0x0123, vb0123x0123, va0x01234567, 0);
144 vacc0x4567 = vdotq_lane_s32(vacc0x4567, vb0123x4567, va0x01234567, 0);
145 vacc1x0123 = vdotq_lane_s32(vacc1x0123, vb0123x0123, va1x01234567, 0);
146 vacc1x4567 = vdotq_lane_s32(vacc1x4567, vb0123x4567, va1x01234567, 0);
147 vacc2x0123 = vdotq_lane_s32(vacc2x0123, vb0123x0123, va2x01234567, 0);
148 vacc2x4567 = vdotq_lane_s32(vacc2x4567, vb0123x4567, va2x01234567, 0);
149 vacc3x0123 = vdotq_lane_s32(vacc3x0123, vb0123x0123, va3x01234567, 0);
150 vacc3x4567 = vdotq_lane_s32(vacc3x4567, vb0123x4567, va3x01234567, 0);
151 vacc4x0123 = vdotq_lane_s32(vacc4x0123, vb0123x0123, va4x01234567, 0);
152 vacc4x4567 = vdotq_lane_s32(vacc4x4567, vb0123x4567, va4x01234567, 0);
153 }
154
155 float32x4_t vout0x0123 = vcvtq_f32_s32(vacc0x0123);
156 float32x4_t vout0x4567 = vcvtq_f32_s32(vacc0x4567);
157 float32x4_t vout1x0123 = vcvtq_f32_s32(vacc1x0123);
158 float32x4_t vout1x4567 = vcvtq_f32_s32(vacc1x4567);
159 float32x4_t vout2x0123 = vcvtq_f32_s32(vacc2x0123);
160 float32x4_t vout2x4567 = vcvtq_f32_s32(vacc2x4567);
161 float32x4_t vout3x0123 = vcvtq_f32_s32(vacc3x0123);
162 float32x4_t vout3x4567 = vcvtq_f32_s32(vacc3x4567);
163 float32x4_t vout4x0123 = vcvtq_f32_s32(vacc4x0123);
164 float32x4_t vout4x4567 = vcvtq_f32_s32(vacc4x4567);
165 const float32x4_t vinput_scale01 = vreinterpretq_f32_s32(vld1q_s32(&quantization_params[0].zero_point));
166 vout0x0123 = vmulq_lane_f32(vout0x0123, vget_low_f32(vinput_scale01), 1);
167 vout1x0123 = vmulq_lane_f32(vout1x0123, vget_high_f32(vinput_scale01), 1);
168 vout0x4567 = vmulq_lane_f32(vout0x4567, vget_low_f32(vinput_scale01), 1);
169 vout1x4567 = vmulq_lane_f32(vout1x4567, vget_high_f32(vinput_scale01), 1);
170 const float32x4_t vinput_scale23 = vreinterpretq_f32_s32(vld1q_s32(&quantization_params[2].zero_point));
171 vout2x0123 = vmulq_lane_f32(vout2x0123, vget_low_f32(vinput_scale23), 1);
172 vout3x0123 = vmulq_lane_f32(vout3x0123, vget_high_f32(vinput_scale23), 1);
173 vout2x4567 = vmulq_lane_f32(vout2x4567, vget_low_f32(vinput_scale23), 1);
174 vout3x4567 = vmulq_lane_f32(vout3x4567, vget_high_f32(vinput_scale23), 1);
175 const float32x4_t vinput_scale4 = vld1q_dup_f32(&quantization_params[4].inv_scale);
176 vout4x0123 = vmulq_f32(vout4x0123, vinput_scale4);
177 vout4x4567 = vmulq_f32(vout4x4567, vinput_scale4);
178
179 const float32x4_t vfilter_output_scale0123 = vld1q_f32(w); w = (const float*) w + 4;
180 const float32x4_t vfilter_output_scale4567 = vld1q_f32(w); w = (const float*) w + 4;
181
182 const float32x4_t vbias0123 = vld1q_f32(w); w = (const float*) w + 4;
183 #if XNN_ARCH_ARM64
184 vout0x0123 = vfmaq_f32(vbias0123, vout0x0123, vfilter_output_scale0123);
185 vout1x0123 = vfmaq_f32(vbias0123, vout1x0123, vfilter_output_scale0123);
186 vout2x0123 = vfmaq_f32(vbias0123, vout2x0123, vfilter_output_scale0123);
187 vout3x0123 = vfmaq_f32(vbias0123, vout3x0123, vfilter_output_scale0123);
188 vout4x0123 = vfmaq_f32(vbias0123, vout4x0123, vfilter_output_scale0123);
189 #else
190 vout0x0123 = vmlaq_f32(vbias0123, vout0x0123, vfilter_output_scale0123);
191 vout1x0123 = vmlaq_f32(vbias0123, vout1x0123, vfilter_output_scale0123);
192 vout2x0123 = vmlaq_f32(vbias0123, vout2x0123, vfilter_output_scale0123);
193 vout3x0123 = vmlaq_f32(vbias0123, vout3x0123, vfilter_output_scale0123);
194 vout4x0123 = vmlaq_f32(vbias0123, vout4x0123, vfilter_output_scale0123);
195 #endif
196 const float32x4_t vbias4567 = vld1q_f32(w); w = (const float*) w + 4;
197 #if XNN_ARCH_ARM64
198 vout0x4567 = vfmaq_f32(vbias4567, vout0x4567, vfilter_output_scale4567);
199 vout1x4567 = vfmaq_f32(vbias4567, vout1x4567, vfilter_output_scale4567);
200 vout2x4567 = vfmaq_f32(vbias4567, vout2x4567, vfilter_output_scale4567);
201 vout3x4567 = vfmaq_f32(vbias4567, vout3x4567, vfilter_output_scale4567);
202 vout4x4567 = vfmaq_f32(vbias4567, vout4x4567, vfilter_output_scale4567);
203 #else
204 vout0x4567 = vmlaq_f32(vbias4567, vout0x4567, vfilter_output_scale4567);
205 vout1x4567 = vmlaq_f32(vbias4567, vout1x4567, vfilter_output_scale4567);
206 vout2x4567 = vmlaq_f32(vbias4567, vout2x4567, vfilter_output_scale4567);
207 vout3x4567 = vmlaq_f32(vbias4567, vout3x4567, vfilter_output_scale4567);
208 vout4x4567 = vmlaq_f32(vbias4567, vout4x4567, vfilter_output_scale4567);
209 #endif
210
211 const float32x4_t voutput_min = vld1q_dup_f32(&params->scalar.min);
212 vout0x0123 = vmaxq_f32(vout0x0123, voutput_min);
213 vout0x4567 = vmaxq_f32(vout0x4567, voutput_min);
214 vout1x0123 = vmaxq_f32(vout1x0123, voutput_min);
215 vout1x4567 = vmaxq_f32(vout1x4567, voutput_min);
216 vout2x0123 = vmaxq_f32(vout2x0123, voutput_min);
217 vout2x4567 = vmaxq_f32(vout2x4567, voutput_min);
218 vout3x0123 = vmaxq_f32(vout3x0123, voutput_min);
219 vout3x4567 = vmaxq_f32(vout3x4567, voutput_min);
220 vout4x0123 = vmaxq_f32(vout4x0123, voutput_min);
221 vout4x4567 = vmaxq_f32(vout4x4567, voutput_min);
222
223 const float32x4_t voutput_max = vld1q_dup_f32(&params->scalar.max);
224 vout0x0123 = vminq_f32(vout0x0123, voutput_max);
225 vout0x4567 = vminq_f32(vout0x4567, voutput_max);
226 vout1x0123 = vminq_f32(vout1x0123, voutput_max);
227 vout1x4567 = vminq_f32(vout1x4567, voutput_max);
228 vout2x0123 = vminq_f32(vout2x0123, voutput_max);
229 vout2x4567 = vminq_f32(vout2x4567, voutput_max);
230 vout3x0123 = vminq_f32(vout3x0123, voutput_max);
231 vout3x4567 = vminq_f32(vout3x4567, voutput_max);
232 vout4x0123 = vminq_f32(vout4x0123, voutput_max);
233 vout4x4567 = vminq_f32(vout4x4567, voutput_max);
234
235 if XNN_LIKELY(nc >= 8) {
236 vst1q_f32(c0, vout0x0123);
237 vst1q_f32(c0 + 4, vout0x4567);
238 vst1q_f32(c1, vout1x0123);
239 vst1q_f32(c1 + 4, vout1x4567);
240 vst1q_f32(c2, vout2x0123);
241 vst1q_f32(c2 + 4, vout2x4567);
242 vst1q_f32(c3, vout3x0123);
243 vst1q_f32(c3 + 4, vout3x4567);
244 vst1q_f32(c4, vout4x0123);
245 vst1q_f32(c4 + 4, vout4x4567);
246
247 a0 = (const int8_t*) ((uintptr_t) a0 - kc);
248 a1 = (const int8_t*) ((uintptr_t) a1 - kc);
249 a2 = (const int8_t*) ((uintptr_t) a2 - kc);
250 a3 = (const int8_t*) ((uintptr_t) a3 - kc);
251 a4 = (const int8_t*) ((uintptr_t) a4 - kc);
252
253 c0 = (float*) ((uintptr_t) c0 + cn_stride);
254 c1 = (float*) ((uintptr_t) c1 + cn_stride);
255 c2 = (float*) ((uintptr_t) c2 + cn_stride);
256 c3 = (float*) ((uintptr_t) c3 + cn_stride);
257 c4 = (float*) ((uintptr_t) c4 + cn_stride);
258
259 nc -= 8;
260 } else {
261 if (nc & 4) {
262 vst1q_f32(c0, vout0x0123); c0 += 4;
263 vout0x0123 = vout0x4567;
264 vst1q_f32(c1, vout1x0123); c1 += 4;
265 vout1x0123 = vout1x4567;
266 vst1q_f32(c2, vout2x0123); c2 += 4;
267 vout2x0123 = vout2x4567;
268 vst1q_f32(c3, vout3x0123); c3 += 4;
269 vout3x0123 = vout3x4567;
270 vst1q_f32(c4, vout4x0123); c4 += 4;
271 vout4x0123 = vout4x4567;
272 }
273 float32x2_t vout0x01 = vget_low_f32(vout0x0123);
274 float32x2_t vout1x01 = vget_low_f32(vout1x0123);
275 float32x2_t vout2x01 = vget_low_f32(vout2x0123);
276 float32x2_t vout3x01 = vget_low_f32(vout3x0123);
277 float32x2_t vout4x01 = vget_low_f32(vout4x0123);
278 if (nc & 2) {
279 vst1_f32(c0, vout0x01); c0 += 2;
280 vst1_f32(c1, vout1x01); c1 += 2;
281 vst1_f32(c2, vout2x01); c2 += 2;
282 vst1_f32(c3, vout3x01); c3 += 2;
283 vst1_f32(c4, vout4x01); c4 += 2;
284 vout0x01 = vget_high_f32(vout0x0123);
285 vout1x01 = vget_high_f32(vout1x0123);
286 vout2x01 = vget_high_f32(vout2x0123);
287 vout3x01 = vget_high_f32(vout3x0123);
288 vout4x01 = vget_high_f32(vout4x0123);
289 }
290 if (nc & 1) {
291 vst1_lane_f32(c0, vout0x01, 0);
292 vst1_lane_f32(c1, vout1x01, 0);
293 vst1_lane_f32(c2, vout2x01, 0);
294 vst1_lane_f32(c3, vout3x01, 0);
295 vst1_lane_f32(c4, vout4x01, 0);
296 }
297 nc = 0;
298 }
299 } while (nc != 0);
300 }