Debian Codegraph @

src/qd8-f32-qc8w-gemm/gen/qd8-f32-qc8w-gemm-2x8c4-minmax-avxvnni-u2-acc2.c

raw
1 // Auto-generated file. Do not edit!
2 // Template: src/qs8-gemm/MRx8c4-avxvnni.c.in
3 // Generator: tools/xngen
4 //
5 // Copyright 2023 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 #include <stdint.h>
12
13 #include <immintrin.h>
14
15 #include "xnnpack/common.h"
16 #include "xnnpack/gemm.h"
17 #include "xnnpack/intrinsics-polyfill.h"
18 #include "xnnpack/math.h"
19 #include "xnnpack/unaligned.h"
20 #include "xnnpack/prefetch.h"
21
22
23 void xnn_qd8_f32_qc8w_gemm_minmax_ukernel_2x8c4__avxvnni_u2_acc2(
24 size_t mr,
25 size_t nc,
26 size_t kc,
27 const int8_t* restrict a,
28 size_t a_stride,
29 const void* restrict w,
30 float* restrict c,
31 size_t cm_stride,
32 size_t cn_stride,
33 const union xnn_f32_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 <= 2);
38 assert(nc != 0);
39 assert(kc != 0);
40 assert(kc % sizeof(int8_t) == 0);
41 assert(a != NULL);
42 assert(w != NULL);
43 assert(c != NULL);
44
45 kc = round_up_po2(kc, 4 * sizeof(int8_t));
46 const int8_t* a0 = a;
47 float* c0 = c;
48 const int8_t* a1 = (const int8_t*) ((uintptr_t) a0 + a_stride);
49 float* c1 = (float*) ((uintptr_t) c0 + cm_stride);
50 if XNN_UNPREDICTABLE(mr != 2) {
51 a1 = a0;
52 c1 = c0;
53 }
54
55 const __m256i vsign_mask =_mm256_set1_epi8(0x80);
56 XNN_FORCE_REALIZATION(vsign_mask);
57 const __m256i vinput_zero_point0 = _mm256_set1_epi32((int) quantization_params[0].zero_point + 128);
58 const __m256i vinput_zero_point1 = _mm256_set1_epi32((int) quantization_params[1].zero_point + 128);
59 const __m256 voutput_min = _mm256_set1_ps(params->scalar.min);
60 const __m256 voutput_max = _mm256_set1_ps(params->scalar.max);
61 // XNN_FORCE_REALIZATION(voutput_min);
62 // XNN_FORCE_REALIZATION(voutput_max);
63 do {
64 const __m256i vksum01234567 = _mm256_load_si256(w);
65 __m256i vacc0x0x01234567 = _mm256_mullo_epi32(vksum01234567, vinput_zero_point0);
66 __m256i vacc0x1x01234567 = _mm256_setzero_si256();
67 __m256i vacc1x0x01234567 = _mm256_mullo_epi32(vksum01234567, vinput_zero_point1);
68 __m256i vacc1x1x01234567 = _mm256_setzero_si256();
69 w = (const int32_t*) w + 8;
70
71 size_t k = kc;
72 while (k >= 8 * sizeof(int8_t)) {
73 __m256i va0x0x0123 = _mm256_set1_epi32((int) unaligned_load_u32(a0 + 0));
74 __m256i va0x1x0123 = _mm256_set1_epi32((int) unaligned_load_u32(a0 + 4));
75 a0 += 8;
76 __m256i va1x0x0123 = _mm256_set1_epi32((int) unaligned_load_u32(a1 + 0));
77 __m256i va1x1x0123 = _mm256_set1_epi32((int) unaligned_load_u32(a1 + 4));
78 a1 += 8;
79
80 va0x0x0123 = _mm256_xor_si256(va0x0x0123, vsign_mask);
81 va0x1x0123 = _mm256_xor_si256(va0x1x0123, vsign_mask);
82 va1x0x0123 = _mm256_xor_si256(va1x0x0123, vsign_mask);
83 va1x1x0123 = _mm256_xor_si256(va1x1x0123, vsign_mask);
84
85 const __m256i vb0x01234567 = _mm256_load_si256((const __m256i*) ((const int8_t*) w + 0));
86 const __m256i vb1x01234567 = _mm256_load_si256((const __m256i*) ((const int8_t*) w + 32));
87 w = (const int8_t*) w + 64;
88
89 vacc0x0x01234567 = _mm256_dpbusd_avx_epi32(vacc0x0x01234567, va0x0x0123, vb0x01234567);
90 vacc0x1x01234567 = _mm256_dpbusd_avx_epi32(vacc0x1x01234567, va0x1x0123, vb1x01234567);
91 vacc1x0x01234567 = _mm256_dpbusd_avx_epi32(vacc1x0x01234567, va1x0x0123, vb0x01234567);
92 vacc1x1x01234567 = _mm256_dpbusd_avx_epi32(vacc1x1x01234567, va1x1x0123, vb1x01234567);
93
94 k -= 8 * sizeof(int8_t);
95 }
96 vacc0x0x01234567 = _mm256_add_epi32(vacc0x0x01234567, vacc0x1x01234567);
97 vacc1x0x01234567 = _mm256_add_epi32(vacc1x0x01234567, vacc1x1x01234567);
98 while (k != 0) {
99 __m256i va0x0123 = _mm256_set1_epi32((int) unaligned_load_u32(a0));
100 a0 += 4;
101 __m256i va1x0123 = _mm256_set1_epi32((int) unaligned_load_u32(a1));
102 a1 += 4;
103
104 va0x0123 = _mm256_xor_si256(va0x0123, vsign_mask);
105 va1x0123 = _mm256_xor_si256(va1x0123, vsign_mask);
106
107 const __m256i vb01234567 = _mm256_load_si256(w);
108
109 vacc0x0x01234567 = _mm256_dpbusd_avx_epi32(vacc0x0x01234567, va0x0123, vb01234567);
110 vacc1x0x01234567 = _mm256_dpbusd_avx_epi32(vacc1x0x01234567, va1x0123, vb01234567);
111
112 w = (const int8_t*) w + 32;
113 k -= 4 * sizeof(int8_t);
114 }
115
116 __m256 vout0x01234567 = _mm256_cvtepi32_ps(vacc0x0x01234567);
117 __m256 vout1x01234567 = _mm256_cvtepi32_ps(vacc1x0x01234567);
118
119 vout0x01234567 = _mm256_mul_ps(vout0x01234567, _mm256_set1_ps(quantization_params[0].inv_scale));
120 vout1x01234567 = _mm256_mul_ps(vout1x01234567, _mm256_set1_ps(quantization_params[1].inv_scale));
121
122 const __m256 vfilter_output_scale01234567 = _mm256_load_ps((const float*) w);
123 const __m256 vbias01234567 = _mm256_load_ps((const float*) w + 8);
124 w = (const float*) w + 16;
125
126 vout0x01234567 = _mm256_fmadd_ps(vout0x01234567, vfilter_output_scale01234567, vbias01234567);
127 vout1x01234567 = _mm256_fmadd_ps(vout1x01234567, vfilter_output_scale01234567, vbias01234567);
128
129 vout0x01234567 = _mm256_max_ps(vout0x01234567, voutput_min);
130 vout1x01234567 = _mm256_max_ps(vout1x01234567, voutput_min);
131
132 vout0x01234567 = _mm256_min_ps(vout0x01234567, voutput_max);
133 vout1x01234567 = _mm256_min_ps(vout1x01234567, voutput_max);
134
135 if XNN_LIKELY(nc >= 8) {
136 _mm256_storeu_ps(c0, vout0x01234567);
137 a0 = (const int8_t*) ((uintptr_t) a0 - kc);
138 c0 = (float*) ((uintptr_t) c0 + cn_stride);
139 _mm256_storeu_ps(c1, vout1x01234567);
140 a1 = (const int8_t*) ((uintptr_t) a1 - kc);
141 c1 = (float*) ((uintptr_t) c1 + cn_stride);
142 nc -= 8;
143 } else {
144 __m128 vout0x0123 = _mm256_castps256_ps128(vout0x01234567);
145 __m128 vout1x0123 = _mm256_castps256_ps128(vout1x01234567);
146 if (nc & 4) {
147 _mm_storeu_ps(c0, vout0x0123);
148 c0 += 4;
149 _mm_storeu_ps(c1, vout1x0123);
150 c1 += 4;
151 vout0x0123 = _mm256_extractf128_ps(vout0x01234567, 1);
152 vout1x0123 = _mm256_extractf128_ps(vout1x01234567, 1);
153 }
154 if (nc & 2) {
155 _mm_storel_pi((__m64*) c0, vout0x0123);
156 c0 += 2;
157 _mm_storel_pi((__m64*) c1, vout1x0123);
158 c1 += 2;
159 vout0x0123 = _mm_movehl_ps(vout0x0123, vout0x0123);
160 vout1x0123 = _mm_movehl_ps(vout1x0123, vout1x0123);
161 }
162 if (nc & 1) {
163 _mm_store_ss(c0, vout0x0123);
164 _mm_store_ss(c1, vout1x0123);
165 }
166 nc = 0;
167 }
168 } while (nc != 0);
169 }