• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright 2021 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 "schema/model_v0_generated.h"
18 #include "src/ops/populate/populate_register.h"
19 #include "nnacl/squeeze_parameter.h"
20 
21 namespace mindspore {
22 namespace lite {
23 namespace {
PopulateSqueezeParameter(const void * prim)24 OpParameter *PopulateSqueezeParameter(const void *prim) {
25   auto *primitive = static_cast<const schema::v0::Primitive *>(prim);
26   MS_ASSERT(primitive != nullptr);
27   auto squeeze_prim = primitive->value_as_Squeeze();
28   if (squeeze_prim == nullptr) {
29     MS_LOG(ERROR) << "squeeze_prim is nullptr";
30     return nullptr;
31   }
32   auto *squeeze_param = reinterpret_cast<SqueezeParameter *>(malloc(sizeof(SqueezeParameter)));
33   if (squeeze_param == nullptr) {
34     MS_LOG(ERROR) << "malloc SqueezeParameter failed.";
35     return nullptr;
36   }
37   memset(squeeze_param, 0, sizeof(SqueezeParameter));
38   squeeze_param->op_parameter_.type_ = schema::PrimitiveType_Squeeze;
39   auto axis = squeeze_prim->axis();
40   if (axis != nullptr) {
41     if (axis->size() > MAX_SHAPE_SIZE) {
42       MS_LOG(ERROR) << "squeeze's attr axis size is too big, which cannot be bigger than " << MAX_SHAPE_SIZE;
43       free(squeeze_param);
44       return nullptr;
45     }
46     squeeze_param->axis_size_ = axis->size();
47     for (size_t i = 0; i < squeeze_param->axis_size_; i++) {
48       squeeze_param->axis_[i] = *(axis->begin() + i);
49     }
50   } else {
51     squeeze_param->axis_size_ = 0;
52   }
53 
54   return reinterpret_cast<OpParameter *>(squeeze_param);
55 }
56 }  // namespace
57 
58 Registry g_squeezeV0ParameterRegistry(schema::v0::PrimitiveType_Squeeze, PopulateSqueezeParameter, SCHEMA_V0);
59 }  // namespace lite
60 }  // namespace mindspore
61