• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright 2019 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 #ifndef TENSORFLOW_LITE_DELEGATES_GPU_METAL_DELEGATE_H_
17 #define TENSORFLOW_LITE_DELEGATES_GPU_METAL_DELEGATE_H_
18 
19 #include "tensorflow/lite/c/common.h"
20 
21 #ifdef __cplusplus
22 extern "C" {
23 #else
24 // For "C" 'bool' is not built-in type.
25 #include <stdbool.h>
26 #endif  // __cplusplus
27 
28 typedef struct TfLiteDelegate TfLiteDelegate;
29 
30 typedef enum {
31   // waitUntilCompleted
32   TFLGpuDelegateWaitTypePassive,
33   // Minimize latency. It uses active spinning instead of mutex and consumes
34   // additional CPU resources.
35   TFLGpuDelegateWaitTypeActive,
36   // Useful when the output is used with GPU pipeline then or if external
37   // command encoder is set.
38   TFLGpuDelegateWaitTypeDoNotWait,
39   // Tries to avoid GPU sleep mode.
40   TFLGpuDelegateWaitTypeAggressive,
41 } TFLGpuDelegateWaitType;
42 
43 // Creates a new delegate instance that need to be destroyed with
44 // DeleteFlowDelegate when delegate is no longer used by tflite.
45 typedef struct {
46   // Allows to quantify tensors, downcast values, process in float16 etc.
47   bool allow_precision_loss;
48   TFLGpuDelegateWaitType wait_type;
49   // Allows execution of integer quantized models
50   bool enable_quantization;
51 } TFLGpuDelegateOptions;
52 
53 // Populates TFLGpuDelegateOptions as follows:
54 //   allow_precision_loss = false;
55 //   wait_type = TFLGpuDelegateWaitType::TFLGpuDelegateWaitTypePassive;
56 //   enable_quantization = true;
57 TFL_CAPI_EXPORT extern TFLGpuDelegateOptions TFLGpuDelegateOptionsDefault(void);
58 
59 // Creates a new delegate instance that need to be destroyed with
60 // `TFLDeleteTfLiteGpuDelegate` when delegate is no longer used by TFLite.
61 // When `options` is set to `nullptr`, the following default values are used:
62 // .precision_loss_allowed = false,
63 // .wait_type = kPassive,
64 TFL_CAPI_EXPORT extern TfLiteDelegate* TFLGpuDelegateCreate(
65     const TFLGpuDelegateOptions* options);
66 
67 // Destroys a delegate created with `TFLGpuDelegateCreate` call.
68 TFL_CAPI_EXPORT extern void TFLGpuDelegateDelete(TfLiteDelegate* delegate);
69 
70 #ifdef __cplusplus
71 }  // extern "C"
72 #endif  // __cplusplus
73 
74 #endif  // TENSORFLOW_LITE_DELEGATES_GPU_METAL_DELEGATE_H_
75