Debian Codegraph @

src/qd8-f32-qc8w-gemm/gen/qd8-f32-qc8w-gemm-1x8c4-minmax-avxvnni-u4-acc4.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_1x8c4__avxvnni_u4_acc4(
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 <= 1);
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
49 const __m256i vsign_mask =_mm256_set1_epi8(0x80);
50 XNN_FORCE_REALIZATION(vsign_mask);
51 const __m256i vinput_zero_point0 = _mm256_set1_epi32((int) quantization_params[0].zero_point + 128);
52 const __m256 voutput_min = _mm256_set1_ps(params->scalar.min);
53 const __m256 voutput_max = _mm256_set1_ps(params->scalar.max);
54 // XNN_FORCE_REALIZATION(voutput_min);
55 // XNN_FORCE_REALIZATION(voutput_max);
56 do {
57 const __m256i vksum01234567 = _mm256_load_si256(w);
58 __m256i vacc0x0x01234567 = _mm256_mullo_epi32(vksum01234567, vinput_zero_point0);
59 __m256i vacc0x1x01234567 = _mm256_setzero_si256();
60 __m256i vacc0x2x01234567 = _mm256_setzero_si256();
61 __m256i vacc0x3x01234567 = _mm256_setzero_si256();
62 w = (const int32_t*) w + 8;
63
64 size_t k = kc;
65 while (k >= 16 * sizeof(int8_t)) {
66 __m256i va0x0x0123 = _mm256_set1_epi32((int) unaligned_load_u32(a0 + 0));
67 __m256i va0x1x0123 = _mm256_set1_epi32((int) unaligned_load_u32(a0 + 4));
68 __m256i va0x2x0123 = _mm256_set1_epi32((int) unaligned_load_u32(a0 + 8));
69 __m256i va0x3x0123 = _mm256_set1_epi32((int) unaligned_load_u32(a0 + 12));
70 a0 += 16;
71
72 va0x0x0123 = _mm256_xor_si256(va0x0x0123, vsign_mask);
73 va0x1x0123 = _mm256_xor_si256(va0x1x0123, vsign_mask);
74 va0x2x0123 = _mm256_xor_si256(va0x2x0123, vsign_mask);
75 va0x3x0123 = _mm256_xor_si256(va0x3x0123, vsign_mask);
76
77 const __m256i vb0x01234567 = _mm256_load_si256((const __m256i*) ((const int8_t*) w + 0));
78 const __m256i vb1x01234567 = _mm256_load_si256((const __m256i*) ((const int8_t*) w + 32));
79 const __m256i vb2x01234567 = _mm256_load_si256((const __m256i*) ((const int8_t*) w + 64));
80 const __m256i vb3x01234567 = _mm256_load_si256((const __m256i*) ((const int8_t*) w + 96));
81 w = (const int8_t*) w + 128;
82
83 vacc0x0x01234567 = _mm256_dpbusd_avx_epi32(vacc0x0x01234567, va0x0x0123, vb0x01234567);
84 vacc0x1x01234567 = _mm256_dpbusd_avx_epi32(vacc0x1x01234567, va0x1x0123, vb1x01234567);
85 vacc0x2x01234567 = _mm256_dpbusd_avx_epi32(vacc0x2x01234567, va0x2x0123, vb2x01234567);
86 vacc0x3x01234567 = _mm256_dpbusd_avx_epi32(vacc0x3x01234567, va0x3x0123, vb3x01234567);
87
88 k -= 16 * sizeof(int8_t);
89 }
90 vacc0x0x01234567 = _mm256_add_epi32(vacc0x0x01234567, vacc0x1x01234567);
91 vacc0x2x01234567 = _mm256_add_epi32(vacc0x2x01234567, vacc0x3x01234567);
92 vacc0x0x01234567 = _mm256_add_epi32(vacc0x0x01234567, vacc0x2x01234567);
93 while (k != 0) {
94 __m256i va0x0123 = _mm256_set1_epi32((int) unaligned_load_u32(a0));
95 a0 += 4;
96
97 va0x0123 = _mm256_xor_si256(va0x0123, vsign_mask);
98
99 const __m256i vb01234567 = _mm256_load_si256(w);
100
101 vacc0x0x01234567 = _mm256_dpbusd_avx_epi32(vacc0x0x01234567, va0x0123, vb01234567);
102
103 w = (const int8_t*) w + 32;
104 k -= 4 * sizeof(int8_t);
105 }
106
107 __m256 vout0x01234567 = _mm256_cvtepi32_ps(vacc0x0x01234567);
108
109 vout0x01234567 = _mm256_mul_ps(vout0x01234567, _mm256_set1_ps(quantization_params[0].inv_scale));
110
111 const __m256 vfilter_output_scale01234567 = _mm256_load_ps((const float*) w);
112 const __m256 vbias01234567 = _mm256_load_ps((const float*) w + 8);
113 w = (const float*) w + 16;
114
115 vout0x01234567 = _mm256_fmadd_ps(vout0x01234567, vfilter_output_scale01234567, vbias01234567);
116
117 vout0x01234567 = _mm256_max_ps(vout0x01234567, voutput_min);
118
119 vout0x01234567 = _mm256_min_ps(vout0x01234567, voutput_max);
120
121 if XNN_LIKELY(nc >= 8) {
122 _mm256_storeu_ps(c0, vout0x01234567);
123 a0 = (const int8_t*) ((uintptr_t) a0 - kc);
124 c0 = (float*) ((uintptr_t) c0 + cn_stride);
125 nc -= 8;
126 } else {
127 __m128 vout0x0123 = _mm256_castps256_ps128(vout0x01234567);
128 if (nc & 4) {
129 _mm_storeu_ps(c0, vout0x0123);
130 c0 += 4;
131 vout0x0123 = _mm256_extractf128_ps(vout0x01234567, 1);
132 }
133 if (nc & 2) {
134 _mm_storel_pi((__m64*) c0, vout0x0123);
135 c0 += 2;
136 vout0x0123 = _mm_movehl_ps(vout0x0123, vout0x0123);
137 }
138 if (nc & 1) {
139 _mm_store_ss(c0, vout0x0123);
140 }
141 nc = 0;
142 }
143 } while (nc != 0);
144 }