1 /* Copyright 2020 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 // This file declares types used by the pure C inference API defined in c_api.h,
17 // some of which are also used in the C++ and C kernel and interpreter APIs.
18 
19 #ifndef TENSORFLOW_LITE_C_C_API_TYPES_H_
20 #define TENSORFLOW_LITE_C_C_API_TYPES_H_
21 
22 #include <stdint.h>
23 
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27 
28 // Define TFL_CAPI_EXPORT macro to export a function properly with a shared
29 // library.
30 #ifdef SWIG
31 #define TFL_CAPI_EXPORT
32 #elif defined(TFL_STATIC_LIBRARY_BUILD)
33 #define TFL_CAPI_EXPORT
34 #else  // not definded TFL_STATIC_LIBRARY_BUILD
35 #if defined(_WIN32)
36 #ifdef TFL_COMPILE_LIBRARY
37 #define TFL_CAPI_EXPORT __declspec(dllexport)
38 #else
39 #define TFL_CAPI_EXPORT __declspec(dllimport)
40 #endif  // TFL_COMPILE_LIBRARY
41 #else
42 #define TFL_CAPI_EXPORT __attribute__((visibility("default")))
43 #endif  // _WIN32
44 #endif  // SWIG
45 
46 typedef enum TfLiteStatus {
47   kTfLiteOk = 0,
48 
49   // Generally referring to an error in the runtime (i.e. interpreter)
50   kTfLiteError = 1,
51 
52   // Generally referring to an error from a TfLiteDelegate itself.
53   kTfLiteDelegateError = 2,
54 
55   // Generally referring to an error in applying a delegate due to
56   // incompatibility between runtime and delegate, e.g., this error is returned
57   // when trying to apply a TfLite delegate onto a model graph that's already
58   // immutable.
59   kTfLiteApplicationError = 3
60 } TfLiteStatus;
61 
62 // Types supported by tensor
63 typedef enum {
64   kTfLiteNoType = 0,
65   kTfLiteFloat32 = 1,
66   kTfLiteInt32 = 2,
67   kTfLiteUInt8 = 3,
68   kTfLiteInt64 = 4,
69   kTfLiteString = 5,
70   kTfLiteBool = 6,
71   kTfLiteInt16 = 7,
72   kTfLiteComplex64 = 8,
73   kTfLiteInt8 = 9,
74   kTfLiteFloat16 = 10,
75   kTfLiteFloat64 = 11,
76   kTfLiteComplex128 = 12,
77   kTfLiteUInt64 = 13,
78   kTfLiteResource = 14,
79   kTfLiteVariant = 15,
80   kTfLiteUInt32 = 16,
81 } TfLiteType;
82 
83 // Legacy. Will be deprecated in favor of TfLiteAffineQuantization.
84 // If per-layer quantization is specified this field will still be populated in
85 // addition to TfLiteAffineQuantization.
86 // Parameters for asymmetric quantization. Quantized values can be converted
87 // back to float using:
88 //     real_value = scale * (quantized_value - zero_point)
89 typedef struct TfLiteQuantizationParams {
90   float scale;
91   int32_t zero_point;
92 } TfLiteQuantizationParams;
93 
94 #ifdef __cplusplus
95 }  // extern C
96 #endif
97 #endif  // TENSORFLOW_LITE_C_C_API_TYPES_H_
98