Debian Codegraph @

src/f16-igemm/gen/f16-igemm-1x32-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_1x32__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 w = (const xnn_float16*) w + 32;
50
51 size_t p = ks;
52 do {
53 const uint16_t* restrict a0 = (const uint16_t*) a[0];
54 assert(a0 != NULL);
55 if XNN_UNPREDICTABLE(a0 != (const uint16_t*) zero) {
56 a0 = (const uint16_t*) ((uintptr_t) a0 + a_offset);
57 }
58 a += 1;
59
60 size_t k = kc;
61 do {
62 const __m512h vb0 = _mm512_load_ph(w);
63 w = (const xnn_float16*) w + 32;
64
65 const __m512h va0 = _mm512_castsi512_ph(_mm512_set1_epi16(*a0));
66 vacc0x0 = _mm512_fmadd_ph(va0, vb0, vacc0x0);
67 a0 += 1;
68
69 k -= sizeof(uint16_t);
70 } while (k != 0);
71
72 p -= 1 * sizeof(void*);
73 } while (p != 0);
74
75 const __m512h vmin = _mm512_castsi512_ph(_mm512_set1_epi16(*(const uint16_t*) &params->scalar.min));
76 vacc0x0 = _mm512_max_ph(vmin, vacc0x0);
77
78 const __m512h vmax = _mm512_castsi512_ph(_mm512_set1_epi16(*(const uint16_t*) &params->scalar.max));
79 vacc0x0 = _mm512_min_ph(vmax, vacc0x0);
80
81 if XNN_LIKELY(nc >= 32) {
82 _mm512_storeu_ph(c0, vacc0x0);
83 c0 = (uint16_t*) ((uintptr_t) c0 + cn_stride);
84
85 a = (const xnn_float16**restrict) ((uintptr_t) a - ks);
86 nc -= 32;
87 } else {
88 assert(nc != 0);
89 assert(nc < 32);
90 // Prepare mask for valid 16-bit elements (depends on nc).
91 const __mmask32 vmask = _cvtu32_mask32((uint32_t) (UINT32_C(1) << nc) - UINT32_C(1));
92 _mm512_mask_storeu_epi16(c0, vmask, _mm512_castph_si512(vacc0x0));
93 nc = 0;
94 }
95 } while (nc != 0);
96 #endif // defined(__AVX512FP16__)
97 }