blob: ffb07c8db234d8bc8a602fa0b54106b9f8c930e2 [file] [log] [blame]
telsoa01ce3e84a2018-08-31 09:31:35 +01001//
2// Copyright © 2017 Arm Ltd. All rights reserved.
David Beck93e48982018-09-05 13:05:09 +01003// SPDX-License-Identifier: MIT
telsoa01ce3e84a2018-08-31 09:31:35 +01004//
5
Matteo Martincighe48bdff2018-09-03 13:50:50 +01006#define LOG_TAG "ArmnnDriver"
7
telsoa01ce3e84a2018-08-31 09:31:35 +01008#include "ArmnnDevice.hpp"
9
10#include <OperationsUtils.h>
11
12#include <log/log.h>
13
14#include <memory>
Nattapat Chaimanowong5404c012019-04-23 15:08:43 +010015#include <string>
telsoa01ce3e84a2018-08-31 09:31:35 +010016
17using namespace android;
18
Nattapat Chaimanowong5404c012019-04-23 15:08:43 +010019namespace
20{
21
22std::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
telsoa01ce3e84a2018-08-31 09:31:35 +010034namespace armnn_driver
35{
36
37ArmnnDevice::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 Armagand6539c52019-05-22 18:00:30 +010054 armnn::IRuntime::CreationOptions runtimeOptions;
55
Matteo Martincigh01c91512019-01-31 15:40:08 +000056#if defined(ARMCOMPUTECL_ENABLED)
telsoa01ce3e84a2018-08-31 09:31:35 +010057 try
58 {
telsoa01ce3e84a2018-08-31 09:31:35 +010059 if (!m_Options.GetClTunedParametersFile().empty())
60 {
Ruomei Yan689c6ee2019-04-25 17:48:41 +010061 m_ClTunedParameters = armnn::IGpuAccTunedParameters::Create(m_Options.GetClTunedParametersMode(),
62 m_Options.GetClTuningLevel());
telsoa01ce3e84a2018-08-31 09:31:35 +010063 try
64 {
65 m_ClTunedParameters->Load(m_Options.GetClTunedParametersFile().c_str());
66 }
Derek Lambertib9cb8442019-11-28 13:34:48 +000067 catch (std::exception& error)
telsoa01ce3e84a2018-08-31 09:31:35 +010068 {
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 Armagand6539c52019-05-22 18:00:30 +010073 runtimeOptions.m_GpuAccTunedParameters = m_ClTunedParameters;
telsoa01ce3e84a2018-08-31 09:31:35 +010074 }
telsoa01ce3e84a2018-08-31 09:31:35 +010075 }
76 catch (const armnn::ClRuntimeUnavailableException& error)
77 {
78 ALOGE("ArmnnDevice: Failed to setup CL runtime: %s. Device will be unavailable.", error.what());
79 }
Derek Lambertib9cb8442019-11-28 13:34:48 +000080 catch (std::exception& error)
81 {
82 ALOGE("ArmnnDevice: Unknown exception: %s. Device will be unavailable.", error.what());
83 }
Matteo Martincigh01c91512019-01-31 15:40:08 +000084#endif
Sadik Armagand6539c52019-05-22 18:00:30 +010085 runtimeOptions.m_EnableGpuProfiling = m_Options.IsGpuProfilingEnabled();
86 m_Runtime = armnn::IRuntime::Create(runtimeOptions);
87
Narumol Prangnawarat856d1c92019-05-03 16:42:52 +010088 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 Armaganf74a3102020-02-21 09:49:34 +000097 ALOGW("ArmnnDevice: Requested unknown backend %s", backend.Get().c_str());
Narumol Prangnawarat856d1c92019-05-03 16:42:52 +010098 }
99 else
100 {
101 backends.push_back(backend);
102 }
103 }
104 }
105
106 if (backends.empty())
107 {
Sadik Armaganf74a3102020-02-21 09:49:34 +0000108 // No known backend specified
109 throw armnn::InvalidArgumentException("ArmnnDevice: No known backend specified.");
Narumol Prangnawarat856d1c92019-05-03 16:42:52 +0100110 }
111
112 m_Options.SetBackends(backends);
Nattapat Chaimanowong5404c012019-04-23 15:08:43 +0100113 ALOGV("ArmnnDevice: Created device with the following backends: %s",
114 GetBackendString(m_Options).c_str());
telsoa01ce3e84a2018-08-31 09:31:35 +0100115}
116
117} // namespace armnn_driver