Debian Codegraph @

src/qd8-f32-qc8w-gemm/gen/qd8-f32-qc8w-gemm-6x8c4-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_6x8c4__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 <= 6);
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 const int8_t* a5 = (const int8_t*) ((uintptr_t) a4 + a_stride);
68 float* c5 = (float*) ((uintptr_t) c4 + cm_stride);
69 if XNN_UNPREDICTABLE(mr != 6) {
70 a5 = a4;
71 c5 = c4;
72 }
73
74 // Loop over groups of 8 columns.
75 do {
76 // Initialize accumulators with bias. 8 bias values are loaded from the
77 // weight matrix, at the start of the group of 8 columns.
78 const int32x4_t vinput_zero_point01 = vld1q_s32(&quantization_params[0].zero_point);
79 const int32x4_t vksum0123 = vld1q_s32(w); w = (const int32_t*) w + 4;
80 int32x4_t vacc0x0123 = vmulq_lane_s32(vksum0123, vget_low_s32(vinput_zero_point01), 0);
81 int32x4_t vacc1x0123 = vmulq_lane_s32(vksum0123, vget_high_s32(vinput_zero_point01), 0);
82 const int32x4_t vksum4567 = vld1q_s32(w); w = (const int32_t*) w + 4;
83 int32x4_t vacc0x4567 = vmulq_lane_s32(vksum4567, vget_low_s32(vinput_zero_point01), 0);
84 int32x4_t vacc1x4567 = vmulq_lane_s32(vksum4567, vget_high_s32(vinput_zero_point01), 0);
85 const int32x4_t vinput_zero_point23 = vld1q_s32(&quantization_params[2].zero_point);
86 int32x4_t vacc2x0123 = vmulq_lane_s32(vksum0123, vget_low_s32(vinput_zero_point23), 0);
87 int32x4_t vacc3x0123 = vmulq_lane_s32(vksum0123, vget_high_s32(vinput_zero_point23), 0);
88 int32x4_t vacc2x4567 = vmulq_lane_s32(vksum4567, vget_low_s32(vinput_zero_point23), 0);
89 int32x4_t vacc3x4567 = vmulq_lane_s32(vksum4567, vget_high_s32(vinput_zero_point23), 0);
90 const int32x4_t vinput_zero_point45 = vld1q_s32(&quantization_params[4].zero_point);
91 int32x4_t vacc4x0123 = vmulq_lane_s32(vksum0123, vget_low_s32(vinput_zero_point45), 0);
92 int32x4_t vacc5x0123 = vmulq_lane_s32(vksum0123, vget_high_s32(vinput_zero_point45), 0);
93 int32x4_t vacc4x4567 = vmulq_lane_s32(vksum4567, vget_low_s32(vinput_zero_point45), 0);
94 int32x4_t vacc5x4567 = vmulq_lane_s32(vksum4567, vget_high_s32(vinput_zero_point45), 0);
95
96 // Inner accumulation loop along the 8 columns.
97 size_t k = kc;
98 // 2x partial unrolled loop to load 8 bytes at a time.
99 while (k >= 8 * sizeof(int8_t)) {
100 // Load a 6x8 block of activations.
101 const int8x8_t va0x01234567 = vld1_s8(a0); a0 += 8;
102 const int8x8_t va1x01234567 = vld1_s8(a1); a1 += 8;
103 const int8x8_t va2x01234567 = vld1_s8(a2); a2 += 8;
104 const int8x8_t va3x01234567 = vld1_s8(a3); a3 += 8;
105 const int8x8_t va4x01234567 = vld1_s8(a4); a4 += 8;
106 const int8x8_t va5x01234567 = vld1_s8(a5); a5 += 8;
107
108 // Load a 8x8 block of weights.
109 const int8x16_t vb0123x0123 = vld1q_s8(w); w = (const int8_t*) w + 16;
110 const int8x16_t vb0123x4567 = vld1q_s8(w); w = (const int8_t*) w + 16;
111 const int8x16_t vb4567x0123 = vld1q_s8(w); w = (const int8_t*) w + 16;
112 const int8x16_t vb4567x4567 = vld1q_s8(w); w = (const int8_t*) w + 16;
113
114 // Multiply-accumulate: 6x8 * 8x8 --> 6x8.
115 vacc0x0123 = vdotq_lane_s32(vacc0x0123, vb0123x0123, va0x01234567, 0);
116 vacc0x4567 = vdotq_lane_s32(vacc0x4567, vb0123x4567, va0x01234567, 0);
117 vacc1x0123 = vdotq_lane_s32(vacc1x0123, vb0123x0123, va1x01234567, 0);
118 vacc1x4567 = vdotq_lane_s32(vacc1x4567, vb0123x4567, va1x01234567, 0);
119 vacc2x0123 = vdotq_lane_s32(vacc2x0123, vb0123x0123, va2x01234567, 0);
120 vacc2x4567 = vdotq_lane_s32(vacc2x4567, vb0123x4567, va2x01234567, 0);
121 vacc3x0123 = vdotq_lane_s32(vacc3x0123, vb0123x0123, va3x01234567, 0);
122 vacc3x4567 = vdotq_lane_s32(vacc3x4567, vb0123x4567, va3x01234567, 0);
123 vacc4x0123 = vdotq_lane_s32(vacc4x0123, vb0123x0123, va4x01234567, 0);
124 vacc4x4567 = vdotq_lane_s32(vacc4x4567, vb0123x4567, va4x01234567, 0);
125 vacc5x0123 = vdotq_lane_s32(vacc5x0123, vb0123x0123, va5x01234567, 0);
126 vacc5x4567 = vdotq_lane_s32(vacc5x4567, vb0123x4567, va5x01234567, 0);
127 vacc0x0123 = vdotq_lane_s32(vacc0x0123, vb4567x0123, va0x01234567, 1);
128 vacc0x4567 = vdotq_lane_s32(vacc0x4567, vb4567x4567, va0x01234567, 1);
129 vacc1x0123 = vdotq_lane_s32(vacc1x0123, vb4567x0123, va1x01234567, 1);
130 vacc1x4567 = vdotq_lane_s32(vacc1x4567, vb4567x4567, va1x01234567, 1);
131 vacc2x0123 = vdotq_lane_s32(vacc2x0123, vb4567x0123, va2x01234567, 1);
132 vacc2x4567 = vdotq_lane_s32(vacc2x4567, vb4567x4567, va2x01234567, 1);
133 vacc3x0123 = vdotq_lane_s32(vacc3x0123, vb4567x0123, va3x01234567, 1);
134 vacc3x4567 = vdotq_lane_s32(vacc3x4567, vb4567x4567, va3x01234567, 1);
135 vacc4x0123 = vdotq_lane_s32(vacc4x0123, vb4567x0123, va4x01234567, 1);
136 vacc4x4567 = vdotq_lane_s32(vacc4x4567, vb4567x4567, va4x01234567, 1);
137 vacc5x0123 = vdotq_lane_s32(vacc5x0123, vb4567x0123, va5x01234567, 1);
138 vacc5x4567 = vdotq_lane_s32(vacc5x4567, vb4567x4567, va5x01234567, 1);
139
140 k -= 8 * sizeof(int8_t);
141 }
142 // Handle up to 4 final positions of `k`
143 if XNN_UNLIKELY(k != 0) {
144 // Load a 6x4 block of activations.
145 const int8x8_t va0x01234567 = vld1_s8(a0); a0 += 4;
146 const int8x8_t va1x01234567 = vld1_s8(a1); a1 += 4;
147 const int8x8_t va2x01234567 = vld1_s8(a2); a2 += 4;
148 const int8x8_t va3x01234567 = vld1_s8(a3); a3 += 4;
149 const int8x8_t va4x01234567 = vld1_s8(a4); a4 += 4;
150 const int8x8_t va5x01234567 = vld1_s8(a5); a5 += 4;
151
152 // Load a 4x8 block of weights.
153 const int8x16_t vb0123x0123 = vld1q_s8(w); w = (const int8_t*) w + 16;
154 const int8x16_t vb0123x4567 = vld1q_s8(w); w = (const int8_t*) w + 16;
155
156 // Multiply-accumulate: 6x4 * 4x8 --> 6x8.
157 vacc0x0123 = vdotq_lane_s32(vacc0x0123, vb0123x0123, va0x01234567, 0);
158 vacc0x4567 = vdotq_lane_s32(vacc0x4567, vb0123x4567, va0x01234567, 0);
159 vacc1x0123 = vdotq_lane_s32(vacc1x0123, vb0123x0123, va1x01234567, 0);
160 vacc1x4567 = vdotq_lane_s32(vacc1x4567, vb0123x4567, va1x01234567, 0);
161 vacc2x0123 = vdotq_lane_s32(vacc2x0123, vb0123x0123, va2x01234567, 0);
162 vacc2x4567 = vdotq_lane_s32(vacc2x4567, vb0123x4567, va2x01234567, 0);
163 vacc3x0123 = vdotq_lane_s32(vacc3x0123, vb0123x0123, va3x01234567, 0);
164 vacc3x4567 = vdotq_lane_s32(vacc3x4567, vb0123x4567, va3x01234567, 0);
165 vacc4x0123 = vdotq_lane_s32(vacc4x0123, vb0123x0123, va4x01234567, 0);
166 vacc4x4567 = vdotq_lane_s32(vacc4x4567, vb0123x4567, va4x01234567, 0);
167 vacc5x0123 = vdotq_lane_s32(vacc5x0123, vb0123x0123, va5x01234567, 0);
168 vacc5x4567 = vdotq_lane_s32(vacc5x4567, vb0123x4567, va5x01234567, 0);
169 }
170
171 float32x4_t vout0x0123 = vcvtq_f32_s32(vacc0x0123);
172 float32x4_t vout0x4567 = vcvtq_f32_s32(vacc0x4567);
173 float32x4_t vout1x0123 = vcvtq_f32_s32(vacc1x0123);
174 float32x4_t vout1x4567 = vcvtq_f32_s32(vacc1x4567);
175 float32x4_t vout2x0123 = vcvtq_f32_s32(vacc2x0123);
176 float32x4_t vout2x4567 = vcvtq_f32_s32(vacc2x4567);
177 float32x4_t vout3x0123 = vcvtq_f32_s32(vacc3x0123);
178 float32x4_t vout3x4567 = vcvtq_f32_s32(vacc3x4567);
179 float32x4_t vout4x0123 = vcvtq_f32_s32(vacc4x0123);
180 float32x4_t vout4x4567 = vcvtq_f32_s32(vacc4x4567);
181 float32x4_t vout5x0123 = vcvtq_f32_s32(vacc5x0123);
182 float32x4_t vout5x4567 = vcvtq_f32_s32(vacc5x4567);
183 const float32x4_t vinput_scale01 = vreinterpretq_f32_s32(vld1q_s32(&quantization_params[0].zero_point));
184 vout0x0123 = vmulq_lane_f32(vout0x0123, vget_low_f32(vinput_scale01), 1);
185 vout1x0123 = vmulq_lane_f32(vout1x0123, vget_high_f32(vinput_scale01), 1);
186 vout0x4567 = vmulq_lane_f32(vout0x4567, vget_low_f32(vinput_scale01), 1);
187 vout1x4567 = vmulq_lane_f32(vout1x4567, vget_high_f32(vinput_scale01), 1);
188 const float32x4_t vinput_scale23 = vreinterpretq_f32_s32(vld1q_s32(&quantization_params[2].zero_point));
189 vout2x0123 = vmulq_lane_f32(vout2x0123, vget_low_f32(vinput_scale23), 1);
190 vout3x0123 = vmulq_lane_f32(vout3x0123, vget_high_f32(vinput_scale23), 1);
191 vout2x4567 = vmulq_lane_f32(vout2x4567, vget_low_f32(vinput_scale23), 1);
192 vout3x4567 = vmulq_lane_f32(vout3x4567, vget_high_f32(vinput_scale23), 1);
193 const float32x4_t vinput_scale45 = vreinterpretq_f32_s32(vld1q_s32(&quantization_params[4].zero_point));
194 vout4x0123 = vmulq_lane_f32(vout4x0123, vget_low_f32(vinput_scale45), 1);
195 vout5x0123 = vmulq_lane_f32(vout5x0123, vget_high_f32(vinput_scale45), 1);
196 vout4x4567 = vmulq_lane_f32(vout4x4567, vget_low_f32(vinput_scale45), 1);
197 vout5x4567 = vmulq_lane_f32(vout5x4567, vget_high_f32(vinput_scale45), 1);
198
199 const float32x4_t vfilter_output_scale0123 = vld1q_f32(w); w = (const float*) w + 4;
200 const float32x4_t vfilter_output_scale4567 = vld1q_f32(w); w = (const float*) w + 4;
201
202 const float32x4_t vbias0123 = vld1q_f32(w); w = (const float*) w + 4;
203 #if XNN_ARCH_ARM64
204 vout0x0123 = vfmaq_f32(vbias0123, vout0x0123, vfilter_output_scale0123);
205 vout1x0123 = vfmaq_f32(vbias0123, vout1x0123, vfilter_output_scale0123);
206 vout2x0123 = vfmaq_f32(vbias0123, vout2x0123, vfilter_output_scale0123);
207 vout3x0123 = vfmaq_f32(vbias0123, vout3x0123, vfilter_output_scale0123);
208 vout4x0123 = vfmaq_f32(vbias0123, vout4x0123, vfilter_output_scale0123);
209 vout5x0123 = vfmaq_f32(vbias0123, vout5x0123, vfilter_output_scale0123);
210 #else
211 vout0x0123 = vmlaq_f32(vbias0123, vout0x0123, vfilter_output_scale0123);
212 vout1x0123 = vmlaq_f32(vbias0123, vout1x0123, vfilter_output_scale0123);
213 vout2x0123 = vmlaq_f32(vbias0123, vout2x0123, vfilter_output_scale0123);
214 vout3x0123 = vmlaq_f32(vbias0123, vout3x0123, vfilter_output_scale0123);
215 vout4x0123 = vmlaq_f32(vbias0123, vout4x0123, vfilter_output_scale0123);
216 vout5x0123 = vmlaq_f32(vbias0123, vout5x0123, vfilter_output_scale0123);
217 #endif
218 const float32x4_t vbias4567 = vld1q_f32(w); w = (const float*) w + 4;
219 #if XNN_ARCH_ARM64
220 vout0x4567 = vfmaq_f32(vbias4567, vout0x4567, vfilter_output_scale4567);
221 vout1x4567 = vfmaq_f32(vbias4567, vout1x4567, vfilter_output_scale4567);
222 vout2x4567 = vfmaq_f32(vbias4567, vout2x4567, vfilter_output_scale4567);
223 vout3x4567 = vfmaq_f32(vbias4567, vout3x4567, vfilter_output_scale4567);
224 vout4x4567 = vfmaq_f32(vbias4567, vout4x4567, vfilter_output_scale4567);
225 vout5x4567 = vfmaq_f32(vbias4567, vout5x4567, vfilter_output_scale4567);
226 #else
227 vout0x4567 = vmlaq_f32(vbias4567, vout0x4567, vfilter_output_scale4567);
228 vout1x4567 = vmlaq_f32(vbias4567, vout1x4567, vfilter_output_scale4567);
229 vout2x4567 = vmlaq_f32(vbias4567, vout2x4567, vfilter_output_scale4567);
230 vout3x4567 = vmlaq_f32(vbias4567, vout3x4567, vfilter_output_scale4567);
231 vout4x4567 = vmlaq_f32(vbias4567, vout4x4567, vfilter_output_scale4567);
232 vout5x4567 = vmlaq_f32(vbias4567, vout5x4567, vfilter_output_scale4567);
233 #endif
234
235 const float32x4_t voutput_min = vld1q_dup_f32(&params->scalar.min);
236 vout0x0123 = vmaxq_f32(vout0x0123, voutput_min);
237 vout0x4567 = vmaxq_f32(vout0x4567, voutput_min);
238 vout1x0123 = vmaxq_f32(vout1x0123, voutput_min);
239 vout1x4567 = vmaxq_f32(vout1x4567, voutput_min);
240 vout2x0123 = vmaxq_f32(vout2x0123, voutput_min);
241 vout2x4567 = vmaxq_f32(vout2x4567, voutput_min);
242 vout3x0123 = vmaxq_f32(vout3x0123, voutput_min);
243 vout3x4567 = vmaxq_f32(vout3x4567, voutput_min);
244 vout4x0123 = vmaxq_f32(vout4x0123, voutput_min);
245 vout4x4567 = vmaxq_f32(vout4x4567, voutput_min);
246 vout5x0123 = vmaxq_f32(vout5x0123, voutput_min);
247 vout5x4567 = vmaxq_f32(vout5x4567, voutput_min);
248
249 const float32x4_t voutput_max = vld1q_dup_f32(&params->scalar.max);
250 vout0x0123 = vminq_f32(vout0x0123, voutput_max);
251 vout0x4567 = vminq_f32(vout0x4567, voutput_max);
252 vout1x0123 = vminq_f32(vout1x0123, voutput_max);
253 vout1x4567 = vminq_f32(vout1x4567, voutput_max);
254 vout2x0123 = vminq_f32(vout2x0123, voutput_max);
255 vout2x4567 = vminq_f32(vout2x4567, voutput_max);
256 vout3x0123 = vminq_f32(vout3x0123, voutput_max);
257 vout3x4567 = vminq_f32(vout3x4567, voutput_max);
258 vout4x0123 = vminq_f32(vout4x0123, voutput_max);
259 vout4x4567 = vminq_f32(vout4x4567, voutput_max);
260 vout5x0123 = vminq_f32(vout5x0123, voutput_max);
261 vout5x4567 = vminq_f32(vout5x4567, voutput_max);
262
263 if XNN_LIKELY(nc >= 8) {
264 vst1q_f32(c0, vout0x0123);
265 vst1q_f32(c0 + 4, vout0x4567);
266 vst1q_f32(c1, vout1x0123);
267 vst1q_f32(c1 + 4, vout1x4567);
268 vst1q_f32(c2, vout2x0123);
269 vst1q_f32(c2 + 4, vout2x4567);
270 vst1q_f32(c3, vout3x0123);
271 vst1q_f32(c3 + 4, vout3x4567);
272 vst1q_f32(c4, vout4x0123);
273 vst1q_f32(c4 + 4, vout4x4567);
274 vst1q_f32(c5, vout5x0123);
275 vst1q_f32(c5 + 4, vout5x4567);
276
277 a0 = (const int8_t*) ((uintptr_t) a0 - kc);
278 a1 = (const int8_t*) ((uintptr_t) a1 - kc);
279 a2 = (const int8_t*) ((uintptr_t) a2 - kc);
280 a3 = (const int8_t*) ((uintptr_t) a3 - kc);
281 a4 = (const int8_t*) ((uintptr_t) a4 - kc);
282 a5 = (const int8_t*) ((uintptr_t) a5 - kc);
283
284 c0 = (float*) ((uintptr_t) c0 + cn_stride);
285 c1 = (float*) ((uintptr_t) c1 + cn_stride);
286 c2 = (float*) ((uintptr_t) c2 + cn_stride);
287 c3 = (float*) ((uintptr_t) c3 + cn_stride);
288 c4 = (float*) ((uintptr_t) c4 + cn_stride);
289 c5 = (float*) ((uintptr_t) c5 + cn_stride);
290
291 nc -= 8;
292 } else {
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 vst1q_f32(c3, vout3x0123); c3 += 4;
301 vout3x0123 = vout3x4567;
302 vst1q_f32(c4, vout4x0123); c4 += 4;
303 vout4x0123 = vout4x4567;
304 vst1q_f32(c5, vout5x0123); c5 += 4;
305 vout5x0123 = vout5x4567;
306 }
307 float32x2_t vout0x01 = vget_low_f32(vout0x0123);
308 float32x2_t vout1x01 = vget_low_f32(vout1x0123);
309 float32x2_t vout2x01 = vget_low_f32(vout2x0123);
310 float32x2_t vout3x01 = vget_low_f32(vout3x0123);
311 float32x2_t vout4x01 = vget_low_f32(vout4x0123);
312 float32x2_t vout5x01 = vget_low_f32(vout5x0123);
313 if (nc & 2) {
314 vst1_f32(c0, vout0x01); c0 += 2;
315 vst1_f32(c1, vout1x01); c1 += 2;
316 vst1_f32(c2, vout2x01); c2 += 2;
317 vst1_f32(c3, vout3x01); c3 += 2;
318 vst1_f32(c4, vout4x01); c4 += 2;
319 vst1_f32(c5, vout5x01); c5 += 2;
320 vout0x01 = vget_high_f32(vout0x0123);
321 vout1x01 = vget_high_f32(vout1x0123);
322 vout2x01 = vget_high_f32(vout2x0123);
323 vout3x01 = vget_high_f32(vout3x0123);
324 vout4x01 = vget_high_f32(vout4x0123);
325 vout5x01 = vget_high_f32(vout5x0123);
326 }
327 if (nc & 1) {
328 vst1_lane_f32(c0, vout0x01, 0);
329 vst1_lane_f32(c1, vout1x01, 0);
330 vst1_lane_f32(c2, vout2x01, 0);
331 vst1_lane_f32(c3, vout3x01, 0);
332 vst1_lane_f32(c4, vout4x01, 0);
333 vst1_lane_f32(c5, vout5x01, 0);
334 }
335 nc = 0;
336 }
337 } while (nc != 0);
338 }