Elffuss BraidHub

kikocis/ncnn public

master · 26.6 KiBRawPermalink
1// Tencent is pleased to support the open source community by making ncnn available.
2//
3// Copyright (C) 2019 THL A29 Limited, a Tencent company. 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
15#include "padding_arm.h"
16
17#if __ARM_NEON
18#include <arm_neon.h>
19#endif // __ARM_NEON
20
21#include "cpu.h"
22
23namespace ncnn {
24
25#if __ARM_NEON
26#include "padding_pack4.h"
27#include "padding_pack4_bf16s_fp16s.h"
28#include "padding_pack8_int8.h"
29#if NCNN_ARM82
30#include "padding_pack8_fp16s.h"
31#endif
32#endif // __ARM_NEON
33
34Padding_arm::Padding_arm()
35{
36#if __ARM_NEON
37 support_packing = true;
38#if NCNN_ARM82
39 support_fp16_storage = cpu_support_arm_asimdhp();
40#endif
41#endif // __ARM_NEON
42
43#if NCNN_BF16
44 support_bf16_storage = true;
45#endif
46}
47
48int Padding_arm::create_pipeline(const Option& opt)
49{
50#if NCNN_ARM82
51 if (support_fp16_storage && opt.use_fp16_storage)
52 {
53 value_fp16 = float32_to_float16(value);
54
55 ncnn::cast_float32_to_float16(per_channel_pad_data, per_channel_pad_data_fp16, opt);
56 }
57#endif
58
59#if NCNN_BF16
60 if (opt.use_bf16_storage)
61 {
62 value_bf16 = float32_to_bfloat16(value);
63
64 ncnn::cast_float32_to_bfloat16(per_channel_pad_data, per_channel_pad_data_bf16, opt);
65 }
66#endif
67
68 return 0;
69}
70
71int Padding_arm::destroy_pipeline(const Option& /*opt*/)
72{
73 return 0;
74}
75
76int Padding_arm::forward(const Mat& bottom_blob, Mat& top_blob, const Option& opt) const
77{
78 if (top == 0 && bottom == 0 && left == 0 && right == 0 && front == 0 && behind == 0)
79 {
80 top_blob = bottom_blob;
81 return 0;
82 }
83
84 int elembits = bottom_blob.elembits();
85
86 if (elembits == 8)
87 return forward_int8(bottom_blob, top_blob, opt);
88
89#if NCNN_ARM82
90 if (support_fp16_storage && opt.use_fp16_storage && elembits == 16)
91 return forward_bf16s_fp16s(bottom_blob, top_blob, opt);
92#endif
93
94#if NCNN_BF16
95 if (opt.use_bf16_storage && elembits == 16)
96 return forward_bf16s_fp16s(bottom_blob, top_blob, opt);
97#endif
98
99 int w = bottom_blob.w;
100 int h = bottom_blob.h;
101 int d = bottom_blob.d;
102 int channels = bottom_blob.c;
103 int dims = bottom_blob.dims;
104 size_t elemsize = bottom_blob.elemsize;
105 int elempack = bottom_blob.elempack;
106
107#if __ARM_NEON
108 if (elempack == 4)
109 {
110 if (dims == 1)
111 {
112 int outw = w * elempack + left + right;
113
114 int out_elempack = outw % 4 == 0 ? 4 : 1;
115 size_t out_elemsize = elemsize / elempack * out_elempack;
116
117 if (left % 4 == 0 && out_elempack == 4 && type == 0)
118 {
119 top_blob.create(outw / out_elempack, out_elemsize, out_elempack, opt.blob_allocator);
120 if (top_blob.empty())
121 return -100;
122
123 float32x4_t pad_value = vdupq_n_f32(value);
124 padding_constant_pack4_neon(bottom_blob, top_blob, 0, 0, left / 4, right / 4, pad_value);
125
126 return 0;
127 }
128 }
129
130 if (dims == 2)
131 {
132 int outw = w + left + right;
133 int outh = h * elempack + top + bottom;
134
135 int out_elempack = outh % 4 == 0 ? 4 : 1;
136 size_t out_elemsize = elemsize / elempack * out_elempack;
137
138 if (top % 4 == 0 && out_elempack == 4 && type == 0)
139 {
140 top_blob.create(outw, outh / out_elempack, out_elemsize, out_elempack, opt.blob_allocator);
141 if (top_blob.empty())
142 return -100;
143
144 float32x4_t pad_value = vdupq_n_f32(value);
145 padding_constant_pack4_neon(bottom_blob, top_blob, top / 4, bottom / 4, left, right, pad_value);
146
147 return 0;
148 }
149 }
150
151 if (dims == 3)
152 {
153 int outw = w + left + right;
154 int outh = h + top + bottom;
155 int outc = channels * elempack + front + behind;
156
157 int out_elempack = outc % 4 == 0 ? 4 : 1;
158 size_t out_elemsize = elemsize / elempack * out_elempack;
159
160 if (front % 4 == 0 && out_elempack == 4 && !(outc != channels * elempack && type != 0))
161 {
162 top_blob.create(outw, outh, outc / out_elempack, out_elemsize, out_elempack, opt.blob_allocator);
163 if (top_blob.empty())
164 return -100;
165
166 int front_ = front / elempack;
167 #pragma omp parallel for num_threads(opt.num_threads)
168 for (int q = 0; q < outc / out_elempack; q++)
169 {
170 Mat borderm = top_blob.channel(q);
171
172 float32x4_t pad_value = per_channel_pad_data_size ? vld1q_f32((const float*)per_channel_pad_data + q * 4) : vdupq_n_f32(value);
173 //Channel padding
174 if ((q - front_) < 0 || (q - front_) >= channels)
175 {
176 borderm.fill(pad_value);
177 }
178 else
179 {
180 const Mat m = bottom_blob.channel(q - front_);
181 if (type == 0)
182 padding_constant_pack4_neon(m, borderm, top, bottom, left, right, pad_value);
183 if (type == 1)
184 padding_replicate_pack4_neon(m, borderm, top, bottom, left, right);
185 if (type == 2)
186 padding_reflect_pack4_neon(m, borderm, top, bottom, left, right);
187 }
188 }
189
190 return 0;
191 }
192 }
193
194 if (dims == 4)
195 {
196 int outw = w + left + right;
197 int outh = h + top + bottom;
198 int outd = d + front + behind;
199
200 if (type == 0)
201 {
202 top_blob.create(outw, outh, outd, channels, elemsize, elempack, opt.blob_allocator);
203 if (top_blob.empty())
204 return -100;
205
206 #pragma omp parallel for num_threads(opt.num_threads)
207 for (int q = 0; q < channels; q++)
208 {
209 float32x4_t pad_value = per_channel_pad_data_size ? vld1q_f32((const float*)per_channel_pad_data + q * 4) : vdupq_n_f32(value);
210
211 for (int z = 0; z < outd; z++)
212 {
213 Mat borderm = top_blob.channel(q).depth(z);
214
215 // depth padding
216 if ((z - front) < 0 || (z - front) >= d)
217 {
218 borderm.fill(pad_value);
219 }
220 else
221 {
222 const Mat m = bottom_blob.channel(q).depth(z - front);
223 padding_constant_pack4_neon(m, borderm, top, bottom, left, right, pad_value);
224 }
225 }
226 }
227
228 return 0;
229 }
230 }
231 }
232#endif // __ARM_NEON
233
234 Mat bottom_blob_unpacked = bottom_blob;
235 if (elempack != 1)
236 {
237 Option opt_pack1 = opt;
238 opt_pack1.blob_allocator = opt.workspace_allocator;
239
240 convert_packing(bottom_blob, bottom_blob_unpacked, 1, opt_pack1);
241 if (bottom_blob_unpacked.empty())
242 return -100;
243 }
244
245 return Padding::forward(bottom_blob_unpacked, top_blob, opt);
246}
247
248int Padding_arm::forward_bf16s_fp16s(const Mat& bottom_blob, Mat& top_blob, const Option& opt) const
249{
250 int w = bottom_blob.w;
251 int h = bottom_blob.h;
252 int d = bottom_blob.d;
253 int channels = bottom_blob.c;
254 int dims = bottom_blob.dims;
255 size_t elemsize = bottom_blob.elemsize;
256 int elempack = bottom_blob.elempack;
257
258#if __ARM_NEON
259#if NCNN_ARM82
260 if (elempack == 8)
261 {
262 if (dims == 1)
263 {
264 int outw = w * elempack + left + right;
265
266 int out_elempack = outw % 8 == 0 ? 8 : outw % 4 == 0 ? 4 : 1;
267 size_t out_elemsize = elemsize / elempack * out_elempack;
268
269 if (left % 8 == 0 && out_elempack == 8 && type == 0)
270 {
271 top_blob.create(outw / out_elempack, out_elemsize, out_elempack, opt.blob_allocator);
272 if (top_blob.empty())
273 return -100;
274
275 uint16x8_t pad_value = vdupq_n_u16(value_fp16);
276 padding_constant_pack8_fp16s_neon(bottom_blob, top_blob, 0, 0, left / 8, right / 8, pad_value);
277
278 return 0;
279 }
280 }
281
282 if (dims == 2)
283 {
284 int outw = w + left + right;
285 int outh = h * elempack + top + bottom;
286
287 int out_elempack = outh % 8 == 0 ? 8 : outh % 4 == 0 ? 4 : 1;
288 size_t out_elemsize = elemsize / elempack * out_elempack;
289
290 if (top % 8 == 0 && out_elempack == 8 && type == 0)
291 {
292 top_blob.create(outw, outh / out_elempack, out_elemsize, out_elempack, opt.blob_allocator);
293 if (top_blob.empty())
294 return -100;
295
296 uint16x8_t pad_value = vdupq_n_u16(value_fp16);
297 padding_constant_pack8_fp16s_neon(bottom_blob, top_blob, top / 8, bottom / 8, left, right, pad_value);
298
299 return 0;
300 }
301 }
302
303 if (dims == 3)
304 {
305 int outw = w + left + right;
306 int outh = h + top + bottom;
307 int outc = channels * elempack + front + behind;
308
309 int out_elempack = outc % 8 == 0 ? 8 : outc % 4 == 0 ? 4 : 1;
310 size_t out_elemsize = elemsize / elempack * out_elempack;
311
312 if (front % 8 == 0 && out_elempack == 8 && !(outc != channels * elempack && type != 0))
313 {
314 top_blob.create(outw, outh, outc / out_elempack, out_elemsize, out_elempack, opt.blob_allocator);
315 if (top_blob.empty())
316 return -100;
317
318 int front_ = front / elempack;
319 #pragma omp parallel for num_threads(opt.num_threads)
320 for (int q = 0; q < outc / out_elempack; q++)
321 {
322 Mat borderm = top_blob.channel(q);
323
324 uint16x8_t pad_value = per_channel_pad_data_size ? vld1q_u16((const unsigned short*)per_channel_pad_data_fp16 + q * 8) : vdupq_n_u16(value_fp16);
325
326 //Channel padding
327 if ((q - front_) < 0 || (q - front_) >= channels)
328 {
329 borderm.fill(pad_value);
330 }
331 else
332 {
333 const Mat m = bottom_blob.channel(q - front_);
334 if (type == 0)
335 padding_constant_pack8_fp16s_neon(m, borderm, top, bottom, left, right, pad_value);
336 if (type == 1)
337 padding_replicate_pack8_fp16s_neon(m, borderm, top, bottom, left, right);
338 if (type == 2)
339 padding_reflect_pack8_fp16s_neon(m, borderm, top, bottom, left, right);
340 }
341 }
342
343 return 0;
344 }
345 }
346
347 if (dims == 4)
348 {
349 int outw = w + left + right;
350 int outh = h + top + bottom;
351 int outd = d + front + behind;
352
353 if (type == 0)
354 {
355 top_blob.create(outw, outh, outd, channels, elemsize, elempack, opt.blob_allocator);
356 if (top_blob.empty())
357 return -100;
358
359 #pragma omp parallel for num_threads(opt.num_threads)
360 for (int q = 0; q < channels; q++)
361 {
362 uint16x8_t pad_value = per_channel_pad_data_size ? vld1q_u16((const unsigned short*)per_channel_pad_data_fp16 + q * 8) : vdupq_n_u16(value_fp16);
363
364 for (int z = 0; z < outd; z++)
365 {
366 Mat borderm = top_blob.channel(q).depth(z);
367
368 // depth padding
369 if ((z - front) < 0 || (z - front) >= d)
370 {
371 borderm.fill(pad_value);
372 }
373 else
374 {
375 const Mat m = bottom_blob.channel(q).depth(z - front);
376 padding_constant_pack8_fp16s_neon(m, borderm, top, bottom, left, right, pad_value);
377 }
378 }
379 }
380
381 return 0;
382 }
383 }
384 }
385#endif
386
387 if (elempack == 4)
388 {
389 if (dims == 1)
390 {
391 int outw = w * elempack + left + right;
392
393#if NCNN_ARM82
394 int out_elempack = support_fp16_storage && opt.use_fp16_arithmetic && outw % 8 == 0 ? 8 : outw % 4 == 0 ? 4 : 1;
395#else
396 int out_elempack = outw % 4 == 0 ? 4 : 1;
397#endif
398 size_t out_elemsize = elemsize / elempack * out_elempack;
399
400 if (left % 4 == 0 && out_elempack == 4 && type == 0)
401 {
402 top_blob.create(outw / out_elempack, out_elemsize, out_elempack, opt.blob_allocator);
403 if (top_blob.empty())
404 return -100;
405
406 // clang-format off
407 // *INDENT-OFF*
408 uint16x4_t pad_value;
409#if NCNN_ARM82
410 if (support_fp16_storage && opt.use_fp16_storage)
411 {
412 pad_value = vdup_n_u16(value_fp16);
413 }
414 else
415#endif
416#if NCNN_BF16
417 if (opt.use_bf16_storage)
418 {
419 pad_value = vdup_n_u16(value_bf16);
420 }
421 else
422#endif
423 {
424 // shall never reach here
425 pad_value = vdup_n_u16(0);
426 }
427 // *INDENT-ON*
428 // clang-format on
429 padding_constant_pack4_bf16_fp16s_neon(bottom_blob, top_blob, 0, 0, left / 4, right / 4, vcombine_u16(pad_value, pad_value));
430
431 return 0;
432 }
433 }
434
435 if (dims == 2)
436 {
437 int outw = w + left + right;
438 int outh = h * elempack + top + bottom;
439
440#if NCNN_ARM82
441 int out_elempack = support_fp16_storage && opt.use_fp16_arithmetic && outh % 8 == 0 ? 8 : outh % 4 == 0 ? 4 : 1;
442#else
443 int out_elempack = outh % 4 == 0 ? 4 : 1;
444#endif
445 size_t out_elemsize = elemsize / elempack * out_elempack;
446
447 if (top % 4 == 0 && out_elempack == 4 && type == 0)
448 {
449 top_blob.create(outw, outh / out_elempack, out_elemsize, out_elempack, opt.blob_allocator);
450 if (top_blob.empty())
451 return -100;
452
453 // clang-format off
454 // *INDENT-OFF*
455 uint16x4_t pad_value;
456#if NCNN_ARM82
457 if (support_fp16_storage && opt.use_fp16_storage)
458 {
459 pad_value = vdup_n_u16(value_fp16);
460 }
461 else
462#endif
463#if NCNN_BF16
464 if (opt.use_bf16_storage)
465 {
466 pad_value = vdup_n_u16(value_bf16);
467 }
468 else
469#endif
470 {
471 // shall never reach here
472 pad_value = vdup_n_u16(0);
473 }
474 // *INDENT-ON*
475 // clang-format on
476 padding_constant_pack4_bf16_fp16s_neon(bottom_blob, top_blob, top / 4, bottom / 4, left, right, vcombine_u16(pad_value, pad_value));
477
478 return 0;
479 }
480 }
481
482 if (dims == 3)
483 {
484 int outw = w + left + right;
485 int outh = h + top + bottom;
486 int outc = channels * elempack + front + behind;
487
488#if NCNN_ARM82
489 int out_elempack = support_fp16_storage && opt.use_fp16_arithmetic && outc % 8 == 0 ? 8 : outc % 4 == 0 ? 4 : 1;
490#else
491 int out_elempack = outc % 4 == 0 ? 4 : 1;
492#endif
493 size_t out_elemsize = elemsize / elempack * out_elempack;
494
495 if (front % 4 == 0 && out_elempack == 4 && !(outc != channels * elempack && type != 0))
496 {
497 top_blob.create(outw, outh, outc / out_elempack, out_elemsize, out_elempack, opt.blob_allocator);
498 if (top_blob.empty())
499 return -100;
500
501 int front_ = front / elempack;
502 #pragma omp parallel for num_threads(opt.num_threads)
503 for (int q = 0; q < outc / out_elempack; q++)
504 {
505 Mat borderm = top_blob.channel(q);
506
507 // clang-format off
508 // *INDENT-OFF*
509 uint16x4_t pad_value;
510#if NCNN_ARM82
511 if (support_fp16_storage && opt.use_fp16_storage)
512 {
513 pad_value = per_channel_pad_data_size ? vld1_u16((const unsigned short*)per_channel_pad_data_fp16 + q * 4) : vdup_n_u16(value_fp16);
514 }
515 else
516#endif
517#if NCNN_BF16
518 if (opt.use_bf16_storage)
519 {
520 pad_value = per_channel_pad_data_size ? vld1_u16((const unsigned short*)per_channel_pad_data_bf16 + q * 4) : vdup_n_u16(value_bf16);
521 }
522 else
523#endif
524 {
525 // shall never reach here
526 pad_value = vdup_n_u16(0);
527 }
528 // *INDENT-ON*
529 // clang-format on
530
531 //Channel padding
532 if ((q - front_) < 0 || (q - front_) >= channels)
533 {
534 borderm.fill(pad_value);
535 }
536 else
537 {
538 const Mat m = bottom_blob.channel(q - front_);
539 if (type == 0)
540 padding_constant_pack4_bf16_fp16s_neon(m, borderm, top, bottom, left, right, vcombine_u16(pad_value, pad_value));
541 if (type == 1)
542 padding_replicate_pack4_bf16_fp16s_neon(m, borderm, top, bottom, left, right);
543 if (type == 2)
544 padding_reflect_pack4_bf16_fp16s_neon(m, borderm, top, bottom, left, right);
545 }
546 }
547
548 return 0;
549 }
550 }
551
552 if (dims == 4)
553 {
554 int outw = w + left + right;
555 int outh = h + top + bottom;
556 int outd = d + front + behind;
557
558 if (type == 0)
559 {
560 top_blob.create(outw, outh, outd, channels, elemsize, elempack, opt.blob_allocator);
561 if (top_blob.empty())
562 return -100;
563
564 #pragma omp parallel for num_threads(opt.num_threads)
565 for (int q = 0; q < channels; q++)
566 {
567 // clang-format off
568 // *INDENT-OFF*
569 uint16x4_t pad_value;
570#if NCNN_ARM82
571 if (support_fp16_storage && opt.use_fp16_storage)
572 {
573 pad_value = per_channel_pad_data_size ? vld1_u16((const unsigned short*)per_channel_pad_data_fp16 + q * 4) : vdup_n_u16(value_fp16);
574 }
575 else
576#endif
577#if NCNN_BF16
578 if (opt.use_bf16_storage)
579 {
580 pad_value = per_channel_pad_data_size ? vld1_u16((const unsigned short*)per_channel_pad_data_bf16 + q * 4) : vdup_n_u16(value_bf16);
581 }
582 else
583#endif
584 {
585 // shall never reach here
586 pad_value = vdup_n_u16(0);
587 }
588 // *INDENT-ON*
589 // clang-format on
590
591 for (int z = 0; z < outd; z++)
592 {
593 Mat borderm = top_blob.channel(q).depth(z);
594
595 // depth padding
596 if ((z - front) < 0 || (z - front) >= d)
597 {
598 borderm.fill(pad_value);
599 }
600 else
601 {
602 const Mat m = bottom_blob.channel(q).depth(z - front);
603 padding_constant_pack4_bf16_fp16s_neon(m, borderm, top, bottom, left, right, vcombine_u16(pad_value, pad_value));
604 }
605 }
606 }
607
608 return 0;
609 }
610 }
611 }
612#endif // __ARM_NEON
613
614 Mat bottom_blob_unpacked = bottom_blob;
615 if (elempack != 1)
616 {
617 Option opt_pack1 = opt;
618 opt_pack1.blob_allocator = opt.workspace_allocator;
619
620 convert_packing(bottom_blob, bottom_blob_unpacked, 1, opt_pack1);
621 if (bottom_blob_unpacked.empty())
622 return -100;
623 }
624
625 return Padding::forward(bottom_blob_unpacked, top_blob, opt);
626}
627
628int Padding_arm::forward_int8(const Mat& bottom_blob, Mat& top_blob, const Option& opt) const
629{
630 int w = bottom_blob.w;
631 int h = bottom_blob.h;
632 int d = bottom_blob.d;
633 int channels = bottom_blob.c;
634 int dims = bottom_blob.dims;
635 size_t elemsize = bottom_blob.elemsize;
636 int elempack = bottom_blob.elempack;
637
638#if __ARM_NEON
639 if (elempack == 8)
640 {
641 if (dims == 1)
642 {
643 int outw = w * elempack + left + right;
644
645 int out_elempack = outw % 8 == 0 ? 8 : 1;
646 size_t out_elemsize = elemsize / elempack * out_elempack;
647
648 if (left % 8 == 0 && out_elempack == 8 && type == 0)
649 {
650 top_blob.create(outw / out_elempack, out_elemsize, out_elempack, opt.blob_allocator);
651 if (top_blob.empty())
652 return -100;
653
654 int8x8_t pad_value = vdup_n_s8((signed char)value);
655 padding_constant_pack8_int8_neon(bottom_blob, top_blob, 0, 0, left / 8, right / 8, pad_value);
656
657 return 0;
658 }
659 }
660
661 if (dims == 2)
662 {
663 int outw = w + left + right;
664 int outh = h * elempack + top + bottom;
665
666 int out_elempack = outh % 8 == 0 ? 8 : 1;
667 size_t out_elemsize = elemsize / elempack * out_elempack;
668
669 if (top % 8 == 0 && out_elempack == 8 && type == 0)
670 {
671 top_blob.create(outw, outh / out_elempack, out_elemsize, out_elempack, opt.blob_allocator);
672 if (top_blob.empty())
673 return -100;
674
675 int8x8_t pad_value = vdup_n_s8((signed char)value);
676 padding_constant_pack8_int8_neon(bottom_blob, top_blob, top / 8, bottom / 8, left, right, pad_value);
677
678 return 0;
679 }
680 }
681
682 if (dims == 3)
683 {
684 int outw = w + left + right;
685 int outh = h + top + bottom;
686 int outc = channels * elempack + front + behind;
687
688 int out_elempack = outc % 8 == 0 ? 8 : 1;
689 size_t out_elemsize = elemsize / elempack * out_elempack;
690
691 top_blob.create(outw, outh, outc / out_elempack, out_elemsize, out_elempack, opt.blob_allocator);
692 if (top_blob.empty())
693 return -100;
694
695 if (front % 8 == 0 && out_elempack == 8 && !(outc != channels * elempack && type != 0))
696 {
697 int front_ = front / elempack;
698 #pragma omp parallel for num_threads(opt.num_threads)
699 for (int q = 0; q < outc / out_elempack; q++)
700 {
701 Mat borderm = top_blob.channel(q);
702
703 // TODO perchannel
704 // int8x8_t pad_value = per_channel_pad_data_size ? vld1_s8(per_channel_pad_data + q * 8) : vdup_n_s8((signed char)value);
705 int8x8_t pad_value = vdup_n_s8((signed char)value);
706
707 //Channel padding
708 if ((q - front_) < 0 || (q - front_) >= channels)
709 {
710 borderm.fill<int8x8_t>(pad_value);
711 }
712 else
713 {
714 const Mat m = bottom_blob.channel(q - front_);
715 if (type == 0)
716 padding_constant_pack8_int8_neon(m, borderm, top, bottom, left, right, pad_value);
717 if (type == 1)
718 padding_replicate_pack8_int8_neon(m, borderm, top, bottom, left, right);
719 if (type == 2)
720 padding_reflect_pack8_int8_neon(m, borderm, top, bottom, left, right);
721 }
722 }
723
724 return 0;
725 }
726 }
727
728 if (dims == 4)
729 {
730 int outw = w + left + right;
731 int outh = h + top + bottom;
732 int outd = d + front + behind;
733
734 top_blob.create(outw, outh, outd, channels, elemsize, elempack, opt.blob_allocator);
735 if (top_blob.empty())
736 return -100;
737
738 if (type == 0)
739 {
740 #pragma omp parallel for num_threads(opt.num_threads)
741 for (int q = 0; q < channels; q++)
742 {
743 // TODO perchannel
744 // int8x8_t pad_value = per_channel_pad_data_size ? vld1_s8(per_channel_pad_data + q * 8) : vdup_n_s8((signed char)value);
745 int8x8_t pad_value = vdup_n_s8((signed char)value);
746
747 for (int z = 0; z < outd; z++)
748 {
749 Mat borderm = top_blob.channel(q).depth(z);
750
751 // depth padding
752 if ((z - front) < 0 || (z - front) >= d)
753 {
754 borderm.fill<int8x8_t>(pad_value);
755 }
756 else
757 {
758 const Mat m = bottom_blob.channel(q).depth(z - front);
759 padding_constant_pack8_int8_neon(m, borderm, top, bottom, left, right, pad_value);
760 }
761 }
762 }
763
764 return 0;
765 }
766 }
767 }
768#endif // __ARM_NEON
769
770 Mat bottom_blob_unpacked = bottom_blob;
771 if (elempack != 1)
772 {
773 Option opt_pack1 = opt;
774 opt_pack1.blob_allocator = opt.workspace_allocator;
775
776 convert_packing(bottom_blob, bottom_blob_unpacked, 1, opt_pack1);
777 if (bottom_blob_unpacked.empty())
778 return -100;
779 }
780
781 return Padding::forward(bottom_blob_unpacked, top_blob, opt);
782}
783
784} // namespace ncnn