diff options
author | Kevin May <kevin.may@arm.com> | 2022-02-10 13:14:03 +0000 |
---|---|---|
committer | Kevin May <kevin.may@arm.com> | 2022-02-11 17:00:02 +0000 |
commit | 138a88cf568fbc420a310344903f7eb9dec8e1e3 (patch) | |
tree | 09dfc013e35ebbed461818e585c3a5611bda7f60 /shim/sl/canonical/ArmnnDevice.cpp | |
parent | f414d999704e2d198aa3136bd556f33a9cc4945f (diff) | |
download | armnn-138a88cf568fbc420a310344903f7eb9dec8e1e3.tar.gz |
IVGCVSW-6226 Arm NN Shim Service and Support Library
Signed-off-by: Kevin May <kevin.may@arm.com>
Change-Id: I542b4c4c7b0592f5153ab3d10141bed4e8f169cd
Diffstat (limited to 'shim/sl/canonical/ArmnnDevice.cpp')
-rw-r--r-- | shim/sl/canonical/ArmnnDevice.cpp | 118 |
1 files changed, 118 insertions, 0 deletions
diff --git a/shim/sl/canonical/ArmnnDevice.cpp b/shim/sl/canonical/ArmnnDevice.cpp new file mode 100644 index 0000000000..2fc7ff1d12 --- /dev/null +++ b/shim/sl/canonical/ArmnnDevice.cpp @@ -0,0 +1,118 @@ +// +// Copyright © 2022 Arm Ltd and Contributors. All rights reserved. +// SPDX-License-Identifier: MIT +// + +#define LOG_TAG "arm-armnn-sl" + +#include "ArmnnDevice.hpp" + +#include <LegacyUtils.h> +#include <OperationsUtils.h> + +#include <log/log.h> + +#include <memory> +#include <string> + +namespace +{ + +std::string GetBackendString(const armnn_driver::DriverOptions& options) +{ + std::stringstream backends; + for (auto&& b : options.GetBackends()) + { + backends << b << " "; + } + return backends.str(); +} + +} // anonymous namespace + +namespace armnn_driver +{ + +using namespace android::nn; + +ArmnnDevice::ArmnnDevice(DriverOptions options) + : m_Runtime(nullptr, nullptr) + , m_ClTunedParameters(nullptr) + , m_Options(std::move(options)) +{ + initVLogMask(); + VLOG(DRIVER) << "ArmnnDevice::ArmnnDevice()"; + + armnn::ConfigureLogging(false, m_Options.IsVerboseLoggingEnabled(), armnn::LogSeverity::Trace); + if (m_Options.IsVerboseLoggingEnabled()) + { + SetMinimumLogSeverity(android::base::VERBOSE); + } + else + { + SetMinimumLogSeverity(android::base::INFO); + } + + armnn::IRuntime::CreationOptions runtimeOptions; + +#if defined(ARMCOMPUTECL_ENABLED) + try + { + if (!m_Options.GetClTunedParametersFile().empty()) + { + m_ClTunedParameters = armnn::IGpuAccTunedParameters::Create(m_Options.GetClTunedParametersMode(), + m_Options.GetClTuningLevel()); + try + { + m_ClTunedParameters->Load(m_Options.GetClTunedParametersFile().c_str()); + } + catch (std::exception& error) + { + // This is only a warning because the file won't exist the first time you are generating it. + VLOG(DRIVER) << "ArmnnDevice: Failed to load CL tuned parameters file " + << m_Options.GetClTunedParametersFile().c_str() << " : " << error.what()); + } + runtimeOptions.m_GpuAccTunedParameters = m_ClTunedParameters; + } + } + catch (const armnn::ClRuntimeUnavailableException& error) + { + VLOG(DRIVER) << "ArmnnDevice: Failed to setup CL runtime: %s. Device will be unavailable." << error.what(); + } + catch (std::exception& error) + { + VLOG(DRIVER) << "ArmnnDevice: Unknown exception: %s. Device will be unavailable." << error.what(); + } +#endif + runtimeOptions.m_EnableGpuProfiling = m_Options.IsGpuProfilingEnabled(); + m_Runtime = armnn::IRuntime::Create(runtimeOptions); + + std::vector<armnn::BackendId> backends; + + if (m_Runtime) + { + const armnn::BackendIdSet supportedDevices = m_Runtime->GetDeviceSpec().GetSupportedBackends(); + for (auto &backend : m_Options.GetBackends()) + { + if (std::find(supportedDevices.cbegin(), supportedDevices.cend(), backend) == supportedDevices.cend()) + { + VLOG(DRIVER) << "ArmnnDevice: Requested unknown backend " << backend.Get().c_str(); + } + else + { + backends.push_back(backend); + } + } + } + + if (backends.empty()) + { + // No known backend specified + throw armnn::InvalidArgumentException("ArmnnDevice: No known backend specified."); + } + + m_Options.SetBackends(backends); + VLOG(DRIVER) << "ArmnnDevice: Created device with the following backends: " << GetBackendString(m_Options).c_str(); +} + +} // namespace armnn_driver |