Debian Codegraph @

src/f16-igemm/gen/f16-igemm-1x64-minmax-avx512fp16-broadcast.c

raw symbols SCIP
1 // Auto-generated file. Do not edit!
2 // Template: src/f16-igemm/avx512fp16-broadcast.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/igemm.h"
15 #include "xnnpack/intrinsics-polyfill.h"
16
17
18 void xnn_f16_igemm_minmax_ukernel_1x64__avx512fp16_broadcast(
19 size_t mr,
20 size_t nc,
21 size_t kc,
22 size_t ks,
23 const xnn_float16** restrict a,
24 const xnn_float16* restrict w,
25 xnn_float16* restrict c,
26 size_t cm_stride,
27 size_t cn_stride,
28 size_t a_offset,
29 const xnn_float16* zero,
30 const union xnn_f16_minmax_params params[restrict XNN_MIN_ELEMENTS(1)])
31 {
32 assert(mr != 0);
33 assert(mr <= 1);
34 assert(nc != 0);
35 assert(kc != 0);
36 assert(kc % sizeof(uint16_t) == 0);
37 assert(ks != 0);
38 assert(ks % (1 * sizeof(void*)) == 0);
39 assert(a_offset % sizeof(xnn_float16) == 0);
40 assert(a != NULL);
41 assert(w != NULL);
42 assert(c != NULL);
43
44 #if defined(__AVX512FP16__)
45 uint16_t* c0 = (uint16_t*) c;
46
47 do {
48 __m512h vacc0x0 = _mm512_load_ph(w);
49 __m512h vacc0x1 = _mm512_load_ph((const uint16_t*) w + 32);
50 w = (const xnn_float16*) w + 64;
51
52 size_t p = ks;
53 do {
54 const uint16_t* restrict a0 = (const uint16_t*) a[0];
55 assert(a0 != NULL);
56 if XNN_UNPREDICTABLE(a0 != (const uint16_t*) zero) {
57 a0 = (const uint16_t*) ((uintptr_t) a0 + a_offset);
58 }
59 a += 1;
60
61 size_t k = kc;
62 do {
63 const __m512h vb0 = _mm512_load_ph(w);
64 const __m512h vb1 = _mm512_load_ph((const uint16_t*) w + 32);
65 w = (const xnn_float16*) w + 64;
66
67 const __m512h va0 = _mm512_castsi512_ph(_mm512_set1_epi16(*a0));
68 vacc0x0 = _mm512_fmadd_ph(va0, vb0, vacc0x0);
69 vacc0x1 = _mm512_fmadd_ph(va0, vb1, vacc0x1);
70 a0 += 1;
71
72 k -= sizeof(uint16_t);
73 } while (k != 0);
74
75 p -= 1 * sizeof(void*);
76 } while (p != 0);
77
78 const __m512h vmin = _mm512_castsi512_ph(_mm512_set1_epi16(*(const uint16_t*) &params->scalar.min));
79 vacc0x0 = _mm512_max_ph(vmin, vacc0x0);
80 vacc0x1 = _mm512_max_ph(vmin, vacc0x1);
81
82 const __m512h vmax = _mm512_castsi512_ph(_mm512_set1_epi16(*(const uint16_t*) &params->scalar.max));
83 vacc0x0 = _mm512_min_ph(vmax, vacc0x0);
84 vacc0x1 = _mm512_min_ph(vmax, vacc0x1);
85
86 if XNN_LIKELY(nc >= 64) {
87 _mm512_storeu_ph(c0, vacc0x0);
88 _mm512_storeu_ph((uint16_t*) c0 + 1, vacc0x1);
89 c0 = (uint16_t*) ((uintptr_t) c0 + cn_stride);
90
91 a = (const xnn_float16**restrict) ((uintptr_t) a - ks);
92 nc -= 64;
93 } else {
94 if (nc & 32) {
95 _mm512_storeu_ph(c0, vacc0x0);
96
97 vacc0x0 = vacc0x1;
98 c0 += 32;
99 }
100 if (nc & 31) {
101 // Prepare mask for valid 16-bit elements (depends on nc).
102 const __mmask32 vmask = _cvtu32_mask32((uint32_t) (UINT32_C(1) << (nc & 31)) - UINT32_C(1));
103 _mm512_mask_storeu_epi16(c0, vmask, _mm512_castph_si512(vacc0x0));
104 }
105 nc = 0;
106 }
107 } while (nc != 0);
108 #endif // defined(__AVX512FP16__)
109 }