Debian Codegraph @

src/qd8-f32-qc4w-gemm/gen/qd8-f32-qc4w-gemm-1x64c4-minmax-avx512amx.c

raw
1 // Auto-generated file. Do not edit!
2 // Template: src/qs8-gemm/c4-avx512amx.c.in
3 // Generator: tools/xngen
4 //
5 // Copyright 2024 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 <immintrin.h>
13
14 #include "xnnpack/common.h"
15 #include "xnnpack/gemm.h"
16 #include "xnnpack/intrinsics-polyfill.h"
17 #include "xnnpack/math.h"
18 #include "xnnpack/unaligned.h"
19
20
21 void xnn_qd8_f32_qc4w_gemm_minmax_ukernel_1x64c4__avx512amx(
22 size_t mr,
23 size_t nc,
24 size_t kc,
25 const int8_t* restrict a,
26 size_t a_stride,
27 const void* restrict w,
28 float* restrict c,
29 size_t cm_stride,
30 size_t cn_stride,
31 const struct xnn_f32_qc4w_minmax_params params[restrict XNN_MIN_ELEMENTS(1)],
32 const struct xnn_qd8_quantization_params quantization_params[restrict XNN_MIN_ELEMENTS(1)])
33 {
34 assert(mr != 0);
35 assert(mr <= 1);
36 assert(nc != 0);
37 assert(kc != 0);
38 assert(kc % sizeof(int8_t) == 0);
39 assert(a != NULL);
40 assert(w != NULL);
41 assert(c != NULL);
42
43 // TODO: amxintrin.h only provide intrinsics for __x86_64__
44 // Update if amxintrin changes
45 #if defined(__x86_64__)
46 __attribute__((aligned(64))) int32_t res0[1 * 16];
47 __attribute__((aligned(64))) int32_t res1[1 * 16];
48 __attribute__((aligned(64))) int32_t res2[1 * 16];
49 __attribute__((aligned(64))) int32_t res3[1 * 16];
50 __attribute__((aligned(64))) int8_t weight_buffer[16 * 64];
51
52 kc = round_up_po2(kc, 4 * sizeof(int8_t));
53 const size_t kremainder = (kc & 63) ? (kc & 63) : 64;
54
55 // Define tile config data structure
56 struct __tile_config {
57 uint8_t palette_id;
58 uint8_t start_row;
59 uint8_t reserved_0[14];
60 uint16_t colsb[8];
61 uint16_t reserved_1[8];
62 uint8_t rows[8];
63 uint8_t reserved_2[8];
64 };
65
66 // Load tile configuration
67 __attribute__((aligned(64))) struct __tile_config tile_data = {0};
68 tile_data.palette_id = 1;
69 tile_data.rows[0] = mr; // tmm0 = res 0
70 tile_data.rows[1] = mr; // tmm1 = res 1
71 tile_data.rows[2] = mr; // tmm2 = res 2
72 tile_data.rows[3] = mr; // tmm3 = res 3
73 tile_data.rows[4] = mr; // tmm4 = input
74 tile_data.rows[5] = 16; // tmm5 = weights
75 tile_data.rows[6] = mr; // tmm6 = input remainder
76 tile_data.rows[7] = kremainder >> 2; // tmm7 = weights remainder
77
78 tile_data.colsb[0] = 64; // tmm0 = res 0
79 tile_data.colsb[1] = 64; // tmm1 = res 1
80 tile_data.colsb[2] = 64; // tmm2 = res 1
81 tile_data.colsb[3] = 64; // tmm3 = res 1
82 tile_data.colsb[4] = 64; // tmm4 = input
83 tile_data.colsb[5] = 64; // tmm5 = weights
84 tile_data.colsb[6] = kremainder; // tmm6 = input remainder
85 tile_data.colsb[7] = 64; // tmm7 = weights remainder
86
87 //_tile_loadconfig(&tile_data);
88 __asm__ volatile ("ldtilecfg %0" :: "m" (tile_data));
89
90 float* c0 = c;
91
92 const __m512 voutput_min = _mm512_set1_ps(params->scalar.min);
93 const __m512 voutput_max = _mm512_set1_ps(params->scalar.max);
94 // XNN_FORCE_REALIZATION(voutput_min);
95 // XNN_FORCE_REALIZATION(voutput_max);
96 const __m512i vmask = _mm512_set1_epi8(0xF0);
97 const __m512i vshl4 = _mm512_set1_epi64(0x01020408);
98 XNN_FORCE_REALIZATION(vmask);
99 XNN_FORCE_REALIZATION(vshl4);
100
101 do {
102 const __m512i vksum0123456789ABCDEF = _mm512_load_epi32((const int32_t*) w + 0);
103 const __m512i vksumGHIJKLMNOPQRSTUV = _mm512_load_epi32((const int32_t*) w + 16);
104 const __m512i vksumWXYZabcdefghijkl = _mm512_load_epi32((const int32_t*) w + 32);
105 const __m512i vksummnopqrstuvwxyz01 = _mm512_load_epi32((const int32_t*) w + 48);
106 w = (const int32_t*) w + 64;
107
108 // Zero tile accumulator
109 __asm__ volatile (
110 "tilezero %%tmm0\n"
111 "tilezero %%tmm1\n"
112 "tilezero %%tmm2\n"
113 "tilezero %%tmm3\n"
114 ::);
115
116 size_t k = kc;
117 while (k >= 64 * sizeof(int8_t)) {
118 _tile_loadd(4, a, a_stride);
119 a += 64;
120 const __m512i vb0x0123456789ABCDEF = _mm512_load_epi32((const int8_t*) w + 0);
121 const __m512i vb1x0123456789ABCDEF = _mm512_load_epi32((const int8_t*) w + 256);
122 const __m512i vb2x0123456789ABCDEF = _mm512_load_epi32((const int8_t*) w + 512);
123 const __m512i vb3x0123456789ABCDEF = _mm512_load_epi32((const int8_t*) w + 768);
124 const __m512i vb4x0123456789ABCDEF = _mm512_load_epi32((const int8_t*) w + 1024);
125 const __m512i vb5x0123456789ABCDEF = _mm512_load_epi32((const int8_t*) w + 1280);
126 const __m512i vb6x0123456789ABCDEF = _mm512_load_epi32((const int8_t*) w + 1536);
127 const __m512i vb7x0123456789ABCDEF = _mm512_load_epi32((const int8_t*) w + 1792);
128 const __m512i vl0x0123456789ABCDEF = _mm512_gf2p8affine_epi64_epi8(vb0x0123456789ABCDEF, vshl4, 0);
129 const __m512i vh0x0123456789ABCDEF = _mm512_and_si512(vb0x0123456789ABCDEF, vmask);
130 const __m512i vl1x0123456789ABCDEF = _mm512_gf2p8affine_epi64_epi8(vb1x0123456789ABCDEF, vshl4, 0);
131 const __m512i vh1x0123456789ABCDEF = _mm512_and_si512(vb1x0123456789ABCDEF, vmask);
132 const __m512i vl2x0123456789ABCDEF = _mm512_gf2p8affine_epi64_epi8(vb2x0123456789ABCDEF, vshl4, 0);
133 const __m512i vh2x0123456789ABCDEF = _mm512_and_si512(vb2x0123456789ABCDEF, vmask);
134 const __m512i vl3x0123456789ABCDEF = _mm512_gf2p8affine_epi64_epi8(vb3x0123456789ABCDEF, vshl4, 0);
135 const __m512i vh3x0123456789ABCDEF = _mm512_and_si512(vb3x0123456789ABCDEF, vmask);
136 const __m512i vl4x0123456789ABCDEF = _mm512_gf2p8affine_epi64_epi8(vb4x0123456789ABCDEF, vshl4, 0);
137 const __m512i vh4x0123456789ABCDEF = _mm512_and_si512(vb4x0123456789ABCDEF, vmask);
138 const __m512i vl5x0123456789ABCDEF = _mm512_gf2p8affine_epi64_epi8(vb5x0123456789ABCDEF, vshl4, 0);
139 const __m512i vh5x0123456789ABCDEF = _mm512_and_si512(vb5x0123456789ABCDEF, vmask);
140 const __m512i vl6x0123456789ABCDEF = _mm512_gf2p8affine_epi64_epi8(vb6x0123456789ABCDEF, vshl4, 0);
141 const __m512i vh6x0123456789ABCDEF = _mm512_and_si512(vb6x0123456789ABCDEF, vmask);
142 const __m512i vl7x0123456789ABCDEF = _mm512_gf2p8affine_epi64_epi8(vb7x0123456789ABCDEF, vshl4, 0);
143 const __m512i vh7x0123456789ABCDEF = _mm512_and_si512(vb7x0123456789ABCDEF, vmask);
144 _mm512_store_epi32(weight_buffer + 0, vl0x0123456789ABCDEF);
145 _mm512_store_epi32(weight_buffer + 64, vh0x0123456789ABCDEF);
146 _mm512_store_epi32(weight_buffer + 128, vl1x0123456789ABCDEF);
147 _mm512_store_epi32(weight_buffer + 192, vh1x0123456789ABCDEF);
148 _mm512_store_epi32(weight_buffer + 256, vl2x0123456789ABCDEF);
149 _mm512_store_epi32(weight_buffer + 320, vh2x0123456789ABCDEF);
150 _mm512_store_epi32(weight_buffer + 384, vl3x0123456789ABCDEF);
151 _mm512_store_epi32(weight_buffer + 448, vh3x0123456789ABCDEF);
152 _mm512_store_epi32(weight_buffer + 512, vl4x0123456789ABCDEF);
153 _mm512_store_epi32(weight_buffer + 576, vh4x0123456789ABCDEF);
154 _mm512_store_epi32(weight_buffer + 640, vl5x0123456789ABCDEF);
155 _mm512_store_epi32(weight_buffer + 704, vh5x0123456789ABCDEF);
156 _mm512_store_epi32(weight_buffer + 768, vl6x0123456789ABCDEF);
157 _mm512_store_epi32(weight_buffer + 832, vh6x0123456789ABCDEF);
158 _mm512_store_epi32(weight_buffer + 896, vl7x0123456789ABCDEF);
159 _mm512_store_epi32(weight_buffer + 960, vh7x0123456789ABCDEF);
160 _tile_loadd(5, weight_buffer, 64);
161 _tile_dpbssd(0, 4, 5);
162 const __m512i vb0xGHIJKLMNOPQRSTUV = _mm512_load_epi32((const int8_t*) w + 64);
163 const __m512i vb1xGHIJKLMNOPQRSTUV = _mm512_load_epi32((const int8_t*) w + 320);
164 const __m512i vb2xGHIJKLMNOPQRSTUV = _mm512_load_epi32((const int8_t*) w + 576);
165 const __m512i vb3xGHIJKLMNOPQRSTUV = _mm512_load_epi32((const int8_t*) w + 832);
166 const __m512i vb4xGHIJKLMNOPQRSTUV = _mm512_load_epi32((const int8_t*) w + 1088);
167 const __m512i vb5xGHIJKLMNOPQRSTUV = _mm512_load_epi32((const int8_t*) w + 1344);
168 const __m512i vb6xGHIJKLMNOPQRSTUV = _mm512_load_epi32((const int8_t*) w + 1600);
169 const __m512i vb7xGHIJKLMNOPQRSTUV = _mm512_load_epi32((const int8_t*) w + 1856);
170 const __m512i vl0xGHIJKLMNOPQRSTUV = _mm512_gf2p8affine_epi64_epi8(vb0xGHIJKLMNOPQRSTUV, vshl4, 0);
171 const __m512i vh0xGHIJKLMNOPQRSTUV = _mm512_and_si512(vb0xGHIJKLMNOPQRSTUV, vmask);
172 const __m512i vl1xGHIJKLMNOPQRSTUV = _mm512_gf2p8affine_epi64_epi8(vb1xGHIJKLMNOPQRSTUV, vshl4, 0);
173 const __m512i vh1xGHIJKLMNOPQRSTUV = _mm512_and_si512(vb1xGHIJKLMNOPQRSTUV, vmask);
174 const __m512i vl2xGHIJKLMNOPQRSTUV = _mm512_gf2p8affine_epi64_epi8(vb2xGHIJKLMNOPQRSTUV, vshl4, 0);
175 const __m512i vh2xGHIJKLMNOPQRSTUV = _mm512_and_si512(vb2xGHIJKLMNOPQRSTUV, vmask);
176 const __m512i vl3xGHIJKLMNOPQRSTUV = _mm512_gf2p8affine_epi64_epi8(vb3xGHIJKLMNOPQRSTUV, vshl4, 0);
177 const __m512i vh3xGHIJKLMNOPQRSTUV = _mm512_and_si512(vb3xGHIJKLMNOPQRSTUV, vmask);
178 const __m512i vl4xGHIJKLMNOPQRSTUV = _mm512_gf2p8affine_epi64_epi8(vb4xGHIJKLMNOPQRSTUV, vshl4, 0);
179 const __m512i vh4xGHIJKLMNOPQRSTUV = _mm512_and_si512(vb4xGHIJKLMNOPQRSTUV, vmask);
180 const __m512i vl5xGHIJKLMNOPQRSTUV = _mm512_gf2p8affine_epi64_epi8(vb5xGHIJKLMNOPQRSTUV, vshl4, 0);
181 const __m512i vh5xGHIJKLMNOPQRSTUV = _mm512_and_si512(vb5xGHIJKLMNOPQRSTUV, vmask);
182 const __m512i vl6xGHIJKLMNOPQRSTUV = _mm512_gf2p8affine_epi64_epi8(vb6xGHIJKLMNOPQRSTUV, vshl4, 0);
183 const __m512i vh6xGHIJKLMNOPQRSTUV = _mm512_and_si512(vb6xGHIJKLMNOPQRSTUV, vmask);
184 const __m512i vl7xGHIJKLMNOPQRSTUV = _mm512_gf2p8affine_epi64_epi8(vb7xGHIJKLMNOPQRSTUV, vshl4, 0);
185 const __m512i vh7xGHIJKLMNOPQRSTUV = _mm512_and_si512(vb7xGHIJKLMNOPQRSTUV, vmask);
186 _mm512_store_epi32(weight_buffer + 0, vl0xGHIJKLMNOPQRSTUV);
187 _mm512_store_epi32(weight_buffer + 64, vh0xGHIJKLMNOPQRSTUV);
188 _mm512_store_epi32(weight_buffer + 128, vl1xGHIJKLMNOPQRSTUV);
189 _mm512_store_epi32(weight_buffer + 192, vh1xGHIJKLMNOPQRSTUV);
190 _mm512_store_epi32(weight_buffer + 256, vl2xGHIJKLMNOPQRSTUV);
191 _mm512_store_epi32(weight_buffer + 320, vh2xGHIJKLMNOPQRSTUV);
192 _mm512_store_epi32(weight_buffer + 384, vl3xGHIJKLMNOPQRSTUV);
193 _mm512_store_epi32(weight_buffer + 448, vh3xGHIJKLMNOPQRSTUV);
194 _mm512_store_epi32(weight_buffer + 512, vl4xGHIJKLMNOPQRSTUV);
195 _mm512_store_epi32(weight_buffer + 576, vh4xGHIJKLMNOPQRSTUV);
196 _mm512_store_epi32(weight_buffer + 640, vl5xGHIJKLMNOPQRSTUV);
197 _mm512_store_epi32(weight_buffer + 704, vh5xGHIJKLMNOPQRSTUV);
198 _mm512_store_epi32(weight_buffer + 768, vl6xGHIJKLMNOPQRSTUV);
199 _mm512_store_epi32(weight_buffer + 832, vh6xGHIJKLMNOPQRSTUV);
200 _mm512_store_epi32(weight_buffer + 896, vl7xGHIJKLMNOPQRSTUV);
201 _mm512_store_epi32(weight_buffer + 960, vh7xGHIJKLMNOPQRSTUV);
202 _tile_loadd(5, weight_buffer, 64);
203 _tile_dpbssd(1, 4, 5);
204 const __m512i vb0xWXYZabcdefghijkl = _mm512_load_epi32((const int8_t*) w + 128);
205 const __m512i vb1xWXYZabcdefghijkl = _mm512_load_epi32((const int8_t*) w + 384);
206 const __m512i vb2xWXYZabcdefghijkl = _mm512_load_epi32((const int8_t*) w + 640);
207 const __m512i vb3xWXYZabcdefghijkl = _mm512_load_epi32((const int8_t*) w + 896);
208 const __m512i vb4xWXYZabcdefghijkl = _mm512_load_epi32((const int8_t*) w + 1152);
209 const __m512i vb5xWXYZabcdefghijkl = _mm512_load_epi32((const int8_t*) w + 1408);
210 const __m512i vb6xWXYZabcdefghijkl = _mm512_load_epi32((const int8_t*) w + 1664);
211 const __m512i vb7xWXYZabcdefghijkl = _mm512_load_epi32((const int8_t*) w + 1920);
212 const __m512i vl0xWXYZabcdefghijkl = _mm512_gf2p8affine_epi64_epi8(vb0xWXYZabcdefghijkl, vshl4, 0);
213 const __m512i vh0xWXYZabcdefghijkl = _mm512_and_si512(vb0xWXYZabcdefghijkl, vmask);
214 const __m512i vl1xWXYZabcdefghijkl = _mm512_gf2p8affine_epi64_epi8(vb1xWXYZabcdefghijkl, vshl4, 0);
215 const __m512i vh1xWXYZabcdefghijkl = _mm512_and_si512(vb1xWXYZabcdefghijkl, vmask);
216 const __m512i vl2xWXYZabcdefghijkl = _mm512_gf2p8affine_epi64_epi8(vb2xWXYZabcdefghijkl, vshl4, 0);
217 const __m512i vh2xWXYZabcdefghijkl = _mm512_and_si512(vb2xWXYZabcdefghijkl, vmask);
218 const __m512i vl3xWXYZabcdefghijkl = _mm512_gf2p8affine_epi64_epi8(vb3xWXYZabcdefghijkl, vshl4, 0);
219 const __m512i vh3xWXYZabcdefghijkl = _mm512_and_si512(vb3xWXYZabcdefghijkl, vmask);
220 const __m512i vl4xWXYZabcdefghijkl = _mm512_gf2p8affine_epi64_epi8(vb4xWXYZabcdefghijkl, vshl4, 0);
221 const __m512i vh4xWXYZabcdefghijkl = _mm512_and_si512(vb4xWXYZabcdefghijkl, vmask);
222 const __m512i vl5xWXYZabcdefghijkl = _mm512_gf2p8affine_epi64_epi8(vb5xWXYZabcdefghijkl, vshl4, 0);
223 const __m512i vh5xWXYZabcdefghijkl = _mm512_and_si512(vb5xWXYZabcdefghijkl, vmask);
224 const __m512i vl6xWXYZabcdefghijkl = _mm512_gf2p8affine_epi64_epi8(vb6xWXYZabcdefghijkl, vshl4, 0);
225 const __m512i vh6xWXYZabcdefghijkl = _mm512_and_si512(vb6xWXYZabcdefghijkl, vmask);
226 const __m512i vl7xWXYZabcdefghijkl = _mm512_gf2p8affine_epi64_epi8(vb7xWXYZabcdefghijkl, vshl4, 0);
227 const __m512i vh7xWXYZabcdefghijkl = _mm512_and_si512(vb7xWXYZabcdefghijkl, vmask);
228 _mm512_store_epi32(weight_buffer + 0, vl0xWXYZabcdefghijkl);
229 _mm512_store_epi32(weight_buffer + 64, vh0xWXYZabcdefghijkl);
230 _mm512_store_epi32(weight_buffer + 128, vl1xWXYZabcdefghijkl);
231 _mm512_store_epi32(weight_buffer + 192, vh1xWXYZabcdefghijkl);
232 _mm512_store_epi32(weight_buffer + 256, vl2xWXYZabcdefghijkl);
233 _mm512_store_epi32(weight_buffer + 320, vh2xWXYZabcdefghijkl);
234 _mm512_store_epi32(weight_buffer + 384, vl3xWXYZabcdefghijkl);
235 _mm512_store_epi32(weight_buffer + 448, vh3xWXYZabcdefghijkl);
236 _mm512_store_epi32(weight_buffer + 512, vl4xWXYZabcdefghijkl);
237 _mm512_store_epi32(weight_buffer + 576, vh4xWXYZabcdefghijkl);
238 _mm512_store_epi32(weight_buffer + 640, vl5xWXYZabcdefghijkl);
239 _mm512_store_epi32(weight_buffer + 704, vh5xWXYZabcdefghijkl);
240 _mm512_store_epi32(weight_buffer + 768, vl6xWXYZabcdefghijkl);
241 _mm512_store_epi32(weight_buffer + 832, vh6xWXYZabcdefghijkl);
242 _mm512_store_epi32(weight_buffer + 896, vl7xWXYZabcdefghijkl);
243 _mm512_store_epi32(weight_buffer + 960, vh7xWXYZabcdefghijkl);
244 _tile_loadd(5, weight_buffer, 64);
245 _tile_dpbssd(2, 4, 5);
246 const __m512i vb0xmnopqrstuvwxyz01 = _mm512_load_epi32((const int8_t*) w + 192);
247 const __m512i vb1xmnopqrstuvwxyz01 = _mm512_load_epi32((const int8_t*) w + 448);
248 const __m512i vb2xmnopqrstuvwxyz01 = _mm512_load_epi32((const int8_t*) w + 704);
249 const __m512i vb3xmnopqrstuvwxyz01 = _mm512_load_epi32((const int8_t*) w + 960);
250 const __m512i vb4xmnopqrstuvwxyz01 = _mm512_load_epi32((const int8_t*) w + 1216);
251 const __m512i vb5xmnopqrstuvwxyz01 = _mm512_load_epi32((const int8_t*) w + 1472);
252 const __m512i vb6xmnopqrstuvwxyz01 = _mm512_load_epi32((const int8_t*) w + 1728);
253 const __m512i vb7xmnopqrstuvwxyz01 = _mm512_load_epi32((const int8_t*) w + 1984);
254 const __m512i vl0xmnopqrstuvwxyz01 = _mm512_gf2p8affine_epi64_epi8(vb0xmnopqrstuvwxyz01, vshl4, 0);
255 const __m512i vh0xmnopqrstuvwxyz01 = _mm512_and_si512(vb0xmnopqrstuvwxyz01, vmask);
256 const __m512i vl1xmnopqrstuvwxyz01 = _mm512_gf2p8affine_epi64_epi8(vb1xmnopqrstuvwxyz01, vshl4, 0);
257 const __m512i vh1xmnopqrstuvwxyz01 = _mm512_and_si512(vb1xmnopqrstuvwxyz01, vmask);
258 const __m512i vl2xmnopqrstuvwxyz01 = _mm512_gf2p8affine_epi64_epi8(vb2xmnopqrstuvwxyz01, vshl4, 0);
259 const __m512i vh2xmnopqrstuvwxyz01 = _mm512_and_si512(vb2xmnopqrstuvwxyz01, vmask);
260 const __m512i vl3xmnopqrstuvwxyz01 = _mm512_gf2p8affine_epi64_epi8(vb3xmnopqrstuvwxyz01, vshl4, 0);
261 const __m512i vh3xmnopqrstuvwxyz01 = _mm512_and_si512(vb3xmnopqrstuvwxyz01, vmask);
262 const __m512i vl4xmnopqrstuvwxyz01 = _mm512_gf2p8affine_epi64_epi8(vb4xmnopqrstuvwxyz01, vshl4, 0);
263 const __m512i vh4xmnopqrstuvwxyz01 = _mm512_and_si512(vb4xmnopqrstuvwxyz01, vmask);
264 const __m512i vl5xmnopqrstuvwxyz01 = _mm512_gf2p8affine_epi64_epi8(vb5xmnopqrstuvwxyz01, vshl4, 0);
265 const __m512i vh5xmnopqrstuvwxyz01 = _mm512_and_si512(vb5xmnopqrstuvwxyz01, vmask);
266 const __m512i vl6xmnopqrstuvwxyz01 = _mm512_gf2p8affine_epi64_epi8(vb6xmnopqrstuvwxyz01, vshl4, 0);
267 const __m512i vh6xmnopqrstuvwxyz01 = _mm512_and_si512(vb6xmnopqrstuvwxyz01, vmask);
268 const __m512i vl7xmnopqrstuvwxyz01 = _mm512_gf2p8affine_epi64_epi8(vb7xmnopqrstuvwxyz01, vshl4, 0);
269 const __m512i vh7xmnopqrstuvwxyz01 = _mm512_and_si512(vb7xmnopqrstuvwxyz01, vmask);
270 _mm512_store_epi32(weight_buffer + 0, vl0xmnopqrstuvwxyz01);
271 _mm512_store_epi32(weight_buffer + 64, vh0xmnopqrstuvwxyz01);
272 _mm512_store_epi32(weight_buffer + 128, vl1xmnopqrstuvwxyz01);
273 _mm512_store_epi32(weight_buffer + 192, vh1xmnopqrstuvwxyz01);
274 _mm512_store_epi32(weight_buffer + 256, vl2xmnopqrstuvwxyz01);
275 _mm512_store_epi32(weight_buffer + 320, vh2xmnopqrstuvwxyz01);
276 _mm512_store_epi32(weight_buffer + 384, vl3xmnopqrstuvwxyz01);
277 _mm512_store_epi32(weight_buffer + 448, vh3xmnopqrstuvwxyz01);
278 _mm512_store_epi32(weight_buffer + 512, vl4xmnopqrstuvwxyz01);
279 _mm512_store_epi32(weight_buffer + 576, vh4xmnopqrstuvwxyz01);
280 _mm512_store_epi32(weight_buffer + 640, vl5xmnopqrstuvwxyz01);
281 _mm512_store_epi32(weight_buffer + 704, vh5xmnopqrstuvwxyz01);
282 _mm512_store_epi32(weight_buffer + 768, vl6xmnopqrstuvwxyz01);
283 _mm512_store_epi32(weight_buffer + 832, vh6xmnopqrstuvwxyz01);
284 _mm512_store_epi32(weight_buffer + 896, vl7xmnopqrstuvwxyz01);
285 _mm512_store_epi32(weight_buffer + 960, vh7xmnopqrstuvwxyz01);
286 _tile_loadd(5, weight_buffer, 64);
287 _tile_dpbssd(3, 4, 5);
288
289 w = (const int8_t*) w + 2048;
290 k -= 64 * sizeof(int8_t);
291 }
292
293 if XNN_UNLIKELY(k != 0) {
294 _tile_loadd(6, a, a_stride);
295 a += kremainder;
296 for (size_t k = 0; k < ((kremainder + 7) >> 3); ++k) {
297 const __m512i vb0123456789ABCDEF = _mm512_load_epi32((const int8_t*) w + 0 + 256 * k);
298 const __m512i vl0123456789ABCDEF = _mm512_gf2p8affine_epi64_epi8(vb0123456789ABCDEF, vshl4, 0);
299 const __m512i vh0123456789ABCDEF = _mm512_and_si512(vb0123456789ABCDEF, vmask);
300 _mm512_store_epi32(weight_buffer + 128 * k + 0, vl0123456789ABCDEF);
301 _mm512_store_epi32(weight_buffer + 128 * k + 64, vh0123456789ABCDEF);
302 }
303 _tile_loadd(7, weight_buffer, 64);
304 _tile_dpbssd(0, 6, 7);
305 for (size_t k = 0; k < ((kremainder + 7) >> 3); ++k) {
306 const __m512i vbGHIJKLMNOPQRSTUV = _mm512_load_epi32((const int8_t*) w + 64 + 256 * k);
307 const __m512i vlGHIJKLMNOPQRSTUV = _mm512_gf2p8affine_epi64_epi8(vbGHIJKLMNOPQRSTUV, vshl4, 0);
308 const __m512i vhGHIJKLMNOPQRSTUV = _mm512_and_si512(vbGHIJKLMNOPQRSTUV, vmask);
309 _mm512_store_epi32(weight_buffer + 128 * k + 0, vlGHIJKLMNOPQRSTUV);
310 _mm512_store_epi32(weight_buffer + 128 * k + 64, vhGHIJKLMNOPQRSTUV);
311 }
312 _tile_loadd(7, weight_buffer, 64);
313 _tile_dpbssd(1, 6, 7);
314 for (size_t k = 0; k < ((kremainder + 7) >> 3); ++k) {
315 const __m512i vbWXYZabcdefghijkl = _mm512_load_epi32((const int8_t*) w + 128 + 256 * k);
316 const __m512i vlWXYZabcdefghijkl = _mm512_gf2p8affine_epi64_epi8(vbWXYZabcdefghijkl, vshl4, 0);
317 const __m512i vhWXYZabcdefghijkl = _mm512_and_si512(vbWXYZabcdefghijkl, vmask);
318 _mm512_store_epi32(weight_buffer + 128 * k + 0, vlWXYZabcdefghijkl);
319 _mm512_store_epi32(weight_buffer + 128 * k + 64, vhWXYZabcdefghijkl);
320 }
321 _tile_loadd(7, weight_buffer, 64);
322 _tile_dpbssd(2, 6, 7);
323 for (size_t k = 0; k < ((kremainder + 7) >> 3); ++k) {
324 const __m512i vbmnopqrstuvwxyz01 = _mm512_load_epi32((const int8_t*) w + 192 + 256 * k);
325 const __m512i vlmnopqrstuvwxyz01 = _mm512_gf2p8affine_epi64_epi8(vbmnopqrstuvwxyz01, vshl4, 0);
326 const __m512i vhmnopqrstuvwxyz01 = _mm512_and_si512(vbmnopqrstuvwxyz01, vmask);
327 _mm512_store_epi32(weight_buffer + 128 * k + 0, vlmnopqrstuvwxyz01);
328 _mm512_store_epi32(weight_buffer + 128 * k + 64, vhmnopqrstuvwxyz01);
329 }
330 _tile_loadd(7, weight_buffer, 64);
331 _tile_dpbssd(3, 6, 7);
332
333 w = (const int8_t*) w + ((kremainder + 7) >> 3) * 256;
334 k -= kremainder * sizeof(int8_t);
335 }
336
337 // Add tile to bias
338 _tile_stored(0, res0, 64);
339 _tile_stored(1, res1, 64);
340 _tile_stored(2, res2, 64);
341 _tile_stored(3, res3, 64);
342
343 __m512i vacc0x0123456789ABCDEF = _mm512_mullo_epi32(vksum0123456789ABCDEF, _mm512_set1_epi32((int) quantization_params[0].zero_point));
344 __m512i vacc0xGHIJKLMNOPQRSTUV = _mm512_mullo_epi32(vksumGHIJKLMNOPQRSTUV, _mm512_set1_epi32((int) quantization_params[0].zero_point));
345 __m512i vacc0xWXYZabcdefghijkl = _mm512_mullo_epi32(vksumWXYZabcdefghijkl, _mm512_set1_epi32((int) quantization_params[0].zero_point));
346 __m512i vacc0xmnopqrstuvwxyz01 = _mm512_mullo_epi32(vksummnopqrstuvwxyz01, _mm512_set1_epi32((int) quantization_params[0].zero_point));
347 vacc0x0123456789ABCDEF = _mm512_add_epi32(vacc0x0123456789ABCDEF, _mm512_load_epi32(res0 + 0));
348 vacc0xGHIJKLMNOPQRSTUV = _mm512_add_epi32(vacc0xGHIJKLMNOPQRSTUV, _mm512_load_epi32(res1 + 0));
349 vacc0xWXYZabcdefghijkl = _mm512_add_epi32(vacc0xWXYZabcdefghijkl, _mm512_load_epi32(res2 + 0));
350 vacc0xmnopqrstuvwxyz01 = _mm512_add_epi32(vacc0xmnopqrstuvwxyz01, _mm512_load_epi32(res3 + 0));
351
352 vacc0x0123456789ABCDEF = _mm512_srai_epi32(vacc0x0123456789ABCDEF, 4);
353 vacc0xGHIJKLMNOPQRSTUV = _mm512_srai_epi32(vacc0xGHIJKLMNOPQRSTUV, 4);
354 vacc0xWXYZabcdefghijkl = _mm512_srai_epi32(vacc0xWXYZabcdefghijkl, 4);
355 vacc0xmnopqrstuvwxyz01 = _mm512_srai_epi32(vacc0xmnopqrstuvwxyz01, 4);
356 __m512 vscaled0x0123456789ABCDEF = _mm512_cvtepi32_ps(vacc0x0123456789ABCDEF);
357 __m512 vscaled0xGHIJKLMNOPQRSTUV = _mm512_cvtepi32_ps(vacc0xGHIJKLMNOPQRSTUV);
358 __m512 vscaled0xWXYZabcdefghijkl = _mm512_cvtepi32_ps(vacc0xWXYZabcdefghijkl);
359 __m512 vscaled0xmnopqrstuvwxyz01 = _mm512_cvtepi32_ps(vacc0xmnopqrstuvwxyz01);
360
361 vscaled0x0123456789ABCDEF = _mm512_mul_ps(vscaled0x0123456789ABCDEF, _mm512_set1_ps(quantization_params[0].inv_scale));
362 vscaled0xGHIJKLMNOPQRSTUV = _mm512_mul_ps(vscaled0xGHIJKLMNOPQRSTUV, _mm512_set1_ps(quantization_params[0].inv_scale));
363 vscaled0xWXYZabcdefghijkl = _mm512_mul_ps(vscaled0xWXYZabcdefghijkl, _mm512_set1_ps(quantization_params[0].inv_scale));
364 vscaled0xmnopqrstuvwxyz01 = _mm512_mul_ps(vscaled0xmnopqrstuvwxyz01, _mm512_set1_ps(quantization_params[0].inv_scale));
365
366 const __m512 vfilter_output_scale0123456789ABCDEF = _mm512_load_ps((const float*) w + 0);
367 const __m512 vfilter_output_scaleGHIJKLMNOPQRSTUV = _mm512_load_ps((const float*) w + 16);
368 const __m512 vfilter_output_scaleWXYZabcdefghijkl = _mm512_load_ps((const float*) w + 32);
369 const __m512 vfilter_output_scalemnopqrstuvwxyz01 = _mm512_load_ps((const float*) w + 48);
370 w = (const int32_t*) w + 64;
371 const __m512 vbias0123456789ABCDEF = _mm512_load_ps((const float*) w + 0);
372 const __m512 vbiasGHIJKLMNOPQRSTUV = _mm512_load_ps((const float*) w + 16);
373 const __m512 vbiasWXYZabcdefghijkl = _mm512_load_ps((const float*) w + 32);
374 const __m512 vbiasmnopqrstuvwxyz01 = _mm512_load_ps((const float*) w + 48);
375 w = (const int32_t*) w + 64;
376
377 vscaled0x0123456789ABCDEF = _mm512_fmadd_ps(vscaled0x0123456789ABCDEF, vfilter_output_scale0123456789ABCDEF, vbias0123456789ABCDEF);
378 vscaled0xGHIJKLMNOPQRSTUV = _mm512_fmadd_ps(vscaled0xGHIJKLMNOPQRSTUV, vfilter_output_scaleGHIJKLMNOPQRSTUV, vbiasGHIJKLMNOPQRSTUV);
379 vscaled0xWXYZabcdefghijkl = _mm512_fmadd_ps(vscaled0xWXYZabcdefghijkl, vfilter_output_scaleWXYZabcdefghijkl, vbiasWXYZabcdefghijkl);
380 vscaled0xmnopqrstuvwxyz01 = _mm512_fmadd_ps(vscaled0xmnopqrstuvwxyz01, vfilter_output_scalemnopqrstuvwxyz01, vbiasmnopqrstuvwxyz01);
381
382 vscaled0x0123456789ABCDEF = _mm512_max_ps(vscaled0x0123456789ABCDEF, voutput_min);
383 vscaled0xGHIJKLMNOPQRSTUV = _mm512_max_ps(vscaled0xGHIJKLMNOPQRSTUV, voutput_min);
384 vscaled0xWXYZabcdefghijkl = _mm512_max_ps(vscaled0xWXYZabcdefghijkl, voutput_min);
385 vscaled0xmnopqrstuvwxyz01 = _mm512_max_ps(vscaled0xmnopqrstuvwxyz01, voutput_min);
386
387 vscaled0x0123456789ABCDEF = _mm512_min_ps(vscaled0x0123456789ABCDEF, voutput_max);
388 vscaled0xGHIJKLMNOPQRSTUV = _mm512_min_ps(vscaled0xGHIJKLMNOPQRSTUV, voutput_max);
389 vscaled0xWXYZabcdefghijkl = _mm512_min_ps(vscaled0xWXYZabcdefghijkl, voutput_max);
390 vscaled0xmnopqrstuvwxyz01 = _mm512_min_ps(vscaled0xmnopqrstuvwxyz01, voutput_max);
391
392 if XNN_LIKELY(nc >= 64) {
393 _mm512_storeu_ps(c0 + 0, vscaled0x0123456789ABCDEF);
394 _mm512_storeu_ps(c0 + 16, vscaled0xGHIJKLMNOPQRSTUV);
395 _mm512_storeu_ps(c0 + 32, vscaled0xWXYZabcdefghijkl);
396 _mm512_storeu_ps(c0 + 48, vscaled0xmnopqrstuvwxyz01);
397 c0 = (float*) ((uintptr_t) c0 + cn_stride);
398
399 a -= kc;
400 nc -= 64;
401 } else {
402 // Prepare mask for valid 32-bit elements (depends on nc).
403 const __mmask16 vmask0 = _cvtu32_mask16((uint32_t) ((((UINT64_C(1) << nc) - 1) >> 0) & 0xFFFF));
404 const __mmask16 vmask1 = _cvtu32_mask16((uint32_t) ((((UINT64_C(1) << nc) - 1) >> 16) & 0xFFFF));
405 const __mmask16 vmask2 = _cvtu32_mask16((uint32_t) ((((UINT64_C(1) << nc) - 1) >> 32) & 0xFFFF));
406 const __mmask16 vmask3 = _cvtu32_mask16((uint32_t) ((((UINT64_C(1) << nc) - 1) >> 48) & 0xFFFF));
407 _mm512_mask_storeu_ps(c0 + 0, vmask0, vscaled0x0123456789ABCDEF);
408 _mm512_mask_storeu_ps(c0 + 16, vmask1, vscaled0xGHIJKLMNOPQRSTUV);
409 _mm512_mask_storeu_ps(c0 + 32, vmask2, vscaled0xWXYZabcdefghijkl);
410 _mm512_mask_storeu_ps(c0 + 48, vmask3, vscaled0xmnopqrstuvwxyz01);
411 nc = 0;
412 }
413 } while (nc != 0);
414 // Release tile config
415 // _tile_release();
416 __asm__ volatile ("tilerelease" ::);
417 #endif // defined(__x86_64__)
418 }