Elffuss BraidHub

kikocis/ncnn public

master · 4.2 KiBRawPermalink
1// BUG1989 is pleased to support the open source community by supporting ncnn available.
2//
3// Copyright (C) 2019 BUG1989. All rights reserved.
4//
5// Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
6// in compliance with the License. You may obtain a copy of the License at
7//
8// https://opensource.org/licenses/BSD-3-Clause
9//
10// Unless required by applicable law or agreed to in writing, software distributed
11// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12// CONDITIONS OF ANY KIND, either express or implied. See the License for the
13// specific language governing permissions and limitations under the License.
14
15static void conv3x3s1_int8_sse(const Mat& bottom_blob, Mat& top_blob, const Mat& _kernel, const Option& opt)
16{
17 int w = bottom_blob.w;
18 int inch = bottom_blob.c;
19
20 int outw = top_blob.w;
21 int outh = top_blob.h;
22 int outch = top_blob.c;
23
24 const signed char* kernel = _kernel;
25
26 #pragma omp parallel for num_threads(opt.num_threads)
27 for (int p = 0; p < outch; p++)
28 {
29 Mat out0 = top_blob.channel(p);
30
31 out0.fill(0);
32
33 const signed char* kernel0 = (const signed char*)kernel + p * inch * 9;
34
35 for (int q = 0; q < inch; q++)
36 {
37 int* outptr0 = out0;
38
39 const signed char* img0 = bottom_blob.channel(q);
40
41 const signed char* r0 = img0;
42 const signed char* r1 = img0 + w;
43 const signed char* r2 = img0 + w * 2;
44
45 for (int i = 0; i < outh; i++)
46 {
47 int remain = outw;
48
49 for (; remain > 0; remain--)
50 {
51 int sum0 = 0;
52
53 sum0 += (int)r0[0] * kernel0[0];
54 sum0 += (int)r0[1] * kernel0[1];
55 sum0 += (int)r0[2] * kernel0[2];
56 sum0 += (int)r1[0] * kernel0[3];
57 sum0 += (int)r1[1] * kernel0[4];
58 sum0 += (int)r1[2] * kernel0[5];
59 sum0 += (int)r2[0] * kernel0[6];
60 sum0 += (int)r2[1] * kernel0[7];
61 sum0 += (int)r2[2] * kernel0[8];
62
63 *outptr0 += sum0;
64
65 r0++;
66 r1++;
67 r2++;
68 outptr0++;
69 }
70
71 r0 += 2;
72 r1 += 2;
73 r2 += 2;
74 }
75
76 kernel0 += 9;
77 }
78 }
79}
80
81static void conv3x3s2_int8_sse(const Mat& bottom_blob, Mat& top_blob, const Mat& _kernel, const Option& opt)
82{
83 int w = bottom_blob.w;
84 int inch = bottom_blob.c;
85
86 int outw = top_blob.w;
87 int outh = top_blob.h;
88 int outch = top_blob.c;
89
90 const int tailstep = w - 2 * outw + w;
91
92 const signed char* kernel = _kernel;
93
94 #pragma omp parallel for num_threads(opt.num_threads)
95 for (int p = 0; p < outch; p++)
96 {
97 Mat out0 = top_blob.channel(p);
98
99 out0.fill(0);
100
101 const signed char* kernel0 = (const signed char*)kernel + p * inch * 9;
102
103 for (int q = 0; q < inch; q++)
104 {
105 int* outptr0 = out0;
106
107 const signed char* img0 = bottom_blob.channel(q);
108
109 const signed char* r0 = img0;
110 const signed char* r1 = img0 + w;
111 const signed char* r2 = img0 + w * 2;
112
113 for (int i = 0; i < outh; i++)
114 {
115 int remain = outw;
116
117 for (; remain > 0; remain--)
118 {
119 int sum0 = 0;
120
121 sum0 += (int)r0[0] * kernel0[0];
122 sum0 += (int)r0[1] * kernel0[1];
123 sum0 += (int)r0[2] * kernel0[2];
124 sum0 += (int)r1[0] * kernel0[3];
125 sum0 += (int)r1[1] * kernel0[4];
126 sum0 += (int)r1[2] * kernel0[5];
127 sum0 += (int)r2[0] * kernel0[6];
128 sum0 += (int)r2[1] * kernel0[7];
129 sum0 += (int)r2[2] * kernel0[8];
130
131 *outptr0 += sum0;
132
133 r0 += 2;
134 r1 += 2;
135 r2 += 2;
136 outptr0++;
137 }
138
139 r0 += tailstep;
140 r1 += tailstep;
141 r2 += tailstep;
142 }
143
144 kernel0 += 9;
145 }
146 }
147}