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 | // Note that new error status values may be added in future in order to |
47 | // indicate more fine-grained internal states, therefore, applications should |
48 | // not rely on status values being members of the enum. |
49 | typedef enum TfLiteStatus { |
50 | kTfLiteOk = 0, |
51 | |
52 | // Generally referring to an error in the runtime (i.e. interpreter) |
53 | kTfLiteError = 1, |
54 | |
55 | // Generally referring to an error from a TfLiteDelegate itself. |
56 | kTfLiteDelegateError = 2, |
57 | |
58 | // Generally referring to an error in applying a delegate due to |
59 | // incompatibility between runtime and delegate, e.g., this error is returned |
60 | // when trying to apply a TF Lite delegate onto a model graph that's already |
61 | // immutable. |
62 | kTfLiteApplicationError = 3, |
63 | |
64 | // Generally referring to serialized delegate data not being found. |
65 | // See tflite::delegates::Serialization. |
66 | kTfLiteDelegateDataNotFound = 4, |
67 | |
68 | // Generally referring to data-writing issues in delegate serialization. |
69 | // See tflite::delegates::Serialization. |
70 | kTfLiteDelegateDataWriteError = 5, |
71 | |
72 | // Generally referring to data-reading issues in delegate serialization. |
73 | // See tflite::delegates::Serialization. |
74 | kTfLiteDelegateDataReadError = 6, |
75 | |
76 | // Generally referring to issues when the TF Lite model has ops that cannot be |
77 | // resolved at runtime. This could happen when the specific op is not |
78 | // registered or built with the TF Lite framework. |
79 | kTfLiteUnresolvedOps = 7, |
80 | } TfLiteStatus; |
81 | |
82 | // Types supported by tensor |
83 | typedef enum { |
84 | kTfLiteNoType = 0, |
85 | kTfLiteFloat32 = 1, |
86 | kTfLiteInt32 = 2, |
87 | kTfLiteUInt8 = 3, |
88 | kTfLiteInt64 = 4, |
89 | kTfLiteString = 5, |
90 | kTfLiteBool = 6, |
91 | kTfLiteInt16 = 7, |
92 | kTfLiteComplex64 = 8, |
93 | kTfLiteInt8 = 9, |
94 | kTfLiteFloat16 = 10, |
95 | kTfLiteFloat64 = 11, |
96 | kTfLiteComplex128 = 12, |
97 | kTfLiteUInt64 = 13, |
98 | kTfLiteResource = 14, |
99 | kTfLiteVariant = 15, |
100 | kTfLiteUInt32 = 16, |
101 | kTfLiteUInt16 = 17, |
102 | } TfLiteType; |
103 | |
104 | // Legacy. Will be deprecated in favor of TfLiteAffineQuantization. |
105 | // If per-layer quantization is specified this field will still be populated in |
106 | // addition to TfLiteAffineQuantization. |
107 | // Parameters for asymmetric quantization. Quantized values can be converted |
108 | // back to float using: |
109 | // real_value = scale * (quantized_value - zero_point) |
110 | typedef struct TfLiteQuantizationParams { |
111 | float scale; |
112 | int32_t zero_point; |
113 | } TfLiteQuantizationParams; |
114 | |
115 | // -------------------------------------------------------------------------- |
116 | // Opaque types used by c_api.h, c_api_opaque.h and common.h. |
117 | |
118 | // TfLiteOpaqueContext is an opaque version of TfLiteContext; |
119 | typedef struct TfLiteOpaqueContext TfLiteOpaqueContext; |
120 | |
121 | // TfLiteOpaqueNode is an opaque version of TfLiteNode; |
122 | typedef struct TfLiteOpaqueNode TfLiteOpaqueNode; |
123 | |
124 | // TfLiteOpaqueTensor is an opaque version of TfLiteTensor; |
125 | typedef struct TfLiteOpaqueTensor TfLiteOpaqueTensor; |
126 | |
127 | // TfLiteOpaqueDelegateStruct: opaque version of TfLiteDelegate; allows |
128 | // delegation of nodes to alternative backends. |
129 | // |
130 | // This is an abstract type that is intended to have the same |
131 | // role as TfLiteDelegate from common.h, but without exposing the implementation |
132 | // details of how delegates are implemented. |
133 | // WARNING: This is an experimental type and subject to change. |
134 | typedef struct TfLiteOpaqueDelegateStruct TfLiteOpaqueDelegateStruct; |
135 | |
136 | #ifdef __cplusplus |
137 | } // extern C |
138 | #endif |
139 | #endif // TENSORFLOW_LITE_C_C_API_TYPES_H_ |
140 | |