telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2017 Arm Ltd. All rights reserved. |
David Beck | 93e4898 | 2018-09-05 13:05:09 +0100 | [diff] [blame] | 3 | // SPDX-License-Identifier: MIT |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 4 | // |
| 5 | |
Matteo Martincigh | e48bdff | 2018-09-03 13:50:50 +0100 | [diff] [blame] | 6 | #define LOG_TAG "ArmnnDriver" |
| 7 | |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 8 | #include "ArmnnDevice.hpp" |
| 9 | |
| 10 | #include <OperationsUtils.h> |
| 11 | |
| 12 | #include <log/log.h> |
| 13 | |
| 14 | #include <memory> |
Nattapat Chaimanowong | 5404c01 | 2019-04-23 15:08:43 +0100 | [diff] [blame] | 15 | #include <string> |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 16 | |
| 17 | using namespace android; |
| 18 | |
Nattapat Chaimanowong | 5404c01 | 2019-04-23 15:08:43 +0100 | [diff] [blame] | 19 | namespace |
| 20 | { |
| 21 | |
| 22 | std::string GetBackendString(const armnn_driver::DriverOptions& options) |
| 23 | { |
| 24 | std::stringstream backends; |
| 25 | for (auto&& b : options.GetBackends()) |
| 26 | { |
| 27 | backends << b << " "; |
| 28 | } |
| 29 | return backends.str(); |
| 30 | } |
| 31 | |
| 32 | } // anonymous namespace |
| 33 | |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 34 | namespace armnn_driver |
| 35 | { |
| 36 | |
| 37 | ArmnnDevice::ArmnnDevice(DriverOptions options) |
| 38 | : m_Runtime(nullptr, nullptr) |
| 39 | , m_ClTunedParameters(nullptr) |
| 40 | , m_Options(std::move(options)) |
| 41 | { |
| 42 | ALOGV("ArmnnDevice::ArmnnDevice()"); |
| 43 | |
| 44 | armnn::ConfigureLogging(false, m_Options.IsVerboseLoggingEnabled(), armnn::LogSeverity::Trace); |
| 45 | if (m_Options.IsVerboseLoggingEnabled()) |
| 46 | { |
| 47 | SetMinimumLogSeverity(base::VERBOSE); |
| 48 | } |
| 49 | else |
| 50 | { |
| 51 | SetMinimumLogSeverity(base::INFO); |
| 52 | } |
| 53 | |
Sadik Armagan | d6539c5 | 2019-05-22 18:00:30 +0100 | [diff] [blame] | 54 | armnn::IRuntime::CreationOptions runtimeOptions; |
| 55 | |
Matteo Martincigh | 01c9151 | 2019-01-31 15:40:08 +0000 | [diff] [blame] | 56 | #if defined(ARMCOMPUTECL_ENABLED) |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 57 | try |
| 58 | { |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 59 | if (!m_Options.GetClTunedParametersFile().empty()) |
| 60 | { |
Ruomei Yan | 689c6ee | 2019-04-25 17:48:41 +0100 | [diff] [blame] | 61 | m_ClTunedParameters = armnn::IGpuAccTunedParameters::Create(m_Options.GetClTunedParametersMode(), |
| 62 | m_Options.GetClTuningLevel()); |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 63 | try |
| 64 | { |
| 65 | m_ClTunedParameters->Load(m_Options.GetClTunedParametersFile().c_str()); |
| 66 | } |
Derek Lamberti | b9cb844 | 2019-11-28 13:34:48 +0000 | [diff] [blame] | 67 | catch (std::exception& error) |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 68 | { |
| 69 | // This is only a warning because the file won't exist the first time you are generating it. |
| 70 | ALOGW("ArmnnDevice: Failed to load CL tuned parameters file '%s': %s", |
| 71 | m_Options.GetClTunedParametersFile().c_str(), error.what()); |
| 72 | } |
Sadik Armagan | d6539c5 | 2019-05-22 18:00:30 +0100 | [diff] [blame] | 73 | runtimeOptions.m_GpuAccTunedParameters = m_ClTunedParameters; |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 74 | } |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 75 | } |
| 76 | catch (const armnn::ClRuntimeUnavailableException& error) |
| 77 | { |
| 78 | ALOGE("ArmnnDevice: Failed to setup CL runtime: %s. Device will be unavailable.", error.what()); |
| 79 | } |
Derek Lamberti | b9cb844 | 2019-11-28 13:34:48 +0000 | [diff] [blame] | 80 | catch (std::exception& error) |
| 81 | { |
| 82 | ALOGE("ArmnnDevice: Unknown exception: %s. Device will be unavailable.", error.what()); |
| 83 | } |
Matteo Martincigh | 01c9151 | 2019-01-31 15:40:08 +0000 | [diff] [blame] | 84 | #endif |
Sadik Armagan | d6539c5 | 2019-05-22 18:00:30 +0100 | [diff] [blame] | 85 | runtimeOptions.m_EnableGpuProfiling = m_Options.IsGpuProfilingEnabled(); |
| 86 | m_Runtime = armnn::IRuntime::Create(runtimeOptions); |
| 87 | |
Narumol Prangnawarat | 856d1c9 | 2019-05-03 16:42:52 +0100 | [diff] [blame] | 88 | std::vector<armnn::BackendId> backends; |
| 89 | |
| 90 | if (m_Runtime) |
| 91 | { |
| 92 | const armnn::BackendIdSet supportedDevices = m_Runtime->GetDeviceSpec().GetSupportedBackends(); |
| 93 | for (auto &backend : m_Options.GetBackends()) |
| 94 | { |
| 95 | if (std::find(supportedDevices.cbegin(), supportedDevices.cend(), backend) == supportedDevices.cend()) |
| 96 | { |
Sadik Armagan | f74a310 | 2020-02-21 09:49:34 +0000 | [diff] [blame] | 97 | ALOGW("ArmnnDevice: Requested unknown backend %s", backend.Get().c_str()); |
Narumol Prangnawarat | 856d1c9 | 2019-05-03 16:42:52 +0100 | [diff] [blame] | 98 | } |
| 99 | else |
| 100 | { |
| 101 | backends.push_back(backend); |
| 102 | } |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | if (backends.empty()) |
| 107 | { |
Sadik Armagan | f74a310 | 2020-02-21 09:49:34 +0000 | [diff] [blame] | 108 | // No known backend specified |
| 109 | throw armnn::InvalidArgumentException("ArmnnDevice: No known backend specified."); |
Narumol Prangnawarat | 856d1c9 | 2019-05-03 16:42:52 +0100 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | m_Options.SetBackends(backends); |
Nattapat Chaimanowong | 5404c01 | 2019-04-23 15:08:43 +0100 | [diff] [blame] | 113 | ALOGV("ArmnnDevice: Created device with the following backends: %s", |
| 114 | GetBackendString(m_Options).c_str()); |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | } // namespace armnn_driver |