Debian Codegraph @

src/qd8-f32-qc8w-gemm/gen/qd8-f32-qc8w-gemm-1x8c8-minmax-avxvnni-prfm.c

raw
1 // Auto-generated file. Do not edit!
2 // Template: src/qs8-gemm/MRx8c8-avxvnni.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/gemm.h"
15 #include "xnnpack/intrinsics-polyfill.h"
16 #include "xnnpack/math.h"
17 #include "xnnpack/unaligned.h"
18 #include "xnnpack/prefetch.h"
19
20
21 void xnn_qd8_f32_qc8w_gemm_minmax_ukernel_1x8c8__avxvnni_prfm(
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 union xnn_f32_minmax_params params[restrict XNN_MIN_ELEMENTS(1)],
32 const struct xnn_qd8_quantization_params quantization_params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS
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 kc = round_up_po2(kc, 8 * sizeof(int8_t));
44 const int8_t* a0 = a;
45 float* c0 = c;
46
47 const __m256i vsign_mask = _mm256_set1_epi8(0x80);
48 XNN_FORCE_REALIZATION(vsign_mask);
49 const __m256i vinput_zero_point0 = _mm256_set1_epi32((int) quantization_params[0].zero_point + 128);
50 const __m256 voutput_min = _mm256_set1_ps(params->scalar.min);
51 const __m256 voutput_max = _mm256_set1_ps(params->scalar.max);
52 // XNN_FORCE_REALIZATION(voutput_min);
53 // XNN_FORCE_REALIZATION(voutput_max);
54 do {
55 const __m256i vksum01234567 = _mm256_load_si256(w);
56 __m256i vsum0x01234567 = _mm256_mullo_epi32(vksum01234567, vinput_zero_point0);
57 __m256i vacc0x0123 = _mm256_cvtepu32_epi64(_mm256_extracti128_si256(vsum0x01234567, 0));
58 __m256i vacc0x4567 = _mm256_cvtepu32_epi64(_mm256_extracti128_si256(vsum0x01234567, 1));
59 __m256i vacc1x0x0123 = _mm256_setzero_si256();
60 __m256i vacc1x0x4567 = _mm256_setzero_si256();
61 w = (const int32_t*) w + 8;
62
63 size_t k = kc;
64 while (k >= 16 * sizeof(int8_t)) {
65 const __m256i va0x01234567 = _mm256_xor_si256(_mm256_set1_epi64x((int64_t) unaligned_load_u64(a0)), vsign_mask);
66 const __m256i va0x89ABCDEF = _mm256_xor_si256(_mm256_set1_epi64x((int64_t) unaligned_load_u64(a0 + 8)), vsign_mask);
67 a0 += 16;
68
69 const __m256i vb01234567x0123 = _mm256_load_si256(w);
70 const __m256i vb89ABCDEFx0123 = _mm256_load_si256((const __m256i*) ((const int8_t*) w + 32));
71 const __m256i vb01234567x4567 = _mm256_load_si256((const __m256i*) ((const int8_t*) w + 64));
72 const __m256i vb89ABCDEFx4567 = _mm256_load_si256((const __m256i*) ((const int8_t*) w + 96));
73 xnn_prefetch_to_l1((const int8_t*) w + 896);
74
75 vacc0x0123 = _mm256_dpbusd_avx_epi32(vacc0x0123, va0x01234567, vb01234567x0123);
76 vacc0x4567 = _mm256_dpbusd_avx_epi32(vacc0x4567, va0x01234567, vb89ABCDEFx0123);
77 xnn_prefetch_to_l1((const int8_t*) w + 960);
78 vacc1x0x0123 = _mm256_dpbusd_avx_epi32(vacc1x0x0123, va0x89ABCDEF, vb01234567x4567);
79 vacc1x0x4567 = _mm256_dpbusd_avx_epi32(vacc1x0x4567, va0x89ABCDEF, vb89ABCDEFx4567);
80
81 w = (const int8_t*) w + 128;
82 k -= 16 * sizeof(int8_t);
83 }
84
85 if (k != 0) {
86 const __m256i va0x01234567 = _mm256_xor_si256(_mm256_set1_epi64x((int64_t) unaligned_load_u64(a0)), vsign_mask);
87 a0 += 8;
88
89 const __m256i vb01234567x0123 = _mm256_load_si256(w);
90 const __m256i vb89ABCDEFx0123 = _mm256_load_si256((const __m256i*) ((const int8_t*) w + 32));
91
92 vacc0x0123 = _mm256_dpbusd_avx_epi32(vacc0x0123, va0x01234567, vb01234567x0123);
93 vacc0x4567 = _mm256_dpbusd_avx_epi32(vacc0x4567, va0x01234567, vb89ABCDEFx0123);
94 xnn_prefetch_to_l1((const int8_t*) w + 960);
95
96 w = (const int8_t*) w + 64;
97 k -= 8 * sizeof(int8_t);
98 }
99 vacc0x0123 = _mm256_add_epi32(vacc0x0123, vacc1x0x0123);
100 vacc0x4567 = _mm256_add_epi32(vacc0x4567, vacc1x0x4567);
101
102 // Add adjacent pairs
103 const __m256i vsum0x02134657 = _mm256_hadd_epi32(vacc0x0123, vacc0x4567);
104 __m256i vacc0x01234567 = _mm256_permute4x64_epi64(vsum0x02134657, _MM_SHUFFLE(3, 1, 2, 0));
105
106 __m256 vout0x01234567 = _mm256_cvtepi32_ps(vacc0x01234567);
107
108 vout0x01234567 = _mm256_mul_ps(vout0x01234567, _mm256_set1_ps(quantization_params[0].inv_scale));
109
110 const __m256 vfilter_output_scale01234567 = _mm256_load_ps((const float*) w);
111 const __m256 vbias01234567 = _mm256_load_ps((const float*) w + 8);
112 w = (const float*) w + 16;
113
114 vout0x01234567 = _mm256_fmadd_ps(vout0x01234567, vfilter_output_scale01234567, vbias01234567);
115
116 vout0x01234567 = _mm256_max_ps(vout0x01234567, voutput_min);
117
118 vout0x01234567 = _mm256_min_ps(vout0x01234567, voutput_max);
119
120 if XNN_LIKELY(nc >= 8) {
121 _mm256_storeu_ps(c0, vout0x01234567);
122 a0 = (const int8_t*) ((uintptr_t) a0 - kc);
123 c0 = (float*) ((uintptr_t) c0 + cn_stride);
124 nc -= 8;
125 } else {
126 __m128 vout0x0123 = _mm256_castps256_ps128(vout0x01234567);
127 if (nc & 4) {
128 _mm_storeu_ps(c0, vout0x0123);
129 c0 += 4;
130 vout0x0123 = _mm256_extractf128_ps(vout0x01234567, 1);
131 }
132 if (nc & 2) {
133 _mm_storel_pi((__m64*) c0, vout0x0123);
134 c0 += 2;
135 vout0x0123 = _mm_movehl_ps(vout0x0123, vout0x0123);
136 }
137 if (nc & 1) {
138 _mm_store_ss(c0, vout0x0123);
139 }
140 nc = 0;
141 }
142 } while (nc != 0);
143 }