• 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/c_api_internal.h"
21 
22 #ifdef __cplusplus
23 extern "C" {
24 #endif  // __cplusplus
25 
26 // TODO(aselle): Consider using "if this then that" for testing.
27 
28 // Useful placeholder to put in otherwise empty structs to avoid size warnings.
29 typedef struct {
30   char dummy;
31 } EmptyStructPlaceholder;
32 
33 // IMPORTANT: All new members of structs must be added at the end to ensure
34 // backwards compatibility.
35 
36 // Possible padding types (for convolutions)
37 typedef enum {
38   kTfLitePaddingUnknown = 0,
39   kTfLitePaddingSame,
40   kTfLitePaddingValid,
41 } TfLitePadding;
42 
43 typedef enum {
44   kTfLiteMirrorPaddingUnknown = 0,
45   kTfLiteMirrorPaddingReflect,
46   kTfLiteMirrorPaddingSymmetric,
47 } TfLiteMirrorPaddingMode;
48 
49 typedef struct {
50   int width;
51   int height;
52 } TfLitePaddingValues;
53 
54 typedef struct {
55   TfLiteMirrorPaddingMode mode;
56 } TfLiteMirrorPaddingParams;
57 
58 // Possible fused activation functions.
59 // TODO(aselle): rename to TfLiteActivation
60 typedef enum {
61   kTfLiteActNone = 0,
62   kTfLiteActRelu,
63   kTfLiteActRelu1,
64   kTfLiteActRelu6,
65   kTfLiteActTanh,
66   kTfLiteActSignBit,
67   kTfLiteActSigmoid,
68 } TfLiteFusedActivation;
69 
70 typedef struct {
71   TfLitePadding padding;
72   int stride_width;
73   int stride_height;
74   int dilation_width_factor;
75   int dilation_height_factor;
76   TfLiteFusedActivation activation;
77 } TfLiteConvParams;
78 
79 typedef struct {
80   TfLitePadding padding;
81   int stride_width;
82   int stride_height;
83   int filter_width;
84   int filter_height;
85   TfLiteFusedActivation activation;
86   struct {
87     TfLitePaddingValues padding;
88   } computed;
89 } TfLitePoolParams;
90 
91 typedef struct {
92   // Parameters for DepthwiseConv version 1 or above.
93   TfLitePadding padding;
94   int stride_width;
95   int stride_height;
96   int depth_multiplier;
97   TfLiteFusedActivation activation;
98   // Parameters for DepthwiseConv version 2 or above.
99   int dilation_width_factor;
100   int dilation_height_factor;
101 } TfLiteDepthwiseConvParams;
102 
103 typedef struct {
104   int rank;
105   TfLiteFusedActivation activation;
106 } TfLiteSVDFParams;
107 
108 typedef struct {
109   TfLiteFusedActivation activation;
110 } TfLiteRNNParams;
111 
112 typedef struct {
113   bool time_major;
114   TfLiteFusedActivation activation;
115 } TfLiteSequenceRNNParams;
116 
117 typedef struct {
118   bool time_major;
119   TfLiteFusedActivation activation;
120   bool merge_outputs;
121 } TfLiteBidirectionalSequenceRNNParams;
122 
123 typedef enum {
124   kTfLiteFullyConnectedWeightsFormatDefault = 0,
125   kTfLiteFullyConnectedWeightsFormatShuffled4x16Int8 = 1,
126 } TfLiteFullyConnectedWeightsFormat;
127 
128 typedef struct {
129   // Parameters for FullyConnected version 1 or above.
130   TfLiteFusedActivation activation;
131 
132   // Parameters for FullyConnected version 2 or above.
133   TfLiteFullyConnectedWeightsFormat weights_format;
134 } TfLiteFullyConnectedParams;
135 
136 typedef enum {
137   kTfLiteLshProjectionUnknown = 0,
138   kTfLiteLshProjectionSparse = 1,
139   kTfLiteLshProjectionDense = 2,
140 } TfLiteLSHProjectionType;
141 
142 typedef struct {
143   TfLiteLSHProjectionType type;
144 } TfLiteLSHProjectionParams;
145 
146 typedef struct {
147   float beta;
148 } TfLiteSoftmaxParams;
149 
150 typedef struct {
151   int axis;
152   TfLiteFusedActivation activation;
153 } TfLiteConcatenationParams;
154 
155 typedef struct {
156   TfLiteFusedActivation activation;
157 } TfLiteAddParams;
158 
159 typedef struct {
160   EmptyStructPlaceholder placeholder;
161 } TfLiteSpaceToBatchNDParams;
162 
163 typedef struct {
164   EmptyStructPlaceholder placeholder;
165 } TfLiteBatchToSpaceNDParams;
166 
167 typedef struct {
168   TfLiteFusedActivation activation;
169 } TfLiteMulParams;
170 
171 typedef struct {
172   TfLiteFusedActivation activation;
173 } TfLiteSubParams;
174 
175 typedef struct {
176   TfLiteFusedActivation activation;
177 } TfLiteDivParams;
178 
179 typedef struct {
180   TfLiteFusedActivation activation;
181 } TfLiteL2NormParams;
182 
183 typedef struct {
184   int radius;
185   float bias;
186   float alpha;
187   float beta;
188 } TfLiteLocalResponseNormParams;
189 
190 typedef enum {
191   kTfLiteLSTMFullKernel = 0,
192   kTfLiteLSTMBasicKernel
193 } TfLiteLSTMKernelType;
194 
195 typedef struct {
196   // Parameters for LSTM version 1.
197   TfLiteFusedActivation activation;
198   float cell_clip;
199   float proj_clip;
200 
201   // Parameters for LSTM version 2.
202   // kTfLiteLSTMBasicKernel is only supported in version 2 or above.
203   TfLiteLSTMKernelType kernel_type;
204 } TfLiteLSTMParams;
205 
206 typedef struct {
207   // Parameters needed for the underlying LSTM.
208   TfLiteFusedActivation activation;
209   float cell_clip;
210   float proj_clip;
211 
212   // If set to true then the first dimension is time, otherwise batch.
213   bool time_major;
214 } TfLiteUnidirectionalSequenceLSTMParams;
215 
216 typedef struct {
217   // Parameters supported by version 1:
218   // Parameters inherited for the LSTM kernel.
219   TfLiteFusedActivation activation;
220   float cell_clip;
221   float proj_clip;
222 
223   // If true, store the outputs of both directions in the first output.
224   bool merge_outputs;
225 
226   // Parameters supported by version 2:
227   // If set to true then the first dimension is time, otherwise batch.
228   bool time_major;
229 } TfLiteBidirectionalSequenceLSTMParams;
230 
231 typedef struct {
232   bool align_corners;
233 } TfLiteResizeBilinearParams;
234 
235 typedef struct {
236   bool align_corners;
237 } TfLiteResizeNearestNeighborParams;
238 
239 typedef struct {
240   EmptyStructPlaceholder placeholder;
241 } TfLitePadParams;
242 
243 typedef struct {
244   EmptyStructPlaceholder placeholder;
245 } TfLitePadV2Params;
246 
247 typedef struct {
248   // TODO(ahentz): We can't have dynamic data in this struct, at least not yet.
249   // For now we will fix the maximum possible number of dimensions.
250   int shape[8];
251   int num_dimensions;
252 } TfLiteReshapeParams;
253 
254 typedef struct {
255   int ngram_size;
256   int max_skip_size;
257   bool include_all_ngrams;
258 } TfLiteSkipGramParams;
259 
260 typedef struct {
261   int block_size;
262 } TfLiteSpaceToDepthParams;
263 
264 typedef struct {
265   TfLiteType in_data_type;
266   TfLiteType out_data_type;
267 } TfLiteCastParams;
268 
269 typedef enum {
270   kTfLiteCombinerTypeSum = 0,
271   kTfLiteCombinerTypeMean = 1,
272   kTfLiteCombinerTypeSqrtn = 2,
273 } TfLiteCombinerType;
274 
275 typedef struct {
276   TfLiteCombinerType combiner;
277 } TfLiteEmbeddingLookupSparseParams;
278 
279 typedef struct {
280   int axis;
281 } TfLiteGatherParams;
282 
283 typedef struct {
284   EmptyStructPlaceholder placeholder;
285 } TfLiteTransposeParams;
286 
287 typedef struct {
288   bool keep_dims;
289 } TfLiteReducerParams;
290 
291 typedef struct {
292   int num_splits;
293 } TfLiteSplitParams;
294 
295 typedef struct {
296   int num_splits;
297 } TfLiteSplitVParams;
298 
299 typedef struct {
300   // TODO(ahentz): We can't have dynamic data in this struct, at least not yet.
301   // For now we will fix the maximum possible number of dimensions.
302   int squeeze_dims[8];
303   int num_squeeze_dims;
304 } TfLiteSqueezeParams;
305 
306 typedef struct {
307   int begin_mask;
308   int end_mask;
309   int ellipsis_mask;
310   int new_axis_mask;
311   int shrink_axis_mask;
312 } TfLiteStridedSliceParams;
313 
314 typedef struct {
315   TfLiteType output_type;
316 } TfLiteArgMaxParams;
317 
318 typedef struct {
319   TfLiteType output_type;
320 } TfLiteArgMinParams;
321 
322 typedef struct {
323   TfLitePadding padding;
324   int stride_width;
325   int stride_height;
326 } TfLiteTransposeConvParams;
327 
328 typedef struct {
329   bool validate_indices;
330 } TfLiteSparseToDenseParams;
331 
332 typedef struct {
333   TfLiteType out_type;
334 } TfLiteShapeParams;
335 
336 typedef struct {
337 } TfLiteRankParams;
338 
339 typedef struct {
340   // Parameters supported by version 1:
341   float min;
342   float max;
343   int num_bits;
344 
345   // Parameters supported by version 2:
346   bool narrow_range;
347 } TfLiteFakeQuantParams;
348 
349 typedef struct {
350   int values_count;
351   int axis;
352 } TfLitePackParams;
353 
354 typedef struct {
355   int axis;
356 } TfLiteOneHotParams;
357 
358 typedef struct {
359   int num;
360   int axis;
361 } TfLiteUnpackParams;
362 
363 typedef struct {
364   float alpha;
365 } TfLiteLeakyReluParams;
366 
367 typedef struct {
368   TfLiteType index_out_type;
369 } TfLiteUniqueParams;
370 
371 typedef struct {
372   int seq_dim;
373   int batch_dim;
374 } TfLiteReverseSequenceParams;
375 
376 #ifdef __cplusplus
377 }  // extern "C"
378 #endif  // __cplusplus
379 
380 #endif  // TENSORFLOW_LITE_C_BUILTIN_OP_DATA_H_
381