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