Debian Codegraph @

src/qd8-f16-qc8w-igemm/gen/qd8-f16-qc8w-igemm-1x8c8-minmax-avx256skx.c

raw
1 // Auto-generated file. Do not edit!
2 // Template: src/qs8-igemm/MRx8c8-avx2.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 <immintrin.h>
13
14 #include "xnnpack/igemm.h"
15 #include "xnnpack/intrinsics-polyfill.h"
16 #include "xnnpack/math.h"
17 #include "xnnpack/unaligned.h"
18
19
20 void xnn_qd8_f16_qc8w_igemm_minmax_ukernel_1x8c8__avx256skx(
21 size_t mr,
22 size_t nc,
23 size_t kc,
24 size_t ks,
25 const int8_t** restrict a,
26 const void* restrict w,
27 xnn_float16* restrict c,
28 size_t cm_stride,
29 size_t cn_stride,
30 size_t a_offset,
31 const int8_t* zero,
32 const int8_t* zero_data,
33 const union xnn_f16_minmax_params params[restrict XNN_MIN_ELEMENTS(1)],
34 const struct xnn_qd8_quantization_params quantization_params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS
35 {
36 assert(mr != 0);
37 assert(mr <= 1);
38 assert(nc != 0);
39 assert(kc != 0);
40 assert(ks != 0);
41 assert(ks % (1 * sizeof(void*)) == 0);
42 assert(a_offset % sizeof(int8_t) == 0);
43 assert(a != NULL);
44 assert(w != NULL);
45 assert(c != NULL);
46
47 kc = round_up_po2(kc, 8 * sizeof(int8_t));
48 uint16_t* c0 = (uint16_t*) c;
49
50 const __m256i vinput_zero_point = _mm256_set1_epi32((int) quantization_params->zero_point);
51 const __m256 vinput_scale = _mm256_broadcast_ss(&quantization_params->inv_scale);
52 const __m256 vmin = _mm256_cvtph_ps(_mm_set1_epi16(*(const uint16_t*) &params->scalar.min));
53 const __m256 vmax = _mm256_cvtph_ps(_mm_set1_epi16(*(const uint16_t*) &params->scalar.max));
54 // XNN_FORCE_REALIZATION(vinput_zero_point);
55 // XNN_FORCE_REALIZATION(vinput_scale);
56 // XNN_FORCE_REALIZATION(vmin);
57 // XNN_FORCE_REALIZATION(vmax);
58
59 do {
60 const __m128i vinit0 = _mm_cvtsi32_si128(((const int*) w)[0]);
61 const __m128i vinit1 = _mm_cvtsi32_si128(((const int*) w)[1]);
62 const __m256i vinit01 = _mm256_inserti128_si256(_mm256_castsi128_si256(vinit0), vinit1, 1);
63 const __m128i vinit2 = _mm_cvtsi32_si128(((const int*) w)[2]);
64 const __m128i vinit3 = _mm_cvtsi32_si128(((const int*) w)[3]);
65 const __m256i vinit23 = _mm256_inserti128_si256(_mm256_castsi128_si256(vinit2), vinit3, 1);
66 const __m128i vinit4 = _mm_cvtsi32_si128(((const int*) w)[4]);
67 const __m128i vinit5 = _mm_cvtsi32_si128(((const int*) w)[5]);
68 const __m256i vinit45 = _mm256_inserti128_si256(_mm256_castsi128_si256(vinit4), vinit5, 1);
69 const __m128i vinit6 = _mm_cvtsi32_si128(((const int*) w)[6]);
70 const __m128i vinit7 = _mm_cvtsi32_si128(((const int*) w)[7]);
71 const __m256i vinit67 = _mm256_inserti128_si256(_mm256_castsi128_si256(vinit6), vinit7, 1);
72 __m256i vacc0x01 = _mm256_mullo_epi32(vinit01, vinput_zero_point);
73 __m256i vacc0x23 = _mm256_mullo_epi32(vinit23, vinput_zero_point);
74 __m256i vacc0x45 = _mm256_mullo_epi32(vinit45, vinput_zero_point);
75 __m256i vacc0x67 = _mm256_mullo_epi32(vinit67, vinput_zero_point);
76 w = (const int32_t*) w + 8;
77
78 size_t p = ks;
79 do {
80 const int8_t* restrict a0 = a[0];
81 if XNN_UNPREDICTABLE(a0 != zero) {
82 a0 = (const int8_t*) ((uintptr_t) a0 + a_offset);
83 } else {
84 a0 = zero_data;
85 }
86 a += 1;
87
88 size_t k = 0;
89 while (k < kc) {
90 const __m128i va0 = _mm_broadcastq_epi64(_mm_loadl_epi64((const __m128i*) a0));
91 const __m256i vxa0 = _mm256_cvtepi8_epi16(va0);
92 a0 += 8;
93
94 const __m128i vb01 = _mm_load_si128((const __m128i*) w);
95 const __m256i vxb01 = _mm256_cvtepi8_epi16(vb01);
96
97 vacc0x01 = _mm256_add_epi32(vacc0x01, _mm256_madd_epi16(vxa0, vxb01));
98 const __m128i vb23 = _mm_load_si128((const __m128i*) ((const int8_t*) w + 16));
99 const __m256i vxb23 = _mm256_cvtepi8_epi16(vb23);
100
101 vacc0x23 = _mm256_add_epi32(vacc0x23, _mm256_madd_epi16(vxa0, vxb23));
102 const __m128i vb45 = _mm_load_si128((const __m128i*) ((const int8_t*) w + 32));
103 const __m256i vxb45 = _mm256_cvtepi8_epi16(vb45);
104
105 vacc0x45 = _mm256_add_epi32(vacc0x45, _mm256_madd_epi16(vxa0, vxb45));
106 const __m128i vb67 = _mm_load_si128((const __m128i*) ((const int8_t*) w + 48));
107 const __m256i vxb67 = _mm256_cvtepi8_epi16(vb67);
108
109 vacc0x67 = _mm256_add_epi32(vacc0x67, _mm256_madd_epi16(vxa0, vxb67));
110
111 w = (const void*) ((const int8_t*) w + 64);
112 k += 8 * sizeof(int8_t);
113 }
114 p -= 1 * sizeof(void*);
115 } while (p != 0);
116
117 const __m256i vacc0x0213 = _mm256_hadd_epi32(vacc0x01, vacc0x23);
118 const __m256i vacc0x4657 = _mm256_hadd_epi32(vacc0x45, vacc0x67);
119
120 const __m256i vacc0x02461357 = _mm256_hadd_epi32(vacc0x0213, vacc0x4657);
121
122 const __m256i vpermute_mask = _mm256_set_epi32(7, 3, 6, 2, 5, 1, 4, 0);
123 __m256i vacc0x01234567 = _mm256_permutevar8x32_epi32(vacc0x02461357, vpermute_mask);
124
125 __m256 vout0x01234567 = _mm256_cvtepi32_ps(vacc0x01234567);
126
127 vout0x01234567 = _mm256_mul_ps(vout0x01234567, vinput_scale);
128
129 const __m256 vfilter_output_scale01234567 = _mm256_load_ps((const float*) w);
130 const __m256 vbias01234567 = _mm256_load_ps((const float*) w + 8);
131 w = (const float*) w + 16;
132 vout0x01234567 = _mm256_fmadd_ps(vout0x01234567, vfilter_output_scale01234567, vbias01234567);
133
134 vout0x01234567 = _mm256_max_ps(vout0x01234567, vmin);
135
136 vout0x01234567 = _mm256_min_ps(vout0x01234567, vmax);
137 __m128i vfp16out0x01234567 = _mm256_cvtps_ph(vout0x01234567, _MM_FROUND_TO_NEAREST_INT);
138 if XNN_LIKELY(nc >= 8) {
139 _mm_storeu_si128((__m128i*) c0, vfp16out0x01234567);
140 c0 = (uint16_t*) ((uintptr_t) c0 + cn_stride);
141
142 a = (const int8_t**restrict) ((uintptr_t) a - ks);
143 nc -= 8;
144 } else {
145 // Prepare mask for valid 16-bit elements (depends on nc).
146 const __mmask8 vmask = _cvtu32_mask8((UINT32_C(1) << nc) - 1);
147 _mm_mask_storeu_epi16(c0, vmask, vfp16out0x01234567);
148 nc = 0;
149 }
150 } while (nc != 0);
151 }