Fix issue where the Interpreter::ModifyGraphWithDelegate and
Subgraph::ModifyGraphWithDelegate methods did not specify the behaviour when the delegate parameter is null. PiperOrigin-RevId: 352655477 Change-Id: Ia3997ba325cb76b3c76c8672c4b6102343da8443
This commit is contained in:
parent
bd29ff22a7
commit
d22d31bebd
@ -1488,6 +1488,11 @@ TfLiteStatus Subgraph::ModifyGraphWithDelegate(TfLiteDelegate* delegate) {
|
|||||||
TFLITE_SCOPED_TAGGED_DEFAULT_PROFILE(profiler_.get(),
|
TFLITE_SCOPED_TAGGED_DEFAULT_PROFILE(profiler_.get(),
|
||||||
"ModifyGraphWithDelegate");
|
"ModifyGraphWithDelegate");
|
||||||
|
|
||||||
|
if (delegate == nullptr) {
|
||||||
|
ReportError("Null delegate.");
|
||||||
|
return kTfLiteDelegateError;
|
||||||
|
}
|
||||||
|
|
||||||
// Restore delegation state if applicable.
|
// Restore delegation state if applicable.
|
||||||
TF_LITE_ENSURE_STATUS(RedoAllDelegates());
|
TF_LITE_ENSURE_STATUS(RedoAllDelegates());
|
||||||
|
|
||||||
|
@ -552,7 +552,8 @@ class Subgraph {
|
|||||||
// Returns one of the following status codes:
|
// Returns one of the following status codes:
|
||||||
// 1. kTfLiteOk: Delegation succeeded
|
// 1. kTfLiteOk: Delegation succeeded
|
||||||
// 2. kTfLiteDelegateError: Delegation failed due to an error *in the
|
// 2. kTfLiteDelegateError: Delegation failed due to an error *in the
|
||||||
// delegate*. The Subgraph has been restored to its pre-delegation state.
|
// delegate*, or the delegate parameter was null. The Subgraph has been
|
||||||
|
// restored to its pre-delegation state.
|
||||||
// NOTE: This reverts all delegates previously applied to the Subgraph.
|
// NOTE: This reverts all delegates previously applied to the Subgraph.
|
||||||
// 3. kTfLiteApplicationError : Delegation failed to be applied due to the
|
// 3. kTfLiteApplicationError : Delegation failed to be applied due to the
|
||||||
// incompatibility with the TfLite runtime, e.g., the model graph is already
|
// incompatibility with the TfLite runtime, e.g., the model graph is already
|
||||||
|
@ -42,6 +42,11 @@ using test_utils::TestFP16Delegation;
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
TEST_F(TestDelegate, NullDelegate) {
|
||||||
|
EXPECT_EQ(interpreter_->ModifyGraphWithDelegate(nullptr),
|
||||||
|
kTfLiteDelegateError);
|
||||||
|
}
|
||||||
|
|
||||||
TEST_F(TestDelegate, BasicDelegate) {
|
TEST_F(TestDelegate, BasicDelegate) {
|
||||||
delegate_ = std::unique_ptr<SimpleDelegate>(new SimpleDelegate({0, 1, 2}));
|
delegate_ = std::unique_ptr<SimpleDelegate>(new SimpleDelegate({0, 1, 2}));
|
||||||
interpreter_->ModifyGraphWithDelegate(delegate_->get_tf_lite_delegate());
|
interpreter_->ModifyGraphWithDelegate(delegate_->get_tf_lite_delegate());
|
||||||
@ -916,6 +921,14 @@ TEST_P(TestFP16Delegation, NonDelegatedInterpreterWorks) {
|
|||||||
VerifyInvoke();
|
VerifyInvoke();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(TestFP16Delegation, NullDelegate) {
|
||||||
|
EXPECT_EQ(interpreter_->ModifyGraphWithDelegate(nullptr),
|
||||||
|
kTfLiteDelegateError);
|
||||||
|
// Verify that resulting interpreter still works, despite null delegate.
|
||||||
|
ASSERT_EQ(interpreter_->AllocateTensors(), kTfLiteOk);
|
||||||
|
VerifyInvoke();
|
||||||
|
}
|
||||||
|
|
||||||
TEST_P(TestFP16Delegation, DelegationWorks) {
|
TEST_P(TestFP16Delegation, DelegationWorks) {
|
||||||
delegate_ = std::unique_ptr<FP16Delegate>(
|
delegate_ = std::unique_ptr<FP16Delegate>(
|
||||||
new FP16Delegate(/**num_delegated_subsets**/ GetParam()));
|
new FP16Delegate(/**num_delegated_subsets**/ GetParam()));
|
||||||
|
@ -469,7 +469,8 @@ class Interpreter {
|
|||||||
/// Returns one of the following four status codes:
|
/// Returns one of the following four status codes:
|
||||||
/// 1. kTfLiteOk: Success.
|
/// 1. kTfLiteOk: Success.
|
||||||
/// 2. kTfLiteDelegateError: Delegation failed due to an error in the
|
/// 2. kTfLiteDelegateError: Delegation failed due to an error in the
|
||||||
/// delegate. The Interpreter has been restored to its pre-delegation state.
|
/// delegate, or the delegate parameter was null. The Interpreter has been
|
||||||
|
/// restored to its pre-delegation state.
|
||||||
/// NOTE: This undoes all delegates previously applied to the Interpreter.
|
/// NOTE: This undoes all delegates previously applied to the Interpreter.
|
||||||
/// 3. kTfLiteApplicationError : Delegation failed to be applied due to the
|
/// 3. kTfLiteApplicationError : Delegation failed to be applied due to the
|
||||||
/// incompatibility with the TfLite runtime, e.g., the model graph is already
|
/// incompatibility with the TfLite runtime, e.g., the model graph is already
|
||||||
|
Loading…
Reference in New Issue
Block a user