From 1bae865fecf99f25cd2d58390e0cf08467a22b4f Mon Sep 17 00:00:00 2001 From: John McLoughlin Date: Tue, 14 Mar 2023 11:47:15 +0000 Subject: IVGCVSW-7197 Implement Pimpl Idiom for Delegate Options * ABI break on the delegate interface. Bumping the version number. Signed-off-by: John Mcloughlin Change-Id: I6ef3bc1ea240ef08b67bb3cb9d363a5bbbbdd906 --- delegate/classic/include/Version.hpp | 2 +- delegate/common/include/DelegateOptions.hpp | 137 +++++--------- delegate/common/src/DelegateOptions.cpp | 279 ++++++++++++++++++++++++---- 3 files changed, 292 insertions(+), 126 deletions(-) (limited to 'delegate') diff --git a/delegate/classic/include/Version.hpp b/delegate/classic/include/Version.hpp index c171d77c16..37dd557c08 100644 --- a/delegate/classic/include/Version.hpp +++ b/delegate/classic/include/Version.hpp @@ -13,7 +13,7 @@ namespace armnnDelegate #define STRINGIFY_MACRO(s) #s // ArmNN Delegate version components -#define DELEGATE_MAJOR_VERSION 28 +#define DELEGATE_MAJOR_VERSION 29 #define DELEGATE_MINOR_VERSION 0 #define DELEGATE_PATCH_VERSION 0 diff --git a/delegate/common/include/DelegateOptions.hpp b/delegate/common/include/DelegateOptions.hpp index 4d48451ef3..3bf9b35191 100644 --- a/delegate/common/include/DelegateOptions.hpp +++ b/delegate/common/include/DelegateOptions.hpp @@ -14,9 +14,15 @@ namespace armnnDelegate { +struct DelegateOptionsImpl; + class DelegateOptions { public: + ~DelegateOptions(); + DelegateOptions(); + DelegateOptions(const DelegateOptions& other); + DelegateOptions(armnn::Compute computeDevice, const std::vector& backendOptions = {}, armnn::Optional logSeverityLevel = armnn::EmptyOptional()); @@ -186,118 +192,61 @@ public: size_t num_options, void (*report_error)(const char*)); - const std::vector& GetBackends() const { return m_Backends; } - - void SetBackends(const std::vector& backends) { m_Backends = backends; } - - void SetDynamicBackendsPath(const std::string& dynamicBackendsPath) - { - m_RuntimeOptions.m_DynamicBackendsPath = dynamicBackendsPath; - } - const std::string& GetDynamicBackendsPath() const - { - return m_RuntimeOptions.m_DynamicBackendsPath; - } - - void SetGpuProfilingState(bool gpuProfilingState) - { - m_RuntimeOptions.m_EnableGpuProfiling = gpuProfilingState; - } - bool GetGpuProfilingState() - { - return m_RuntimeOptions.m_EnableGpuProfiling; - } - - const std::vector& GetBackendOptions() const - { - return m_RuntimeOptions.m_BackendOptions; - } + const std::vector& GetBackends() const; + + void SetBackends(const std::vector& backends); + + void SetDynamicBackendsPath(const std::string& dynamicBackendsPath); + + const std::string& GetDynamicBackendsPath() const; + + void SetGpuProfilingState(bool gpuProfilingState); + + bool GetGpuProfilingState(); + + const std::vector& GetBackendOptions() const; /// Appends a backend option to the list of backend options - void AddBackendOption(const armnn::BackendOptions& option) - { - m_RuntimeOptions.m_BackendOptions.push_back(option); - } + void AddBackendOption(const armnn::BackendOptions& option); /// Sets the severity level for logging within ArmNN that will be used on creation of the delegate - void SetLoggingSeverity(const armnn::LogSeverity& level) { m_LoggingSeverity = level; } - void SetLoggingSeverity(const std::string& level) { m_LoggingSeverity = armnn::StringToLogLevel(level); } + void SetLoggingSeverity(const armnn::LogSeverity& level); + void SetLoggingSeverity(const std::string& level); /// Returns the severity level for logging within ArmNN - armnn::LogSeverity GetLoggingSeverity() { return m_LoggingSeverity.value(); } + armnn::LogSeverity GetLoggingSeverity(); - bool IsLoggingEnabled() { return m_LoggingSeverity.has_value(); } + bool IsLoggingEnabled(); - const armnn::OptimizerOptions& GetOptimizerOptions() const { return m_OptimizerOptions; } + const armnn::OptimizerOptions& GetOptimizerOptions() const; - void SetOptimizerOptions(const armnn::OptimizerOptions& optimizerOptions) { m_OptimizerOptions = optimizerOptions; } + void SetOptimizerOptions(const armnn::OptimizerOptions& optimizerOptions); - const armnn::Optional& GetDebugCallbackFunction() const - { return m_DebugCallbackFunc; } + const armnn::Optional& GetDebugCallbackFunction() const; void SetInternalProfilingParams(bool internalProfilingState, - const armnn::ProfilingDetailsMethod& internalProfilingDetail) - { m_InternalProfilingEnabled = internalProfilingState; m_InternalProfilingDetail = internalProfilingDetail; } + const armnn::ProfilingDetailsMethod& internalProfilingDetail); + + bool GetInternalProfilingState() const; - bool GetInternalProfilingState() const { return m_InternalProfilingEnabled; } - const armnn::ProfilingDetailsMethod& GetInternalProfilingDetail() const { return m_InternalProfilingDetail; } + const armnn::ProfilingDetailsMethod& GetInternalProfilingDetail() const; - void SetSerializeToDot(const std::string& serializeToDotFile) { m_SerializeToDot = serializeToDotFile; } - const std::string& GetSerializeToDot() const { return m_SerializeToDot; } + void SetSerializeToDot(const std::string& serializeToDotFile); + + const std::string& GetSerializeToDot() const; /// @Note: This might overwrite options that were set with other setter functions of DelegateOptions - void SetRuntimeOptions(const armnn::IRuntime::CreationOptions& runtimeOptions) - { - m_RuntimeOptions = runtimeOptions; - } - - const armnn::IRuntime::CreationOptions& GetRuntimeOptions() - { - return m_RuntimeOptions; - } - - void DisableTfLiteRuntimeFallback(bool fallbackState) - { - m_DisableTfLiteRuntimeFallback = fallbackState; - } - bool TfLiteRuntimeFallbackDisabled() - { - return m_DisableTfLiteRuntimeFallback; - } + void SetRuntimeOptions(const armnn::IRuntime::CreationOptions& runtimeOptions); + + const armnn::IRuntime::CreationOptions& GetRuntimeOptions(); + + void DisableTfLiteRuntimeFallback(bool fallbackState); + + bool TfLiteRuntimeFallbackDisabled(); private: - /// Which backend to run Delegate on. - /// Examples of possible values are: CpuRef, CpuAcc, GpuAcc. - /// CpuRef as default. - std::vector m_Backends = { armnn::Compute::CpuRef }; - - /// Creation options for the ArmNN runtime - /// Contains options for global settings that are valid for the whole lifetime of ArmNN - /// i.e. BackendOptions, DynamicBackendPath, ExternalProfilingOptions and more - armnn::IRuntime::CreationOptions m_RuntimeOptions; - - /// Options for the optimization step for the network - armnn::OptimizerOptions m_OptimizerOptions; - - /// Internal profiling options. Written to INetworkProperties during model load. - /// Indicates whether internal profiling is enabled or not. - bool m_InternalProfilingEnabled = false; - /// Sets the level of detail output by the profiling. Options are DetailsWithEvents = 1 and DetailsOnly = 2 - armnn::ProfilingDetailsMethod m_InternalProfilingDetail = armnn::ProfilingDetailsMethod::DetailsWithEvents; - - /// Severity level for logging within ArmNN that will be used on creation of the delegate - armnn::Optional m_LoggingSeverity; - - /// A callback function to debug layers performing custom computations on intermediate tensors. - /// If a function is not registered, and debug is enabled in OptimizerOptions, - /// debug will print information of the intermediate tensors. - armnn::Optional m_DebugCallbackFunc; - - /// If not empty then the optimized model will be serialized to a file with this file name in "dot" format. - std::string m_SerializeToDot = ""; - - /// Option to disable TfLite Runtime fallback for unsupported operators. - bool m_DisableTfLiteRuntimeFallback = false; + std::unique_ptr p_DelegateOptionsImpl; + }; } // namespace armnnDelegate diff --git a/delegate/common/src/DelegateOptions.cpp b/delegate/common/src/DelegateOptions.cpp index fc4858fa29..c4f0ad71bc 100644 --- a/delegate/common/src/DelegateOptions.cpp +++ b/delegate/common/src/DelegateOptions.cpp @@ -10,31 +10,119 @@ namespace armnnDelegate { +struct DelegateOptionsImpl +{ + ~DelegateOptionsImpl() = default; + DelegateOptionsImpl() = default; + + explicit DelegateOptionsImpl(armnn::Compute computeDevice, + const std::vector& backendOptions, + const armnn::Optional logSeverityLevel) + : p_Backends({computeDevice}), p_RuntimeOptions(), m_LoggingSeverity(logSeverityLevel) + { + p_RuntimeOptions.m_BackendOptions = backendOptions; + } + + explicit DelegateOptionsImpl(const std::vector& backends, + const std::vector& backendOptions, + const armnn::Optional logSeverityLevel) + : p_Backends(backends), p_RuntimeOptions(), m_LoggingSeverity(logSeverityLevel) + { + p_RuntimeOptions.m_BackendOptions = backendOptions; + } + + explicit DelegateOptionsImpl(armnn::Compute computeDevice, + const armnn::OptimizerOptions& optimizerOptions, + const armnn::Optional& logSeverityLevel, + const armnn::Optional& func) + : p_Backends({computeDevice}), + p_RuntimeOptions(), + p_OptimizerOptions(optimizerOptions), + m_LoggingSeverity(logSeverityLevel), + p_DebugCallbackFunc(func) + { + } + + explicit DelegateOptionsImpl(const std::vector& backends, + const armnn::OptimizerOptions& optimizerOptions, + const armnn::Optional& logSeverityLevel, + const armnn::Optional& func) + : p_Backends(backends), + p_RuntimeOptions(), + p_OptimizerOptions(optimizerOptions), + m_LoggingSeverity(logSeverityLevel), + p_DebugCallbackFunc(func) + { + } + + /// Which backend to run Delegate on. + /// Examples of possible values are: CpuRef, CpuAcc, GpuAcc. + /// CpuRef as default. + std::vector p_Backends = {armnn::Compute::CpuRef }; + + /// Creation options for the ArmNN runtime + /// Contains options for global settings that are valid for the whole lifetime of ArmNN + /// i.e. BackendOptions, DynamicBackendPath, ExternalProfilingOptions and more + armnn::IRuntime::CreationOptions p_RuntimeOptions; + + /// Options for the optimization step for the network + armnn::OptimizerOptions p_OptimizerOptions; + + /// Internal profiling options. Written to INetworkProperties during model load. + /// Indicates whether internal profiling is enabled or not. + bool m_InternalProfilingEnabled = false; + + /// Sets the level of detail output by the profiling. Options are DetailsWithEvents = 1 and DetailsOnly = 2 + armnn::ProfilingDetailsMethod p_InternalProfilingDetail = armnn::ProfilingDetailsMethod::DetailsWithEvents; + + /// Severity level for logging within ArmNN that will be used on creation of the delegate + armnn::Optional m_LoggingSeverity; + + /// A callback function to debug layers performing custom computations on intermediate tensors. + /// If a function is not registered, and debug is enabled in OptimizerOptions, + /// debug will print information of the intermediate tensors. + armnn::Optional p_DebugCallbackFunc; + + /// If not empty then the optimized model will be serialized to a file with this file name in "dot" format. + std::string m_SerializeToDot = ""; + + /// Option to disable TfLite Runtime fallback for unsupported operators. + bool m_DisableTfLiteRuntimeFallback = false; + +}; + +DelegateOptions::~DelegateOptions() = default; + +DelegateOptions::DelegateOptions() + : p_DelegateOptionsImpl(std::make_unique()) +{ +} + +DelegateOptions::DelegateOptions(DelegateOptions const &other) + : p_DelegateOptionsImpl(std::make_unique(*other.p_DelegateOptionsImpl)) +{ +} + DelegateOptions::DelegateOptions(armnn::Compute computeDevice, const std::vector& backendOptions, const armnn::Optional logSeverityLevel) - : m_Backends({computeDevice}), m_RuntimeOptions(), m_LoggingSeverity(logSeverityLevel) + : p_DelegateOptionsImpl(std::make_unique(computeDevice, backendOptions, logSeverityLevel)) { - m_RuntimeOptions.m_BackendOptions = backendOptions; } DelegateOptions::DelegateOptions(const std::vector& backends, const std::vector& backendOptions, const armnn::Optional logSeverityLevel) - : m_Backends(backends), m_RuntimeOptions(), m_LoggingSeverity(logSeverityLevel) + : p_DelegateOptionsImpl(std::make_unique(backends, backendOptions, logSeverityLevel)) { - m_RuntimeOptions.m_BackendOptions = backendOptions; } DelegateOptions::DelegateOptions(armnn::Compute computeDevice, const armnn::OptimizerOptions& optimizerOptions, const armnn::Optional& logSeverityLevel, const armnn::Optional& func) - : m_Backends({computeDevice}), - m_RuntimeOptions(), - m_OptimizerOptions(optimizerOptions), - m_LoggingSeverity(logSeverityLevel), - m_DebugCallbackFunc(func) + : p_DelegateOptionsImpl(std::make_unique(computeDevice, optimizerOptions, + logSeverityLevel, func)) { } @@ -42,11 +130,8 @@ DelegateOptions::DelegateOptions(const std::vector& backends, const armnn::OptimizerOptions& optimizerOptions, const armnn::Optional& logSeverityLevel, const armnn::Optional& func) - : m_Backends(backends), - m_RuntimeOptions(), - m_OptimizerOptions(optimizerOptions), - m_LoggingSeverity(logSeverityLevel), - m_DebugCallbackFunc(func) + : p_DelegateOptionsImpl(std::make_unique(backends, optimizerOptions, + logSeverityLevel, func)) { } @@ -54,6 +139,7 @@ DelegateOptions::DelegateOptions(char const* const* options_keys, char const* const* options_values, size_t num_options, void (*report_error)(const char*)) + : p_DelegateOptionsImpl(std::make_unique()) { armnn::IRuntime::CreationOptions runtimeOptions; armnn::OptimizerOptions optimizerOptions; @@ -73,7 +159,7 @@ DelegateOptions::DelegateOptions(char const* const* options_keys, backends.push_back(pch); pch = strtok (NULL, ","); } - this->SetBackends(backends); + SetBackends(backends); } // Process dynamic-backends-path else if (std::string(options_keys[i]) == std::string("dynamic-backends-path")) @@ -83,22 +169,25 @@ DelegateOptions::DelegateOptions(char const* const* options_keys, // Process logging level else if (std::string(options_keys[i]) == std::string("logging-severity")) { - this->SetLoggingSeverity(options_values[i]); + SetLoggingSeverity(options_values[i]); } // Process GPU backend options else if (std::string(options_keys[i]) == std::string("gpu-tuning-level")) { - armnn::BackendOptions option("GpuAcc", {{"TuningLevel", atoi(options_values[i])}}); + armnn::BackendOptions option("GpuAcc", {{"TuningLevel", + atoi(options_values[i])}}); runtimeOptions.m_BackendOptions.push_back(option); } else if (std::string(options_keys[i]) == std::string("gpu-mlgo-tuning-file")) { - armnn::BackendOptions option("GpuAcc", {{"MLGOTuningFilePath", std::string(options_values[i])}}); + armnn::BackendOptions option("GpuAcc", {{"MLGOTuningFilePath", + std::string(options_values[i])}}); optimizerOptions.m_ModelOptions.push_back(option); } else if (std::string(options_keys[i]) == std::string("gpu-tuning-file")) { - armnn::BackendOptions option("GpuAcc", {{"TuningFile", std::string(options_values[i])}}); + armnn::BackendOptions option("GpuAcc", {{"TuningFile", + std::string(options_values[i])}}); runtimeOptions.m_BackendOptions.push_back(option); } else if (std::string(options_keys[i]) == std::string("gpu-enable-profiling")) @@ -119,25 +208,27 @@ DelegateOptions::DelegateOptions(char const* const* options_keys, } else if (std::string(options_keys[i]) == std::string("cached-network-filepath")) { - armnn::BackendOptions option("GpuAcc", {{"CachedNetworkFilePath", std::string(options_values[i])}}); + armnn::BackendOptions option("GpuAcc", {{"CachedNetworkFilePath", + std::string(options_values[i])}}); optimizerOptions.m_ModelOptions.push_back(option); } // Process GPU & CPU backend options else if (std::string(options_keys[i]) == std::string("enable-fast-math")) { armnn::BackendOptions modelOptionGpu("GpuAcc", {{"FastMathEnabled", - armnn::stringUtils::StringToBool(options_values[i])}}); + armnn::stringUtils::StringToBool(options_values[i])}}); optimizerOptions.m_ModelOptions.push_back(modelOptionGpu); armnn::BackendOptions modelOptionCpu("CpuAcc", {{"FastMathEnabled", - armnn::stringUtils::StringToBool(options_values[i])}}); + armnn::stringUtils::StringToBool(options_values[i])}}); optimizerOptions.m_ModelOptions.push_back(modelOptionCpu); } // Process CPU backend options else if (std::string(options_keys[i]) == std::string("number-of-threads")) { unsigned int numberOfThreads = armnn::numeric_cast(atoi(options_values[i])); - armnn::BackendOptions modelOption("CpuAcc", {{"NumberOfThreads", numberOfThreads}}); + armnn::BackendOptions modelOption("CpuAcc", + {{"NumberOfThreads", numberOfThreads}}); optimizerOptions.m_ModelOptions.push_back(modelOption); } // Process reduce-fp32-to-fp16 option @@ -205,7 +296,8 @@ DelegateOptions::DelegateOptions(char const* const* options_keys, // Process timeline-profiling else if (std::string(options_keys[i]) == std::string("timeline-profiling")) { - runtimeOptions.m_ProfilingOptions.m_TimelineEnabled = armnn::stringUtils::StringToBool(options_values[i]); + runtimeOptions.m_ProfilingOptions.m_TimelineEnabled = + armnn::stringUtils::StringToBool(options_values[i]); } // Process outgoing-capture-file else if (std::string(options_keys[i]) == std::string("outgoing-capture-file")) @@ -225,7 +317,8 @@ DelegateOptions::DelegateOptions(char const* const* options_keys, // Process counter-capture-period else if (std::string(options_keys[i]) == std::string("counter-capture-period")) { - runtimeOptions.m_ProfilingOptions.m_CapturePeriod = static_cast(std::stoul(options_values[i])); + runtimeOptions.m_ProfilingOptions.m_CapturePeriod = + static_cast(std::stoul(options_values[i])); } // Process profiling-file-format else if (std::string(options_keys[i]) == std::string("profiling-file-format")) @@ -235,22 +328,146 @@ DelegateOptions::DelegateOptions(char const* const* options_keys, // Process serialize-to-dot else if (std::string(options_keys[i]) == std::string("serialize-to-dot")) { - this->SetSerializeToDot(options_values[i]); + SetSerializeToDot(options_values[i]); } - // Process disable-tflite-runtime-fallback + // Process disable-tflite-runtime-fallback else if (std::string(options_keys[i]) == std::string("disable-tflite-runtime-fallback")) { this->DisableTfLiteRuntimeFallback(armnn::stringUtils::StringToBool(options_values[i])); } else { - throw armnn::Exception("Unknown option for the ArmNN Delegate given: " + std::string(options_keys[i])); + throw armnn::Exception("Unknown option for the ArmNN Delegate given: " + + std::string(options_keys[i])); } } - this->SetRuntimeOptions(runtimeOptions); - this->SetOptimizerOptions(optimizerOptions); - this->SetInternalProfilingParams(internalProfilingState, internalProfilingDetail); + SetRuntimeOptions(runtimeOptions); + SetOptimizerOptions(optimizerOptions); + SetInternalProfilingParams(internalProfilingState, internalProfilingDetail); +} + +const std::vector& DelegateOptions::GetBackends() const +{ + return p_DelegateOptionsImpl->p_Backends; +} + +void DelegateOptions::SetBackends(const std::vector& backends) +{ + p_DelegateOptionsImpl->p_Backends = backends; +} + +void DelegateOptions::SetDynamicBackendsPath(const std::string& dynamicBackendsPath) +{ + p_DelegateOptionsImpl->p_RuntimeOptions.m_DynamicBackendsPath = dynamicBackendsPath; +} + +const std::string& DelegateOptions::GetDynamicBackendsPath() const +{ + return p_DelegateOptionsImpl->p_RuntimeOptions.m_DynamicBackendsPath; +} + +void DelegateOptions::SetGpuProfilingState(bool gpuProfilingState) +{ + p_DelegateOptionsImpl->p_RuntimeOptions.m_EnableGpuProfiling = gpuProfilingState; +} + +bool DelegateOptions::GetGpuProfilingState() +{ + return p_DelegateOptionsImpl->p_RuntimeOptions.m_EnableGpuProfiling; +} + +const std::vector& DelegateOptions::GetBackendOptions() const +{ + return p_DelegateOptionsImpl->p_RuntimeOptions.m_BackendOptions; +} + +void DelegateOptions::AddBackendOption(const armnn::BackendOptions& option) +{ + p_DelegateOptionsImpl->p_RuntimeOptions.m_BackendOptions.push_back(option); +} + +void DelegateOptions::SetLoggingSeverity(const armnn::LogSeverity& level) +{ + p_DelegateOptionsImpl->m_LoggingSeverity = level; +} + +void DelegateOptions::SetLoggingSeverity(const std::string& level) +{ + p_DelegateOptionsImpl->m_LoggingSeverity = armnn::StringToLogLevel(level); +} + +armnn::LogSeverity DelegateOptions::GetLoggingSeverity() +{ + return p_DelegateOptionsImpl->m_LoggingSeverity.value(); +} + +bool DelegateOptions::IsLoggingEnabled() +{ + return p_DelegateOptionsImpl->m_LoggingSeverity.has_value(); +} + +const armnn::OptimizerOptions& DelegateOptions::GetOptimizerOptions() const +{ + return p_DelegateOptionsImpl->p_OptimizerOptions; +} + +void DelegateOptions::SetOptimizerOptions(const armnn::OptimizerOptions& optimizerOptions) +{ + p_DelegateOptionsImpl->p_OptimizerOptions = optimizerOptions; +} + +const armnn::Optional& DelegateOptions::GetDebugCallbackFunction() const +{ + return p_DelegateOptionsImpl->p_DebugCallbackFunc; } + +void DelegateOptions::SetInternalProfilingParams(bool internalProfilingState, + const armnn::ProfilingDetailsMethod& internalProfilingDetail) +{ + p_DelegateOptionsImpl->m_InternalProfilingEnabled = internalProfilingState; + p_DelegateOptionsImpl->p_InternalProfilingDetail = internalProfilingDetail; +} + +bool DelegateOptions::GetInternalProfilingState() const +{ + return p_DelegateOptionsImpl->m_InternalProfilingEnabled; +} + +const armnn::ProfilingDetailsMethod& DelegateOptions::GetInternalProfilingDetail() const +{ + return p_DelegateOptionsImpl->p_InternalProfilingDetail; +} + +void DelegateOptions::SetSerializeToDot(const std::string& serializeToDotFile) +{ + p_DelegateOptionsImpl->m_SerializeToDot = serializeToDotFile; +} + +const std::string& DelegateOptions::GetSerializeToDot() const +{ + return p_DelegateOptionsImpl->m_SerializeToDot; +} + +void DelegateOptions::SetRuntimeOptions(const armnn::IRuntime::CreationOptions& runtimeOptions) +{ + p_DelegateOptionsImpl->p_RuntimeOptions = runtimeOptions; +} + +const armnn::IRuntime::CreationOptions& DelegateOptions::GetRuntimeOptions() +{ + return p_DelegateOptionsImpl->p_RuntimeOptions; +} + +void DelegateOptions::DisableTfLiteRuntimeFallback(bool fallbackState) +{ + p_DelegateOptionsImpl->m_DisableTfLiteRuntimeFallback = fallbackState; +} + +bool DelegateOptions::TfLiteRuntimeFallbackDisabled() +{ + return p_DelegateOptionsImpl->m_DisableTfLiteRuntimeFallback; +} + } // namespace armnnDelegate -- cgit v1.2.1