1 /* Copyright 2022 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_C_API_OPAQUE_H_ 16 #define TENSORFLOW_LITE_C_C_API_OPAQUE_H_ 17 18 #include "tensorflow/lite/c/c_api.h" 19 #include "tensorflow/lite/c/c_api_types.h" // IWYU pragma: export 20 21 #ifdef __cplusplus 22 extern "C" { 23 #endif // __cplusplus 24 25 // -------------------------------------------------------------------------- 26 /// C API for TensorFlow Lite Opaque Types. 27 /// 28 /// These APIs are accessors for TFLite Opaque Types. 29 /// 30 /// WARNING: This is an experimental API and subject to change. 31 32 // -------------------------------------------------------------------------- 33 // Accessors for TfLiteOpaqueTensor. 34 35 // Returns the type of a tensor element. 36 TFL_CAPI_EXPORT extern TfLiteType TfLiteOpaqueTensorType( 37 const TfLiteOpaqueTensor* opaque_tensor); 38 39 // Returns the number of dimensions that the tensor has. 40 TFL_CAPI_EXPORT extern int32_t TfLiteOpaqueTensorNumDims( 41 const TfLiteOpaqueTensor* opaque_tensor); 42 43 // Returns the length of the tensor in the "dim_index" dimension. 44 TFL_CAPI_EXPORT extern int32_t TfLiteOpaqueTensorDim( 45 const TfLiteOpaqueTensor* opaque_tensor, int32_t dim_index); 46 47 // Returns the size of the underlying data in bytes. 48 TFL_CAPI_EXPORT extern size_t TfLiteOpaqueTensorByteSize( 49 const TfLiteOpaqueTensor* opaque_tensor); 50 51 // Returns a pointer to the underlying data buffer. 52 TFL_CAPI_EXPORT extern void* TfLiteOpaqueTensorData( 53 const TfLiteOpaqueTensor* opaque_tensor); 54 55 // Returns the (null-terminated) name of the tensor. 56 TFL_CAPI_EXPORT extern const char* TfLiteOpaqueTensorName( 57 const TfLiteOpaqueTensor* opaque_tensor); 58 59 // Copies from the provided input buffer into the tensor's buffer. 60 TFL_CAPI_EXPORT extern TfLiteStatus TfLiteOpaqueTensorCopyFromBuffer( 61 TfLiteOpaqueTensor* opaque_tensor, const void* input_data, 62 size_t input_data_size); 63 64 // Copies to the provided output buffer from the tensor's buffer. 65 TFL_CAPI_EXPORT extern TfLiteStatus TfLiteOpaqueTensorCopyToBuffer( 66 const TfLiteOpaqueTensor* opaque_tensor, void* output_data, 67 size_t output_data_size); 68 69 // -------------------------------------------------------------------------- 70 // Accessors for TfLiteOpaqueNode. 71 72 // Returns the input tensor of the given node. 73 TFL_CAPI_EXPORT extern const TfLiteOpaqueTensor* TfLiteOpaqueNodeGetInput( 74 TfLiteOpaqueContext* opaque_context, const TfLiteOpaqueNode* opaque_node, 75 int index); 76 77 // Returns the output tensor of the given node. 78 TFL_CAPI_EXPORT extern TfLiteOpaqueTensor* TfLiteOpaqueNodeGetOutput( 79 TfLiteOpaqueContext* opaque_context, const TfLiteOpaqueNode* opaque_node, 80 int index); 81 82 // Returns opaque data provided by the node implementer. The value returned 83 // from this function is the value that was returned from the `init` callback 84 // that was passed to `TfLiteRegistrationExternalSetInit`. 85 TFL_CAPI_EXPORT extern void* TfLiteOpaqueNodeGetUserData( 86 const TfLiteOpaqueNode* opaque_node); 87 88 #ifdef __cplusplus 89 } // extern "C" 90 #endif // __cplusplus 91 92 #endif // TENSORFLOW_LITE_C_C_API_OPAQUE_H_ 93