• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright 2019-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 #include "src/common/ops/populate/strided_slice_populate.h"
17 using mindspore::schema::PrimitiveType_StridedSlice;
18 
19 namespace mindspore {
20 namespace lite {
PopulateStridedSliceParameter(const void * prim)21 OpParameter *PopulateStridedSliceParameter(const void *prim) {
22   auto primitive = static_cast<const schema::Primitive *>(prim);
23   MS_ASSERT(primitive != nullptr);
24   auto value = primitive->value_as_StridedSlice();
25   if (value == nullptr) {
26     MS_LOG(ERROR) << "value is nullptr";
27     return nullptr;
28   }
29 
30   auto *param = reinterpret_cast<StridedSliceParameter *>(malloc(sizeof(StridedSliceParameter)));
31   if (param == nullptr) {
32     MS_LOG(ERROR) << "malloc StridedSliceParameter failed.";
33     return nullptr;
34   }
35   memset(param, 0, sizeof(StridedSliceParameter));
36 
37   param->op_parameter_.type_ = primitive->value_type();
38   param->begins_mask_ = value->begin_mask();
39   param->ends_mask_ = value->end_mask();
40   param->ellipsisMask_ = value->ellipsis_mask();
41   param->newAxisMask_ = value->new_axis_mask();
42   param->shrinkAxisMask_ = value->shrink_axis_mask();
43   if (param->begins_mask_ < C0NUM || param->ends_mask_ < C0NUM || param->ellipsisMask_ < C0NUM ||
44       param->newAxisMask_ < C0NUM || param->shrinkAxisMask_ < C0NUM) {
45     MS_LOG(ERROR) << "invalid StridedSliceParameter value";
46     free(param);
47     return nullptr;
48   }
49   return reinterpret_cast<OpParameter *>(param);
50 }
51 
52 REG_POPULATE(PrimitiveType_StridedSlice, PopulateStridedSliceParameter, SCHEMA_CUR)
53 }  // namespace lite
54 }  // namespace mindspore
55