• 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/compat/attr_transfer_common.h"
19 
20 namespace mindspore {
21 namespace lite {
TransferGatherAttr(LiteGraph::Node * node,std::vector<schema::Tensor * > * dst_tensors,std::vector<char * > * const tensor_bufs)22 int TransferGatherAttr(LiteGraph::Node *node, std::vector<schema::Tensor *> *dst_tensors,
23                        std::vector<char *> *const tensor_bufs) {
24   if (node == nullptr || node->primitive_ == nullptr || dst_tensors == nullptr || tensor_bufs == nullptr) {
25     MS_LOG(ERROR) << "the parameter of this function is nullptr.";
26     return RET_ERROR;
27   }
28   dst_tensors->clear();
29   auto prim = reinterpret_cast<const schema::v0::Primitive *>(node->primitive_);
30   MS_ASSERT(prim != nullptr);
31   auto param = prim->value_as_Gather();
32   if (param == nullptr) {
33     MS_LOG(ERROR) << "param is nullptr";
34     return RET_ERROR;
35   }
36   auto axis_attr = param->axis();
37   auto axis_tensor = AttrToTensor(&axis_attr, 1, false, kNumberTypeInt32, tensor_bufs);
38   if (axis_tensor == nullptr) {
39     MS_LOG(ERROR) << "attr tensor is nullptr, transform is failed.";
40     return RET_NULL_PTR;
41   }
42   dst_tensors->push_back(axis_tensor);
43   return RET_OK;
44 }
45 
46 Register GatherTransferRegistry(SCHEMA_VERSION::SCHEMA_V0, schema::v0::PrimitiveType_Gather, TransferGatherAttr);
47 }  // namespace lite
48 }  // namespace mindspore
49