diff options
author | John McLoughlin <johmcl01@e129317.arm.com> | 2023-03-14 11:47:15 +0000 |
---|---|---|
committer | John Mcloughlin <john.mcloughlin@arm.com> | 2023-04-06 10:55:46 +0100 |
commit | 1bae865fecf99f25cd2d58390e0cf08467a22b4f (patch) | |
tree | 69fc59fd26e79e7176085a7febd45295b0a165c8 /delegate/common/src/DelegateOptions.cpp | |
parent | 54cf011c89ed7512853ec4472a6fd52fb8f9495f (diff) | |
download | armnn-1bae865fecf99f25cd2d58390e0cf08467a22b4f.tar.gz |
IVGCVSW-7197 Implement Pimpl Idiom for Delegate Options
* ABI break on the delegate interface. Bumping the version number.
Signed-off-by: John Mcloughlin <john.mcloughlin@arm.com>
Change-Id: I6ef3bc1ea240ef08b67bb3cb9d363a5bbbbdd906
Diffstat (limited to 'delegate/common/src/DelegateOptions.cpp')
-rw-r--r-- | delegate/common/src/DelegateOptions.cpp | 279 |
1 files changed, 248 insertions, 31 deletions
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<armnn::BackendOptions>& backendOptions, + const armnn::Optional<armnn::LogSeverity> logSeverityLevel) + : p_Backends({computeDevice}), p_RuntimeOptions(), m_LoggingSeverity(logSeverityLevel) + { + p_RuntimeOptions.m_BackendOptions = backendOptions; + } + + explicit DelegateOptionsImpl(const std::vector<armnn::BackendId>& backends, + const std::vector<armnn::BackendOptions>& backendOptions, + const armnn::Optional<armnn::LogSeverity> 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<armnn::LogSeverity>& logSeverityLevel, + const armnn::Optional<armnn::DebugCallbackFunction>& func) + : p_Backends({computeDevice}), + p_RuntimeOptions(), + p_OptimizerOptions(optimizerOptions), + m_LoggingSeverity(logSeverityLevel), + p_DebugCallbackFunc(func) + { + } + + explicit DelegateOptionsImpl(const std::vector<armnn::BackendId>& backends, + const armnn::OptimizerOptions& optimizerOptions, + const armnn::Optional<armnn::LogSeverity>& logSeverityLevel, + const armnn::Optional<armnn::DebugCallbackFunction>& 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<armnn::BackendId> 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<armnn::LogSeverity> 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<armnn::DebugCallbackFunction> 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<DelegateOptionsImpl>()) +{ +} + +DelegateOptions::DelegateOptions(DelegateOptions const &other) + : p_DelegateOptionsImpl(std::make_unique<DelegateOptionsImpl>(*other.p_DelegateOptionsImpl)) +{ +} + DelegateOptions::DelegateOptions(armnn::Compute computeDevice, const std::vector<armnn::BackendOptions>& backendOptions, const armnn::Optional<armnn::LogSeverity> logSeverityLevel) - : m_Backends({computeDevice}), m_RuntimeOptions(), m_LoggingSeverity(logSeverityLevel) + : p_DelegateOptionsImpl(std::make_unique<DelegateOptionsImpl>(computeDevice, backendOptions, logSeverityLevel)) { - m_RuntimeOptions.m_BackendOptions = backendOptions; } DelegateOptions::DelegateOptions(const std::vector<armnn::BackendId>& backends, const std::vector<armnn::BackendOptions>& backendOptions, const armnn::Optional<armnn::LogSeverity> logSeverityLevel) - : m_Backends(backends), m_RuntimeOptions(), m_LoggingSeverity(logSeverityLevel) + : p_DelegateOptionsImpl(std::make_unique<DelegateOptionsImpl>(backends, backendOptions, logSeverityLevel)) { - m_RuntimeOptions.m_BackendOptions = backendOptions; } DelegateOptions::DelegateOptions(armnn::Compute computeDevice, const armnn::OptimizerOptions& optimizerOptions, const armnn::Optional<armnn::LogSeverity>& logSeverityLevel, const armnn::Optional<armnn::DebugCallbackFunction>& func) - : m_Backends({computeDevice}), - m_RuntimeOptions(), - m_OptimizerOptions(optimizerOptions), - m_LoggingSeverity(logSeverityLevel), - m_DebugCallbackFunc(func) + : p_DelegateOptionsImpl(std::make_unique<DelegateOptionsImpl>(computeDevice, optimizerOptions, + logSeverityLevel, func)) { } @@ -42,11 +130,8 @@ DelegateOptions::DelegateOptions(const std::vector<armnn::BackendId>& backends, const armnn::OptimizerOptions& optimizerOptions, const armnn::Optional<armnn::LogSeverity>& logSeverityLevel, const armnn::Optional<armnn::DebugCallbackFunction>& func) - : m_Backends(backends), - m_RuntimeOptions(), - m_OptimizerOptions(optimizerOptions), - m_LoggingSeverity(logSeverityLevel), - m_DebugCallbackFunc(func) + : p_DelegateOptionsImpl(std::make_unique<DelegateOptionsImpl>(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<DelegateOptionsImpl>()) { 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<unsigned int>(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<uint32_t>(std::stoul(options_values[i])); + runtimeOptions.m_ProfilingOptions.m_CapturePeriod = + static_cast<uint32_t>(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<armnn::BackendId>& DelegateOptions::GetBackends() const +{ + return p_DelegateOptionsImpl->p_Backends; +} + +void DelegateOptions::SetBackends(const std::vector<armnn::BackendId>& 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<armnn::BackendOptions>& 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<armnn::DebugCallbackFunction>& 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 |