• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright 2023 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 #ifndef MINDSPORE_LITE_SRC_LITERT_KERNEL_CPU_BOLT_BOLT_POPULATOR_PARAMETER_H_
18 #define MINDSPORE_LITE_SRC_LITERT_KERNEL_CPU_BOLT_BOLT_POPULATOR_PARAMETER_H_
19 
20 #include <map>
21 #include "bolt/common/uni/include/parameter_spec.h"
22 #include "nnacl/op_base.h"
23 #include "src/common/log_adapter.h"
24 
25 namespace mindspore::kernel::bolt {
26 typedef ParameterSpec *(*BoltParameterPtrGen)(const OpParameter *op_parameter);
27 
28 class BoltParameterRegistry {
29  public:
GetInstance()30   static BoltParameterRegistry *GetInstance() {
31     static BoltParameterRegistry registry;
32     return &registry;
33   }
34 
InsertParameterMap(int type,BoltParameterPtrGen creator)35   void InsertParameterMap(int type, BoltParameterPtrGen creator) { op_parameters_[type] = creator; }
36 
CreateBoltParameter(const OpParameter * op_parameter)37   ParameterSpec *CreateBoltParameter(const OpParameter *op_parameter) {
38     MS_CHECK_TRUE_RET(op_parameter != nullptr, nullptr);
39     auto iter = op_parameters_.find(op_parameter->type_);
40     if (iter == op_parameters_.end()) {
41       MS_LOG(DEBUG) << "Unsupported op in creator " << op_parameter->type_;
42       return nullptr;
43     }
44     auto bolt_param = iter->second(op_parameter);
45     return bolt_param;
46   }
47 
48  protected:
49   std::map<int, BoltParameterPtrGen> op_parameters_;
50 };
51 
52 class Registry {
53  public:
Registry(int type,BoltParameterPtrGen creator)54   Registry(int type, BoltParameterPtrGen creator) noexcept {
55     BoltParameterRegistry::GetInstance()->InsertParameterMap(type, creator);
56   }
57   ~Registry() = default;
58 };
59 
60 #define REG_BOLT_PARAMETER_POPULATE(type, creator) static Registry g_##type(type, creator);
61 }  // namespace mindspore::kernel::bolt
62 #endif  // MINDSPORE_LITE_SRC_LITERT_KERNEL_CPU_BOLT_BOLT_POPULATOR_PARAMETER_H_
63