• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright 2018 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_DELEGATES_FLEX_DELEGATE_H_
16 #define TENSORFLOW_LITE_DELEGATES_FLEX_DELEGATE_H_
17 
18 #include "tensorflow/lite/c/c_api_internal.h"
19 #include "tensorflow/lite/delegates/flex/delegate_data.h"
20 
21 namespace tflite {
22 
23 // WARNING: This is an experimental interface that is subject to change.
24 // Delegate that can be used to extract parts of a graph that are designed to be
25 // executed by TensorFlow's runtime via Eager.
26 //
27 // The interpreter must be constructed after the FlexDelegate and destructed
28 // before the FlexDelegate. This delegate may be used with multiple
29 // interpreters, but it is *not* thread-safe.
30 //
31 // Usage:
32 //   auto delegate = FlexDelegate::Create();
33 //   ... build interpreter ...
34 //
35 //   if (delegate) {
36 //     interpreter->ModifyGraphWithDelegate(
37 //         delegate.get(), /*allow_dynamic_tensors=*/true);
38 //   }
39 //   ... run inference ...
40 //   ... destroy interpreter ...
41 //   ... destroy delegate ...
42 class FlexDelegate : public TfLiteDelegate {
43  public:
44   // Creates a delegate that supports TF ops.
45   //
46   // If the underyling TF Flex context creation fails, returns null.
47   static std::unique_ptr<FlexDelegate> Create();
48 
49   ~FlexDelegate();
50 
51  private:
52   FlexDelegate();
53 
54   flex::DelegateData delegate_data_;
55 };
56 
57 }  // namespace tflite
58 
59 #endif  // TENSORFLOW_LITE_DELEGATES_FLEX_DELEGATE_H_
60