blob: c96798a803352be5e409b7e29b1330dc0e74b7aa [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
Matteo Martincigh01c91512019-01-31 15:40:08 +000054#if defined(ARMCOMPUTECL_ENABLED)
telsoa01ce3e84a2018-08-31 09:31:35 +010055 try
56 {
57 armnn::IRuntime::CreationOptions options;
58 if (!m_Options.GetClTunedParametersFile().empty())
59 {
Ruomei Yan689c6ee2019-04-25 17:48:41 +010060 m_ClTunedParameters = armnn::IGpuAccTunedParameters::Create(m_Options.GetClTunedParametersMode(),
61 m_Options.GetClTuningLevel());
telsoa01ce3e84a2018-08-31 09:31:35 +010062 try
63 {
64 m_ClTunedParameters->Load(m_Options.GetClTunedParametersFile().c_str());
65 }
66 catch (const armnn::Exception& error)
67 {
68 // This is only a warning because the file won't exist the first time you are generating it.
69 ALOGW("ArmnnDevice: Failed to load CL tuned parameters file '%s': %s",
70 m_Options.GetClTunedParametersFile().c_str(), error.what());
71 }
72 options.m_GpuAccTunedParameters = m_ClTunedParameters;
73 }
74
75 options.m_EnableGpuProfiling = m_Options.IsGpuProfilingEnabled();
76
77 m_Runtime = armnn::IRuntime::Create(options);
78 }
79 catch (const armnn::ClRuntimeUnavailableException& error)
80 {
81 ALOGE("ArmnnDevice: Failed to setup CL runtime: %s. Device will be unavailable.", error.what());
82 }
Matteo Martincigh01c91512019-01-31 15:40:08 +000083#endif
Narumol Prangnawarat856d1c92019-05-03 16:42:52 +010084 std::vector<armnn::BackendId> backends;
85
86 if (m_Runtime)
87 {
88 const armnn::BackendIdSet supportedDevices = m_Runtime->GetDeviceSpec().GetSupportedBackends();
89 for (auto &backend : m_Options.GetBackends())
90 {
91 if (std::find(supportedDevices.cbegin(), supportedDevices.cend(), backend) == supportedDevices.cend())
92 {
93 ALOGW("Requested unknown backend %s", backend.Get().c_str());
94 }
95 else
96 {
97 backends.push_back(backend);
98 }
99 }
100 }
101
102 if (backends.empty())
103 {
104 backends.emplace_back("GpuAcc");
105 ALOGW("No known backend specified. Defaulting to: GpuAcc");
106 }
107
108 m_Options.SetBackends(backends);
Nattapat Chaimanowong5404c012019-04-23 15:08:43 +0100109 ALOGV("ArmnnDevice: Created device with the following backends: %s",
110 GetBackendString(m_Options).c_str());
telsoa01ce3e84a2018-08-31 09:31:35 +0100111}
112
113} // namespace armnn_driver