xref: /aosp_15_r20/external/tensorflow/tensorflow/lite/c/common_internal.h (revision b6fb3261f9314811a0f4371741dbb8839866f948)
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_COMMON_INTERNAL_H_
16 #define TENSORFLOW_LITE_C_C_API_COMMON_INTERNAL_H_
17 
18 #include "tensorflow/lite/c/c_api_types.h"
19 #include "tensorflow/lite/c/common.h"
20 
21 // Internal structures and subroutines used by the C API. These are likely to
22 // change and should not be depended on directly by any C API clients.
23 //
24 // NOTE: This header does not follow C conventions and does not define a C API.
25 // It is effectively an (internal) implementation detail of the C API.
26 
27 // `TfLiteRegistrationExternal` is an external version of `TfLiteRegistration`
28 // for C API which doesn't use internal types (such as `TfLiteContext`) but only
29 // uses stable API types (such as `TfLiteOpaqueContext`). The purpose of each
30 // field is the exactly the same as with `TfLiteRegistration`.
31 typedef struct TfLiteRegistrationExternal {
32   // Custom op name.
33   const char* custom_name;
34 
35   // The version of the op. The version should be higher than 0.
36   int version;
37 
38   // Initializes the op from serialized data.
39   void* (*init)(TfLiteOpaqueContext* context, const char* buffer,
40                 size_t length);
41 
42   // The pointer `buffer` is the data previously returned by an init invocation.
43   void (*free)(TfLiteOpaqueContext* context, void* buffer);
44 
45   // Called when the inputs that this node depends on have been resized.
46   TfLiteStatus (*prepare)(TfLiteOpaqueContext* context, TfLiteOpaqueNode* node);
47 
48   // Called when the node is executed. (should read node->inputs and output to
49   // node->outputs).
50   TfLiteStatus (*invoke)(TfLiteOpaqueContext* context, TfLiteOpaqueNode* node);
51 } TfLiteRegistrationExternal;
52 
53 #endif  // TENSORFLOW_LITE_C_C_API_INTERNAL_H_
54