• 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 
17 #include "schema/ops_generated.h"
18 #include "schema/model_generated.h"
19 #include "nnacl/all_gather_parameter.h"
20 #include "src/common/ops/populate/populate_register.h"
21 
22 using mindspore::schema::PrimitiveType_AllGather;
23 namespace mindspore {
24 namespace lite {
PopulateAllGatherParameter(const void * prim)25 OpParameter *PopulateAllGatherParameter(const void *prim) {
26   auto *primitive = static_cast<const schema::Primitive *>(prim);
27   MS_ASSERT(primitive != nullptr);
28   auto value = primitive->value_as_AllGather();
29   if (value == nullptr) {
30     MS_LOG(ERROR) << "cast all_gather_primitive to value failed";
31     return nullptr;
32   }
33   auto group = value->group();
34   if (group == nullptr) {
35     MS_LOG(ERROR) << "attr group must be not a nullptr.";
36     return nullptr;
37   }
38   if (group->size() >= DEFAULT_GROUP_NAME_LEN) {
39     MS_LOG(ERROR) << "group name size error: " << value->group()->size() << ", which is larger than 100.";
40     return nullptr;
41   }
42 
43   auto *param = static_cast<AllGatherParameter *>(malloc(sizeof(AllGatherParameter)));
44   if (param == nullptr) {
45     MS_LOG(ERROR) << "Malloc AllGatherParameter failed.";
46     return nullptr;
47   }
48   (void)memset(param, 0, sizeof(AllGatherParameter));
49   (void)memcpy(param->group_, value->group()->c_str(), value->group()->size());
50   param->rank_size_ = value->rank_size();
51   param->op_parameter_.type_ = primitive->value_type();
52 
53   return reinterpret_cast<OpParameter *>(param);
54 }
55 REG_POPULATE(PrimitiveType_AllGather, PopulateAllGatherParameter, SCHEMA_CUR)
56 }  // namespace lite
57 }  // namespace mindspore
58