Debian Codegraph @

src/qd8-f32-qc8w-gemm/gen/qd8-f32-qc8w-gemm-3x16c4-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_3x16c4__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 <= 3);
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
56 // Loop over groups of 16 columns.
57 do {
58 // Initialize accumulators with bias. 16 bias values are loaded from the
59 // weight matrix, at the start of the group of 16 columns.
60 const int32x4_t vinput_zero_point01 = vld1q_s32(&quantization_params[0].zero_point);
61 const int32x4_t vksum0123 = vld1q_s32(w); w = (const int32_t*) w + 4;
62 int32x4_t vacc0x0123 = vmulq_lane_s32(vksum0123, vget_low_s32(vinput_zero_point01), 0);
63 int32x4_t vacc1x0123 = vmulq_lane_s32(vksum0123, vget_high_s32(vinput_zero_point01), 0);
64 const int32x4_t vksum4567 = vld1q_s32(w); w = (const int32_t*) w + 4;
65 int32x4_t vacc0x4567 = vmulq_lane_s32(vksum4567, vget_low_s32(vinput_zero_point01), 0);
66 int32x4_t vacc1x4567 = vmulq_lane_s32(vksum4567, vget_high_s32(vinput_zero_point01), 0);
67 const int32x4_t vksum89AB = vld1q_s32(w); w = (const int32_t*) w + 4;
68 int32x4_t vacc0x89AB = vmulq_lane_s32(vksum89AB, vget_low_s32(vinput_zero_point01), 0);
69 int32x4_t vacc1x89AB = vmulq_lane_s32(vksum89AB, vget_high_s32(vinput_zero_point01), 0);
70 const int32x4_t vksumCDEF = vld1q_s32(w); w = (const int32_t*) w + 4;
71 int32x4_t vacc0xCDEF = vmulq_lane_s32(vksumCDEF, vget_low_s32(vinput_zero_point01), 0);
72 int32x4_t vacc1xCDEF = vmulq_lane_s32(vksumCDEF, vget_high_s32(vinput_zero_point01), 0);
73 const int32x4_t vinput_zero_point2 = vld1q_dup_s32(&quantization_params[2].zero_point);
74 int32x4_t vacc2x0123 = vmulq_s32(vksum0123, vinput_zero_point2);
75 int32x4_t vacc2x4567 = vmulq_s32(vksum4567, vinput_zero_point2);
76 int32x4_t vacc2x89AB = vmulq_s32(vksum89AB, vinput_zero_point2);
77 int32x4_t vacc2xCDEF = vmulq_s32(vksumCDEF, vinput_zero_point2);
78
79 // Inner accumulation loop along the 16 columns.
80 size_t k = kc;
81 // 2x partial unrolled loop to load 8 bytes at a time.
82 while (k >= 8 * sizeof(int8_t)) {
83 // Load a 3x8 block of activations.
84 const int8x8_t va0x01234567 = vld1_s8(a0); a0 += 8;
85 const int8x8_t va1x01234567 = vld1_s8(a1); a1 += 8;
86 const int8x8_t va2x01234567 = vld1_s8(a2); a2 += 8;
87
88 // Load a 8x16 block of weights.
89 const int8x16_t vb0123x0123 = vld1q_s8(w); w = (const int8_t*) w + 16;
90 const int8x16_t vb0123x4567 = vld1q_s8(w); w = (const int8_t*) w + 16;
91 const int8x16_t vb0123x89AB = vld1q_s8(w); w = (const int8_t*) w + 16;
92 const int8x16_t vb0123xCDEF = vld1q_s8(w); w = (const int8_t*) w + 16;
93 const int8x16_t vb4567x0123 = vld1q_s8(w); w = (const int8_t*) w + 16;
94 const int8x16_t vb4567x4567 = vld1q_s8(w); w = (const int8_t*) w + 16;
95 const int8x16_t vb4567x89AB = vld1q_s8(w); w = (const int8_t*) w + 16;
96 const int8x16_t vb4567xCDEF = vld1q_s8(w); w = (const int8_t*) w + 16;
97
98 // Multiply-accumulate: 3x8 * 8x16 --> 3x16.
99 vacc0x0123 = vdotq_lane_s32(vacc0x0123, vb0123x0123, va0x01234567, 0);
100 vacc0x4567 = vdotq_lane_s32(vacc0x4567, vb0123x4567, va0x01234567, 0);
101 vacc0x89AB = vdotq_lane_s32(vacc0x89AB, vb0123x89AB, va0x01234567, 0);
102 vacc0xCDEF = vdotq_lane_s32(vacc0xCDEF, vb0123xCDEF, va0x01234567, 0);
103 vacc1x0123 = vdotq_lane_s32(vacc1x0123, vb0123x0123, va1x01234567, 0);
104 vacc1x4567 = vdotq_lane_s32(vacc1x4567, vb0123x4567, va1x01234567, 0);
105 vacc1x89AB = vdotq_lane_s32(vacc1x89AB, vb0123x89AB, va1x01234567, 0);
106 vacc1xCDEF = vdotq_lane_s32(vacc1xCDEF, vb0123xCDEF, va1x01234567, 0);
107 vacc2x0123 = vdotq_lane_s32(vacc2x0123, vb0123x0123, va2x01234567, 0);
108 vacc2x4567 = vdotq_lane_s32(vacc2x4567, vb0123x4567, va2x01234567, 0);
109 vacc2x89AB = vdotq_lane_s32(vacc2x89AB, vb0123x89AB, va2x01234567, 0);
110 vacc2xCDEF = vdotq_lane_s32(vacc2xCDEF, vb0123xCDEF, va2x01234567, 0);
111 vacc0x0123 = vdotq_lane_s32(vacc0x0123, vb4567x0123, va0x01234567, 1);
112 vacc0x4567 = vdotq_lane_s32(vacc0x4567, vb4567x4567, va0x01234567, 1);
113 vacc0x89AB = vdotq_lane_s32(vacc0x89AB, vb4567x89AB, va0x01234567, 1);
114 vacc0xCDEF = vdotq_lane_s32(vacc0xCDEF, vb4567xCDEF, va0x01234567, 1);
115 vacc1x0123 = vdotq_lane_s32(vacc1x0123, vb4567x0123, va1x01234567, 1);
116 vacc1x4567 = vdotq_lane_s32(vacc1x4567, vb4567x4567, va1x01234567, 1);
117 vacc1x89AB = vdotq_lane_s32(vacc1x89AB, vb4567x89AB, va1x01234567, 1);
118 vacc1xCDEF = vdotq_lane_s32(vacc1xCDEF, vb4567xCDEF, va1x01234567, 1);
119 vacc2x0123 = vdotq_lane_s32(vacc2x0123, vb4567x0123, va2x01234567, 1);
120 vacc2x4567 = vdotq_lane_s32(vacc2x4567, vb4567x4567, va2x01234567, 1);
121 vacc2x89AB = vdotq_lane_s32(vacc2x89AB, vb4567x89AB, va2x01234567, 1);
122 vacc2xCDEF = vdotq_lane_s32(vacc2xCDEF, vb4567xCDEF, va2x01234567, 1);
123
124 k -= 8 * sizeof(int8_t);
125 }
126 // Handle up to 4 final positions of `k`
127 if XNN_UNLIKELY(k != 0) {
128 // Load a 3x4 block of activations.
129 const int8x8_t va0x01234567 = vld1_s8(a0); a0 += 4;
130 const int8x8_t va1x01234567 = vld1_s8(a1); a1 += 4;
131 const int8x8_t va2x01234567 = vld1_s8(a2); a2 += 4;
132
133 // Load a 4x16 block of weights.
134 const int8x16_t vb0123x0123 = vld1q_s8(w); w = (const int8_t*) w + 16;
135 const int8x16_t vb0123x4567 = vld1q_s8(w); w = (const int8_t*) w + 16;
136 const int8x16_t vb0123x89AB = vld1q_s8(w); w = (const int8_t*) w + 16;
137 const int8x16_t vb0123xCDEF = vld1q_s8(w); w = (const int8_t*) w + 16;
138
139 // Multiply-accumulate: 3x4 * 4x16 --> 3x16.
140 vacc0x0123 = vdotq_lane_s32(vacc0x0123, vb0123x0123, va0x01234567, 0);
141 vacc0x4567 = vdotq_lane_s32(vacc0x4567, vb0123x4567, va0x01234567, 0);
142 vacc0x89AB = vdotq_lane_s32(vacc0x89AB, vb0123x89AB, va0x01234567, 0);
143 vacc0xCDEF = vdotq_lane_s32(vacc0xCDEF, vb0123xCDEF, va0x01234567, 0);
144 vacc1x0123 = vdotq_lane_s32(vacc1x0123, vb0123x0123, va1x01234567, 0);
145 vacc1x4567 = vdotq_lane_s32(vacc1x4567, vb0123x4567, va1x01234567, 0);
146 vacc1x89AB = vdotq_lane_s32(vacc1x89AB, vb0123x89AB, va1x01234567, 0);
147 vacc1xCDEF = vdotq_lane_s32(vacc1xCDEF, vb0123xCDEF, va1x01234567, 0);
148 vacc2x0123 = vdotq_lane_s32(vacc2x0123, vb0123x0123, va2x01234567, 0);
149 vacc2x4567 = vdotq_lane_s32(vacc2x4567, vb0123x4567, va2x01234567, 0);
150 vacc2x89AB = vdotq_lane_s32(vacc2x89AB, vb0123x89AB, va2x01234567, 0);
151 vacc2xCDEF = vdotq_lane_s32(vacc2xCDEF, vb0123xCDEF, va2x01234567, 0);
152 }
153
154 float32x4_t vout0x0123 = vcvtq_f32_s32(vacc0x0123);
155 float32x4_t vout0x4567 = vcvtq_f32_s32(vacc0x4567);
156 float32x4_t vout0x89AB = vcvtq_f32_s32(vacc0x89AB);
157 float32x4_t vout0xCDEF = vcvtq_f32_s32(vacc0xCDEF);
158 float32x4_t vout1x0123 = vcvtq_f32_s32(vacc1x0123);
159 float32x4_t vout1x4567 = vcvtq_f32_s32(vacc1x4567);
160 float32x4_t vout1x89AB = vcvtq_f32_s32(vacc1x89AB);
161 float32x4_t vout1xCDEF = vcvtq_f32_s32(vacc1xCDEF);
162 float32x4_t vout2x0123 = vcvtq_f32_s32(vacc2x0123);
163 float32x4_t vout2x4567 = vcvtq_f32_s32(vacc2x4567);
164 float32x4_t vout2x89AB = vcvtq_f32_s32(vacc2x89AB);
165 float32x4_t vout2xCDEF = vcvtq_f32_s32(vacc2xCDEF);
166 const float32x4_t vinput_scale01 = vreinterpretq_f32_s32(vld1q_s32(&quantization_params[0].zero_point));
167 vout0x0123 = vmulq_lane_f32(vout0x0123, vget_low_f32(vinput_scale01), 1);
168 vout1x0123 = vmulq_lane_f32(vout1x0123, vget_high_f32(vinput_scale01), 1);
169 vout0x4567 = vmulq_lane_f32(vout0x4567, vget_low_f32(vinput_scale01), 1);
170 vout1x4567 = vmulq_lane_f32(vout1x4567, vget_high_f32(vinput_scale01), 1);
171 vout0x89AB = vmulq_lane_f32(vout0x89AB, vget_low_f32(vinput_scale01), 1);
172 vout1x89AB = vmulq_lane_f32(vout1x89AB, vget_high_f32(vinput_scale01), 1);
173 vout0xCDEF = vmulq_lane_f32(vout0xCDEF, vget_low_f32(vinput_scale01), 1);
174 vout1xCDEF = vmulq_lane_f32(vout1xCDEF, vget_high_f32(vinput_scale01), 1);
175 const float32x4_t vinput_scale2 = vld1q_dup_f32(&quantization_params[2].inv_scale);
176 vout2x0123 = vmulq_f32(vout2x0123, vinput_scale2);
177 vout2x4567 = vmulq_f32(vout2x4567, vinput_scale2);
178 vout2x89AB = vmulq_f32(vout2x89AB, vinput_scale2);
179 vout2xCDEF = vmulq_f32(vout2xCDEF, vinput_scale2);
180
181 const float32x4_t vfilter_output_scale0123 = vld1q_f32(w); w = (const float*) w + 4;
182 const float32x4_t vfilter_output_scale4567 = vld1q_f32(w); w = (const float*) w + 4;
183 const float32x4_t vfilter_output_scale89AB = vld1q_f32(w); w = (const float*) w + 4;
184 const float32x4_t vfilter_output_scaleCDEF = vld1q_f32(w); w = (const float*) w + 4;
185
186 const float32x4_t vbias0123 = vld1q_f32(w); w = (const float*) w + 4;
187 #if XNN_ARCH_ARM64
188 vout0x0123 = vfmaq_f32(vbias0123, vout0x0123, vfilter_output_scale0123);
189 vout1x0123 = vfmaq_f32(vbias0123, vout1x0123, vfilter_output_scale0123);
190 vout2x0123 = vfmaq_f32(vbias0123, vout2x0123, vfilter_output_scale0123);
191 #else
192 vout0x0123 = vmlaq_f32(vbias0123, vout0x0123, vfilter_output_scale0123);
193 vout1x0123 = vmlaq_f32(vbias0123, vout1x0123, vfilter_output_scale0123);
194 vout2x0123 = vmlaq_f32(vbias0123, vout2x0123, 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 #else
202 vout0x4567 = vmlaq_f32(vbias4567, vout0x4567, vfilter_output_scale4567);
203 vout1x4567 = vmlaq_f32(vbias4567, vout1x4567, vfilter_output_scale4567);
204 vout2x4567 = vmlaq_f32(vbias4567, vout2x4567, vfilter_output_scale4567);
205 #endif
206 const float32x4_t vbias89AB = vld1q_f32(w); w = (const float*) w + 4;
207 #if XNN_ARCH_ARM64
208 vout0x89AB = vfmaq_f32(vbias89AB, vout0x89AB, vfilter_output_scale89AB);
209 vout1x89AB = vfmaq_f32(vbias89AB, vout1x89AB, vfilter_output_scale89AB);
210 vout2x89AB = vfmaq_f32(vbias89AB, vout2x89AB, vfilter_output_scale89AB);
211 #else
212 vout0x89AB = vmlaq_f32(vbias89AB, vout0x89AB, vfilter_output_scale89AB);
213 vout1x89AB = vmlaq_f32(vbias89AB, vout1x89AB, vfilter_output_scale89AB);
214 vout2x89AB = vmlaq_f32(vbias89AB, vout2x89AB, vfilter_output_scale89AB);
215 #endif
216 const float32x4_t vbiasCDEF = vld1q_f32(w); w = (const float*) w + 4;
217 #if XNN_ARCH_ARM64
218 vout0xCDEF = vfmaq_f32(vbiasCDEF, vout0xCDEF, vfilter_output_scaleCDEF);
219 vout1xCDEF = vfmaq_f32(vbiasCDEF, vout1xCDEF, vfilter_output_scaleCDEF);
220 vout2xCDEF = vfmaq_f32(vbiasCDEF, vout2xCDEF, vfilter_output_scaleCDEF);
221 #else
222 vout0xCDEF = vmlaq_f32(vbiasCDEF, vout0xCDEF, vfilter_output_scaleCDEF);
223 vout1xCDEF = vmlaq_f32(vbiasCDEF, vout1xCDEF, vfilter_output_scaleCDEF);
224 vout2xCDEF = vmlaq_f32(vbiasCDEF, vout2xCDEF, vfilter_output_scaleCDEF);
225 #endif
226
227 const float32x4_t voutput_min = vld1q_dup_f32(&params->scalar.min);
228 vout0x0123 = vmaxq_f32(vout0x0123, voutput_min);
229 vout0x4567 = vmaxq_f32(vout0x4567, voutput_min);
230 vout0x89AB = vmaxq_f32(vout0x89AB, voutput_min);
231 vout0xCDEF = vmaxq_f32(vout0xCDEF, voutput_min);
232 vout1x0123 = vmaxq_f32(vout1x0123, voutput_min);
233 vout1x4567 = vmaxq_f32(vout1x4567, voutput_min);
234 vout1x89AB = vmaxq_f32(vout1x89AB, voutput_min);
235 vout1xCDEF = vmaxq_f32(vout1xCDEF, voutput_min);
236 vout2x0123 = vmaxq_f32(vout2x0123, voutput_min);
237 vout2x4567 = vmaxq_f32(vout2x4567, voutput_min);
238 vout2x89AB = vmaxq_f32(vout2x89AB, voutput_min);
239 vout2xCDEF = vmaxq_f32(vout2xCDEF, voutput_min);
240
241 const float32x4_t voutput_max = vld1q_dup_f32(&params->scalar.max);
242 vout0x0123 = vminq_f32(vout0x0123, voutput_max);
243 vout0x4567 = vminq_f32(vout0x4567, voutput_max);
244 vout0x89AB = vminq_f32(vout0x89AB, voutput_max);
245 vout0xCDEF = vminq_f32(vout0xCDEF, voutput_max);
246 vout1x0123 = vminq_f32(vout1x0123, voutput_max);
247 vout1x4567 = vminq_f32(vout1x4567, voutput_max);
248 vout1x89AB = vminq_f32(vout1x89AB, voutput_max);
249 vout1xCDEF = vminq_f32(vout1xCDEF, voutput_max);
250 vout2x0123 = vminq_f32(vout2x0123, voutput_max);
251 vout2x4567 = vminq_f32(vout2x4567, voutput_max);
252 vout2x89AB = vminq_f32(vout2x89AB, voutput_max);
253 vout2xCDEF = vminq_f32(vout2xCDEF, voutput_max);
254
255 if XNN_LIKELY(nc >= 16) {
256 vst1q_f32(c0, vout0x0123);
257 vst1q_f32(c0 + 4, vout0x4567);
258 vst1q_f32(c0 + 8, vout0x89AB);
259 vst1q_f32(c0 + 12, vout0xCDEF);
260 vst1q_f32(c1, vout1x0123);
261 vst1q_f32(c1 + 4, vout1x4567);
262 vst1q_f32(c1 + 8, vout1x89AB);
263 vst1q_f32(c1 + 12, vout1xCDEF);
264 vst1q_f32(c2, vout2x0123);
265 vst1q_f32(c2 + 4, vout2x4567);
266 vst1q_f32(c2 + 8, vout2x89AB);
267 vst1q_f32(c2 + 12, vout2xCDEF);
268
269 a0 = (const int8_t*) ((uintptr_t) a0 - kc);
270 a1 = (const int8_t*) ((uintptr_t) a1 - kc);
271 a2 = (const int8_t*) ((uintptr_t) a2 - kc);
272
273 c0 = (float*) ((uintptr_t) c0 + cn_stride);
274 c1 = (float*) ((uintptr_t) c1 + cn_stride);
275 c2 = (float*) ((uintptr_t) c2 + cn_stride);
276
277 nc -= 16;
278 } else {
279 if (nc & 8) {
280 vst1q_f32(c0, vout0x0123); c0 += 4;
281 vout0x0123 = vout0x89AB;
282 vst1q_f32(c1, vout1x0123); c1 += 4;
283 vout1x0123 = vout1x89AB;
284 vst1q_f32(c2, vout2x0123); c2 += 4;
285 vout2x0123 = vout2x89AB;
286 vst1q_f32(c0, vout0x4567); c0 += 4;
287 vout0x4567 = vout0xCDEF;
288 vst1q_f32(c1, vout1x4567); c1 += 4;
289 vout1x4567 = vout1xCDEF;
290 vst1q_f32(c2, vout2x4567); c2 += 4;
291 vout2x4567 = vout2xCDEF;
292 }
293 if (nc & 4) {
294 vst1q_f32(c0, vout0x0123); c0 += 4;
295 vout0x0123 = vout0x4567;
296 vst1q_f32(c1, vout1x0123); c1 += 4;
297 vout1x0123 = vout1x4567;
298 vst1q_f32(c2, vout2x0123); c2 += 4;
299 vout2x0123 = vout2x4567;
300 }
301 float32x2_t vout0x01 = vget_low_f32(vout0x0123);
302 float32x2_t vout1x01 = vget_low_f32(vout1x0123);
303 float32x2_t vout2x01 = vget_low_f32(vout2x0123);
304 if (nc & 2) {
305 vst1_f32(c0, vout0x01); c0 += 2;
306 vst1_f32(c1, vout1x01); c1 += 2;
307 vst1_f32(c2, vout2x01); c2 += 2;
308 vout0x01 = vget_high_f32(vout0x0123);
309 vout1x01 = vget_high_f32(vout1x0123);
310 vout2x01 = vget_high_f32(vout2x0123);
311 }
312 if (nc & 1) {
313 vst1_lane_f32(c0, vout0x01, 0);
314 vst1_lane_f32(c1, vout1x01, 0);
315 vst1_lane_f32(c2, vout2x01, 0);
316 }
317 nc = 0;
318 }
319 } while (nc != 0);
320 }