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 61 // Generally referring to serialized delegate data not being found. 62 // See tflite::delegates::Serialization. 63 kTfLiteDelegateDataNotFound = 4, 64 65 // Generally referring to data-writing issues in delegate serialization. 66 // See tflite::delegates::Serialization. 67 kTfLiteDelegateDataWriteError = 5, 68 69 // Generally referring to data-reading issues in delegate serialization. 70 // See tflite::delegates::Serialization. 71 kTfLiteDelegateDataReadError = 5, 72 } TfLiteStatus; 73 74 // Types supported by tensor 75 typedef enum { 76 kTfLiteNoType = 0, 77 kTfLiteFloat32 = 1, 78 kTfLiteInt32 = 2, 79 kTfLiteUInt8 = 3, 80 kTfLiteInt64 = 4, 81 kTfLiteString = 5, 82 kTfLiteBool = 6, 83 kTfLiteInt16 = 7, 84 kTfLiteComplex64 = 8, 85 kTfLiteInt8 = 9, 86 kTfLiteFloat16 = 10, 87 kTfLiteFloat64 = 11, 88 kTfLiteComplex128 = 12, 89 kTfLiteUInt64 = 13, 90 kTfLiteResource = 14, 91 kTfLiteVariant = 15, 92 kTfLiteUInt32 = 16, 93 } TfLiteType; 94 95 // Legacy. Will be deprecated in favor of TfLiteAffineQuantization. 96 // If per-layer quantization is specified this field will still be populated in 97 // addition to TfLiteAffineQuantization. 98 // Parameters for asymmetric quantization. Quantized values can be converted 99 // back to float using: 100 // real_value = scale * (quantized_value - zero_point) 101 typedef struct TfLiteQuantizationParams { 102 float scale; 103 int32_t zero_point; 104 } TfLiteQuantizationParams; 105 106 #ifdef __cplusplus 107 } // extern C 108 #endif 109 #endif // TENSORFLOW_LITE_C_C_API_TYPES_H_ 110