• 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 #include "src/runtime/kernel/arm/base/crop_base.h"
17 #include <vector>
18 #include "src/runtime/kernel/arm/fp32/crop_fp32.h"
19 #include "schema/model_generated.h"
20 #include "src/kernel_registry.h"
21 #include "include/errorcode.h"
22 #include "include/context.h"
23 
24 using mindspore::lite::KernelRegistrar;
25 using mindspore::lite::RET_ERROR;
26 using mindspore::lite::RET_OK;
27 using mindspore::schema::PrimitiveType_Crop;
28 
29 namespace mindspore::kernel {
Init()30 int CropBaseCPUKernel::Init() { return RET_OK; }
31 
ReSize()32 int CropBaseCPUKernel::ReSize() {
33   auto *input_tensor = in_tensors_.at(kInputIndex);
34   auto *out_tensor = out_tensors_.at(kOutputIndex);
35   input_shape_ = input_tensor->shape();
36   output_shape_ = out_tensor->shape();
37   size_t input_dim = input_shape_.size();
38   crop_para_->in_shape_ = input_shape_.data();
39   crop_para_->out_shape_ = output_shape_.data();
40   MS_ASSERT(input_dim <= CROP_OFFSET_MAX_SIZE);
41   crop_para_->input_dim_ = input_dim;
42   PadOffset(input_dim, crop_para_);
43   return RET_OK;
44 }
45 
PadOffset(int input_dim,CropParameter * crop_para) const46 void CropBaseCPUKernel::PadOffset(int input_dim, CropParameter *crop_para) const {
47   auto axis = crop_para->axis_;
48   auto offsets_size = crop_para->offset_size_;
49   MS_ASSERT(axis <= input_dim);
50   if (offsets_size > 1) {
51     MS_ASSERT(axis + offsets_size == input_dim);
52   }
53   for (int i = 0; i < input_dim; i++) {
54     int crop_offset = 0;
55     if (i >= axis) {
56       if (offsets_size == 1) {
57         crop_offset = crop_para->offset_[0];
58       } else if (offsets_size > 1) {
59         if (i - axis < CROP_OFFSET_MAX_SIZE) {
60           crop_offset = crop_para->offset_[i - axis];
61         }
62       }
63     }
64     crop_para->in_offset_[i] = crop_offset;
65   }
66 }
67 }  // namespace mindspore::kernel
68