• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Auto-generated file. Do not edit!
2 //   Template: src/f32-dwconv/up-avx512.c.in
3 //   Generator: tools/xngen
4 //
5 // Copyright 2019 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/dwconv.h>
15 #include <xnnpack/intrinsics-polyfill.h>
16 
17 
xnn_f32_dwconv_ukernel_up32x4__avx512f(size_t channels,size_t output_width,const float ** input,const float * weights,float * output,size_t input_stride,size_t output_increment,const union xnn_f32_output_params params[restrict static1])18 void xnn_f32_dwconv_ukernel_up32x4__avx512f(
19     size_t channels,
20     size_t output_width,
21     const float** input,
22     const float* weights,
23     float* output,
24     size_t input_stride,
25     size_t output_increment,
26     const union xnn_f32_output_params params[restrict static 1])
27 {
28   assert(channels != 0);
29   assert(output_width != 0);
30 
31   const __m512 vmax = _mm512_broadcast_f32x4(_mm_load_ps(params->sse.max));
32   const __m512 vmin = _mm512_broadcast_f32x4(_mm_load_ps(params->sse.min));
33   do {
34     const float* i0 = input[0];
35     assert(i0 != NULL);
36     const float* i1 = input[1];
37     assert(i1 != NULL);
38     const float* i2 = input[2];
39     assert(i2 != NULL);
40     const float* i3 = input[3];
41     assert(i3 != NULL);
42     input = (const float**) ((uintptr_t) input + input_stride);
43 
44     size_t c = channels;
45     const float* w = weights;
46     for (; c >= 32; c -= 32) {
47       __m512 vacc0123456789ABCDEFp0 = _mm512_load_ps(w);
48       __m512 vaccGHIJKLMNOPQRSTUVp0 = _mm512_load_ps(w + 16);
49 
50 
51       const __m512 vi0x0123456789ABCDEF = _mm512_loadu_ps(i0);
52       const __m512 vi0xGHIJKLMNOPQRSTUV = _mm512_loadu_ps(i0 + 16);
53       i0 += 32;
54 
55       const __m512 vk0x0123456789ABCDEF = _mm512_load_ps(w + 32);
56       const __m512 vk0xGHIJKLMNOPQRSTUV = _mm512_load_ps(w + 48);
57       vacc0123456789ABCDEFp0 = _mm512_fmadd_ps(vi0x0123456789ABCDEF, vk0x0123456789ABCDEF, vacc0123456789ABCDEFp0);
58       vaccGHIJKLMNOPQRSTUVp0 = _mm512_fmadd_ps(vi0xGHIJKLMNOPQRSTUV, vk0xGHIJKLMNOPQRSTUV, vaccGHIJKLMNOPQRSTUVp0);
59 
60       const __m512 vi1x0123456789ABCDEF = _mm512_loadu_ps(i1);
61       const __m512 vi1xGHIJKLMNOPQRSTUV = _mm512_loadu_ps(i1 + 16);
62       i1 += 32;
63 
64       const __m512 vk1x0123456789ABCDEF = _mm512_load_ps(w + 64);
65       const __m512 vk1xGHIJKLMNOPQRSTUV = _mm512_load_ps(w + 80);
66       vacc0123456789ABCDEFp0 = _mm512_fmadd_ps(vi1x0123456789ABCDEF, vk1x0123456789ABCDEF, vacc0123456789ABCDEFp0);
67       vaccGHIJKLMNOPQRSTUVp0 = _mm512_fmadd_ps(vi1xGHIJKLMNOPQRSTUV, vk1xGHIJKLMNOPQRSTUV, vaccGHIJKLMNOPQRSTUVp0);
68 
69       const __m512 vi2x0123456789ABCDEF = _mm512_loadu_ps(i2);
70       const __m512 vi2xGHIJKLMNOPQRSTUV = _mm512_loadu_ps(i2 + 16);
71       i2 += 32;
72 
73       const __m512 vk2x0123456789ABCDEF = _mm512_load_ps(w + 96);
74       const __m512 vk2xGHIJKLMNOPQRSTUV = _mm512_load_ps(w + 112);
75       vacc0123456789ABCDEFp0 = _mm512_fmadd_ps(vi2x0123456789ABCDEF, vk2x0123456789ABCDEF, vacc0123456789ABCDEFp0);
76       vaccGHIJKLMNOPQRSTUVp0 = _mm512_fmadd_ps(vi2xGHIJKLMNOPQRSTUV, vk2xGHIJKLMNOPQRSTUV, vaccGHIJKLMNOPQRSTUVp0);
77 
78       const __m512 vi3x0123456789ABCDEF = _mm512_loadu_ps(i3);
79       const __m512 vi3xGHIJKLMNOPQRSTUV = _mm512_loadu_ps(i3 + 16);
80       i3 += 32;
81 
82       const __m512 vk3x0123456789ABCDEF = _mm512_load_ps(w + 128);
83       const __m512 vk3xGHIJKLMNOPQRSTUV = _mm512_load_ps(w + 144);
84       vacc0123456789ABCDEFp0 = _mm512_fmadd_ps(vi3x0123456789ABCDEF, vk3x0123456789ABCDEF, vacc0123456789ABCDEFp0);
85       vaccGHIJKLMNOPQRSTUVp0 = _mm512_fmadd_ps(vi3xGHIJKLMNOPQRSTUV, vk3xGHIJKLMNOPQRSTUV, vaccGHIJKLMNOPQRSTUVp0);
86 
87       w += 160;
88 
89 
90       __m512 vacc0123456789ABCDEF = _mm512_max_ps(vacc0123456789ABCDEFp0, vmin);
91       __m512 vaccGHIJKLMNOPQRSTUV = _mm512_max_ps(vaccGHIJKLMNOPQRSTUVp0, vmin);
92       vacc0123456789ABCDEF = _mm512_min_ps(vacc0123456789ABCDEF, vmax);
93       vaccGHIJKLMNOPQRSTUV = _mm512_min_ps(vaccGHIJKLMNOPQRSTUV, vmax);
94 
95       _mm512_storeu_ps(output, vacc0123456789ABCDEF);
96       _mm512_storeu_ps(output + 16, vaccGHIJKLMNOPQRSTUV);
97       output += 32;
98     }
99     for (; c >= 16; c -= 16) {
100       __m512 vacc0123456789ABCDEFp0 = _mm512_load_ps(w);
101 
102       const __m512 vi0x0123456789ABCDEF = _mm512_loadu_ps(i0);
103       i0 += 16;
104 
105       const __m512 vk0x0123456789ABCDEF = _mm512_load_ps(w + 32);
106       vacc0123456789ABCDEFp0 = _mm512_fmadd_ps(vi0x0123456789ABCDEF, vk0x0123456789ABCDEF, vacc0123456789ABCDEFp0);
107 
108       const __m512 vi1x0123456789ABCDEF = _mm512_loadu_ps(i1);
109       i1 += 16;
110 
111       const __m512 vk1x0123456789ABCDEF = _mm512_load_ps(w + 64);
112       vacc0123456789ABCDEFp0 = _mm512_fmadd_ps(vi1x0123456789ABCDEF, vk1x0123456789ABCDEF, vacc0123456789ABCDEFp0);
113 
114       const __m512 vi2x0123456789ABCDEF = _mm512_loadu_ps(i2);
115       i2 += 16;
116 
117       const __m512 vk2x0123456789ABCDEF = _mm512_load_ps(w + 96);
118       vacc0123456789ABCDEFp0 = _mm512_fmadd_ps(vi2x0123456789ABCDEF, vk2x0123456789ABCDEF, vacc0123456789ABCDEFp0);
119 
120       const __m512 vi3x0123456789ABCDEF = _mm512_loadu_ps(i3);
121       i3 += 16;
122 
123       const __m512 vk3x0123456789ABCDEF = _mm512_load_ps(w + 128);
124       vacc0123456789ABCDEFp0 = _mm512_fmadd_ps(vi3x0123456789ABCDEF, vk3x0123456789ABCDEF, vacc0123456789ABCDEFp0);
125 
126       w += 16;
127 
128 
129       __m512 vacc0123456789ABCDEF = _mm512_max_ps(vacc0123456789ABCDEFp0, vmin);
130       vacc0123456789ABCDEF = _mm512_min_ps(vacc0123456789ABCDEF, vmax);
131 
132       _mm512_storeu_ps(output, vacc0123456789ABCDEF);
133       output += 16;
134     }
135     if XNN_UNLIKELY(c != 0) {
136       assert(c >= 1);
137       assert(c <= 16);
138       // Prepare mask for valid 32-bit elements (depends on nc).
139       const __mmask16 vmask = _cvtu32_mask16((uint16_t) ((uint32_t) (UINT32_C(1) << c) - UINT32_C(1)));
140 
141       __m512 vacc0123456789ABCDEFp0 = _mm512_maskz_loadu_ps(vmask, w);
142 
143       const __m512 vi0x0123456789ABCDEF = _mm512_maskz_loadu_ps(vmask, i0);
144       const __m512 vk0x0123456789ABCDEF = _mm512_maskz_loadu_ps(vmask, w + 32);
145       vacc0123456789ABCDEFp0 = _mm512_fmadd_ps(vi0x0123456789ABCDEF, vk0x0123456789ABCDEF, vacc0123456789ABCDEFp0);
146 
147       const __m512 vi1x0123456789ABCDEF = _mm512_maskz_loadu_ps(vmask, i1);
148       const __m512 vk1x0123456789ABCDEF = _mm512_maskz_loadu_ps(vmask, w + 64);
149       vacc0123456789ABCDEFp0 = _mm512_fmadd_ps(vi1x0123456789ABCDEF, vk1x0123456789ABCDEF, vacc0123456789ABCDEFp0);
150 
151       const __m512 vi2x0123456789ABCDEF = _mm512_maskz_loadu_ps(vmask, i2);
152       const __m512 vk2x0123456789ABCDEF = _mm512_maskz_loadu_ps(vmask, w + 96);
153       vacc0123456789ABCDEFp0 = _mm512_fmadd_ps(vi2x0123456789ABCDEF, vk2x0123456789ABCDEF, vacc0123456789ABCDEFp0);
154 
155       const __m512 vi3x0123456789ABCDEF = _mm512_maskz_loadu_ps(vmask, i3);
156       const __m512 vk3x0123456789ABCDEF = _mm512_maskz_loadu_ps(vmask, w + 128);
157       vacc0123456789ABCDEFp0 = _mm512_fmadd_ps(vi3x0123456789ABCDEF, vk3x0123456789ABCDEF, vacc0123456789ABCDEFp0);
158 
159 
160       __m512 vacc0123456789ABCDEF = _mm512_max_ps(vacc0123456789ABCDEFp0, vmin);
161       vacc0123456789ABCDEF = _mm512_min_ps(vacc0123456789ABCDEF, vmax);
162 
163       _mm512_mask_storeu_ps(output, vmask, vacc0123456789ABCDEF);
164       output += c;
165     }
166 
167     output = (float*) ((uintptr_t) output + output_increment);
168   } while (--output_width != 0);
169 }
170