1 /* Copyright 2018 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 #include "tensorflow/lite/toco/tflite/whitelisted_flex_ops.h"
16
17 #include <set>
18
19 namespace toco {
20 namespace tflite {
21
IsWhitelistedFlexOp(const std::string & tensorflow_op_name)22 bool IsWhitelistedFlexOp(const std::string& tensorflow_op_name) {
23 static const std::set<std::string>* whitelisted_flex_ops =
24 new std::set<std::string>({
25 "Abort",
26 "Abs",
27 "Add",
28 "AddN",
29 "AddV2",
30 "All",
31 "Any",
32 "ApplyAdadelta",
33 "ApplyAdagrad",
34 "ApplyAdagradDA",
35 "ApplyAdam",
36 "ApplyAdaMax",
37 "ApplyAddSign",
38 "ApplyCenteredRMSProp",
39 "ApplyFtrl",
40 "ApplyFtrlV2",
41 "ApplyGradientDescent",
42 "ApplyMomentum",
43 "ApplyPowerSign",
44 "ApplyProximalAdagrad",
45 "ApplyProximalGradientDescent",
46 "ApplyRMSProp",
47 "ApproximateEqual",
48 "_Arg",
49 "ArgMax",
50 "ArgMin",
51 "_ArrayToList",
52 "Assert",
53 "Assign",
54 "AssignAdd",
55 "AssignSub",
56 "AudioSpectrogram",
57 "AvgPool",
58 "AvgPool3D",
59 "AvgPoolGrad",
60 "BatchMatMul",
61 "BatchNormWithGlobalNormalization",
62 "BatchNormWithGlobalNormalizationGrad",
63 "BatchToSpace",
64 "BatchToSpaceND",
65 "BiasAdd",
66 "BiasAddGrad",
67 "BiasAddV1",
68 "BroadcastArgs",
69 "BroadcastGradientArgs",
70 "Cast",
71 "Ceil",
72 "CheckNumerics",
73 "ComplexAbs",
74 "Concat",
75 "ConcatOffset",
76 "ConcatV2",
77 "ConjugateTranspose",
78 "Const",
79 "ControlTrigger",
80 "Conv2D",
81 "Conv2DBackpropFilter",
82 "Conv2DBackpropInput",
83 "Conv3D",
84 "Cos",
85 "Cosh",
86 "CropAndResize",
87 "CropAndResizeGradBoxes",
88 "CropAndResizeGradImage",
89 "CTCBeamSearchDecoder",
90 "CTCGreedyDecoder",
91 "DataFormatDimMap",
92 "DataFormatVecPermute",
93 "DebugGradientIdentity",
94 "DebugGradientRefIdentity",
95 "DecodeBmp",
96 "DecodeWav",
97 "DeleteSessionTensor",
98 "DepthToSpace",
99 "DepthwiseConv2dNative",
100 "Dequantize",
101 "DestroyTemporaryVariable",
102 "Div",
103 "DivNoNan",
104 "DynamicPartition",
105 "DynamicStitch",
106 "Elu",
107 "EluGrad",
108 "EncodeWav",
109 "EnsureShape",
110 "Enter",
111 "Equal",
112 "Exit",
113 "Exp",
114 "ExpandDims",
115 "FakeQuantWithMinMaxArgs",
116 "FakeQuantWithMinMaxArgsGradient",
117 "FakeQuantWithMinMaxVars",
118 "FakeQuantWithMinMaxVarsGradient",
119 "FakeQuantWithMinMaxVarsPerChannel",
120 "FakeQuantWithMinMaxVarsPerChannelGradient",
121 "FakeQueue",
122 "FFT",
123 "FFT2D",
124 "FFT3D",
125 "FIFOQueue",
126 "FIFOQueueV2",
127 "Fill",
128 "Floor",
129 "FloorDiv",
130 "FloorMod",
131 "FusedBatchNorm",
132 "FusedBatchNormGrad",
133 "FusedBatchNormGradV2",
134 "FusedBatchNormV2",
135 "FusedPadConv2D",
136 "FusedResizeAndPadConv2D",
137 "Gather",
138 "GatherNd",
139 "GatherV2",
140 "GetSessionHandle",
141 "GetSessionHandleV2",
142 "GetSessionTensor",
143 "Greater",
144 "GreaterEqual",
145 "_HostCast",
146 "_HostRecv",
147 "_HostSend",
148 "Identity",
149 "IdentityN",
150 "IFFT",
151 "IFFT2D",
152 "IFFT3D",
153 "IRFFT",
154 "IRFFT2D",
155 "IRFFT3D",
156 "ImmutableConst",
157 "InTopK",
158 "InTopKV2",
159 "Inv",
160 "InvertPermutation",
161 "InvGrad",
162 "IsFinite",
163 "IsNan",
164 "IsVariableInitialized",
165 "LeakyRelu",
166 "LeakyReluGrad",
167 "Less",
168 "LessEqual",
169 "LinSpace",
170 "ListDiff",
171 "_ListToArray",
172 "Log",
173 "LogicalAnd",
174 "LogicalNot",
175 "LogicalOr",
176 "LogSoftmax",
177 "LoopCond",
178 "LRN",
179 "MatMul",
180 "Max",
181 "Maximum",
182 "MaxPool",
183 "MaxPool3D",
184 "MaxPoolGrad",
185 "MaxPoolGradGrad",
186 "MaxPoolGradGradV2",
187 "MaxPoolGradV2",
188 "MaxPoolGradWithArgmax",
189 "MaxPoolV2",
190 "MaxPoolWithArgmax",
191 "Mean",
192 "Merge",
193 "MergeV2Checkpoints",
194 "Mfcc",
195 "Min",
196 "Minimum",
197 "MirrorPad",
198 "MirrorPadGrad",
199 "Mul",
200 "Multinomial",
201 "Neg",
202 "NextIteration",
203 "NonMaxSuppression",
204 "NonMaxSuppressionV2",
205 "NonMaxSuppressionV3",
206 "NonMaxSuppressionV4",
207 "NonMaxSuppressionWithOverlaps",
208 "NoOp",
209 "NotEqual",
210 "OneHot",
211 "OnesLike",
212 "Pack",
213 "Pad",
214 "PaddingFIFOQueue",
215 "PaddingFIFOQueueV2",
216 "PadV2",
217 "ParallelDynamicStitch",
218 "ParseExample",
219 "ParseSequenceExample",
220 "ParseSingleExample",
221 "ParseSingleSequenceExample",
222 "Placeholder",
223 "PlaceholderV2",
224 "PlaceholderWithDefault",
225 "Pow",
226 "PreventGradient",
227 "Print",
228 "PrintV2",
229 "Prod",
230 "QuantizedAdd",
231 "QuantizedAvgPool",
232 "QuantizedBatchNormWithGlobalNormalization",
233 "QuantizedBiasAdd",
234 "QuantizedConcat",
235 "QuantizedConv2D",
236 "QuantizedInstanceNorm",
237 "QuantizedMatMul",
238 "QuantizedMaxPool",
239 "QuantizedMul",
240 "QuantizeDownAndShrinkRange",
241 "QuantizedRelu",
242 "QuantizedRelu6",
243 "QuantizedReshape",
244 "QuantizedResizeBilinear",
245 "QuantizeV2",
246 "QueueClose",
247 "QueueCloseV2",
248 "QueueDequeue",
249 "QueueDequeueMany",
250 "QueueDequeueManyV2",
251 "QueueDequeueUpTo",
252 "QueueDequeueUpToV2",
253 "QueueDequeueV2",
254 "QueueEnqueue",
255 "QueueEnqueueMany",
256 "QueueEnqueueManyV2",
257 "QueueEnqueueV2",
258 "QueueIsClosed",
259 "QueueIsClosedV2",
260 "QueueSize",
261 "QueueSizeV2",
262 "RandomGamma",
263 "RandomStandardNormal",
264 "RandomUniform",
265 "RandomUniformInt",
266 "Range",
267 "Rank",
268 "RealDiv",
269 "Reciprocal",
270 "ReciprocalGrad",
271 "_Recv",
272 "RefEnter",
273 "RefExit",
274 "RefIdentity",
275 "RefMerge",
276 "RefNextIteration",
277 "RefSelect",
278 "RefSwitch",
279 "Relu",
280 "Relu6",
281 "Relu6Grad",
282 "ReluGrad",
283 "RemoteCall",
284 "RequantizationRange",
285 "Requantize",
286 "Reshape",
287 "ResizeBilinear",
288 "ResizeBilinearGrad",
289 "ResizeNearestNeighbor",
290 "ResizeNearestNeighborGrad",
291 "ResourceApplyAdadelta",
292 "ResourceApplyAdagrad",
293 "ResourceApplyAdagradDA",
294 "ResourceApplyAdam",
295 "ResourceApplyAdaMax",
296 "ResourceApplyAddSign",
297 "ResourceApplyCenteredRMSProp",
298 "ResourceApplyFtrl",
299 "ResourceApplyFtrlV2",
300 "ResourceApplyGradientDescent",
301 "ResourceApplyMomentum",
302 "ResourceApplyPowerSign",
303 "ResourceApplyProximalAdagrad",
304 "ResourceApplyProximalGradientDescent",
305 "ResourceApplyRMSProp",
306 "ResourceSparseApplyAdadelta",
307 "ResourceSparseApplyAdagrad",
308 "ResourceSparseApplyAdagradDA",
309 "ResourceSparseApplyCenteredRMSProp",
310 "ResourceSparseApplyFtrl",
311 "ResourceSparseApplyFtrlV2",
312 "ResourceSparseApplyMomentum",
313 "ResourceSparseApplyProximalAdagrad",
314 "ResourceSparseApplyProximalGradientDescent",
315 "ResourceSparseApplyRMSProp",
316 "ResourceStridedSliceAssign",
317 "Restore",
318 "RestoreSlice",
319 "RestoreV2",
320 "_Retval",
321 "Reverse",
322 "ReverseSequence",
323 "ReverseV2",
324 "RFFT",
325 "RFFT2D",
326 "RFFT3D",
327 "Round",
328 "Rsqrt",
329 "RsqrtGrad",
330 "Save",
331 "SaveSlices",
332 "SaveV2",
333 "SegmentMax",
334 "SegmentMean",
335 "SegmentMin",
336 "SegmentProd",
337 "SegmentSum",
338 "Select",
339 "Selu",
340 "SeluGrad",
341 "_Send",
342 "Shape",
343 "ShapeN",
344 "ShardedFilename",
345 "ShardedFilespec",
346 "Sigmoid",
347 "SigmoidGrad",
348 "Sign",
349 "Sin",
350 "Sinh",
351 "Size",
352 "Slice",
353 "Softmax",
354 "SoftmaxCrossEntropyWithLogits",
355 "Softplus",
356 "SoftplusGrad",
357 "Softsign",
358 "SoftsignGrad",
359 "SpaceToBatch",
360 "SpaceToBatchND",
361 "SpaceToDepth",
362 "SparseApplyAdadelta",
363 "SparseApplyAdagrad",
364 "SparseApplyAdagradDA",
365 "SparseApplyCenteredRMSProp",
366 "SparseApplyFtrl",
367 "SparseApplyFtrlV2",
368 "SparseApplyMomentum",
369 "SparseApplyProximalAdagrad",
370 "SparseApplyProximalGradientDescent",
371 "SparseApplyRMSProp",
372 "SparseFillEmptyRows",
373 "SparseFillEmptyRowsGrad",
374 "SparseReshape",
375 "SparseSegmentMean",
376 "SparseSegmentMeanGrad",
377 "SparseSegmentMeanWithNumSegments",
378 "SparseSegmentSqrtN",
379 "SparseSegmentSqrtNGrad",
380 "SparseSegmentSqrtNWithNumSegments",
381 "SparseSegmentSum",
382 "SparseSegmentSumWithNumSegments",
383 "SparseToDense",
384 "Split",
385 "SplitV",
386 "Sqrt",
387 "SqrtGrad",
388 "Square",
389 "SquaredDifference",
390 "Squeeze",
391 "Stack",
392 "StackClose",
393 "StackCloseV2",
394 "StackPop",
395 "StackPopV2",
396 "StackPush",
397 "StackPushV2",
398 "StackV2",
399 "StopGradient",
400 "StridedSlice",
401 "StridedSliceAssign",
402 "StridedSliceGrad",
403 "StringJoin",
404 "Sub",
405 "Sum",
406 "Switch",
407 "SymbolicGradient",
408 "Tan",
409 "Tanh",
410 "TanhGrad",
411 "TemporaryVariable",
412 "TensorArray",
413 "TensorArrayClose",
414 "TensorArrayCloseV2",
415 "TensorArrayCloseV3",
416 "TensorArrayConcat",
417 "TensorArrayConcatV2",
418 "TensorArrayConcatV3",
419 "TensorArrayGather",
420 "TensorArrayGatherV2",
421 "TensorArrayGatherV3",
422 "TensorArrayGrad",
423 "TensorArrayGradV2",
424 "TensorArrayGradV3",
425 "TensorArrayGradWithShape",
426 "TensorArrayPack",
427 "TensorArrayRead",
428 "TensorArrayReadV2",
429 "TensorArrayReadV3",
430 "TensorArrayScatter",
431 "TensorArrayScatterV2",
432 "TensorArrayScatterV3",
433 "TensorArraySize",
434 "TensorArraySizeV2",
435 "TensorArraySizeV3",
436 "TensorArraySplit",
437 "TensorArraySplitV2",
438 "TensorArraySplitV3",
439 "TensorArrayUnpack",
440 "TensorArrayV2",
441 "TensorArrayV3",
442 "TensorArrayWrite",
443 "TensorArrayWriteV2",
444 "TensorArrayWriteV3",
445 "Tile",
446 "TileGrad",
447 "Timestamp",
448 "TopK",
449 "TopKV2",
450 "Transpose",
451 "TruncateDiv",
452 "TruncatedNormal",
453 "Unique",
454 "UniqueV2",
455 "UniqueWithCounts",
456 "UniqueWithCountsV2",
457 "Unpack",
458 "UnsortedSegmentMax",
459 "UnsortedSegmentMin",
460 "UnsortedSegmentProd",
461 "UnsortedSegmentSum",
462 "Variable",
463 "VariableV2",
464 "Where",
465 "Xdivy",
466 "Xlogy",
467 "ZerosLike",
468 });
469 return whitelisted_flex_ops->find(tensorflow_op_name) !=
470 whitelisted_flex_ops->end();
471 }
472
473 } // namespace tflite
474 } // namespace toco
475