Make ModifyGraphWithDelegate(TfLiteDelegatePtr) public.

PiperOrigin-RevId: 253180610
This commit is contained in:
A. Unique TensorFlower 2019-06-14 00:39:16 -07:00 committed by TensorFlower Gardener
parent 1bbc7ef9a8
commit 6b181c748b
2 changed files with 17 additions and 14 deletions

View File

@ -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) {

View File

@ -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<TfLiteDelegate, void (*)(TfLiteDelegate*)>;
/// 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<TfLiteDelegate, void (*)(TfLiteDelegate*)>;
/// 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.