diff options
author | Teresa Charlin <teresa.charlinreyes@arm.com> | 2023-10-04 11:17:03 +0100 |
---|---|---|
committer | TeresaARM <teresa.charlinreyes@arm.com> | 2023-10-05 18:18:29 +0000 |
commit | 19ad816539037a095749cdd41852292a3d87dd2b (patch) | |
tree | 409697e5f10ac6a4e1b86cd86bfba5e0663f16ba /delegate/common | |
parent | 727d017aa3559cb33c97a8d77b5a32fbb98b9e35 (diff) | |
download | armnn-19ad816539037a095749cdd41852292a3d87dd2b.tar.gz |
IVGCVSW-8060 Add ArmNNSettings parser function for Opaque Delegate
* Add Unit Tests
* Update DelegateOptions constructor
Signed-off-by: Teresa Charlin <teresa.charlinreyes@arm.com>
Change-Id: I0e88403ac280e4cf8710ae7ee38b3b56dba42adc
Diffstat (limited to 'delegate/common')
-rw-r--r-- | delegate/common/include/DelegateOptions.hpp | 22 | ||||
-rw-r--r-- | delegate/common/src/DelegateOptions.cpp | 168 |
2 files changed, 128 insertions, 62 deletions
diff --git a/delegate/common/include/DelegateOptions.hpp b/delegate/common/include/DelegateOptions.hpp index abf446a402..d4924ccf65 100644 --- a/delegate/common/include/DelegateOptions.hpp +++ b/delegate/common/include/DelegateOptions.hpp @@ -120,6 +120,17 @@ public: * Possible values: ["true"/"false"] \n * Description: Add debug data for easier troubleshooting * + * Option key: "infer-output-shape" \n + * Possible values: ["true"/"false"] \n + * Description: Infers output tensor shape from input tensor shape and validate where applicable. + * + * Option key: "allow-expanded-dims" \n + * Possible values: ["true"/"false"] \n + * Description: If true will disregard dimensions with a size of 1 when validating tensor shapes but tensor + * sizes must still match. \n + * This is an Experimental parameter that is incompatible with "infer-output-shape". \n + * This parameter may be removed in a later update. + * * Option key: "memory-import" \n * Possible values: ["true"/"false"] \n * Description: Enable memory import @@ -164,17 +175,6 @@ public: * Possible values: [filenameString] \n * Description: Serialize the optimized network to the file specified in "dot" format. * - * Option key: "infer-output-shape" \n - * Possible values: ["true"/"false"] \n - * Description: Infers output tensor shape from input tensor shape and validate where applicable. - * - * Option key: "allow-expanded-dims" \n - * Possible values: ["true"/"false"] \n - * Description: If true will disregard dimensions with a size of 1 when validating tensor shapes but tensor - * sizes must still match. \n - * This is an Experimental parameter that is incompatible with "infer-output-shape". \n - * This parameter may be removed in a later update. - * * Option key: "disable-tflite-runtime-fallback" \n * Possible values: ["true"/"false"] \n * Description: Disable TfLite Runtime fallback in the Arm NN TfLite delegate. diff --git a/delegate/common/src/DelegateOptions.cpp b/delegate/common/src/DelegateOptions.cpp index dca9af38c4..4596159fce 100644 --- a/delegate/common/src/DelegateOptions.cpp +++ b/delegate/common/src/DelegateOptions.cpp @@ -16,9 +16,9 @@ struct DelegateOptionsImpl DelegateOptionsImpl() = default; explicit DelegateOptionsImpl(armnn::Compute computeDevice, - const std::vector<armnn::BackendOptions>& backendOptions, - const armnn::Optional<armnn::LogSeverity> logSeverityLevel) - : m_Backends({computeDevice}), m_RuntimeOptions(), m_LoggingSeverity(logSeverityLevel) + const std::vector<armnn::BackendOptions>& backendOptions, + const armnn::Optional<armnn::LogSeverity> logSeverityLevel) + : m_Backends({computeDevice}), m_RuntimeOptions(), m_LoggingSeverity(logSeverityLevel) { m_RuntimeOptions.m_BackendOptions = backendOptions; } @@ -145,6 +145,10 @@ DelegateOptions::DelegateOptions(char const* const* options_keys, armnn::OptimizerOptionsOpaque optimizerOptions; bool internalProfilingState = false; armnn::ProfilingDetailsMethod internalProfilingDetail = armnn::ProfilingDetailsMethod::DetailsWithEvents; + + bool GpuAccFound = false; + bool CpuAccFound = false; + for (size_t i = 0; i < num_options; ++i) { // Process backends @@ -160,6 +164,8 @@ DelegateOptions::DelegateOptions(char const* const* options_keys, pch = strtok (NULL, ","); } SetBackends(backends); + GpuAccFound = std::count(GetBackends().begin(), GetBackends().end(), "GpuAcc"); + CpuAccFound = std::count(GetBackends().begin(), GetBackends().end(), "CpuAcc"); } // Process dynamic-backends-path else if (std::string(options_keys[i]) == std::string("dynamic-backends-path")) @@ -174,21 +180,45 @@ DelegateOptions::DelegateOptions(char const* const* options_keys, // 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])}}); - runtimeOptions.m_BackendOptions.push_back(option); + if (GpuAccFound) + { + armnn::BackendOptions option("GpuAcc", {{"TuningLevel", + atoi(options_values[i])}}); + runtimeOptions.m_BackendOptions.push_back(option); + } + else + { + ARMNN_LOG(warning) << + "WARNING: TuningLevel is enabled, but no backends that accept this option are set."; + } } else if (std::string(options_keys[i]) == std::string("gpu-mlgo-tuning-file")) { - armnn::BackendOptions option("GpuAcc", {{"MLGOTuningFilePath", - std::string(options_values[i])}}); - optimizerOptions.AddModelOption(option); + if (GpuAccFound) + { + armnn::BackendOptions option("GpuAcc", {{"MLGOTuningFilePath", + std::string(options_values[i])}}); + optimizerOptions.AddModelOption(option); + } + else + { + ARMNN_LOG(warning) << + "WARNING: MLGOTuningFilePath is enabled, but no backends that accept this option are set."; + } } else if (std::string(options_keys[i]) == std::string("gpu-tuning-file")) { - armnn::BackendOptions option("GpuAcc", {{"TuningFile", - std::string(options_values[i])}}); - runtimeOptions.m_BackendOptions.push_back(option); + if (GpuAccFound) + { + armnn::BackendOptions option("GpuAcc", {{"TuningFile", + std::string(options_values[i])}}); + runtimeOptions.m_BackendOptions.push_back(option); + } + else + { + ARMNN_LOG(warning) << + "WARNING: TuningFile is enabled, but no backends that accept this option are set."; + } } else if (std::string(options_keys[i]) == std::string("gpu-enable-profiling")) { @@ -196,40 +226,82 @@ DelegateOptions::DelegateOptions(char const* const* options_keys, } else if (std::string(options_keys[i]) == std::string("gpu-kernel-profiling-enabled")) { - armnn::BackendOptions option("GpuAcc", {{"KernelProfilingEnabled", - armnn::stringUtils::StringToBool(options_values[i])}}); - runtimeOptions.m_BackendOptions.push_back(option); + if (GpuAccFound) + { + armnn::BackendOptions option("GpuAcc", {{"KernelProfilingEnabled", + armnn::stringUtils::StringToBool(options_values[i])}}); + runtimeOptions.m_BackendOptions.push_back(option); + } + else + { + ARMNN_LOG(warning) << + "WARNING: KernelProfilingEnabled is enabled, but no backends that accept this option are set."; + } } else if (std::string(options_keys[i]) == std::string("save-cached-network")) { - armnn::BackendOptions option("GpuAcc", {{"SaveCachedNetwork", - armnn::stringUtils::StringToBool(options_values[i])}}); - optimizerOptions.AddModelOption(option); + if (GpuAccFound) + { + armnn::BackendOptions option("GpuAcc", {{"SaveCachedNetwork", + armnn::stringUtils::StringToBool(options_values[i])}}); + optimizerOptions.AddModelOption(option); + } + else + { + ARMNN_LOG(warning) << + "WARNING: SaveCachedNetwork is enabled, but no backends that accept this option are set."; + } } else if (std::string(options_keys[i]) == std::string("cached-network-filepath")) { - armnn::BackendOptions option("GpuAcc", {{"CachedNetworkFilePath", - std::string(options_values[i])}}); - optimizerOptions.AddModelOption(option); + if (GpuAccFound) + { + armnn::BackendOptions option("GpuAcc", {{"CachedNetworkFilePath", + std::string(options_values[i])}}); + optimizerOptions.AddModelOption(option); + } + else + { + ARMNN_LOG(warning) << + "WARNING: CachedNetworkFilePath is enabled, but no backends that accept this option are set."; + } } // 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])}}); - optimizerOptions.AddModelOption(modelOptionGpu); - - armnn::BackendOptions modelOptionCpu("CpuAcc", {{"FastMathEnabled", - armnn::stringUtils::StringToBool(options_values[i])}}); - optimizerOptions.AddModelOption(modelOptionCpu); + if (GpuAccFound) + { + armnn::BackendOptions modelOptionGpu("GpuAcc", {{"FastMathEnabled", + armnn::stringUtils::StringToBool(options_values[i])}}); + optimizerOptions.AddModelOption(modelOptionGpu); + } + if (CpuAccFound) + { + armnn::BackendOptions modelOptionCpu("CpuAcc", {{"FastMathEnabled", + armnn::stringUtils::StringToBool(options_values[i])}}); + optimizerOptions.AddModelOption(modelOptionCpu); + } + if (!GpuAccFound and !CpuAccFound) + { + ARMNN_LOG(warning) << + "WARNING: Fastmath is enabled, but no backends that accept this option are set."; + } } // 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}}); - optimizerOptions.AddModelOption(modelOption); + if (CpuAccFound) + { + unsigned int numberOfThreads = armnn::numeric_cast<unsigned int>(atoi(options_values[i])); + armnn::BackendOptions modelOption("CpuAcc", + {{"NumberOfThreads", numberOfThreads}}); + optimizerOptions.AddModelOption(modelOption); + } + else + { + ARMNN_LOG(warning) << + "WARNING: NumberOfThreads is enabled, but no backends that accept this option are set."; + } } // Process reduce-fp32-to-fp16 option else if (std::string(options_keys[i]) == std::string("reduce-fp32-to-fp16")) @@ -244,20 +316,19 @@ DelegateOptions::DelegateOptions(char const* const* options_keys, // Infer output-shape else if (std::string(options_keys[i]) == std::string("infer-output-shape")) { - armnn::BackendOptions backendOption("ShapeInferenceMethod", + if (armnn::stringUtils::StringToBool(options_values[i])) + { + optimizerOptions.SetShapeInferenceMethod(armnn::ShapeInferenceMethod::InferAndValidate); + } + else { - { "InferAndValidate", armnn::stringUtils::StringToBool(options_values[i]) } - }); - optimizerOptions.AddModelOption(backendOption); + optimizerOptions.SetShapeInferenceMethod(armnn::ShapeInferenceMethod::ValidateOnly); + } } // Allow expanded dims else if (std::string(options_keys[i]) == std::string("allow-expanded-dims")) { - armnn::BackendOptions backendOption("AllowExpandedDims", - { - { "AllowExpandedDims", armnn::stringUtils::StringToBool(options_values[i]) } - }); - optimizerOptions.AddModelOption(backendOption); + optimizerOptions.SetAllowExpandedDims(armnn::stringUtils::StringToBool(options_values[i])); } // Process memory-import else if (std::string(options_keys[i]) == std::string("memory-import")) @@ -290,14 +361,12 @@ DelegateOptions::DelegateOptions(char const* const* options_keys, // Process enable-external-profiling else if (std::string(options_keys[i]) == std::string("enable-external-profiling")) { - runtimeOptions.m_ProfilingOptions.m_EnableProfiling = - armnn::stringUtils::StringToBool(options_values[i]); + runtimeOptions.m_ProfilingOptions.m_EnableProfiling = armnn::stringUtils::StringToBool(options_values[i]); } // 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")) @@ -312,14 +381,12 @@ DelegateOptions::DelegateOptions(char const* const* options_keys, // Process file-only-external-profiling else if (std::string(options_keys[i]) == std::string("file-only-external-profiling")) { - runtimeOptions.m_ProfilingOptions.m_FileOnly = - armnn::stringUtils::StringToBool(options_values[i]); + runtimeOptions.m_ProfilingOptions.m_FileOnly = armnn::stringUtils::StringToBool(options_values[i]); } // 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")) @@ -339,8 +406,7 @@ DelegateOptions::DelegateOptions(char const* const* options_keys, } 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])); } } |