• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Auto-generated file. Do not edit!
2 //   Template: src/f32-dwconv2d-chw/3x3s2p1-scalar.c.in
3 //   Generator: tools/xngen
4 //
5 // Copyright 2020 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 <xnnpack/dwconv.h>
13 #include <xnnpack/math.h>
14 
15 
xnn_f32_dwconv2d_chw_ukernel_3x3s2p1__scalar_1x1_acc3(size_t input_height,size_t input_width,const float * input,const float * weights,const float * zero,float * output,uint32_t padding_top,const union xnn_f32_chw_params params[restrict XNN_MIN_ELEMENTS (1)])16 void xnn_f32_dwconv2d_chw_ukernel_3x3s2p1__scalar_1x1_acc3(
17     size_t input_height,
18     size_t input_width,
19     const float* input,
20     const float* weights,
21     const float* zero,
22     float* output,
23     uint32_t padding_top,
24     const union xnn_f32_chw_params params[restrict XNN_MIN_ELEMENTS(1)])
25 {
26   assert(input_height != 0);
27   assert(input_width != 0);
28   assert(input_width % sizeof(float) == 0);
29   assert(padding_top >= 0);
30   assert(padding_top <= 1);
31 
32   const float vmin = params->scalar.min;
33   const float vmax = params->scalar.max;
34 
35   const float vbias = weights[0];
36   const float vk00 = weights[1];
37   const float vk01 = weights[2];
38   const float vk02 = weights[3];
39   const float vk10 = weights[4];
40   const float vk11 = weights[5];
41   const float vk12 = weights[6];
42   const float vk20 = weights[7];
43   const float vk21 = weights[8];
44   const float vk22 = weights[9];
45 
46 
47   const float* i0 = (const float*) ((uintptr_t) input - ((-padding_top) & input_width));
48   const float* i1 = (const float*) ((uintptr_t) i0 + input_width);
49   if XNN_UNPREDICTABLE(padding_top != 0) {
50     i0 = zero;
51   }
52   const float* i2 = (const float*) ((uintptr_t) i1 + input_width);
53 
54   float* o0 = output;
55 
56   size_t padded_input_height = input_height + padding_top + 1 /* padding bottom */;
57   size_t output_height = (padded_input_height - 3 /* kernel size */ + 2 /* subsampling */) / 2;
58   do {
59     if XNN_UNPREDICTABLE(padded_input_height < 4) {
60       i2 = zero;
61     }
62 
63     float vi0x0 = 0.0f;
64     float vi1x0 = 0.0f;
65     float vi2x0 = 0.0f;
66 
67     size_t w = input_width;
68     for (; w >= 2 * sizeof(float); w -= 2 * sizeof(float)) {
69       const float vi0x1 = i0[0];
70       const float vi1x1 = i1[0];
71       const float vi2x1 = i2[0];
72 
73       float vo0p0 = vbias + vi0x0 * vk00;
74       float vo0p1 = vi1x0 * vk10;
75       float vo0p2 = vi2x0 * vk20;
76 
77       const float vi0x2 = i0[1];
78       i0 += 2;
79       const float vi1x2 = i1[1];
80       i1 += 2;
81       const float vi2x2 = i2[1];
82       i2 += 2;
83 
84       vo0p0 += vi0x1 * vk01;
85       vo0p1 += vi1x1 * vk11;
86       vo0p2 += vi2x1 * vk21;
87 
88       vi0x0 = vi0x2;
89       vi1x0 = vi1x2;
90       vi2x0 = vi2x2;
91 
92       vo0p0 += vi0x2 * vk02;
93       vo0p1 += vi1x2 * vk12;
94       vo0p2 += vi2x2 * vk22;
95 
96       vo0p0 += vo0p1;
97       vo0p0 += vo0p2;
98 
99       float vo0 = math_max_f32(vo0p0, vmin);
100 
101       vo0 = math_min_f32(vo0, vmax);
102 
103       *o0++ = vo0;
104     }
105     // Potentially process the last pixel.
106     assert(w <= 1 * sizeof(float));
107     if (w != 0) {
108       const float vi0x1 = *i0++;
109       const float vi1x1 = *i1++;
110       const float vi2x1 = *i2++;
111 
112       float vo0p0 = vbias + vi0x0 * vk00;
113       float vo0p1 = vi1x0 * vk10;
114       float vo0p2 = vi2x0 * vk20;
115 
116       vo0p0 += vi0x1 * vk01;
117       vo0p1 += vi1x1 * vk11;
118       vo0p2 += vi2x1 * vk21;
119 
120       vo0p0 += vo0p1;
121       vo0p0 += vo0p2;
122 
123       float vo0 = math_max_f32(vo0p0, vmin);
124 
125       vo0 = math_min_f32(vo0, vmax);
126 
127       *o0++ = vo0;
128     }
129 
130     i0 = (const float*) ((uintptr_t) i1);
131     i1 = (const float*) ((uintptr_t) i2);
132     i2 = (const float*) ((uintptr_t) i1 + input_width);
133 
134 
135     output_height -= 1;
136     padded_input_height -= 2;
137   } while (output_height != 0);
138 }
139