Move delegate providers into a separate directory as they are used for both evaluation tools and benchmark tools.
PiperOrigin-RevId: 307549889 Change-Id: I9234d5e187155b52a7518586dff01266fb426168
This commit is contained in:
parent
0ede71e954
commit
d524812b82
@ -98,13 +98,13 @@ cc_test(
|
|||||||
deps = [
|
deps = [
|
||||||
":benchmark_performance_options",
|
":benchmark_performance_options",
|
||||||
":benchmark_tflite_model_lib",
|
":benchmark_tflite_model_lib",
|
||||||
":delegate_provider_hdr",
|
|
||||||
"//tensorflow/lite:framework",
|
"//tensorflow/lite:framework",
|
||||||
"//tensorflow/lite:string_util",
|
"//tensorflow/lite:string_util",
|
||||||
"//tensorflow/lite/c:common",
|
"//tensorflow/lite/c:common",
|
||||||
"//tensorflow/lite/testing:util",
|
"//tensorflow/lite/testing:util",
|
||||||
"//tensorflow/lite/tools:command_line_flags",
|
"//tensorflow/lite/tools:command_line_flags",
|
||||||
"//tensorflow/lite/tools:logging",
|
"//tensorflow/lite/tools:logging",
|
||||||
|
"//tensorflow/lite/tools/delegates:delegate_provider_hdr",
|
||||||
"@com_google_absl//absl/algorithm",
|
"@com_google_absl//absl/algorithm",
|
||||||
"@com_google_absl//absl/memory",
|
"@com_google_absl//absl/memory",
|
||||||
"@com_google_absl//absl/strings:str_format",
|
"@com_google_absl//absl/strings:str_format",
|
||||||
@ -139,10 +139,7 @@ cc_library(
|
|||||||
deps = [
|
deps = [
|
||||||
":benchmark_model_lib",
|
":benchmark_model_lib",
|
||||||
":benchmark_utils",
|
":benchmark_utils",
|
||||||
":coreml_delegate_provider",
|
|
||||||
":delegate_provider_hdr",
|
|
||||||
":profiling_listener",
|
":profiling_listener",
|
||||||
":tflite_execution_providers",
|
|
||||||
"//tensorflow/lite:framework",
|
"//tensorflow/lite:framework",
|
||||||
"//tensorflow/lite:string_util",
|
"//tensorflow/lite:string_util",
|
||||||
"//tensorflow/lite/kernels:builtin_ops",
|
"//tensorflow/lite/kernels:builtin_ops",
|
||||||
@ -150,6 +147,8 @@ cc_library(
|
|||||||
"//tensorflow/lite/profiling:profile_summary_formatter",
|
"//tensorflow/lite/profiling:profile_summary_formatter",
|
||||||
"//tensorflow/lite/profiling:profiler",
|
"//tensorflow/lite/profiling:profiler",
|
||||||
"//tensorflow/lite/tools:logging",
|
"//tensorflow/lite/tools:logging",
|
||||||
|
"//tensorflow/lite/tools/delegates:delegate_provider_hdr",
|
||||||
|
"//tensorflow/lite/tools/delegates:tflite_execution_providers",
|
||||||
"//tensorflow/lite/tools/evaluation:utils",
|
"//tensorflow/lite/tools/evaluation:utils",
|
||||||
"@com_google_absl//absl/base:core_headers",
|
"@com_google_absl//absl/base:core_headers",
|
||||||
"@com_google_absl//absl/strings",
|
"@com_google_absl//absl/strings",
|
||||||
@ -210,152 +209,6 @@ cc_library(
|
|||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
cc_library(
|
|
||||||
name = "delegate_provider_hdr",
|
|
||||||
hdrs = [
|
|
||||||
"delegate_provider.h",
|
|
||||||
],
|
|
||||||
copts = common_copts,
|
|
||||||
deps = [
|
|
||||||
":benchmark_params",
|
|
||||||
"//tensorflow/lite/c:common",
|
|
||||||
"//tensorflow/lite/tools:command_line_flags",
|
|
||||||
"//tensorflow/lite/tools:logging",
|
|
||||||
],
|
|
||||||
)
|
|
||||||
|
|
||||||
# A convenient library for all inference execution providers.
|
|
||||||
cc_library(
|
|
||||||
name = "tflite_execution_providers",
|
|
||||||
copts = tflite_copts(),
|
|
||||||
deps = [
|
|
||||||
":default_execution_provider",
|
|
||||||
":external_delegate_provider",
|
|
||||||
":gpu_delegate_provider",
|
|
||||||
":hexagon_delegate_provider",
|
|
||||||
":nnapi_delegate_provider",
|
|
||||||
] + select({
|
|
||||||
"//tensorflow:fuchsia": [],
|
|
||||||
"//tensorflow:windows": [],
|
|
||||||
"//conditions:default": [
|
|
||||||
":xnnpack_delegate_provider",
|
|
||||||
],
|
|
||||||
}),
|
|
||||||
alwayslink = 1,
|
|
||||||
)
|
|
||||||
|
|
||||||
cc_library(
|
|
||||||
name = "default_execution_provider",
|
|
||||||
srcs = ["default_execution_provider.cc"],
|
|
||||||
copts = tflite_copts(),
|
|
||||||
linkstatic = True,
|
|
||||||
visibility = ["//visibility:public"],
|
|
||||||
deps = [
|
|
||||||
":delegate_provider_hdr",
|
|
||||||
],
|
|
||||||
alwayslink = 1,
|
|
||||||
)
|
|
||||||
|
|
||||||
cc_library(
|
|
||||||
name = "gpu_delegate_provider",
|
|
||||||
srcs = ["gpu_delegate_provider.cc"],
|
|
||||||
copts = common_copts + select({
|
|
||||||
"//tensorflow:ios": [
|
|
||||||
"-xobjective-c++",
|
|
||||||
],
|
|
||||||
"//conditions:default": [],
|
|
||||||
}),
|
|
||||||
deps = [
|
|
||||||
":delegate_provider_hdr",
|
|
||||||
"//tensorflow/lite/tools/evaluation:utils",
|
|
||||||
] + select({
|
|
||||||
"//tensorflow:android": [
|
|
||||||
"//tensorflow/lite/delegates/gpu:delegate",
|
|
||||||
],
|
|
||||||
"//tensorflow:ios": [
|
|
||||||
"//tensorflow/lite/delegates/gpu:metal_delegate",
|
|
||||||
],
|
|
||||||
"//conditions:default": [],
|
|
||||||
}),
|
|
||||||
alwayslink = 1,
|
|
||||||
)
|
|
||||||
|
|
||||||
cc_library(
|
|
||||||
name = "nnapi_delegate_provider",
|
|
||||||
srcs = ["nnapi_delegate_provider.cc"],
|
|
||||||
copts = common_copts,
|
|
||||||
deps = [
|
|
||||||
":delegate_provider_hdr",
|
|
||||||
"//tensorflow/lite/tools/evaluation:utils",
|
|
||||||
],
|
|
||||||
alwayslink = 1,
|
|
||||||
)
|
|
||||||
|
|
||||||
cc_library(
|
|
||||||
name = "hexagon_delegate_provider",
|
|
||||||
srcs = ["hexagon_delegate_provider.cc"],
|
|
||||||
copts = common_copts,
|
|
||||||
deps = [
|
|
||||||
":delegate_provider_hdr",
|
|
||||||
"//tensorflow/lite/tools/evaluation:utils",
|
|
||||||
] + select({
|
|
||||||
"//tensorflow:android_arm": [
|
|
||||||
"//tensorflow/lite/experimental/delegates/hexagon:hexagon_delegate",
|
|
||||||
],
|
|
||||||
"//tensorflow:android_arm64": [
|
|
||||||
"//tensorflow/lite/experimental/delegates/hexagon:hexagon_delegate",
|
|
||||||
],
|
|
||||||
"//conditions:default": [],
|
|
||||||
}),
|
|
||||||
alwayslink = 1,
|
|
||||||
)
|
|
||||||
|
|
||||||
cc_library(
|
|
||||||
name = "coreml_delegate_provider",
|
|
||||||
srcs = ["coreml_delegate_provider.cc"],
|
|
||||||
copts = common_copts + select({
|
|
||||||
"//tensorflow:ios": [
|
|
||||||
"-xobjective-c++",
|
|
||||||
],
|
|
||||||
"//conditions:default": [],
|
|
||||||
}),
|
|
||||||
deps = [
|
|
||||||
":delegate_provider_hdr",
|
|
||||||
"//tensorflow/lite/tools/evaluation:utils",
|
|
||||||
] + select({
|
|
||||||
"//tensorflow:ios": [
|
|
||||||
"//tensorflow/lite/experimental/delegates/coreml:coreml_delegate",
|
|
||||||
],
|
|
||||||
"//conditions:default": [],
|
|
||||||
}),
|
|
||||||
alwayslink = 1,
|
|
||||||
)
|
|
||||||
|
|
||||||
cc_library(
|
|
||||||
name = "xnnpack_delegate_provider",
|
|
||||||
srcs = ["xnnpack_delegate_provider.cc"],
|
|
||||||
copts = tflite_copts(),
|
|
||||||
linkstatic = True,
|
|
||||||
visibility = ["//visibility:public"],
|
|
||||||
deps = [
|
|
||||||
":delegate_provider_hdr",
|
|
||||||
"//tensorflow/lite/tools/evaluation:utils",
|
|
||||||
],
|
|
||||||
alwayslink = 1,
|
|
||||||
)
|
|
||||||
|
|
||||||
cc_library(
|
|
||||||
name = "external_delegate_provider",
|
|
||||||
srcs = ["external_delegate_provider.cc"],
|
|
||||||
copts = tflite_copts(),
|
|
||||||
linkstatic = True,
|
|
||||||
visibility = ["//visibility:public"],
|
|
||||||
deps = [
|
|
||||||
":delegate_provider_hdr",
|
|
||||||
],
|
|
||||||
alwayslink = 1,
|
|
||||||
)
|
|
||||||
|
|
||||||
cc_library(
|
cc_library(
|
||||||
name = "benchmark_utils",
|
name = "benchmark_utils",
|
||||||
srcs = [
|
srcs = [
|
||||||
|
@ -29,8 +29,8 @@ limitations under the License.
|
|||||||
#include "tensorflow/lite/testing/util.h"
|
#include "tensorflow/lite/testing/util.h"
|
||||||
#include "tensorflow/lite/tools/benchmark/benchmark_performance_options.h"
|
#include "tensorflow/lite/tools/benchmark/benchmark_performance_options.h"
|
||||||
#include "tensorflow/lite/tools/benchmark/benchmark_tflite_model.h"
|
#include "tensorflow/lite/tools/benchmark/benchmark_tflite_model.h"
|
||||||
#include "tensorflow/lite/tools/benchmark/delegate_provider.h"
|
|
||||||
#include "tensorflow/lite/tools/command_line_flags.h"
|
#include "tensorflow/lite/tools/command_line_flags.h"
|
||||||
|
#include "tensorflow/lite/tools/delegates/delegate_provider.h"
|
||||||
#include "tensorflow/lite/tools/logging.h"
|
#include "tensorflow/lite/tools/logging.h"
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
@ -88,7 +88,8 @@ BenchmarkParams CreateParams(int32_t num_runs, float min_secs, float max_secs,
|
|||||||
params.AddParam("enable_platform_tracing",
|
params.AddParam("enable_platform_tracing",
|
||||||
BenchmarkParam::Create<bool>(false));
|
BenchmarkParam::Create<bool>(false));
|
||||||
|
|
||||||
for (const auto& delegate_provider : GetRegisteredDelegateProviders()) {
|
for (const auto& delegate_provider :
|
||||||
|
tools::GetRegisteredDelegateProviders()) {
|
||||||
params.Merge(delegate_provider->DefaultParams());
|
params.Merge(delegate_provider->DefaultParams());
|
||||||
}
|
}
|
||||||
return params;
|
return params;
|
||||||
|
@ -36,8 +36,8 @@ limitations under the License.
|
|||||||
#include "tensorflow/lite/profiling/profile_summary_formatter.h"
|
#include "tensorflow/lite/profiling/profile_summary_formatter.h"
|
||||||
#include "tensorflow/lite/string_util.h"
|
#include "tensorflow/lite/string_util.h"
|
||||||
#include "tensorflow/lite/tools/benchmark/benchmark_utils.h"
|
#include "tensorflow/lite/tools/benchmark/benchmark_utils.h"
|
||||||
#include "tensorflow/lite/tools/benchmark/delegate_provider.h"
|
|
||||||
#include "tensorflow/lite/tools/benchmark/profiling_listener.h"
|
#include "tensorflow/lite/tools/benchmark/profiling_listener.h"
|
||||||
|
#include "tensorflow/lite/tools/delegates/delegate_provider.h"
|
||||||
#include "tensorflow/lite/tools/logging.h"
|
#include "tensorflow/lite/tools/logging.h"
|
||||||
|
|
||||||
void RegisterSelectedOps(::tflite::MutableOpResolver* resolver);
|
void RegisterSelectedOps(::tflite::MutableOpResolver* resolver);
|
||||||
@ -272,8 +272,9 @@ BenchmarkParams BenchmarkTfLiteModel::DefaultParams() {
|
|||||||
default_params.AddParam("enable_platform_tracing",
|
default_params.AddParam("enable_platform_tracing",
|
||||||
BenchmarkParam::Create<bool>(false));
|
BenchmarkParam::Create<bool>(false));
|
||||||
|
|
||||||
for (const auto& delegate_util : GetRegisteredDelegateProviders()) {
|
for (const auto& delegate_provider :
|
||||||
default_params.Merge(delegate_util->DefaultParams());
|
tools::GetRegisteredDelegateProviders()) {
|
||||||
|
default_params.Merge(delegate_provider->DefaultParams());
|
||||||
}
|
}
|
||||||
|
|
||||||
return default_params;
|
return default_params;
|
||||||
@ -332,8 +333,9 @@ std::vector<Flag> BenchmarkTfLiteModel::GetFlags() {
|
|||||||
|
|
||||||
flags.insert(flags.end(), specific_flags.begin(), specific_flags.end());
|
flags.insert(flags.end(), specific_flags.begin(), specific_flags.end());
|
||||||
|
|
||||||
for (const auto& delegate_util : GetRegisteredDelegateProviders()) {
|
for (const auto& delegate_provider :
|
||||||
auto delegate_flags = delegate_util->CreateFlags(¶ms_);
|
tools::GetRegisteredDelegateProviders()) {
|
||||||
|
auto delegate_flags = delegate_provider->CreateFlags(¶ms_);
|
||||||
flags.insert(flags.end(), delegate_flags.begin(), delegate_flags.end());
|
flags.insert(flags.end(), delegate_flags.begin(), delegate_flags.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -372,8 +374,9 @@ void BenchmarkTfLiteModel::LogParams() {
|
|||||||
TFLITE_LOG(INFO) << "Enable platform-wide tracing: ["
|
TFLITE_LOG(INFO) << "Enable platform-wide tracing: ["
|
||||||
<< params_.Get<bool>("enable_platform_tracing") << "]";
|
<< params_.Get<bool>("enable_platform_tracing") << "]";
|
||||||
|
|
||||||
for (const auto& delegate_util : GetRegisteredDelegateProviders()) {
|
for (const auto& delegate_provider :
|
||||||
delegate_util->LogParams(params_);
|
tools::GetRegisteredDelegateProviders()) {
|
||||||
|
delegate_provider->LogParams(params_);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -615,7 +618,8 @@ TfLiteStatus BenchmarkTfLiteModel::Init() {
|
|||||||
interpreter_->SetAllowFp16PrecisionForFp32(params_.Get<bool>("allow_fp16"));
|
interpreter_->SetAllowFp16PrecisionForFp32(params_.Get<bool>("allow_fp16"));
|
||||||
|
|
||||||
owned_delegates_.clear();
|
owned_delegates_.clear();
|
||||||
for (const auto& delegate_provider : GetRegisteredDelegateProviders()) {
|
for (const auto& delegate_provider :
|
||||||
|
tools::GetRegisteredDelegateProviders()) {
|
||||||
auto delegate = delegate_provider->CreateTfLiteDelegate(params_);
|
auto delegate = delegate_provider->CreateTfLiteDelegate(params_);
|
||||||
// It's possible that a delegate of certain type won't be created as
|
// It's possible that a delegate of certain type won't be created as
|
||||||
// user-specified benchmark params tells not to.
|
// user-specified benchmark params tells not to.
|
||||||
|
152
tensorflow/lite/tools/delegates/BUILD
Normal file
152
tensorflow/lite/tools/delegates/BUILD
Normal file
@ -0,0 +1,152 @@
|
|||||||
|
load("//tensorflow/lite:build_def.bzl", "tflite_copts")
|
||||||
|
|
||||||
|
package(
|
||||||
|
default_visibility = [
|
||||||
|
"//visibility:public",
|
||||||
|
],
|
||||||
|
licenses = ["notice"], # Apache 2.0
|
||||||
|
)
|
||||||
|
|
||||||
|
common_copts = ["-Wall"] + tflite_copts()
|
||||||
|
|
||||||
|
cc_library(
|
||||||
|
name = "delegate_provider_hdr",
|
||||||
|
hdrs = [
|
||||||
|
"delegate_provider.h",
|
||||||
|
],
|
||||||
|
copts = common_copts,
|
||||||
|
deps = [
|
||||||
|
"//tensorflow/lite/c:common",
|
||||||
|
"//tensorflow/lite/tools:command_line_flags",
|
||||||
|
"//tensorflow/lite/tools:logging",
|
||||||
|
"//tensorflow/lite/tools:tool_params",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
# A convenient library for all inference execution providers.
|
||||||
|
cc_library(
|
||||||
|
name = "tflite_execution_providers",
|
||||||
|
copts = tflite_copts(),
|
||||||
|
deps = [
|
||||||
|
":coreml_delegate_provider",
|
||||||
|
":default_execution_provider",
|
||||||
|
":external_delegate_provider",
|
||||||
|
":gpu_delegate_provider",
|
||||||
|
":hexagon_delegate_provider",
|
||||||
|
":nnapi_delegate_provider",
|
||||||
|
":xnnpack_delegate_provider",
|
||||||
|
],
|
||||||
|
alwayslink = 1,
|
||||||
|
)
|
||||||
|
|
||||||
|
cc_library(
|
||||||
|
name = "default_execution_provider",
|
||||||
|
srcs = ["default_execution_provider.cc"],
|
||||||
|
copts = tflite_copts(),
|
||||||
|
linkstatic = True,
|
||||||
|
visibility = ["//visibility:public"],
|
||||||
|
deps = [
|
||||||
|
":delegate_provider_hdr",
|
||||||
|
],
|
||||||
|
alwayslink = 1,
|
||||||
|
)
|
||||||
|
|
||||||
|
cc_library(
|
||||||
|
name = "gpu_delegate_provider",
|
||||||
|
srcs = ["gpu_delegate_provider.cc"],
|
||||||
|
copts = common_copts + select({
|
||||||
|
"//tensorflow:ios": [
|
||||||
|
"-xobjective-c++",
|
||||||
|
],
|
||||||
|
"//conditions:default": [],
|
||||||
|
}),
|
||||||
|
deps = [
|
||||||
|
":delegate_provider_hdr",
|
||||||
|
"//tensorflow/lite/tools/evaluation:utils",
|
||||||
|
] + select({
|
||||||
|
"//tensorflow:android": [
|
||||||
|
"//tensorflow/lite/delegates/gpu:delegate",
|
||||||
|
],
|
||||||
|
"//tensorflow:ios": [
|
||||||
|
"//tensorflow/lite/delegates/gpu:metal_delegate",
|
||||||
|
],
|
||||||
|
"//conditions:default": [],
|
||||||
|
}),
|
||||||
|
alwayslink = 1,
|
||||||
|
)
|
||||||
|
|
||||||
|
cc_library(
|
||||||
|
name = "nnapi_delegate_provider",
|
||||||
|
srcs = ["nnapi_delegate_provider.cc"],
|
||||||
|
copts = common_copts,
|
||||||
|
deps = [
|
||||||
|
":delegate_provider_hdr",
|
||||||
|
"//tensorflow/lite/tools/evaluation:utils",
|
||||||
|
],
|
||||||
|
alwayslink = 1,
|
||||||
|
)
|
||||||
|
|
||||||
|
cc_library(
|
||||||
|
name = "hexagon_delegate_provider",
|
||||||
|
srcs = ["hexagon_delegate_provider.cc"],
|
||||||
|
copts = common_copts,
|
||||||
|
deps = [
|
||||||
|
":delegate_provider_hdr",
|
||||||
|
"//tensorflow/lite/tools/evaluation:utils",
|
||||||
|
] + select({
|
||||||
|
"//tensorflow:android_arm": [
|
||||||
|
"//tensorflow/lite/experimental/delegates/hexagon:hexagon_delegate",
|
||||||
|
],
|
||||||
|
"//tensorflow:android_arm64": [
|
||||||
|
"//tensorflow/lite/experimental/delegates/hexagon:hexagon_delegate",
|
||||||
|
],
|
||||||
|
"//conditions:default": [],
|
||||||
|
}),
|
||||||
|
alwayslink = 1,
|
||||||
|
)
|
||||||
|
|
||||||
|
cc_library(
|
||||||
|
name = "coreml_delegate_provider",
|
||||||
|
srcs = ["coreml_delegate_provider.cc"],
|
||||||
|
copts = common_copts + select({
|
||||||
|
"//tensorflow:ios": [
|
||||||
|
"-xobjective-c++",
|
||||||
|
],
|
||||||
|
"//conditions:default": [],
|
||||||
|
}),
|
||||||
|
deps = [
|
||||||
|
":delegate_provider_hdr",
|
||||||
|
"//tensorflow/lite/tools/evaluation:utils",
|
||||||
|
] + select({
|
||||||
|
"//tensorflow:ios": [
|
||||||
|
"//tensorflow/lite/experimental/delegates/coreml:coreml_delegate",
|
||||||
|
],
|
||||||
|
"//conditions:default": [],
|
||||||
|
}),
|
||||||
|
alwayslink = 1,
|
||||||
|
)
|
||||||
|
|
||||||
|
cc_library(
|
||||||
|
name = "xnnpack_delegate_provider",
|
||||||
|
srcs = ["xnnpack_delegate_provider.cc"],
|
||||||
|
copts = tflite_copts(),
|
||||||
|
linkstatic = True,
|
||||||
|
visibility = ["//visibility:public"],
|
||||||
|
deps = [
|
||||||
|
":delegate_provider_hdr",
|
||||||
|
"//tensorflow/lite/tools/evaluation:utils",
|
||||||
|
],
|
||||||
|
alwayslink = 1,
|
||||||
|
)
|
||||||
|
|
||||||
|
cc_library(
|
||||||
|
name = "external_delegate_provider",
|
||||||
|
srcs = ["external_delegate_provider.cc"],
|
||||||
|
copts = tflite_copts(),
|
||||||
|
linkstatic = True,
|
||||||
|
visibility = ["//visibility:public"],
|
||||||
|
deps = [
|
||||||
|
":delegate_provider_hdr",
|
||||||
|
],
|
||||||
|
alwayslink = 1,
|
||||||
|
)
|
@ -14,7 +14,7 @@ limitations under the License.
|
|||||||
==============================================================================*/
|
==============================================================================*/
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "tensorflow/lite/tools/benchmark/delegate_provider.h"
|
#include "tensorflow/lite/tools/delegates/delegate_provider.h"
|
||||||
#include "tensorflow/lite/tools/evaluation/utils.h"
|
#include "tensorflow/lite/tools/evaluation/utils.h"
|
||||||
#if defined(__APPLE__)
|
#if defined(__APPLE__)
|
||||||
#if TARGET_OS_IPHONE && !TARGET_IPHONE_SIMULATOR
|
#if TARGET_OS_IPHONE && !TARGET_IPHONE_SIMULATOR
|
||||||
@ -25,28 +25,27 @@ limitations under the License.
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace tflite {
|
namespace tflite {
|
||||||
namespace benchmark {
|
namespace tools {
|
||||||
|
|
||||||
class CoreMlDelegateProvider : public DelegateProvider {
|
class CoreMlDelegateProvider : public DelegateProvider {
|
||||||
public:
|
public:
|
||||||
CoreMlDelegateProvider() {
|
CoreMlDelegateProvider() {
|
||||||
#if defined(REAL_IPHONE_DEVICE)
|
#if defined(REAL_IPHONE_DEVICE)
|
||||||
default_params_.AddParam("use_coreml", BenchmarkParam::Create<bool>(true));
|
default_params_.AddParam("use_coreml", ToolParam::Create<bool>(true));
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
std::vector<Flag> CreateFlags(BenchmarkParams* params) const final;
|
std::vector<Flag> CreateFlags(ToolParams* params) const final;
|
||||||
|
|
||||||
void LogParams(const BenchmarkParams& params) const final;
|
void LogParams(const ToolParams& params) const final;
|
||||||
|
|
||||||
TfLiteDelegatePtr CreateTfLiteDelegate(
|
TfLiteDelegatePtr CreateTfLiteDelegate(const ToolParams& params) const final;
|
||||||
const BenchmarkParams& params) const final;
|
|
||||||
|
|
||||||
std::string GetName() const final { return "COREML"; }
|
std::string GetName() const final { return "COREML"; }
|
||||||
};
|
};
|
||||||
REGISTER_DELEGATE_PROVIDER(CoreMlDelegateProvider);
|
REGISTER_DELEGATE_PROVIDER(CoreMlDelegateProvider);
|
||||||
|
|
||||||
std::vector<Flag> CoreMlDelegateProvider::CreateFlags(
|
std::vector<Flag> CoreMlDelegateProvider::CreateFlags(
|
||||||
BenchmarkParams* params) const {
|
ToolParams* params) const {
|
||||||
#if defined(REAL_IPHONE_DEVICE)
|
#if defined(REAL_IPHONE_DEVICE)
|
||||||
std::vector<Flag> flags = {
|
std::vector<Flag> flags = {
|
||||||
CreateFlag<bool>("use_coreml", params, "use Core ML"),
|
CreateFlag<bool>("use_coreml", params, "use Core ML"),
|
||||||
@ -57,7 +56,7 @@ std::vector<Flag> CoreMlDelegateProvider::CreateFlags(
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void CoreMlDelegateProvider::LogParams(const BenchmarkParams& params) const {
|
void CoreMlDelegateProvider::LogParams(const ToolParams& params) const {
|
||||||
#if defined(REAL_IPHONE_DEVICE)
|
#if defined(REAL_IPHONE_DEVICE)
|
||||||
TFLITE_LOG(INFO) << "Use Core ML : [" << params.Get<bool>("use_coreml")
|
TFLITE_LOG(INFO) << "Use Core ML : [" << params.Get<bool>("use_coreml")
|
||||||
<< "]";
|
<< "]";
|
||||||
@ -65,7 +64,7 @@ void CoreMlDelegateProvider::LogParams(const BenchmarkParams& params) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TfLiteDelegatePtr CoreMlDelegateProvider::CreateTfLiteDelegate(
|
TfLiteDelegatePtr CoreMlDelegateProvider::CreateTfLiteDelegate(
|
||||||
const BenchmarkParams& params) const {
|
const ToolParams& params) const {
|
||||||
TfLiteDelegatePtr delegate(nullptr, [](TfLiteDelegate*) {});
|
TfLiteDelegatePtr delegate(nullptr, [](TfLiteDelegate*) {});
|
||||||
|
|
||||||
#if defined(REAL_IPHONE_DEVICE)
|
#if defined(REAL_IPHONE_DEVICE)
|
||||||
@ -88,5 +87,5 @@ TfLiteDelegatePtr CoreMlDelegateProvider::CreateTfLiteDelegate(
|
|||||||
return delegate;
|
return delegate;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace benchmark
|
} // namespace tools
|
||||||
} // namespace tflite
|
} // namespace tflite
|
@ -14,10 +14,10 @@ limitations under the License.
|
|||||||
==============================================================================*/
|
==============================================================================*/
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "tensorflow/lite/tools/benchmark/delegate_provider.h"
|
#include "tensorflow/lite/tools/delegates/delegate_provider.h"
|
||||||
|
|
||||||
namespace tflite {
|
namespace tflite {
|
||||||
namespace benchmark {
|
namespace tools {
|
||||||
|
|
||||||
// This class actually doesn't provide any TFLite delegate instances, it simply
|
// This class actually doesn't provide any TFLite delegate instances, it simply
|
||||||
// provides common params and flags that are common to all actual delegate
|
// provides common params and flags that are common to all actual delegate
|
||||||
@ -25,23 +25,22 @@ namespace benchmark {
|
|||||||
class DefaultExecutionProvider : public DelegateProvider {
|
class DefaultExecutionProvider : public DelegateProvider {
|
||||||
public:
|
public:
|
||||||
DefaultExecutionProvider() {
|
DefaultExecutionProvider() {
|
||||||
default_params_.AddParam("num_threads", BenchmarkParam::Create<int32_t>(1));
|
default_params_.AddParam("num_threads", ToolParam::Create<int32_t>(1));
|
||||||
default_params_.AddParam("max_delegated_partitions",
|
default_params_.AddParam("max_delegated_partitions",
|
||||||
BenchmarkParam::Create<int32_t>(0));
|
ToolParam::Create<int32_t>(0));
|
||||||
default_params_.AddParam("min_nodes_per_partition",
|
default_params_.AddParam("min_nodes_per_partition",
|
||||||
BenchmarkParam::Create<int32_t>(0));
|
ToolParam::Create<int32_t>(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<Flag> CreateFlags(BenchmarkParams* params) const final;
|
std::vector<Flag> CreateFlags(ToolParams* params) const final;
|
||||||
void LogParams(const BenchmarkParams& params) const final;
|
void LogParams(const ToolParams& params) const final;
|
||||||
TfLiteDelegatePtr CreateTfLiteDelegate(
|
TfLiteDelegatePtr CreateTfLiteDelegate(const ToolParams& params) const final;
|
||||||
const BenchmarkParams& params) const final;
|
|
||||||
std::string GetName() const final { return "Default-NoDelegate"; }
|
std::string GetName() const final { return "Default-NoDelegate"; }
|
||||||
};
|
};
|
||||||
REGISTER_DELEGATE_PROVIDER(DefaultExecutionProvider);
|
REGISTER_DELEGATE_PROVIDER(DefaultExecutionProvider);
|
||||||
|
|
||||||
std::vector<Flag> DefaultExecutionProvider::CreateFlags(
|
std::vector<Flag> DefaultExecutionProvider::CreateFlags(
|
||||||
BenchmarkParams* params) const {
|
ToolParams* params) const {
|
||||||
std::vector<Flag> flags = {
|
std::vector<Flag> flags = {
|
||||||
CreateFlag<int32_t>("num_threads", params,
|
CreateFlag<int32_t>("num_threads", params,
|
||||||
"number of threads used for inference on CPU."),
|
"number of threads used for inference on CPU."),
|
||||||
@ -55,7 +54,7 @@ std::vector<Flag> DefaultExecutionProvider::CreateFlags(
|
|||||||
return flags;
|
return flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DefaultExecutionProvider::LogParams(const BenchmarkParams& params) const {
|
void DefaultExecutionProvider::LogParams(const ToolParams& params) const {
|
||||||
TFLITE_LOG(INFO) << "#threads used for CPU inference: ["
|
TFLITE_LOG(INFO) << "#threads used for CPU inference: ["
|
||||||
<< params.Get<int32_t>("num_threads") << "]";
|
<< params.Get<int32_t>("num_threads") << "]";
|
||||||
TFLITE_LOG(INFO) << "Max number of delegated partitions : ["
|
TFLITE_LOG(INFO) << "Max number of delegated partitions : ["
|
||||||
@ -65,9 +64,9 @@ void DefaultExecutionProvider::LogParams(const BenchmarkParams& params) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TfLiteDelegatePtr DefaultExecutionProvider::CreateTfLiteDelegate(
|
TfLiteDelegatePtr DefaultExecutionProvider::CreateTfLiteDelegate(
|
||||||
const BenchmarkParams& params) const {
|
const ToolParams& params) const {
|
||||||
return TfLiteDelegatePtr(nullptr, [](TfLiteDelegate*) {});
|
return TfLiteDelegatePtr(nullptr, [](TfLiteDelegate*) {});
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace benchmark
|
} // namespace tools
|
||||||
} // namespace tflite
|
} // namespace tflite
|
@ -13,19 +13,19 @@ See the License for the specific language governing permissions and
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
==============================================================================*/
|
==============================================================================*/
|
||||||
|
|
||||||
#ifndef TENSORFLOW_LITE_TOOLS_BENCHMARK_DELEGATE_PROVIDER_H_
|
#ifndef TENSORFLOW_LITE_TOOLS_DELEGATES_DELEGATE_PROVIDER_H_
|
||||||
#define TENSORFLOW_LITE_TOOLS_BENCHMARK_DELEGATE_PROVIDER_H_
|
#define TENSORFLOW_LITE_TOOLS_DELEGATES_DELEGATE_PROVIDER_H_
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "tensorflow/lite/c/common.h"
|
#include "tensorflow/lite/c/common.h"
|
||||||
#include "tensorflow/lite/tools/benchmark/benchmark_params.h"
|
|
||||||
#include "tensorflow/lite/tools/command_line_flags.h"
|
#include "tensorflow/lite/tools/command_line_flags.h"
|
||||||
#include "tensorflow/lite/tools/logging.h"
|
#include "tensorflow/lite/tools/logging.h"
|
||||||
|
#include "tensorflow/lite/tools/tool_params.h"
|
||||||
|
|
||||||
namespace tflite {
|
namespace tflite {
|
||||||
namespace benchmark {
|
namespace tools {
|
||||||
|
|
||||||
// Same w/ Interpreter::TfLiteDelegatePtr to avoid pulling
|
// Same w/ Interpreter::TfLiteDelegatePtr to avoid pulling
|
||||||
// tensorflow/lite/interpreter.h dependency
|
// tensorflow/lite/interpreter.h dependency
|
||||||
@ -36,31 +36,30 @@ class DelegateProvider {
|
|||||||
public:
|
public:
|
||||||
virtual ~DelegateProvider() {}
|
virtual ~DelegateProvider() {}
|
||||||
|
|
||||||
// Create a list of command-line parsable flags based on benchmark params
|
// Create a list of command-line parsable flags based on tool params inside
|
||||||
// inside 'params' whose value will be set to the corresponding runtime flag
|
// 'params' whose value will be set to the corresponding runtime flag value.
|
||||||
// value.
|
virtual std::vector<Flag> CreateFlags(ToolParams* params) const = 0;
|
||||||
virtual std::vector<Flag> CreateFlags(BenchmarkParams* params) const = 0;
|
|
||||||
|
|
||||||
// Log benchmark params.
|
// Log tool params.
|
||||||
virtual void LogParams(const BenchmarkParams& params) const = 0;
|
virtual void LogParams(const ToolParams& params) const = 0;
|
||||||
|
|
||||||
// Create a TfLiteDelegate based on benchmark params.
|
// Create a TfLiteDelegate based on tool params.
|
||||||
virtual TfLiteDelegatePtr CreateTfLiteDelegate(
|
virtual TfLiteDelegatePtr CreateTfLiteDelegate(
|
||||||
const BenchmarkParams& params) const = 0;
|
const ToolParams& params) const = 0;
|
||||||
|
|
||||||
virtual std::string GetName() const = 0;
|
virtual std::string GetName() const = 0;
|
||||||
|
|
||||||
const BenchmarkParams& DefaultParams() const { return default_params_; }
|
const ToolParams& DefaultParams() const { return default_params_; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
template <typename T>
|
template <typename T>
|
||||||
Flag CreateFlag(const char* name, BenchmarkParams* params,
|
Flag CreateFlag(const char* name, ToolParams* params,
|
||||||
const std::string& usage) const {
|
const std::string& usage) const {
|
||||||
return Flag(
|
return Flag(
|
||||||
name, [params, name](const T& val) { params->Set<T>(name, val); },
|
name, [params, name](const T& val) { params->Set<T>(name, val); },
|
||||||
default_params_.Get<T>(name), usage, Flag::kOptional);
|
default_params_.Get<T>(name), usage, Flag::kOptional);
|
||||||
}
|
}
|
||||||
BenchmarkParams default_params_;
|
ToolParams default_params_;
|
||||||
};
|
};
|
||||||
|
|
||||||
using DelegateProviderPtr = std::unique_ptr<DelegateProvider>;
|
using DelegateProviderPtr = std::unique_ptr<DelegateProvider>;
|
||||||
@ -102,7 +101,7 @@ class DelegateProviderRegistrar {
|
|||||||
inline const DelegateProviderList& GetRegisteredDelegateProviders() {
|
inline const DelegateProviderList& GetRegisteredDelegateProviders() {
|
||||||
return DelegateProviderRegistrar::GetProviders();
|
return DelegateProviderRegistrar::GetProviders();
|
||||||
}
|
}
|
||||||
} // namespace benchmark
|
} // namespace tools
|
||||||
} // namespace tflite
|
} // namespace tflite
|
||||||
|
|
||||||
#endif // TENSORFLOW_LITE_TOOLS_BENCHMARK_DELEGATE_PROVIDER_H_
|
#endif // TENSORFLOW_LITE_TOOLS_DELEGATES_DELEGATE_PROVIDER_H_
|
@ -12,7 +12,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|||||||
See the License for the specific language governing permissions and
|
See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
==============================================================================*/
|
==============================================================================*/
|
||||||
#include "tensorflow/lite/tools/benchmark/delegate_provider.h"
|
#include "tensorflow/lite/tools/delegates/delegate_provider.h"
|
||||||
|
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
@ -25,7 +25,7 @@ limitations under the License.
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
namespace tflite {
|
namespace tflite {
|
||||||
namespace benchmark {
|
namespace tools {
|
||||||
namespace {
|
namespace {
|
||||||
// Library Support construct to handle dynamic library operations
|
// Library Support construct to handle dynamic library operations
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
@ -97,24 +97,23 @@ class ExternalDelegateProvider : public DelegateProvider {
|
|||||||
public:
|
public:
|
||||||
ExternalDelegateProvider() {
|
ExternalDelegateProvider() {
|
||||||
default_params_.AddParam("external_delegate_path",
|
default_params_.AddParam("external_delegate_path",
|
||||||
BenchmarkParam::Create<std::string>(""));
|
ToolParam::Create<std::string>(""));
|
||||||
default_params_.AddParam("external_delegate_options",
|
default_params_.AddParam("external_delegate_options",
|
||||||
BenchmarkParam::Create<std::string>(""));
|
ToolParam::Create<std::string>(""));
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<Flag> CreateFlags(BenchmarkParams* params) const final;
|
std::vector<Flag> CreateFlags(ToolParams* params) const final;
|
||||||
|
|
||||||
void LogParams(const BenchmarkParams& params) const final;
|
void LogParams(const ToolParams& params) const final;
|
||||||
|
|
||||||
TfLiteDelegatePtr CreateTfLiteDelegate(
|
TfLiteDelegatePtr CreateTfLiteDelegate(const ToolParams& params) const final;
|
||||||
const BenchmarkParams& params) const final;
|
|
||||||
|
|
||||||
std::string GetName() const final { return "EXTERNAL"; }
|
std::string GetName() const final { return "EXTERNAL"; }
|
||||||
};
|
};
|
||||||
REGISTER_DELEGATE_PROVIDER(ExternalDelegateProvider);
|
REGISTER_DELEGATE_PROVIDER(ExternalDelegateProvider);
|
||||||
|
|
||||||
std::vector<Flag> ExternalDelegateProvider::CreateFlags(
|
std::vector<Flag> ExternalDelegateProvider::CreateFlags(
|
||||||
BenchmarkParams* params) const {
|
ToolParams* params) const {
|
||||||
std::vector<Flag> flags = {
|
std::vector<Flag> flags = {
|
||||||
CreateFlag<std::string>("external_delegate_path", params,
|
CreateFlag<std::string>("external_delegate_path", params,
|
||||||
"The library path for the underlying external."),
|
"The library path for the underlying external."),
|
||||||
@ -124,7 +123,7 @@ std::vector<Flag> ExternalDelegateProvider::CreateFlags(
|
|||||||
return flags;
|
return flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ExternalDelegateProvider::LogParams(const BenchmarkParams& params) const {
|
void ExternalDelegateProvider::LogParams(const ToolParams& params) const {
|
||||||
TFLITE_LOG(INFO) << "External delegate path : ["
|
TFLITE_LOG(INFO) << "External delegate path : ["
|
||||||
<< params.Get<std::string>("external_delegate_path") << "]";
|
<< params.Get<std::string>("external_delegate_path") << "]";
|
||||||
TFLITE_LOG(INFO) << "External delegate options : ["
|
TFLITE_LOG(INFO) << "External delegate options : ["
|
||||||
@ -133,7 +132,7 @@ void ExternalDelegateProvider::LogParams(const BenchmarkParams& params) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TfLiteDelegatePtr ExternalDelegateProvider::CreateTfLiteDelegate(
|
TfLiteDelegatePtr ExternalDelegateProvider::CreateTfLiteDelegate(
|
||||||
const BenchmarkParams& params) const {
|
const ToolParams& params) const {
|
||||||
TfLiteDelegatePtr delegate(nullptr, [](TfLiteDelegate*) {});
|
TfLiteDelegatePtr delegate(nullptr, [](TfLiteDelegate*) {});
|
||||||
std::string lib_path = params.Get<std::string>("external_delegate_path");
|
std::string lib_path = params.Get<std::string>("external_delegate_path");
|
||||||
if (!lib_path.empty()) {
|
if (!lib_path.empty()) {
|
||||||
@ -167,5 +166,5 @@ TfLiteDelegatePtr ExternalDelegateProvider::CreateTfLiteDelegate(
|
|||||||
}
|
}
|
||||||
return delegate;
|
return delegate;
|
||||||
}
|
}
|
||||||
} // namespace benchmark
|
} // namespace tools
|
||||||
} // namespace tflite
|
} // namespace tflite
|
@ -14,7 +14,7 @@ limitations under the License.
|
|||||||
==============================================================================*/
|
==============================================================================*/
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "tensorflow/lite/tools/benchmark/delegate_provider.h"
|
#include "tensorflow/lite/tools/delegates/delegate_provider.h"
|
||||||
#include "tensorflow/lite/tools/evaluation/utils.h"
|
#include "tensorflow/lite/tools/evaluation/utils.h"
|
||||||
#if defined(__ANDROID__)
|
#if defined(__ANDROID__)
|
||||||
#include "tensorflow/lite/delegates/gpu/delegate.h"
|
#include "tensorflow/lite/delegates/gpu/delegate.h"
|
||||||
@ -28,39 +28,37 @@ limitations under the License.
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace tflite {
|
namespace tflite {
|
||||||
namespace benchmark {
|
namespace tools {
|
||||||
|
|
||||||
class GpuDelegateProvider : public DelegateProvider {
|
class GpuDelegateProvider : public DelegateProvider {
|
||||||
public:
|
public:
|
||||||
GpuDelegateProvider() {
|
GpuDelegateProvider() {
|
||||||
default_params_.AddParam("use_gpu", BenchmarkParam::Create<bool>(false));
|
default_params_.AddParam("use_gpu", ToolParam::Create<bool>(false));
|
||||||
#if defined(__ANDROID__) || defined(REAL_IPHONE_DEVICE)
|
#if defined(__ANDROID__) || defined(REAL_IPHONE_DEVICE)
|
||||||
default_params_.AddParam("gpu_precision_loss_allowed",
|
default_params_.AddParam("gpu_precision_loss_allowed",
|
||||||
BenchmarkParam::Create<bool>(true));
|
ToolParam::Create<bool>(true));
|
||||||
#endif
|
#endif
|
||||||
#if defined(__ANDROID__)
|
#if defined(__ANDROID__)
|
||||||
default_params_.AddParam("gpu_experimental_enable_quant",
|
default_params_.AddParam("gpu_experimental_enable_quant",
|
||||||
BenchmarkParam::Create<bool>(true));
|
ToolParam::Create<bool>(true));
|
||||||
#endif
|
#endif
|
||||||
#if defined(REAL_IPHONE_DEVICE)
|
#if defined(REAL_IPHONE_DEVICE)
|
||||||
default_params_.AddParam("gpu_wait_type",
|
default_params_.AddParam("gpu_wait_type",
|
||||||
BenchmarkParam::Create<std::string>(""));
|
ToolParam::Create<std::string>(""));
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<Flag> CreateFlags(BenchmarkParams* params) const final;
|
std::vector<Flag> CreateFlags(ToolParams* params) const final;
|
||||||
|
|
||||||
void LogParams(const BenchmarkParams& params) const final;
|
void LogParams(const ToolParams& params) const final;
|
||||||
|
|
||||||
TfLiteDelegatePtr CreateTfLiteDelegate(
|
TfLiteDelegatePtr CreateTfLiteDelegate(const ToolParams& params) const final;
|
||||||
const BenchmarkParams& params) const final;
|
|
||||||
|
|
||||||
std::string GetName() const final { return "GPU"; }
|
std::string GetName() const final { return "GPU"; }
|
||||||
};
|
};
|
||||||
REGISTER_DELEGATE_PROVIDER(GpuDelegateProvider);
|
REGISTER_DELEGATE_PROVIDER(GpuDelegateProvider);
|
||||||
|
|
||||||
std::vector<Flag> GpuDelegateProvider::CreateFlags(
|
std::vector<Flag> GpuDelegateProvider::CreateFlags(ToolParams* params) const {
|
||||||
BenchmarkParams* params) const {
|
|
||||||
std::vector<Flag> flags = {
|
std::vector<Flag> flags = {
|
||||||
CreateFlag<bool>("use_gpu", params, "use gpu"),
|
CreateFlag<bool>("use_gpu", params, "use gpu"),
|
||||||
#if defined(__ANDROID__) || defined(REAL_IPHONE_DEVICE)
|
#if defined(__ANDROID__) || defined(REAL_IPHONE_DEVICE)
|
||||||
@ -83,7 +81,7 @@ std::vector<Flag> GpuDelegateProvider::CreateFlags(
|
|||||||
return flags;
|
return flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GpuDelegateProvider::LogParams(const BenchmarkParams& params) const {
|
void GpuDelegateProvider::LogParams(const ToolParams& params) const {
|
||||||
TFLITE_LOG(INFO) << "Use gpu : [" << params.Get<bool>("use_gpu") << "]";
|
TFLITE_LOG(INFO) << "Use gpu : [" << params.Get<bool>("use_gpu") << "]";
|
||||||
#if defined(__ANDROID__) || defined(REAL_IPHONE_DEVICE)
|
#if defined(__ANDROID__) || defined(REAL_IPHONE_DEVICE)
|
||||||
TFLITE_LOG(INFO) << "Allow lower precision in gpu : ["
|
TFLITE_LOG(INFO) << "Allow lower precision in gpu : ["
|
||||||
@ -100,7 +98,7 @@ void GpuDelegateProvider::LogParams(const BenchmarkParams& params) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TfLiteDelegatePtr GpuDelegateProvider::CreateTfLiteDelegate(
|
TfLiteDelegatePtr GpuDelegateProvider::CreateTfLiteDelegate(
|
||||||
const BenchmarkParams& params) const {
|
const ToolParams& params) const {
|
||||||
TfLiteDelegatePtr delegate(nullptr, [](TfLiteDelegate*) {});
|
TfLiteDelegatePtr delegate(nullptr, [](TfLiteDelegate*) {});
|
||||||
|
|
||||||
if (params.Get<bool>("use_gpu")) {
|
if (params.Get<bool>("use_gpu")) {
|
||||||
@ -139,8 +137,8 @@ TfLiteDelegatePtr GpuDelegateProvider::CreateTfLiteDelegate(
|
|||||||
delegate = TfLiteDelegatePtr(TFLGpuDelegateCreate(&gpu_opts),
|
delegate = TfLiteDelegatePtr(TFLGpuDelegateCreate(&gpu_opts),
|
||||||
&TFLGpuDelegateDelete);
|
&TFLGpuDelegateDelete);
|
||||||
#else
|
#else
|
||||||
TFLITE_LOG(WARN) << "The GPU delegate compile options are only supported "
|
TFLITE_LOG(WARN) << "The GPU delegate compile options are only supported on"
|
||||||
"to be benchmarked on Android or iOS platforms.";
|
"Android or iOS platforms.";
|
||||||
delegate = evaluation::CreateGPUDelegate();
|
delegate = evaluation::CreateGPUDelegate();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -151,5 +149,5 @@ TfLiteDelegatePtr GpuDelegateProvider::CreateTfLiteDelegate(
|
|||||||
return delegate;
|
return delegate;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace benchmark
|
} // namespace tools
|
||||||
} // namespace tflite
|
} // namespace tflite
|
@ -14,7 +14,7 @@ limitations under the License.
|
|||||||
==============================================================================*/
|
==============================================================================*/
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "tensorflow/lite/tools/benchmark/delegate_provider.h"
|
#include "tensorflow/lite/tools/delegates/delegate_provider.h"
|
||||||
#include "tensorflow/lite/tools/evaluation/utils.h"
|
#include "tensorflow/lite/tools/evaluation/utils.h"
|
||||||
|
|
||||||
#if (defined(ANDROID) || defined(__ANDROID__)) && \
|
#if (defined(ANDROID) || defined(__ANDROID__)) && \
|
||||||
@ -27,35 +27,32 @@ limitations under the License.
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace tflite {
|
namespace tflite {
|
||||||
namespace benchmark {
|
namespace tools {
|
||||||
|
|
||||||
class HexagonDelegateProvider : public DelegateProvider {
|
class HexagonDelegateProvider : public DelegateProvider {
|
||||||
public:
|
public:
|
||||||
HexagonDelegateProvider() {
|
HexagonDelegateProvider() {
|
||||||
#if defined(TFLITE_ENABLE_HEXAGON)
|
#if defined(TFLITE_ENABLE_HEXAGON)
|
||||||
default_params_.AddParam("use_hexagon",
|
default_params_.AddParam("use_hexagon", ToolParam::Create<bool>(false));
|
||||||
BenchmarkParam::Create<bool>(false));
|
default_params_.AddParam("hexagon_lib_path",
|
||||||
default_params_.AddParam(
|
ToolParam::Create<std::string>("/data/local/tmp"));
|
||||||
"hexagon_lib_path",
|
|
||||||
BenchmarkParam::Create<std::string>("/data/local/tmp"));
|
|
||||||
default_params_.AddParam("hexagon_profiling",
|
default_params_.AddParam("hexagon_profiling",
|
||||||
BenchmarkParam::Create<bool>(false));
|
ToolParam::Create<bool>(false));
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<Flag> CreateFlags(BenchmarkParams* params) const final;
|
std::vector<Flag> CreateFlags(ToolParams* params) const final;
|
||||||
|
|
||||||
void LogParams(const BenchmarkParams& params) const final;
|
void LogParams(const ToolParams& params) const final;
|
||||||
|
|
||||||
TfLiteDelegatePtr CreateTfLiteDelegate(
|
TfLiteDelegatePtr CreateTfLiteDelegate(const ToolParams& params) const final;
|
||||||
const BenchmarkParams& params) const final;
|
|
||||||
|
|
||||||
std::string GetName() const final { return "Hexagon"; }
|
std::string GetName() const final { return "Hexagon"; }
|
||||||
};
|
};
|
||||||
REGISTER_DELEGATE_PROVIDER(HexagonDelegateProvider);
|
REGISTER_DELEGATE_PROVIDER(HexagonDelegateProvider);
|
||||||
|
|
||||||
std::vector<Flag> HexagonDelegateProvider::CreateFlags(
|
std::vector<Flag> HexagonDelegateProvider::CreateFlags(
|
||||||
BenchmarkParams* params) const {
|
ToolParams* params) const {
|
||||||
#if defined(TFLITE_ENABLE_HEXAGON)
|
#if defined(TFLITE_ENABLE_HEXAGON)
|
||||||
std::vector<Flag> flags = {
|
std::vector<Flag> flags = {
|
||||||
CreateFlag<bool>("use_hexagon", params, "Use Hexagon delegate"),
|
CreateFlag<bool>("use_hexagon", params, "Use Hexagon delegate"),
|
||||||
@ -70,7 +67,7 @@ std::vector<Flag> HexagonDelegateProvider::CreateFlags(
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void HexagonDelegateProvider::LogParams(const BenchmarkParams& params) const {
|
void HexagonDelegateProvider::LogParams(const ToolParams& params) const {
|
||||||
#if defined(TFLITE_ENABLE_HEXAGON)
|
#if defined(TFLITE_ENABLE_HEXAGON)
|
||||||
TFLITE_LOG(INFO) << "Use Hexagon : [" << params.Get<bool>("use_hexagon")
|
TFLITE_LOG(INFO) << "Use Hexagon : [" << params.Get<bool>("use_hexagon")
|
||||||
<< "]";
|
<< "]";
|
||||||
@ -82,7 +79,7 @@ void HexagonDelegateProvider::LogParams(const BenchmarkParams& params) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TfLiteDelegatePtr HexagonDelegateProvider::CreateTfLiteDelegate(
|
TfLiteDelegatePtr HexagonDelegateProvider::CreateTfLiteDelegate(
|
||||||
const BenchmarkParams& params) const {
|
const ToolParams& params) const {
|
||||||
TfLiteDelegatePtr delegate(nullptr, [](TfLiteDelegate*) {});
|
TfLiteDelegatePtr delegate(nullptr, [](TfLiteDelegate*) {});
|
||||||
#if defined(TFLITE_ENABLE_HEXAGON)
|
#if defined(TFLITE_ENABLE_HEXAGON)
|
||||||
if (params.Get<bool>("use_hexagon")) {
|
if (params.Get<bool>("use_hexagon")) {
|
||||||
@ -105,5 +102,5 @@ TfLiteDelegatePtr HexagonDelegateProvider::CreateTfLiteDelegate(
|
|||||||
return delegate;
|
return delegate;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace benchmark
|
} // namespace tools
|
||||||
} // namespace tflite
|
} // namespace tflite
|
@ -14,40 +14,38 @@ limitations under the License.
|
|||||||
==============================================================================*/
|
==============================================================================*/
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "tensorflow/lite/tools/benchmark/delegate_provider.h"
|
#include "tensorflow/lite/tools/delegates/delegate_provider.h"
|
||||||
#include "tensorflow/lite/tools/evaluation/utils.h"
|
#include "tensorflow/lite/tools/evaluation/utils.h"
|
||||||
#if defined(__ANDROID__)
|
#if defined(__ANDROID__)
|
||||||
#include "tensorflow/lite/nnapi/nnapi_util.h"
|
#include "tensorflow/lite/nnapi/nnapi_util.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace tflite {
|
namespace tflite {
|
||||||
namespace benchmark {
|
namespace tools {
|
||||||
|
|
||||||
class NnapiDelegateProvider : public DelegateProvider {
|
class NnapiDelegateProvider : public DelegateProvider {
|
||||||
public:
|
public:
|
||||||
NnapiDelegateProvider() {
|
NnapiDelegateProvider() {
|
||||||
default_params_.AddParam("use_nnapi", BenchmarkParam::Create<bool>(false));
|
default_params_.AddParam("use_nnapi", ToolParam::Create<bool>(false));
|
||||||
default_params_.AddParam("nnapi_execution_preference",
|
default_params_.AddParam("nnapi_execution_preference",
|
||||||
BenchmarkParam::Create<std::string>(""));
|
ToolParam::Create<std::string>(""));
|
||||||
default_params_.AddParam("nnapi_accelerator_name",
|
default_params_.AddParam("nnapi_accelerator_name",
|
||||||
BenchmarkParam::Create<std::string>(""));
|
ToolParam::Create<std::string>(""));
|
||||||
default_params_.AddParam("disable_nnapi_cpu",
|
default_params_.AddParam("disable_nnapi_cpu",
|
||||||
BenchmarkParam::Create<bool>(false));
|
ToolParam::Create<bool>(false));
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<Flag> CreateFlags(BenchmarkParams* params) const final;
|
std::vector<Flag> CreateFlags(ToolParams* params) const final;
|
||||||
|
|
||||||
void LogParams(const BenchmarkParams& params) const final;
|
void LogParams(const ToolParams& params) const final;
|
||||||
|
|
||||||
TfLiteDelegatePtr CreateTfLiteDelegate(
|
TfLiteDelegatePtr CreateTfLiteDelegate(const ToolParams& params) const final;
|
||||||
const BenchmarkParams& params) const final;
|
|
||||||
|
|
||||||
std::string GetName() const final { return "NNAPI"; }
|
std::string GetName() const final { return "NNAPI"; }
|
||||||
};
|
};
|
||||||
REGISTER_DELEGATE_PROVIDER(NnapiDelegateProvider);
|
REGISTER_DELEGATE_PROVIDER(NnapiDelegateProvider);
|
||||||
|
|
||||||
std::vector<Flag> NnapiDelegateProvider::CreateFlags(
|
std::vector<Flag> NnapiDelegateProvider::CreateFlags(ToolParams* params) const {
|
||||||
BenchmarkParams* params) const {
|
|
||||||
std::vector<Flag> flags = {
|
std::vector<Flag> flags = {
|
||||||
CreateFlag<bool>("use_nnapi", params, "use nnapi delegate api"),
|
CreateFlag<bool>("use_nnapi", params, "use nnapi delegate api"),
|
||||||
CreateFlag<std::string>("nnapi_execution_preference", params,
|
CreateFlag<std::string>("nnapi_execution_preference", params,
|
||||||
@ -63,7 +61,7 @@ std::vector<Flag> NnapiDelegateProvider::CreateFlags(
|
|||||||
return flags;
|
return flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
void NnapiDelegateProvider::LogParams(const BenchmarkParams& params) const {
|
void NnapiDelegateProvider::LogParams(const ToolParams& params) const {
|
||||||
#if defined(__ANDROID__)
|
#if defined(__ANDROID__)
|
||||||
TFLITE_LOG(INFO) << "Use nnapi : [" << params.Get<bool>("use_nnapi") << "]";
|
TFLITE_LOG(INFO) << "Use nnapi : [" << params.Get<bool>("use_nnapi") << "]";
|
||||||
if (params.Get<bool>("use_nnapi")) {
|
if (params.Get<bool>("use_nnapi")) {
|
||||||
@ -90,7 +88,7 @@ void NnapiDelegateProvider::LogParams(const BenchmarkParams& params) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TfLiteDelegatePtr NnapiDelegateProvider::CreateTfLiteDelegate(
|
TfLiteDelegatePtr NnapiDelegateProvider::CreateTfLiteDelegate(
|
||||||
const BenchmarkParams& params) const {
|
const ToolParams& params) const {
|
||||||
TfLiteDelegatePtr delegate(nullptr, [](TfLiteDelegate*) {});
|
TfLiteDelegatePtr delegate(nullptr, [](TfLiteDelegate*) {});
|
||||||
if (params.Get<bool>("use_nnapi")) {
|
if (params.Get<bool>("use_nnapi")) {
|
||||||
StatefulNnApiDelegate::Options options;
|
StatefulNnApiDelegate::Options options;
|
||||||
@ -150,5 +148,5 @@ TfLiteDelegatePtr NnapiDelegateProvider::CreateTfLiteDelegate(
|
|||||||
return delegate;
|
return delegate;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace benchmark
|
} // namespace tools
|
||||||
} // namespace tflite
|
} // namespace tflite
|
@ -14,44 +14,42 @@ limitations under the License.
|
|||||||
==============================================================================*/
|
==============================================================================*/
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "tensorflow/lite/tools/benchmark/delegate_provider.h"
|
#include "tensorflow/lite/tools/delegates/delegate_provider.h"
|
||||||
#include "tensorflow/lite/tools/evaluation/utils.h"
|
#include "tensorflow/lite/tools/evaluation/utils.h"
|
||||||
|
|
||||||
namespace tflite {
|
namespace tflite {
|
||||||
namespace benchmark {
|
namespace tools {
|
||||||
|
|
||||||
class XnnpackDelegateProvider : public DelegateProvider {
|
class XnnpackDelegateProvider : public DelegateProvider {
|
||||||
public:
|
public:
|
||||||
XnnpackDelegateProvider() {
|
XnnpackDelegateProvider() {
|
||||||
default_params_.AddParam("use_xnnpack",
|
default_params_.AddParam("use_xnnpack", ToolParam::Create<bool>(false));
|
||||||
BenchmarkParam::Create<bool>(false));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<Flag> CreateFlags(BenchmarkParams* params) const final;
|
std::vector<Flag> CreateFlags(ToolParams* params) const final;
|
||||||
|
|
||||||
void LogParams(const BenchmarkParams& params) const final;
|
void LogParams(const ToolParams& params) const final;
|
||||||
|
|
||||||
TfLiteDelegatePtr CreateTfLiteDelegate(
|
TfLiteDelegatePtr CreateTfLiteDelegate(const ToolParams& params) const final;
|
||||||
const BenchmarkParams& params) const final;
|
|
||||||
|
|
||||||
std::string GetName() const final { return "XNNPACK"; }
|
std::string GetName() const final { return "XNNPACK"; }
|
||||||
};
|
};
|
||||||
REGISTER_DELEGATE_PROVIDER(XnnpackDelegateProvider);
|
REGISTER_DELEGATE_PROVIDER(XnnpackDelegateProvider);
|
||||||
|
|
||||||
std::vector<Flag> XnnpackDelegateProvider::CreateFlags(
|
std::vector<Flag> XnnpackDelegateProvider::CreateFlags(
|
||||||
BenchmarkParams* params) const {
|
ToolParams* params) const {
|
||||||
std::vector<Flag> flags = {
|
std::vector<Flag> flags = {
|
||||||
CreateFlag<bool>("use_xnnpack", params, "use XNNPack")};
|
CreateFlag<bool>("use_xnnpack", params, "use XNNPack")};
|
||||||
return flags;
|
return flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
void XnnpackDelegateProvider::LogParams(const BenchmarkParams& params) const {
|
void XnnpackDelegateProvider::LogParams(const ToolParams& params) const {
|
||||||
TFLITE_LOG(INFO) << "Use xnnpack : [" << params.Get<bool>("use_xnnpack")
|
TFLITE_LOG(INFO) << "Use xnnpack : [" << params.Get<bool>("use_xnnpack")
|
||||||
<< "]";
|
<< "]";
|
||||||
}
|
}
|
||||||
|
|
||||||
TfLiteDelegatePtr XnnpackDelegateProvider::CreateTfLiteDelegate(
|
TfLiteDelegatePtr XnnpackDelegateProvider::CreateTfLiteDelegate(
|
||||||
const BenchmarkParams& params) const {
|
const ToolParams& params) const {
|
||||||
if (params.Get<bool>("use_xnnpack")) {
|
if (params.Get<bool>("use_xnnpack")) {
|
||||||
return evaluation::CreateXNNPACKDelegate(
|
return evaluation::CreateXNNPACKDelegate(
|
||||||
params.Get<int32_t>("num_threads"));
|
params.Get<int32_t>("num_threads"));
|
||||||
@ -59,5 +57,5 @@ TfLiteDelegatePtr XnnpackDelegateProvider::CreateTfLiteDelegate(
|
|||||||
return TfLiteDelegatePtr(nullptr, [](TfLiteDelegate*) {});
|
return TfLiteDelegatePtr(nullptr, [](TfLiteDelegate*) {});
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace benchmark
|
} // namespace tools
|
||||||
} // namespace tflite
|
} // namespace tflite
|
@ -57,6 +57,7 @@ cc_library(
|
|||||||
"//conditions:default": [],
|
"//conditions:default": [],
|
||||||
}) + select({
|
}) + select({
|
||||||
"//tensorflow:fuchsia": [],
|
"//tensorflow:fuchsia": [],
|
||||||
|
"//tensorflow:windows": [],
|
||||||
"//conditions:default": [
|
"//conditions:default": [
|
||||||
"//tensorflow/lite/delegates/xnnpack:xnnpack_delegate",
|
"//tensorflow/lite/delegates/xnnpack:xnnpack_delegate",
|
||||||
],
|
],
|
||||||
@ -73,8 +74,8 @@ cc_library(
|
|||||||
"//tensorflow/lite/tools:command_line_flags",
|
"//tensorflow/lite/tools:command_line_flags",
|
||||||
"//tensorflow/lite/tools:logging",
|
"//tensorflow/lite/tools:logging",
|
||||||
"//tensorflow/lite/tools:tool_params",
|
"//tensorflow/lite/tools:tool_params",
|
||||||
"//tensorflow/lite/tools/benchmark:delegate_provider_hdr",
|
"//tensorflow/lite/tools/delegates:delegate_provider_hdr",
|
||||||
"//tensorflow/lite/tools/benchmark:tflite_execution_providers",
|
"//tensorflow/lite/tools/delegates:tflite_execution_providers",
|
||||||
"//tensorflow/lite/tools/evaluation/proto:evaluation_stages_cc_proto",
|
"//tensorflow/lite/tools/evaluation/proto:evaluation_stages_cc_proto",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
@ -78,7 +78,7 @@ TfLiteDelegatePtr CreateTfLiteDelegate(const TfliteInferenceParams& params,
|
|||||||
}
|
}
|
||||||
|
|
||||||
DelegateProviders::DelegateProviders()
|
DelegateProviders::DelegateProviders()
|
||||||
: delegates_list_(benchmark::GetRegisteredDelegateProviders()),
|
: delegates_list_(tools::GetRegisteredDelegateProviders()),
|
||||||
delegates_map_([=]() -> std::unordered_map<std::string, int> {
|
delegates_map_([=]() -> std::unordered_map<std::string, int> {
|
||||||
std::unordered_map<std::string, int> delegates_map;
|
std::unordered_map<std::string, int> delegates_map;
|
||||||
for (int i = 0; i < delegates_list_.size(); ++i) {
|
for (int i = 0; i < delegates_list_.size(); ++i) {
|
||||||
|
@ -20,7 +20,7 @@ limitations under the License.
|
|||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "tensorflow/lite/tools/benchmark/delegate_provider.h"
|
#include "tensorflow/lite/tools/delegates/delegate_provider.h"
|
||||||
#include "tensorflow/lite/tools/evaluation/proto/evaluation_stages.pb.h"
|
#include "tensorflow/lite/tools/evaluation/proto/evaluation_stages.pb.h"
|
||||||
#include "tensorflow/lite/tools/evaluation/utils.h"
|
#include "tensorflow/lite/tools/evaluation/utils.h"
|
||||||
#include "tensorflow/lite/tools/tool_params.h"
|
#include "tensorflow/lite/tools/tool_params.h"
|
||||||
@ -73,7 +73,7 @@ class DelegateProviders {
|
|||||||
// flags.
|
// flags.
|
||||||
tools::ToolParams params_;
|
tools::ToolParams params_;
|
||||||
|
|
||||||
const benchmark::DelegateProviderList& delegates_list_;
|
const tools::DelegateProviderList& delegates_list_;
|
||||||
// Key is the delegate name, and the value is the index to the
|
// Key is the delegate name, and the value is the index to the
|
||||||
// 'delegates_list_'.
|
// 'delegates_list_'.
|
||||||
const std::unordered_map<std::string, int> delegates_map_;
|
const std::unordered_map<std::string, int> delegates_map_;
|
||||||
|
@ -212,7 +212,7 @@ TF_LITE_CC_SRCS := $(filter-out $(CORE_CC_EXCLUDE_SRCS), $(CORE_CC_ALL_SRCS))
|
|||||||
|
|
||||||
# Benchmark sources
|
# Benchmark sources
|
||||||
BENCHMARK_SRCS_DIR := tensorflow/lite/tools/benchmark
|
BENCHMARK_SRCS_DIR := tensorflow/lite/tools/benchmark
|
||||||
DELEGATE_PROVIDER_SRCS_DIR := tensorflow/lite/tools/benchmark
|
DELEGATE_PROVIDER_SRCS_DIR := tensorflow/lite/tools/delegates
|
||||||
EVALUATION_UTILS_SRCS := \
|
EVALUATION_UTILS_SRCS := \
|
||||||
tensorflow/lite/tools/evaluation/utils.cc
|
tensorflow/lite/tools/evaluation/utils.cc
|
||||||
BENCHMARK_ALL_SRCS := \
|
BENCHMARK_ALL_SRCS := \
|
||||||
|
Loading…
Reference in New Issue
Block a user