ONE - On-device Neural Engine
Loading...
Searching...
No Matches
GraphBuilderRegistry.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2019 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 __MOCO_FRONTEND_ONNX_GRAPH_BUILDER_REGISTRY_H__
18#define __MOCO_FRONTEND_ONNX_GRAPH_BUILDER_REGISTRY_H__
19
20#include "GraphBuilder.h"
21
22#include <map>
23
24namespace moco
25{
26namespace onnx
27{
28
33{
34public:
39 const GraphBuilder *lookup(const std::string &op) const
40 {
41 if (_builder_map.find(op) == _builder_map.end())
42 return nullptr;
43
44 return _builder_map.at(op).get();
45 }
46
48 {
49 static GraphBuilderRegistry me;
50 return me;
51 }
52
53public:
54 void add(const std::string op, std::unique_ptr<GraphBuilder> &&builder)
55 {
56 _builder_map[op] = std::move(builder);
57 }
58
59private:
60 std::map<const std::string, std::unique_ptr<GraphBuilder>> _builder_map;
61};
62
63} // namespace onnx
64} // namespace moco
65
66#include <memory>
67
68#define REGISTER_OP_BUILDER(NAME, BUILDER) \
69 namespace \
70 { \
71 __attribute__((constructor)) void reg_op(void) \
72 { \
73 std::unique_ptr<moco::onnx::BUILDER> builder = std::make_unique<moco::onnx::BUILDER>(); \
74 moco::onnx::GraphBuilderRegistry::get().add(#NAME, std::move(builder)); \
75 } \
76 }
77
78#endif // __MOCO_FRONTEND_ONNX_GRAPH_BUILDER_REGISTRY_H__
Parent class of onnx operation graph builders.
Class to return graph builder for passed onnx Operator.
static GraphBuilderRegistry & get()
void add(const std::string op, std::unique_ptr< GraphBuilder > &&builder)
const GraphBuilder * lookup(const std::string &op) const
Returns registered GraphBuilder pointer for operator or nullptr if not registered.
Definition Log.h:23