2 * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #ifndef __TFLITE_OP_REGISTRY_H__
18 #define __TFLITE_OP_REGISTRY_H__
20 #include "TFliteOpChef.h"
21 #include "TFliteOpChefs.h"
29 * @brief tflchef operator registry
31 class TFliteOpRegistry
35 * @brief Returns registered TFliteOpChef pointer for BuiltinOperator or
36 * nullptr if not registered
38 const TFliteOpChef *lookup(tflite::BuiltinOperator op) const
40 if (_tfliteop_map.find(op) == _tfliteop_map.end())
43 return _tfliteop_map.at(op).get();
46 static TFliteOpRegistry &get()
48 static TFliteOpRegistry me;
55 #define REG_TFL_OP(OPCODE, CLASS) \
56 _tfliteop_map[tflite::BuiltinOperator_##OPCODE] = std::make_unique<CLASS>()
58 REG_TFL_OP(ABS, TFliteOpAbs);
59 REG_TFL_OP(ADD, TFliteOpAdd);
60 REG_TFL_OP(ADD_N, TFliteOpAddN);
61 REG_TFL_OP(ARG_MAX, TFliteOpArgMax);
62 REG_TFL_OP(ARG_MIN, TFliteOpArgMin);
63 REG_TFL_OP(AVERAGE_POOL_2D, TFliteOpAveragePool2D);
64 REG_TFL_OP(BATCH_MATMUL, TFliteOpBatchMatMul);
65 REG_TFL_OP(BATCH_TO_SPACE_ND, TFliteOpBatchToSpaceND);
66 REG_TFL_OP(BIDIRECTIONAL_SEQUENCE_LSTM, TFliteOpBidirectionalSequenceLSTM);
67 REG_TFL_OP(CAST, TFliteOpCast);
68 REG_TFL_OP(CEIL, TFliteOpCeil);
69 REG_TFL_OP(CONCATENATION, TFliteOpConcatenation);
70 REG_TFL_OP(CONV_2D, TFliteOpConv2D);
71 REG_TFL_OP(COS, TFliteOpCos);
72 REG_TFL_OP(DEPTH_TO_SPACE, TFliteOpDepthToSpace);
73 REG_TFL_OP(DEPTHWISE_CONV_2D, TFliteOpDepthwiseConv2D);
74 REG_TFL_OP(DEQUANTIZE, TFliteOpDequantize);
75 REG_TFL_OP(DIV, TFliteOpDiv);
76 REG_TFL_OP(ELU, TFliteOpELU);
77 REG_TFL_OP(EQUAL, TFliteOpEqual);
78 REG_TFL_OP(EXP, TFliteOpExp);
79 REG_TFL_OP(EXPAND_DIMS, TFliteOpExpandDims);
80 REG_TFL_OP(FAKE_QUANT, TFliteOpFakeQuant);
81 REG_TFL_OP(FILL, TFliteOpFill);
82 REG_TFL_OP(FLOOR, TFliteOpFloor);
83 REG_TFL_OP(FLOOR_DIV, TFliteOpFloorDiv);
84 REG_TFL_OP(FLOOR_MOD, TFliteOpFloorMod);
85 REG_TFL_OP(FULLY_CONNECTED, TFliteOpFullyConnected);
86 REG_TFL_OP(GATHER, TFliteOpGather);
87 REG_TFL_OP(GATHER_ND, TFliteOpGatherNd);
88 REG_TFL_OP(GELU, TFliteOpGelu);
89 REG_TFL_OP(GREATER, TFliteOpGreater);
90 REG_TFL_OP(GREATER_EQUAL, TFliteOpGreaterEqual);
91 REG_TFL_OP(HARD_SWISH, TFliteOpHardSwish);
92 REG_TFL_OP(L2_NORMALIZATION, TFliteOpL2Normalize);
93 REG_TFL_OP(L2_POOL_2D, TFliteOpL2Pool2D);
94 REG_TFL_OP(LEAKY_RELU, TFliteOpLeakyRelu);
95 REG_TFL_OP(LESS, TFliteOpLess);
96 REG_TFL_OP(LESS_EQUAL, TFliteOpLessEqual);
97 REG_TFL_OP(LOCAL_RESPONSE_NORMALIZATION, TFliteOpLocalResponseNormalization);
98 REG_TFL_OP(LOG, TFliteOpLog);
99 REG_TFL_OP(LOGICAL_AND, TFliteOpLogicalAnd);
100 REG_TFL_OP(LOGICAL_NOT, TFliteOpLogicalNot);
101 REG_TFL_OP(LOGICAL_OR, TFliteOpLogicalOr);
102 REG_TFL_OP(LOGISTIC, TFliteOpLogistic);
103 REG_TFL_OP(LOG_SOFTMAX, TFliteOpLogSoftmax);
104 REG_TFL_OP(MATRIX_DIAG, TFliteOpMatrixDiag);
105 REG_TFL_OP(MAX_POOL_2D, TFliteOpMaxPool2D);
106 REG_TFL_OP(MATRIX_SET_DIAG, TFliteOpMatrixSetDiag);
107 REG_TFL_OP(MAXIMUM, TFliteOpMaximum);
108 REG_TFL_OP(MEAN, TFliteOpMean);
109 REG_TFL_OP(MINIMUM, TFliteOpMinimum);
110 REG_TFL_OP(MIRROR_PAD, TFliteOpMirrorPad);
111 REG_TFL_OP(MUL, TFliteOpMul);
112 REG_TFL_OP(NEG, TFliteOpNeg);
113 REG_TFL_OP(NON_MAX_SUPPRESSION_V4, TFliteOpNonMaxSuppressionV4);
114 REG_TFL_OP(NON_MAX_SUPPRESSION_V5, TFliteOpNonMaxSuppressionV5);
115 REG_TFL_OP(NOT_EQUAL, TFliteOpNotEqual);
116 REG_TFL_OP(ONE_HOT, TFliteOpOneHot);
117 REG_TFL_OP(PACK, TFliteOpPack);
118 REG_TFL_OP(PAD, TFliteOpPad);
119 REG_TFL_OP(PADV2, TFliteOpPadV2);
120 REG_TFL_OP(POW, TFliteOpPow);
121 REG_TFL_OP(PRELU, TFliteOpPRelu);
122 REG_TFL_OP(QUANTIZE, TFliteOpQuantize);
123 REG_TFL_OP(RANGE, TFliteOpRange);
124 REG_TFL_OP(RANK, TFliteOpRank);
125 REG_TFL_OP(REDUCE_ANY, TFliteOpReduceAny);
126 REG_TFL_OP(REDUCE_MAX, TFliteOpReduceMax);
127 REG_TFL_OP(REDUCE_MIN, TFliteOpReduceMin);
128 REG_TFL_OP(REDUCE_PROD, TFliteOpReduceProd);
129 REG_TFL_OP(RELU, TFliteOpReLU);
130 REG_TFL_OP(RELU6, TFliteOpReLU6);
131 REG_TFL_OP(RELU_N1_TO_1, TFliteOpReLUN1To1);
132 REG_TFL_OP(RESHAPE, TFliteOpReshape);
133 REG_TFL_OP(RESIZE_BILINEAR, TFliteOpResizeBilinear);
134 REG_TFL_OP(RESIZE_NEAREST_NEIGHBOR, TFliteOpResizeNearestNeighbor);
135 REG_TFL_OP(REVERSE_SEQUENCE, TFliteOpReverseSequence);
136 REG_TFL_OP(REVERSE_V2, TFliteOpReverseV2);
137 REG_TFL_OP(ROUND, TFliteOpRound);
138 REG_TFL_OP(RSQRT, TFliteOpRsqrt);
139 REG_TFL_OP(SCATTER_ND, TFliteOpScatterNd);
140 REG_TFL_OP(SEGMENT_SUM, TFliteOpSegmentSum);
141 REG_TFL_OP(SELECT, TFliteOpSelect);
142 REG_TFL_OP(SELECT_V2, TFliteOpSelectV2);
143 REG_TFL_OP(SHAPE, TFliteOpShape);
144 REG_TFL_OP(SIN, TFliteOpSin);
145 REG_TFL_OP(SLICE, TFliteOpSlice);
146 REG_TFL_OP(SOFTMAX, TFliteOpSoftmax);
147 REG_TFL_OP(SPACE_TO_BATCH_ND, TFliteOpSpaceToBatchND);
148 REG_TFL_OP(SPACE_TO_DEPTH, TFliteOpSpaceToDepth);
149 REG_TFL_OP(SPARSE_TO_DENSE, TFliteOpSparseToDense);
150 REG_TFL_OP(SPLIT, TFliteOpSplit);
151 REG_TFL_OP(SPLIT_V, TFliteOpSplitV);
152 REG_TFL_OP(SQRT, TFliteOpSqrt);
153 REG_TFL_OP(SQUARE, TFliteOpSquare);
154 REG_TFL_OP(SQUARED_DIFFERENCE, TFliteOpSquaredDifference);
155 REG_TFL_OP(SQUEEZE, TFliteOpSqueeze);
156 REG_TFL_OP(STRIDED_SLICE, TFliteOpStridedSlice);
157 REG_TFL_OP(SUB, TFliteOpSub);
158 REG_TFL_OP(SUM, TFliteOpSum);
159 REG_TFL_OP(SVDF, TFliteOpSVDF);
160 REG_TFL_OP(TANH, TFliteOpTanh);
161 REG_TFL_OP(TILE, TFliteOpTile);
162 REG_TFL_OP(TOPK_V2, TFliteOpTopKV2);
163 REG_TFL_OP(TRANSPOSE, TFliteOpTranspose);
164 REG_TFL_OP(TRANSPOSE_CONV, TFliteOpTransposeConv);
165 REG_TFL_OP(UNIDIRECTIONAL_SEQUENCE_LSTM, TFliteOpUnidirectionalSequenceLSTM);
166 REG_TFL_OP(UNIQUE, TFliteOpUnique);
167 REG_TFL_OP(UNPACK, TFliteOpUnpack);
168 REG_TFL_OP(WHERE, TFliteOpWhere);
169 REG_TFL_OP(ZEROS_LIKE, TFliteOpZerosLike);
175 std::map<tflite::BuiltinOperator, std::unique_ptr<TFliteOpChef>> _tfliteop_map;
178 } // namespace tflchef
180 #endif // __TFLITE_OP_REGISTRY_H__