• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright 2020 Huawei Technologies Co., Ltd
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include "nnacl/base/conv1x1_base.h"
18 
Conv1x1InputPack(const void * src_ptr,void * dst_ptr,ConvParameter * conv_param,int data_size)19 void Conv1x1InputPack(const void *src_ptr, void *dst_ptr, ConvParameter *conv_param, int data_size) {
20   /* support nhwc */
21   char *src = (char *)src_ptr;
22   char *dst = (char *)dst_ptr;
23   for (int dst_h = 0; dst_h < conv_param->output_h_; dst_h++) {
24     int src_h = dst_h * conv_param->stride_h_ - conv_param->pad_u_;
25     if (src_h < 0 || src_h >= conv_param->input_h_) {
26       continue;
27     }
28     const char *src_h_ptr = src + src_h * conv_param->input_w_ * conv_param->input_channel_ * data_size;
29     char *dst_h_ptr = dst + dst_h * conv_param->output_w_ * conv_param->input_channel_ * data_size;
30     for (int dst_w = 0; dst_w < conv_param->output_w_; dst_w++) {
31       int src_w = dst_w * conv_param->stride_w_ - conv_param->pad_l_;
32       if (src_w < 0 || src_w >= conv_param->input_w_) {
33         continue;
34       }
35       memcpy(dst_h_ptr + dst_w * conv_param->input_channel_ * data_size,
36              src_h_ptr + src_w * conv_param->input_channel_ * data_size, conv_param->input_channel_ * data_size);
37     }
38   }
39   return;
40 }
41