Imported Upstream version 1.7.0
[platform/core/ml/nnfw.git] / compiler / circlechef / circle / src / CircleOpRegistry.h
1 /*
2  * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved
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 __CIRCLE_OP_REGISTRY_H__
18 #define __CIRCLE_OP_REGISTRY_H__
19
20 #include "CircleOpChef.h"
21 #include "CircleOpChefs.h"
22
23 #include <memory>
24
25 namespace circlechef
26 {
27
28 /**
29  * @brief circlechef operator registry
30  */
31 class CircleOpRegistry
32 {
33 public:
34   /**
35    * @brief Returns registered CircleOpChef pointer for BuiltinOperator or
36    *        nullptr if not registered
37    */
38   const CircleOpChef *lookup(circle::BuiltinOperator op) const
39   {
40     if (_circleop_map.find(op) == _circleop_map.end())
41       return nullptr;
42
43     return _circleop_map.at(op).get();
44   }
45
46   static CircleOpRegistry &get()
47   {
48     static CircleOpRegistry me;
49     return me;
50   }
51
52 private:
53   CircleOpRegistry()
54   {
55 #define REG_TFL_OP(OPCODE, CLASS) \
56   _circleop_map[circle::BuiltinOperator_##OPCODE] = std::make_unique<CLASS>()
57
58     REG_TFL_OP(BATCH_MATMUL, CircleOpBatchMatMul);
59     REG_TFL_OP(BCQ_FULLY_CONNECTED, CircleOpBCQFullyConnected);
60     REG_TFL_OP(BCQ_GATHER, CircleOpBCQGather);
61     REG_TFL_OP(INSTANCE_NORM, CircleOpInstanceNorm);
62 #undef REG_TFL_OP
63   }
64
65 private:
66   std::map<circle::BuiltinOperator, std::unique_ptr<CircleOpChef>> _circleop_map;
67 };
68
69 } // namespace circlechef
70
71 #endif // __CIRCLE_OP_REGISTRY_H__