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 #ifndef TENSORFLOW_LITE_EXPERIMENTAL_DELEGATES_COREML_COREML_DELEGATE_H_
16 #define TENSORFLOW_LITE_EXPERIMENTAL_DELEGATES_COREML_COREML_DELEGATE_H_
17 
18 #include "tensorflow/lite/c/common.h"
19 
20 #ifdef __cplusplus
21 extern "C" {
22 #endif  // __cplusplus
23 typedef enum {
24   // Create Core ML delegate only on devices with Apple Neural Engine.
25   // Returns nullptr otherwise.
26   TfLiteCoreMlDelegateDevicesWithNeuralEngine,
27   // Always create Core ML delegate
28   TfLiteCoreMlDelegateAllDevices
29 } TfLiteCoreMlDelegateEnabledDevices;
30 
31 typedef struct {
32   // Only create delegate when Neural Engine is available on the device.
33   TfLiteCoreMlDelegateEnabledDevices enabled_devices;
34   // Specifies target Core ML version for model conversion.
35   // Core ML 3 come with a lot more ops, but some ops (e.g. reshape) is not
36   // delegated due to input rank constraint.
37   // if not set to one of the valid versions, the delegate will use highest
38   // version possible in the platform.
39   // Valid versions: (2, 3)
40   int coreml_version;
41   // This sets the maximum number of Core ML delegates created.
42   // Each graph corresponds to one delegated node subset in the
43   // TFLite model. Set this to 0 to delegate all possible partitions.
44   int max_delegated_partitions;
45   // This sets the minimum number of nodes per partition delegated with
46   // Core ML delegate. Defaults to 2.
47   int min_nodes_per_partition;
48 } TfLiteCoreMlDelegateOptions;
49 
50 // Return a delegate that uses CoreML for ops execution.
51 // Must outlive the interpreter.
52 TfLiteDelegate* TfLiteCoreMlDelegateCreate(
53     const TfLiteCoreMlDelegateOptions* options);
54 
55 // Do any needed cleanup and delete 'delegate'.
56 void TfLiteCoreMlDelegateDelete(TfLiteDelegate* delegate);
57 
58 #ifdef __cplusplus
59 }
60 #endif  // __cplusplus
61 
62 #endif  // TENSORFLOW_LITE_EXPERIMENTAL_DELEGATES_COREML_COREML_DELEGATE_H_
63