From 958990b4706580bfa25dc57dfe6ed49abee93d70 Mon Sep 17 00:00:00 2001 From: Chao Mei Date: Tue, 2 Jun 2020 01:34:05 -0700 Subject: [PATCH] Small changes to SimpleDelegate APIs: 1. change name() to Name(). 2. change Invoke to Eval(). PiperOrigin-RevId: 314287361 Change-Id: I7c5324a1ee7c4ea5f06987da2f55c245e2d6153e --- tensorflow/lite/delegates/flex/delegate.cc | 2 +- tensorflow/lite/delegates/flex/delegate.h | 2 +- tensorflow/lite/delegates/flex/kernel.cc | 2 +- tensorflow/lite/delegates/flex/kernel.h | 2 +- tensorflow/lite/delegates/utils/simple_delegate.cc | 6 +++--- tensorflow/lite/delegates/utils/simple_delegate.h | 6 ++---- tensorflow/lite/delegates/utils/simple_delegate_test.cc | 4 ++-- 7 files changed, 11 insertions(+), 13 deletions(-) diff --git a/tensorflow/lite/delegates/flex/delegate.cc b/tensorflow/lite/delegates/flex/delegate.cc index 13ce5ff2a22..4741bddc2f5 100644 --- a/tensorflow/lite/delegates/flex/delegate.cc +++ b/tensorflow/lite/delegates/flex/delegate.cc @@ -72,7 +72,7 @@ TfLiteStatus FlexDelegate::Initialize(TfLiteContext* context) { return kTfLiteOk; } -const char* FlexDelegate::name() const { +const char* FlexDelegate::Name() const { static constexpr char kName[] = "TfLiteFlexDelegate"; return kName; } diff --git a/tensorflow/lite/delegates/flex/delegate.h b/tensorflow/lite/delegates/flex/delegate.h index a760d941656..be890a5456d 100644 --- a/tensorflow/lite/delegates/flex/delegate.h +++ b/tensorflow/lite/delegates/flex/delegate.h @@ -69,7 +69,7 @@ class FlexDelegate : public SimpleDelegateInterface { FlexDelegate() {} - const char* name() const override; + const char* Name() const override; bool IsNodeSupportedByDelegate(const TfLiteRegistration* registration, const TfLiteNode* node, diff --git a/tensorflow/lite/delegates/flex/kernel.cc b/tensorflow/lite/delegates/flex/kernel.cc index b6e809647d5..e7705ecf3ce 100644 --- a/tensorflow/lite/delegates/flex/kernel.cc +++ b/tensorflow/lite/delegates/flex/kernel.cc @@ -485,7 +485,7 @@ TfLiteStatus DelegateKernel::Prepare(TfLiteContext* context, TfLiteNode* node) { return kTfLiteOk; } -TfLiteStatus DelegateKernel::Invoke(TfLiteContext* context, TfLiteNode* node) { +TfLiteStatus DelegateKernel::Eval(TfLiteContext* context, TfLiteNode* node) { BufferMap* buffer_map = op_data_->buffer_map; // Insert a tensor in the buffer map for all inputs that are not constant. diff --git a/tensorflow/lite/delegates/flex/kernel.h b/tensorflow/lite/delegates/flex/kernel.h index 27cbfeadc14..9a7b93e31f2 100644 --- a/tensorflow/lite/delegates/flex/kernel.h +++ b/tensorflow/lite/delegates/flex/kernel.h @@ -32,7 +32,7 @@ class DelegateKernel : public SimpleDelegateKernelInterface { TfLiteStatus Init(TfLiteContext* context, const TfLiteDelegateParams* params) override; TfLiteStatus Prepare(TfLiteContext* context, TfLiteNode* node) override; - TfLiteStatus Invoke(TfLiteContext* context, TfLiteNode* node) override; + TfLiteStatus Eval(TfLiteContext* context, TfLiteNode* node) override; private: std::unique_ptr op_data_; diff --git a/tensorflow/lite/delegates/utils/simple_delegate.cc b/tensorflow/lite/delegates/utils/simple_delegate.cc index 156f6a9679a..f8c0a027cca 100644 --- a/tensorflow/lite/delegates/utils/simple_delegate.cc +++ b/tensorflow/lite/delegates/utils/simple_delegate.cc @@ -31,7 +31,7 @@ TfLiteRegistration GetDelegateKernelRegistration( TfLiteRegistration kernel_registration; kernel_registration.profiling_string = nullptr; kernel_registration.builtin_code = kTfLiteBuiltinDelegate; - kernel_registration.custom_name = delegate->name(); + kernel_registration.custom_name = delegate->Name(); kernel_registration.version = 1; kernel_registration.free = [](TfLiteContext* context, void* buffer) -> void { delete reinterpret_cast(buffer); @@ -68,7 +68,7 @@ TfLiteRegistration GetDelegateKernelRegistration( SimpleDelegateKernelInterface* delegate_kernel = reinterpret_cast(node->user_data); TFLITE_DCHECK(delegate_kernel != nullptr); - return delegate_kernel->Invoke(context, node); + return delegate_kernel->Eval(context, node); }; return kernel_registration; @@ -94,7 +94,7 @@ TfLiteStatus DelegatePrepare(TfLiteContext* context, TFLITE_LOG_PROD(tflite::TFLITE_LOG_INFO, "%s delegate: %d nodes delegated out of %d nodes with " "%d partitions.\n", - delegate->name(), supported_nodes.size(), + delegate->Name(), supported_nodes.size(), helper.num_total_nodes(), helper.num_partitions()); TfLiteRegistration delegate_kernel_registration = GetDelegateKernelRegistration(delegate); diff --git a/tensorflow/lite/delegates/utils/simple_delegate.h b/tensorflow/lite/delegates/utils/simple_delegate.h index 54473e41901..7b6be43047b 100644 --- a/tensorflow/lite/delegates/utils/simple_delegate.h +++ b/tensorflow/lite/delegates/utils/simple_delegate.h @@ -56,8 +56,7 @@ class SimpleDelegateKernelInterface { // Actual subgraph inference should happen on this call. // Returns status, and signalling any errors. - // TODO(b/157882025): change this to Eval to be consistent w/ a TFLite kernel. - virtual TfLiteStatus Invoke(TfLiteContext* context, TfLiteNode* node) = 0; + virtual TfLiteStatus Eval(TfLiteContext* context, TfLiteNode* node) = 0; }; // Pure Interface that clients should implement. @@ -87,8 +86,7 @@ class SimpleDelegateInterface { // Returns a name that identifies the delegate. // This name is used for debugging/logging/profiling. - // TODO(b/157882025): change this to Name() - virtual const char* name() const = 0; + virtual const char* Name() const = 0; // Returns instance of an object that implements the interface // SimpleDelegateKernelInterface. diff --git a/tensorflow/lite/delegates/utils/simple_delegate_test.cc b/tensorflow/lite/delegates/utils/simple_delegate_test.cc index 42c0ace6cb7..12a790fff1a 100644 --- a/tensorflow/lite/delegates/utils/simple_delegate_test.cc +++ b/tensorflow/lite/delegates/utils/simple_delegate_test.cc @@ -52,7 +52,7 @@ class TestSimpleDelegateKernel : public SimpleDelegateKernelInterface { return !options_.error_during_prepare ? kTfLiteOk : kTfLiteError; } - TfLiteStatus Invoke(TfLiteContext* context, TfLiteNode* node) override { + TfLiteStatus Eval(TfLiteContext* context, TfLiteNode* node) override { return !options_.error_during_invoke ? kTfLiteOk : kTfLiteError; } @@ -74,7 +74,7 @@ class TestSimpleDelegate : public SimpleDelegateInterface { TfLiteStatus Initialize(TfLiteContext* context) override { return kTfLiteOk; } - const char* name() const override { + const char* Name() const override { static constexpr char kName[] = "TestSimpleDelegate"; return kName; }