1 /**
2 * Copyright 2020 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 <memory>
18 #include <string>
19
20 #include "ops/primitive_c.h"
21 #include "utils/check_convert_utils.h"
22 namespace mindspore {
23 namespace ops {
InitIOName(const std::vector<std::string> & inputs_name,const std::vector<std::string> & outputs_name)24 void PrimitiveC::InitIOName(const std::vector<std::string> &inputs_name, const std::vector<std::string> &outputs_name) {
25 (void)this->AddAttr("input_names", MakeValue(inputs_name));
26 (void)this->AddAttr("output_names", MakeValue(outputs_name));
27 }
28
Infer(const AbstractBasePtrList & abstract_list)29 AbstractBasePtr PrimitiveC::Infer(const AbstractBasePtrList &abstract_list) {
30 auto infer_map = abstract::GetPrimitiveToEvalImplMap();
31 auto iter = infer_map.find(std::make_shared<Primitive>(this->name()));
32 if (iter == infer_map.end()) {
33 MS_EXCEPTION(NotExistsError) << "Cannot find the " << this->name() << "infer function in the infer map!";
34 }
35 auto infer_function = iter->second.infer_shape_impl_;
36 return infer_function(nullptr, shared_from_base<Primitive>(), abstract_list);
37 }
38
GetInstance()39 OpPrimCRegister &OpPrimCRegister::GetInstance() {
40 static OpPrimCRegister instance = OpPrimCRegister();
41 return instance;
42 }
43
GetPrimCMap()44 std::map<std::string, OpPrimCDefineFunc> OpPrimCRegister::GetPrimCMap() { return op_primc_fns_; }
SetPrimCMap(const std::string & kname,const OpPrimCDefineFunc & fn)45 void OpPrimCRegister::SetPrimCMap(const std::string &kname, const OpPrimCDefineFunc &fn) { op_primc_fns_[kname] = fn; }
46 } // namespace ops
47 } // namespace mindspore
48