xref: /aosp_15_r20/external/mesa3d/include/tensorflow/lite/core/c/c_api_types.h (revision 6104692788411f58d303aa86923a9ff6ecaded22)
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 /// WARNING: Users of TensorFlow Lite should not include this file directly,
20 /// but should instead include
21 /// "third_party/tensorflow/lite/c/c_api_types.h".
22 /// Only the TensorFlow Lite implementation itself should include this
23 /// file directly.
24 // IWYU pragma: private, include "third_party/tensorflow/lite/c/c_api_types.h"
25 
26 #ifndef TENSORFLOW_LITE_CORE_C_C_API_TYPES_H_
27 #define TENSORFLOW_LITE_CORE_C_C_API_TYPES_H_
28 
29 #include <stdint.h>
30 
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34 
35 // Define TFL_CAPI_EXPORT macro to export a function properly with a shared
36 // library.
37 #ifdef SWIG
38 #define TFL_CAPI_EXPORT
39 #elif defined(TFL_STATIC_LIBRARY_BUILD)
40 #define TFL_CAPI_EXPORT
41 #else  // not definded TFL_STATIC_LIBRARY_BUILD
42 #if defined(_WIN32)
43 #ifdef TFL_COMPILE_LIBRARY
44 #define TFL_CAPI_EXPORT __declspec(dllexport)
45 #else
46 #define TFL_CAPI_EXPORT __declspec(dllimport)
47 #endif  // TFL_COMPILE_LIBRARY
48 #else
49 #define TFL_CAPI_EXPORT __attribute__((visibility("default")))
50 #endif  // _WIN32
51 #endif  // SWIG
52 
53 // Note that new error status values may be added in future in order to
54 // indicate more fine-grained internal states, therefore, applications should
55 // not rely on status values being members of the enum.
56 typedef enum TfLiteStatus {
57   kTfLiteOk = 0,
58 
59   // Generally referring to an error in the runtime (i.e. interpreter)
60   kTfLiteError = 1,
61 
62   // Generally referring to an error from a TfLiteDelegate itself.
63   kTfLiteDelegateError = 2,
64 
65   // Generally referring to an error in applying a delegate due to
66   // incompatibility between runtime and delegate, e.g., this error is returned
67   // when trying to apply a TF Lite delegate onto a model graph that's already
68   // immutable.
69   kTfLiteApplicationError = 3,
70 
71   // Generally referring to serialized delegate data not being found.
72   // See tflite::delegates::Serialization.
73   kTfLiteDelegateDataNotFound = 4,
74 
75   // Generally referring to data-writing issues in delegate serialization.
76   // See tflite::delegates::Serialization.
77   kTfLiteDelegateDataWriteError = 5,
78 
79   // Generally referring to data-reading issues in delegate serialization.
80   // See tflite::delegates::Serialization.
81   kTfLiteDelegateDataReadError = 6,
82 
83   // Generally referring to issues when the TF Lite model has ops that cannot be
84   // resolved at runtime. This could happen when the specific op is not
85   // registered or built with the TF Lite framework.
86   kTfLiteUnresolvedOps = 7,
87 
88   // Generally referring to invocation cancelled by the user.
89   // See `interpreter::Cancel`.
90   // TODO(b/194915839): Implement `interpreter::Cancel`.
91   // TODO(b/250636993): Cancellation triggered by `SetCancellationFunction`
92   // should also return this status code.
93   kTfLiteCancelled = 8,
94 } TfLiteStatus;
95 
96 // Types supported by tensor
97 typedef enum {
98   kTfLiteNoType = 0,
99   kTfLiteFloat32 = 1,
100   kTfLiteInt32 = 2,
101   kTfLiteUInt8 = 3,
102   kTfLiteInt64 = 4,
103   kTfLiteString = 5,
104   kTfLiteBool = 6,
105   kTfLiteInt16 = 7,
106   kTfLiteComplex64 = 8,
107   kTfLiteInt8 = 9,
108   kTfLiteFloat16 = 10,
109   kTfLiteFloat64 = 11,
110   kTfLiteComplex128 = 12,
111   kTfLiteUInt64 = 13,
112   kTfLiteResource = 14,
113   kTfLiteVariant = 15,
114   kTfLiteUInt32 = 16,
115   kTfLiteUInt16 = 17,
116   kTfLiteInt4 = 18,
117 } TfLiteType;
118 
119 // Legacy. Will be deprecated in favor of TfLiteAffineQuantization.
120 // If per-layer quantization is specified this field will still be populated in
121 // addition to TfLiteAffineQuantization.
122 // Parameters for asymmetric quantization. Quantized values can be converted
123 // back to float using:
124 //     real_value = scale * (quantized_value - zero_point)
125 typedef struct TfLiteQuantizationParams {
126   float scale;
127   int32_t zero_point;
128 } TfLiteQuantizationParams;
129 
130 // --------------------------------------------------------------------------
131 // Opaque types used by c_api.h, c_api_opaque.h and common.h.
132 
133 // TfLiteOpaqueContext is an opaque version of TfLiteContext;
134 typedef struct TfLiteOpaqueContext TfLiteOpaqueContext;
135 
136 // TfLiteOpaqueNode is an opaque version of TfLiteNode;
137 typedef struct TfLiteOpaqueNode TfLiteOpaqueNode;
138 
139 // TfLiteOpaqueTensor is an opaque version of TfLiteTensor;
140 typedef struct TfLiteOpaqueTensor TfLiteOpaqueTensor;
141 
142 // TfLiteDelegate: allows delegation of nodes to alternative backends.
143 // Forward declaration of concrete type declared in common.h.
144 typedef struct TfLiteDelegate TfLiteDelegate;
145 
146 // TfLiteOpaqueDelegateStruct: unconditionally opaque version of
147 // TfLiteDelegate; allows delegation of nodes to alternative backends.
148 //
149 // This is an abstract type that is intended to have the same
150 // role as TfLiteDelegate, but without exposing the implementation
151 // details of how delegates are implemented.
152 // WARNING: This is an experimental type and subject to change.
153 typedef struct TfLiteOpaqueDelegateStruct TfLiteOpaqueDelegateStruct;
154 
155 // TfLiteOpaqueDelegate: conditionally opaque version of
156 // TfLiteDelegate; allows delegation of nodes to alternative backends.
157 // For TF Lite in Play Services, this is an opaque type,
158 // but for regular TF Lite, this is just a typedef for TfLiteDelegate.
159 // WARNING: This is an experimental type and subject to change.
160 #if TFLITE_WITH_STABLE_ABI || TFLITE_USE_OPAQUE_DELEGATE
161 typedef TfLiteOpaqueDelegateStruct TfLiteOpaqueDelegate;
162 #else
163 typedef TfLiteDelegate TfLiteOpaqueDelegate;
164 #endif
165 
166 #ifdef __cplusplus
167 }  // extern C
168 #endif
169 #endif  // TENSORFLOW_LITE_CORE_C_C_API_TYPES_H_
170