• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright 2017 The TensorFlow Authors. All Rights Reserved.
2 
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
6 
7     http://www.apache.org/licenses/LICENSE-2.0
8 
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License.
14 ==============================================================================*/
15 
16 #include "tensorflow/contrib/lite/kernels/register.h"
17 
18 namespace tflite {
19 namespace ops {
20 namespace builtin {
21 
22 TfLiteRegistration* Register_RELU();
23 TfLiteRegistration* Register_RELU_N1_TO_1();
24 TfLiteRegistration* Register_RELU6();
25 TfLiteRegistration* Register_TANH();
26 TfLiteRegistration* Register_LOGISTIC();
27 TfLiteRegistration* Register_AVERAGE_POOL_2D();
28 TfLiteRegistration* Register_MAX_POOL_2D();
29 TfLiteRegistration* Register_L2_POOL_2D();
30 TfLiteRegistration* Register_CONV_2D();
31 TfLiteRegistration* Register_DEPTHWISE_CONV_2D();
32 TfLiteRegistration* Register_SVDF();
33 TfLiteRegistration* Register_RNN();
34 TfLiteRegistration* Register_BIDIRECTIONAL_SEQUENCE_RNN();
35 TfLiteRegistration* Register_UNIDIRECTIONAL_SEQUENCE_RNN();
36 TfLiteRegistration* Register_EMBEDDING_LOOKUP();
37 TfLiteRegistration* Register_EMBEDDING_LOOKUP_SPARSE();
38 TfLiteRegistration* Register_FULLY_CONNECTED();
39 TfLiteRegistration* Register_LSH_PROJECTION();
40 TfLiteRegistration* Register_HASHTABLE_LOOKUP();
41 TfLiteRegistration* Register_SOFTMAX();
42 TfLiteRegistration* Register_CONCATENATION();
43 TfLiteRegistration* Register_ADD();
44 TfLiteRegistration* Register_SPACE_TO_BATCH_ND();
45 TfLiteRegistration* Register_DIV();
46 TfLiteRegistration* Register_SUB();
47 TfLiteRegistration* Register_BATCH_TO_SPACE_ND();
48 TfLiteRegistration* Register_MUL();
49 TfLiteRegistration* Register_L2_NORMALIZATION();
50 TfLiteRegistration* Register_LOCAL_RESPONSE_NORMALIZATION();
51 TfLiteRegistration* Register_LSTM();
52 TfLiteRegistration* Register_UNIDIRECTIONAL_SEQUENCE_LSTM();
53 TfLiteRegistration* Register_PAD();
54 TfLiteRegistration* Register_RESHAPE();
55 TfLiteRegistration* Register_RESIZE_BILINEAR();
56 TfLiteRegistration* Register_SKIP_GRAM();
57 TfLiteRegistration* Register_SPACE_TO_DEPTH();
58 TfLiteRegistration* Register_GATHER();
59 TfLiteRegistration* Register_TRANSPOSE();
60 TfLiteRegistration* Register_MEAN();
61 TfLiteRegistration* Register_SPLIT();
62 TfLiteRegistration* Register_SQUEEZE();
63 TfLiteRegistration* Register_STRIDED_SLICE();
64 TfLiteRegistration* Register_EXP();
65 TfLiteRegistration* Register_TOPK_V2();
66 
BuiltinOpResolver()67 BuiltinOpResolver::BuiltinOpResolver() {
68   AddBuiltin(BuiltinOperator_RELU, Register_RELU());
69   AddBuiltin(BuiltinOperator_RELU_N1_TO_1, Register_RELU_N1_TO_1());
70   AddBuiltin(BuiltinOperator_RELU6, Register_RELU6());
71   AddBuiltin(BuiltinOperator_TANH, Register_TANH());
72   AddBuiltin(BuiltinOperator_LOGISTIC, Register_LOGISTIC());
73   AddBuiltin(BuiltinOperator_AVERAGE_POOL_2D, Register_AVERAGE_POOL_2D());
74   AddBuiltin(BuiltinOperator_MAX_POOL_2D, Register_MAX_POOL_2D());
75   AddBuiltin(BuiltinOperator_L2_POOL_2D, Register_L2_POOL_2D());
76   AddBuiltin(BuiltinOperator_CONV_2D, Register_CONV_2D());
77   AddBuiltin(BuiltinOperator_DEPTHWISE_CONV_2D, Register_DEPTHWISE_CONV_2D());
78   AddBuiltin(BuiltinOperator_SVDF, Register_SVDF());
79   AddBuiltin(BuiltinOperator_RNN, Register_RNN());
80   AddBuiltin(BuiltinOperator_BIDIRECTIONAL_SEQUENCE_RNN,
81              Register_BIDIRECTIONAL_SEQUENCE_RNN());
82   AddBuiltin(BuiltinOperator_UNIDIRECTIONAL_SEQUENCE_RNN,
83              Register_UNIDIRECTIONAL_SEQUENCE_RNN());
84   AddBuiltin(BuiltinOperator_EMBEDDING_LOOKUP, Register_EMBEDDING_LOOKUP());
85   AddBuiltin(BuiltinOperator_EMBEDDING_LOOKUP_SPARSE,
86              Register_EMBEDDING_LOOKUP_SPARSE());
87   AddBuiltin(BuiltinOperator_FULLY_CONNECTED, Register_FULLY_CONNECTED());
88   AddBuiltin(BuiltinOperator_LSH_PROJECTION, Register_LSH_PROJECTION());
89   AddBuiltin(BuiltinOperator_HASHTABLE_LOOKUP, Register_HASHTABLE_LOOKUP());
90   AddBuiltin(BuiltinOperator_SOFTMAX, Register_SOFTMAX());
91   AddBuiltin(BuiltinOperator_CONCATENATION, Register_CONCATENATION());
92   AddBuiltin(BuiltinOperator_ADD, Register_ADD());
93   AddBuiltin(BuiltinOperator_SPACE_TO_BATCH_ND, Register_SPACE_TO_BATCH_ND());
94   AddBuiltin(BuiltinOperator_BATCH_TO_SPACE_ND, Register_BATCH_TO_SPACE_ND());
95   AddBuiltin(BuiltinOperator_MUL, Register_MUL());
96   AddBuiltin(BuiltinOperator_L2_NORMALIZATION, Register_L2_NORMALIZATION());
97   AddBuiltin(BuiltinOperator_LOCAL_RESPONSE_NORMALIZATION,
98              Register_LOCAL_RESPONSE_NORMALIZATION());
99   AddBuiltin(BuiltinOperator_LSTM, Register_LSTM());
100   AddBuiltin(BuiltinOperator_UNIDIRECTIONAL_SEQUENCE_LSTM,
101              Register_UNIDIRECTIONAL_SEQUENCE_LSTM());
102   AddBuiltin(BuiltinOperator_PAD, Register_PAD());
103   AddBuiltin(BuiltinOperator_RESHAPE, Register_RESHAPE());
104   AddBuiltin(BuiltinOperator_RESIZE_BILINEAR, Register_RESIZE_BILINEAR());
105   AddBuiltin(BuiltinOperator_SKIP_GRAM, Register_SKIP_GRAM());
106   AddBuiltin(BuiltinOperator_SPACE_TO_DEPTH, Register_SPACE_TO_DEPTH());
107   AddBuiltin(BuiltinOperator_GATHER, Register_GATHER());
108   AddBuiltin(BuiltinOperator_TRANSPOSE, Register_TRANSPOSE());
109   AddBuiltin(BuiltinOperator_MEAN, Register_MEAN());
110   AddBuiltin(BuiltinOperator_DIV, Register_DIV());
111   AddBuiltin(BuiltinOperator_SUB, Register_SUB());
112   AddBuiltin(BuiltinOperator_SPLIT, Register_SPLIT());
113   AddBuiltin(BuiltinOperator_SQUEEZE, Register_SQUEEZE());
114   AddBuiltin(BuiltinOperator_STRIDED_SLICE, Register_STRIDED_SLICE());
115   AddBuiltin(BuiltinOperator_EXP, Register_EXP());
116   AddBuiltin(BuiltinOperator_TOPK_V2, Register_TOPK_V2());
117 }
118 
FindOp(tflite::BuiltinOperator op) const119 TfLiteRegistration* BuiltinOpResolver::FindOp(
120     tflite::BuiltinOperator op) const {
121   auto it = builtins_.find(op);
122   return it != builtins_.end() ? it->second : nullptr;
123 }
124 
FindOp(const char * op) const125 TfLiteRegistration* BuiltinOpResolver::FindOp(const char* op) const {
126   auto it = custom_ops_.find(op);
127   return it != custom_ops_.end() ? it->second : nullptr;
128 }
129 
AddBuiltin(tflite::BuiltinOperator op,TfLiteRegistration * registration)130 void BuiltinOpResolver::AddBuiltin(tflite::BuiltinOperator op,
131                                    TfLiteRegistration* registration) {
132   registration->builtin_code = op;
133   builtins_.insert(std::make_pair(op, registration));
134 }
135 
AddCustom(const char * name,TfLiteRegistration * registration)136 void BuiltinOpResolver::AddCustom(const char* name,
137                                   TfLiteRegistration* registration) {
138   registration->builtin_code = BuiltinOperator_CUSTOM;
139   custom_ops_.insert(std::make_pair(std::string(name), registration));
140 }
141 
142 }  // namespace builtin
143 }  // namespace ops
144 }  // namespace tflite
145