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 | |
Matteo Martincigh | 01c9151 | 2019-01-31 15:40:08 +0000 | [diff] [blame] | 54 | #if defined(ARMCOMPUTECL_ENABLED) |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 55 | try |
| 56 | { |
| 57 | armnn::IRuntime::CreationOptions options; |
| 58 | if (!m_Options.GetClTunedParametersFile().empty()) |
| 59 | { |
| 60 | m_ClTunedParameters = armnn::IGpuAccTunedParameters::Create(m_Options.GetClTunedParametersMode()); |
| 61 | try |
| 62 | { |
| 63 | m_ClTunedParameters->Load(m_Options.GetClTunedParametersFile().c_str()); |
| 64 | } |
| 65 | catch (const armnn::Exception& error) |
| 66 | { |
| 67 | // This is only a warning because the file won't exist the first time you are generating it. |
| 68 | ALOGW("ArmnnDevice: Failed to load CL tuned parameters file '%s': %s", |
| 69 | m_Options.GetClTunedParametersFile().c_str(), error.what()); |
| 70 | } |
| 71 | options.m_GpuAccTunedParameters = m_ClTunedParameters; |
| 72 | } |
| 73 | |
| 74 | options.m_EnableGpuProfiling = m_Options.IsGpuProfilingEnabled(); |
| 75 | |
| 76 | m_Runtime = armnn::IRuntime::Create(options); |
| 77 | } |
| 78 | catch (const armnn::ClRuntimeUnavailableException& error) |
| 79 | { |
| 80 | ALOGE("ArmnnDevice: Failed to setup CL runtime: %s. Device will be unavailable.", error.what()); |
| 81 | } |
Matteo Martincigh | 01c9151 | 2019-01-31 15:40:08 +0000 | [diff] [blame] | 82 | #endif |
Nattapat Chaimanowong | 5404c01 | 2019-04-23 15:08:43 +0100 | [diff] [blame^] | 83 | ALOGV("ArmnnDevice: Created device with the following backends: %s", |
| 84 | GetBackendString(m_Options).c_str()); |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | } // namespace armnn_driver |