• 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 #ifndef TENSORFLOW_LITE_C_BUILTIN_OP_DATA_H_
16 #define TENSORFLOW_LITE_C_BUILTIN_OP_DATA_H_
17 
18 #include <stdint.h>
19 
20 #include "tensorflow/lite/c/common.h"
21 
22 #ifdef __cplusplus
23 extern "C" {
24 #endif  // __cplusplus
25 
26 // TfLiteReshapeParams can't have dynamic data so we fix the maximum possible
27 // number of dimensions.
28 #define TFLITE_RESHAPE_PARAMS_MAX_DIMENSION_COUNT 8
29 
30 // TODO(aselle): Consider using "if this then that" for testing.
31 
32 // Useful placeholder to put in otherwise empty structs to avoid size warnings.
33 typedef struct {
34   char dummy;
35 } EmptyStructPlaceholder;
36 
37 // IMPORTANT: All new members of structs must be added at the end to ensure
38 // backwards compatibility.
39 
40 // Possible padding types (for convolutions)
41 typedef enum {
42   kTfLitePaddingUnknown = 0,
43   kTfLitePaddingSame,
44   kTfLitePaddingValid,
45 } TfLitePadding;
46 
47 typedef enum {
48   kTfLiteMirrorPaddingUnknown = 0,
49   kTfLiteMirrorPaddingReflect,
50   kTfLiteMirrorPaddingSymmetric,
51 } TfLiteMirrorPaddingMode;
52 
53 // TODO(b/130259536): We should move this out of builtin_op_data.
54 typedef struct {
55   int width;
56   int height;
57   int width_offset;
58   int height_offset;
59 } TfLitePaddingValues;
60 
61 typedef struct {
62   TfLiteMirrorPaddingMode mode;
63 } TfLiteMirrorPaddingParams;
64 
65 // Possible fused activation functions.
66 // TODO(aselle): rename to TfLiteActivation
67 typedef enum {
68   kTfLiteActNone = 0,
69   kTfLiteActRelu,
70   kTfLiteActRelu1,  // min(max(-1, x), 1)
71   kTfLiteActRelu6,  // min(max(0, x), 6)
72   kTfLiteActTanh,
73   kTfLiteActSignBit,
74   kTfLiteActSigmoid,
75 } TfLiteFusedActivation;
76 
77 typedef struct {
78   // Parameters for CONV_2D version 1.
79   TfLitePadding padding;
80   int stride_width;
81   int stride_height;
82   TfLiteFusedActivation activation;
83 
84   // Parameters for CONV_2D version 2.
85   // Note: Version 2 supports dilation values not equal to 1.
86   int dilation_width_factor;
87   int dilation_height_factor;
88 } TfLiteConvParams;
89 
90 typedef struct {
91   TfLitePadding padding;
92   int stride_width;
93   int stride_height;
94   int filter_width;
95   int filter_height;
96   TfLiteFusedActivation activation;
97   struct {
98     TfLitePaddingValues padding;
99   } computed;
100 } TfLitePoolParams;
101 
102 typedef struct {
103   // Parameters for DepthwiseConv version 1 or above.
104   TfLitePadding padding;
105   int stride_width;
106   int stride_height;
107   // `depth_multiplier` is redundant. It's used by CPU kernels in
108   // TensorFlow 2.0 or below, but ignored in versions above.
109   //
110   // The information can be deduced from the shape of input and the shape of
111   // weights. Since the TFLiteConverter toolchain doesn't support partially
112   // specificed shapes, relying on `depth_multiplier` stops us from supporting
113   // graphs with dynamic shape tensors.
114   //
115   // Note: Some of the delegates (e.g. NNAPI, GPU) are still relying on this
116   // field.
117   int depth_multiplier;
118   TfLiteFusedActivation activation;
119   // Parameters for DepthwiseConv version 2 or above.
120   int dilation_width_factor;
121   int dilation_height_factor;
122 } TfLiteDepthwiseConvParams;
123 
124 typedef struct {
125   int rank;
126   TfLiteFusedActivation activation;
127 } TfLiteSVDFParams;
128 
129 typedef struct {
130   TfLiteFusedActivation activation;
131 } TfLiteRNNParams;
132 
133 typedef struct {
134   bool time_major;
135   TfLiteFusedActivation activation;
136 } TfLiteSequenceRNNParams;
137 
138 typedef struct {
139   bool time_major;
140   TfLiteFusedActivation activation;
141   bool merge_outputs;
142 } TfLiteBidirectionalSequenceRNNParams;
143 
144 typedef enum {
145   kTfLiteFullyConnectedWeightsFormatDefault = 0,
146   kTfLiteFullyConnectedWeightsFormatShuffled4x16Int8 = 1,
147 } TfLiteFullyConnectedWeightsFormat;
148 
149 typedef struct {
150   // Parameters for FullyConnected version 1 or above.
151   TfLiteFusedActivation activation;
152 
153   // Parameters for FullyConnected version 2 or above.
154   TfLiteFullyConnectedWeightsFormat weights_format;
155 
156   // Parameters for FullyConnected version 5 or above.
157   // If set to true, then the number of dimensions in the input and the output
158   // tensors are the same. Furthermore, all but the last dimension of the input
159   // and output shapes will be equal.
160   bool keep_num_dims;
161 } TfLiteFullyConnectedParams;
162 
163 typedef enum {
164   kTfLiteLshProjectionUnknown = 0,
165   kTfLiteLshProjectionSparse = 1,
166   kTfLiteLshProjectionDense = 2,
167 } TfLiteLSHProjectionType;
168 
169 typedef struct {
170   TfLiteLSHProjectionType type;
171 } TfLiteLSHProjectionParams;
172 
173 typedef struct {
174   float beta;
175 } TfLiteSoftmaxParams;
176 
177 typedef struct {
178   int axis;
179   TfLiteFusedActivation activation;
180 } TfLiteConcatenationParams;
181 
182 typedef struct {
183   TfLiteFusedActivation activation;
184 } TfLiteAddParams;
185 
186 typedef struct {
187   EmptyStructPlaceholder placeholder;
188 } TfLiteSpaceToBatchNDParams;
189 
190 typedef struct {
191   EmptyStructPlaceholder placeholder;
192 } TfLiteBatchToSpaceNDParams;
193 
194 typedef struct {
195   TfLiteFusedActivation activation;
196 } TfLiteMulParams;
197 
198 typedef struct {
199   TfLiteFusedActivation activation;
200 } TfLiteSubParams;
201 
202 typedef struct {
203   TfLiteFusedActivation activation;
204 } TfLiteDivParams;
205 
206 typedef struct {
207   TfLiteFusedActivation activation;
208 } TfLiteL2NormParams;
209 
210 typedef struct {
211   int radius;
212   float bias;
213   float alpha;
214   float beta;
215 } TfLiteLocalResponseNormParams;
216 
217 typedef enum {
218   kTfLiteLSTMFullKernel = 0,
219   kTfLiteLSTMBasicKernel
220 } TfLiteLSTMKernelType;
221 
222 typedef struct {
223   // Parameters for LSTM version 1.
224   TfLiteFusedActivation activation;
225   float cell_clip;
226   float proj_clip;
227 
228   // Parameters for LSTM version 2.
229   // kTfLiteLSTMBasicKernel is only supported in version 2 or above.
230   TfLiteLSTMKernelType kernel_type;
231 } TfLiteLSTMParams;
232 
233 typedef struct {
234   // Parameters needed for the underlying LSTM.
235   TfLiteFusedActivation activation;
236   float cell_clip;
237   float proj_clip;
238 
239   // If set to true then the first dimension is time, otherwise batch.
240   bool time_major;
241 } TfLiteUnidirectionalSequenceLSTMParams;
242 
243 typedef struct {
244   // Parameters supported by version 1:
245   // Parameters inherited for the LSTM kernel.
246   TfLiteFusedActivation activation;
247   float cell_clip;
248   float proj_clip;
249 
250   // If true, store the outputs of both directions in the first output.
251   bool merge_outputs;
252 
253   // Parameters supported by version 2:
254   // If set to true then the first dimension is time, otherwise batch.
255   bool time_major;
256 } TfLiteBidirectionalSequenceLSTMParams;
257 
258 typedef struct {
259   bool align_corners;
260   // half_pixel_centers assumes pixels are of half the actual dimensions, and
261   // yields more accurate resizes. Corresponds to the same argument for the
262   // original TensorFlow op in TF2.0.
263   bool half_pixel_centers;
264 } TfLiteResizeBilinearParams;
265 
266 typedef struct {
267   bool align_corners;
268 } TfLiteResizeNearestNeighborParams;
269 
270 typedef struct {
271   EmptyStructPlaceholder placeholder;
272 } TfLitePadParams;
273 
274 typedef struct {
275   EmptyStructPlaceholder placeholder;
276 } TfLitePadV2Params;
277 
278 typedef struct {
279   // TODO(ahentz): We can't have dynamic data in this struct, at least not yet.
280   // For now we will fix the maximum possible number of dimensions.
281   int shape[TFLITE_RESHAPE_PARAMS_MAX_DIMENSION_COUNT];
282   int num_dimensions;
283 } TfLiteReshapeParams;
284 
285 typedef struct {
286   int ngram_size;
287   int max_skip_size;
288   bool include_all_ngrams;
289 } TfLiteSkipGramParams;
290 
291 typedef struct {
292   int block_size;
293 } TfLiteSpaceToDepthParams;
294 
295 typedef struct {
296   int block_size;
297 } TfLiteDepthToSpaceParams;
298 
299 typedef struct {
300   TfLiteType in_data_type;
301   TfLiteType out_data_type;
302 } TfLiteCastParams;
303 
304 typedef enum {
305   kTfLiteCombinerTypeSum = 0,
306   kTfLiteCombinerTypeMean = 1,
307   kTfLiteCombinerTypeSqrtn = 2,
308 } TfLiteCombinerType;
309 
310 typedef struct {
311   TfLiteCombinerType combiner;
312 } TfLiteEmbeddingLookupSparseParams;
313 
314 typedef struct {
315   int axis;
316 } TfLiteGatherParams;
317 
318 typedef struct {
319   EmptyStructPlaceholder placeholder;
320 } TfLiteTransposeParams;
321 
322 typedef struct {
323   bool keep_dims;
324 } TfLiteReducerParams;
325 
326 typedef struct {
327   int num_splits;
328 } TfLiteSplitParams;
329 
330 typedef struct {
331   int num_splits;
332 } TfLiteSplitVParams;
333 
334 typedef struct {
335   // TODO(ahentz): We can't have dynamic data in this struct, at least not yet.
336   // For now we will fix the maximum possible number of dimensions.
337   int squeeze_dims[8];
338   int num_squeeze_dims;
339 } TfLiteSqueezeParams;
340 
341 typedef struct {
342   int begin_mask;
343   int end_mask;
344   int ellipsis_mask;
345   int new_axis_mask;
346   int shrink_axis_mask;
347 } TfLiteStridedSliceParams;
348 
349 typedef struct {
350   TfLiteType output_type;
351 } TfLiteArgMaxParams;
352 
353 typedef struct {
354   TfLiteType output_type;
355 } TfLiteArgMinParams;
356 
357 typedef struct {
358   TfLitePadding padding;
359   int stride_width;
360   int stride_height;
361 } TfLiteTransposeConvParams;
362 
363 typedef struct {
364   bool validate_indices;
365 } TfLiteSparseToDenseParams;
366 
367 typedef struct {
368   TfLiteType out_type;
369 } TfLiteShapeParams;
370 
371 typedef struct {
372   EmptyStructPlaceholder placeholder;
373 } TfLiteRankParams;
374 
375 typedef struct {
376   // Parameters supported by version 1:
377   float min;
378   float max;
379   int num_bits;
380 
381   // Parameters supported by version 2:
382   bool narrow_range;
383 } TfLiteFakeQuantParams;
384 
385 typedef struct {
386   int values_count;
387   int axis;
388 } TfLitePackParams;
389 
390 typedef struct {
391   int axis;
392 } TfLiteOneHotParams;
393 
394 typedef struct {
395   int num;
396   int axis;
397 } TfLiteUnpackParams;
398 
399 typedef struct {
400   float alpha;
401 } TfLiteLeakyReluParams;
402 
403 typedef struct {
404   TfLiteType index_out_type;
405 } TfLiteUniqueParams;
406 
407 typedef struct {
408   int seq_dim;
409   int batch_dim;
410 } TfLiteReverseSequenceParams;
411 
412 typedef struct {
413   EmptyStructPlaceholder placeholder;
414 } TfLiteMatrixDiagParams;
415 
416 typedef struct {
417   EmptyStructPlaceholder placeholder;
418 } TfLiteMatrixSetDiagParams;
419 
420 typedef struct {
421   int then_subgraph_index;
422   int else_subgraph_index;
423 } TfLiteIfParams;
424 
425 typedef struct {
426   int cond_subgraph_index;
427   int body_subgraph_index;
428 } TfLiteWhileParams;
429 
430 #ifdef __cplusplus
431 }  // extern "C"
432 #endif  // __cplusplus
433 
434 #endif  // TENSORFLOW_LITE_C_BUILTIN_OP_DATA_H_
435