• 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 #ifndef MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_OP_MAPPER_REGISTRY_H_
18 #define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_OP_MAPPER_REGISTRY_H_
19 
20 #include <vector>
21 #include <string>
22 #include <memory>
23 #include <unordered_map>
24 #include "mapper/op_mapper.h"
25 
26 namespace mindspore {
27 namespace dpico {
28 class OpMapperRegistry {
29  public:
30   OpMapperRegistry();
31 
32   virtual ~OpMapperRegistry() = default;
33 
34   static OpMapperRegistry *GetInstance();
35 
36   OpMapperPtr GetOpMapper(const std::string &name);
37 
38   std::unordered_map<std::string, OpMapperPtr> op_mappers_;
39 };
40 
41 class OpMapperRegistrar {
42  public:
OpMapperRegistrar(const std::string & op_type_name,const OpMapperPtr & op_mapper)43   OpMapperRegistrar(const std::string &op_type_name, const OpMapperPtr &op_mapper) {
44     OpMapperRegistry::GetInstance()->op_mappers_[op_type_name] = op_mapper;
45   }
46   ~OpMapperRegistrar() = default;
47 };
48 
49 #define REG_MAPPER(primitive_type, mapper) \
50   static OpMapperRegistrar g_##primitive_type##MapperReg(#primitive_type, std::make_shared<mapper>());
51 }  // namespace dpico
52 }  // namespace mindspore
53 #endif  // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_OP_MAPPER_REGISTRY_H_
54