diff --git a/tensorflow/lite/interpreter.cc b/tensorflow/lite/interpreter.cc index 9edef3751dd..cdd154b30b6 100644 --- a/tensorflow/lite/interpreter.cc +++ b/tensorflow/lite/interpreter.cc @@ -227,6 +227,13 @@ TfLiteStatus Interpreter::ModifyGraphWithDelegate(TfLiteDelegate* delegate) { return kTfLiteOk; } +TfLiteStatus Interpreter::ModifyGraphWithDelegate(TfLiteDelegatePtr delegate) { + // Note that we retain ownership of the delegate even if graph modification + // fails, as delegate use will be in an indeterminate state at that point. + owned_delegates_.push_back(std::move(delegate)); + return ModifyGraphWithDelegate(owned_delegates_.back().get()); +} + TfLiteStatus Interpreter::SetBufferHandle(int tensor_index, TfLiteBufferHandle buffer_handle, TfLiteDelegate* delegate) { diff --git a/tensorflow/lite/interpreter.h b/tensorflow/lite/interpreter.h index 44359f54432..36b7b4456de 100644 --- a/tensorflow/lite/interpreter.h +++ b/tensorflow/lite/interpreter.h @@ -373,16 +373,22 @@ class Interpreter { /// WARNING: This is an experimental API and subject to change. void SetCancellationFunction(void* data, bool (*check_cancelled_func)(void*)); - // Owning handle to a TfLiteDelegate instance. - using TfLiteDelegatePtr = - std::unique_ptr; - /// Allow a delegate to look at the graph and modify the graph to handle /// parts of the graph themselves. After this is called, the graph may /// contain new nodes that replace 1 more nodes. /// WARNING: This is an experimental API and subject to change. TfLiteStatus ModifyGraphWithDelegate(TfLiteDelegate* delegate); + // Owning handle to a TfLiteDelegate instance. + using TfLiteDelegatePtr = + std::unique_ptr; + + /// Same as ModifyGraphWithDelegate except this interpreter takes + /// ownership of the provided delegate. Be sure to construct the unique_ptr + /// with a suitable destruction function. + /// WARNING: This is an experimental API and subject to change. + TfLiteStatus ModifyGraphWithDelegate(TfLiteDelegatePtr delegate); + /// Ensure the data in `tensor.data` is readable. In case delegate is used, /// it might require to copy the data from delegate buffer to raw memory. /// WARNING: This is an experimental API and subject to change. @@ -499,16 +505,6 @@ class Interpreter { TfLiteExternalContextType type, TfLiteExternalContext* ctx); - /// Variant of the public ModifyGraphWithDelegate method that additionally - /// Assumes ownership of the provided delegate. - /// WARNING: This is an experimental API and subject to change. - TfLiteStatus ModifyGraphWithDelegate(TfLiteDelegatePtr delegate) { - // Note that we retain ownership of the delegate even if graph modification - // fails, as delegate use will be in an indeterminate state at that point. - owned_delegates_.push_back(std::move(delegate)); - return ModifyGraphWithDelegate(owned_delegates_.back().get()); - } - // A pure C data structure used to communicate with the pure C plugin // interface. To avoid copying tensor metadata, this is also the definitive // structure to store tensors.