@@ -42,6 +42,7 @@ limitations under the License.
42
42
#ifndef TENSORFLOW_LITE_CORE_C_COMMON_H_
43
43
#define TENSORFLOW_LITE_CORE_C_COMMON_H_
44
44
45
+ #include <stdarg.h>
45
46
#include <stdbool.h>
46
47
#include <stddef.h>
47
48
#include <stdint.h>
@@ -648,23 +649,26 @@ void TfLiteTensorReset(TfLiteType type, const char* name, TfLiteIntArray* dims,
648
649
TfLiteStatus TfLiteTensorCopy (const TfLiteTensor * src , TfLiteTensor * dst );
649
650
650
651
// Change the size of the memory block owned by `tensor` to `num_bytes`.
651
- // Tensors with allocation types other than kTfLiteDynamic will be ignored.
652
+ // Tensors with allocation types other than `kTfLiteDynamic` will be ignored and
653
+ // a kTfLiteOk will be returned.
652
654
// `tensor`'s internal data buffer will be assigned a pointer
653
655
// which can safely be passed to free or realloc if `num_bytes` is zero.
654
- // Behaviour is undefined if `tensor` is NULL.
655
656
// If `preserve_data` is true, tensor data will be unchanged in the range from
656
- // the start of the region up to the minimum of the old and new sizes.
657
- void TfLiteTensorResizeMaybeCopy (size_t num_bytes , TfLiteTensor * tensor ,
658
- bool preserve_data );
657
+ // the start of the region up to the minimum of the old and new sizes. In the
658
+ // case of NULL tensor, or an error allocating new memory, returns
659
+ // `kTfLiteError`.
660
+ TfLiteStatus TfLiteTensorResizeMaybeCopy (size_t num_bytes , TfLiteTensor * tensor ,
661
+ bool preserve_data );
659
662
660
663
// Change the size of the memory block owned by `tensor` to `num_bytes`.
661
- // Tensors with allocation types other than kTfLiteDynamic will be ignored.
664
+ // Tensors with allocation types other than kTfLiteDynamic will be ignored and
665
+ // a kTfLiteOk will be returned.
662
666
// `tensor`'s internal data buffer will be assigned a pointer
663
667
// which can safely be passed to free or realloc if `num_bytes` is zero.
664
- // Behaviour is undefined if `tensor` is NULL.
665
668
// Tensor data will be unchanged in the range from the start of the region up to
666
- // the minimum of the old and new sizes.
667
- void TfLiteTensorRealloc (size_t num_bytes , TfLiteTensor * tensor );
669
+ // the minimum of the old and new sizes. In the case
670
+ // of NULL tensor, or an error allocating new memory, returns `kTfLiteError`.
671
+ TfLiteStatus TfLiteTensorRealloc (size_t num_bytes , TfLiteTensor * tensor );
668
672
#endif // TF_LITE_STATIC_MEMORY
669
673
670
674
// WARNING: This is an experimental interface that is subject to change.
@@ -955,12 +959,53 @@ typedef struct TfLiteRegistration {
955
959
// ops. We keep it inside of `TfLiteRegistration` and use it to route
956
960
// callbacks properly.
957
961
TfLiteRegistrationExternal * registration_external ;
962
+
963
+ // Retrieves asynchronous kernel.
964
+ //
965
+ // If the `async_kernel` field is nullptr, it means the operation described by
966
+ // this TfLiteRegistration object does not support asynchronous execution.
967
+ // Otherwise, the function that the field points to should only be called for
968
+ // delegate kernel nodes, i.e. `node` should be a delegate kernel node created
969
+ // by applying a delegate.
970
+ // If the function returns nullptr, that means that the underlying delegate
971
+ // does not support asynchronous execution for this `node`.
972
+ struct TfLiteAsyncKernel * (* async_kernel )(TfLiteContext * context ,
973
+ TfLiteNode * node );
958
974
} TfLiteRegistration ;
959
975
976
+ /// \private
977
+ // Old version of `TfLiteRegistration` to maintain binary backward
978
+ // compatibility.
979
+ // The legacy registration type must be a POD struct type whose field types must
980
+ // be a prefix of the field types in TfLiteRegistration, and offset of the first
981
+ // field in TfLiteRegistration that is not present in the legacy registration
982
+ // type must be greater than or equal to the size of the legacy registration
983
+ // type.
984
+ // WARNING: This structure is deprecated / not an official part of the
985
+ // API. It should be only used for binary backward compatibility.
986
+ typedef struct TfLiteRegistration_V2 {
987
+ void * (* init )(TfLiteContext * context , const char * buffer , size_t length );
988
+ void (* free )(TfLiteContext * context , void * buffer );
989
+ TfLiteStatus (* prepare )(TfLiteContext * context , TfLiteNode * node );
990
+ TfLiteStatus (* invoke )(TfLiteContext * context , TfLiteNode * node );
991
+ const char * (* profiling_string )(const TfLiteContext * context ,
992
+ const TfLiteNode * node );
993
+ int32_t builtin_code ;
994
+ const char * custom_name ;
995
+ int version ;
996
+ TfLiteRegistrationExternal * registration_external ;
997
+ } TfLiteRegistration_V2 ;
998
+
999
+ /// \private
960
1000
// Old version of `TfLiteRegistration` to maintain binary backward
961
1001
// compatibility.
962
- // WARNING: This structure is deprecated / not an official part of the API.
963
- // It should be only used for binary backward compatibility.
1002
+ // The legacy registration type must be a POD struct type whose field types must
1003
+ // be a prefix of the field types in TfLiteRegistration, and offset of the first
1004
+ // field in TfLiteRegistration that is not present in the legacy registration
1005
+ // type must be greater than or equal to the size of the legacy registration
1006
+ // type.
1007
+ // WARNING: This structure is deprecated / not an official part of the
1008
+ // API. It should be only used for binary backward compatibility.
964
1009
typedef struct TfLiteRegistration_V1 {
965
1010
void * (* init )(TfLiteContext * context , const char * buffer , size_t length );
966
1011
void (* free )(TfLiteContext * context , void * buffer );
@@ -1135,6 +1180,20 @@ TfLiteOpaqueDelegate* TfLiteOpaqueDelegateCreate(
1135
1180
// 'delegate' is a null pointer.
1136
1181
void TfLiteOpaqueDelegateDelete (TfLiteOpaqueDelegate * delegate );
1137
1182
1183
+ // Returns a pointer to the data associated with the provided opaque 'delegate'.
1184
+ //
1185
+ // A null pointer will be returned when:
1186
+ // - The 'delegate' is null.
1187
+ // - The 'data' field of the 'TfLiteOpaqueDelegateBuilder' used to construct the
1188
+ // 'delegate' was null.
1189
+ // - Or in case of any other error.
1190
+ // - The 'delegate' has been constructed via a 'TfLiteOpaqueDelegateBuilder',
1191
+ // but the 'data' field of the 'TfLiteOpaqueDelegateBuilder' is null.
1192
+ //
1193
+ // The data_ field of 'delegate' will be returned if the
1194
+ // 'opaque_delegate_builder' field is null.
1195
+ void * TfLiteOpaqueDelegateGetData (const TfLiteOpaqueDelegate * delegate );
1196
+
1138
1197
#ifdef __cplusplus
1139
1198
} // extern "C"
1140
1199
#endif // __cplusplus
0 commit comments