1 /* Copyright 2021 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_EXPERIMENTAL_ACCELERATION_CONFIGURATION_C_DELEGATE_PLUGIN_H_
16 #define TENSORFLOW_LITE_EXPERIMENTAL_ACCELERATION_CONFIGURATION_C_DELEGATE_PLUGIN_H_
17 
18 // C API types for TF Lite delegate plugins.
19 
20 #include "tensorflow/lite/c/common.h"
21 
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25 
26 // Type of function to allocate and construct a delegate.
27 // The tflite_settings parameter should be a pointer to a FlatBuffer table
28 // object of type tflite::TFLiteSettings.  (We use 'void *' here since this
29 // is a C API so we don't want to directly reference C++ types such
30 // as tflite::TFLiteSettings.)
31 typedef TfLiteDelegate *TfLiteDelegatePluginCreateFunc(
32     const void *tflite_settings);
33 
34 // Type of function to destroy and deallocate a delegate.
35 // The delegate argument must have been created with the corresponding
36 // create function from the same delegate plugin.
37 typedef void TfLiteDelegatePluginDestroyFunc(TfLiteDelegate *);
38 
39 // Type of function to return an error code for the last delegate operation.
40 // The delegate argument must have been created with the corresponding
41 // create function from the same delegate plugin.
42 typedef int TfLiteDelegatePluginGetDelegateErrnoFunc(TfLiteDelegate *);
43 
44 // Struct to hold all the methods for a delegate plugin.
45 typedef struct TfLiteDelegatePlugin {
46   // Function to allocate and construct a delegate.
47   TfLiteDelegatePluginCreateFunc *create;
48 
49   // Function to deallocate a delegate.
50   TfLiteDelegatePluginDestroyFunc *destroy;
51 
52   // Function to return an error code for the last delegate operation.
53   TfLiteDelegatePluginGetDelegateErrnoFunc *get_delegate_errno;
54 } TfLiteDelegatePlugin;
55 
56 #ifdef __cplusplus
57 };  // extern "C"
58 #endif
59 
60 #endif  // TENSORFLOW_LITE_EXPERIMENTAL_ACCELERATION_CONFIGURATION_C_DELEGATE_PLUGIN_H_
61