blob: be355932e257d21ee4a2b8ef4d82cbcf1831ff50 [file] [log] [blame]
Kevin May42477c12020-03-26 13:34:14 +00001//
2// Copyright © 2020 Arm Ltd. All rights reserved.
3// SPDX-License-Identifier: MIT
4//
5
6#pragma once
7
8#include <HalInterfaces.h>
9
10#include "../ArmnnDevice.hpp"
11#include "ArmnnDriverImpl.hpp"
12#include "HalPolicy.hpp"
13
14#include "../ArmnnDriverImpl.hpp"
15#include "../1.3/ArmnnDriverImpl.hpp"
16#include "../1.3/HalPolicy.hpp"
17#include "../1.2/ArmnnDriverImpl.hpp"
18#include "../1.2/HalPolicy.hpp"
19#include "../1.1/ArmnnDriverImpl.hpp"
20#include "../1.1/HalPolicy.hpp"
21#include "../1.0/ArmnnDriverImpl.hpp"
22#include "../1.0/HalPolicy.hpp"
23
24#include <log/log.h>
25
26namespace armnn_driver
27{
28namespace hal_1_3
29{
30
31class ArmnnDriver : public ArmnnDevice, public V1_3::IDevice
32{
33public:
34
35 ArmnnDriver(DriverOptions options)
36 : ArmnnDevice(std::move(options))
37 {
38 ALOGV("hal_1_3::ArmnnDriver::ArmnnDriver()");
39 }
40 ~ArmnnDriver() {}
41
42 using HidlToken = android::hardware::hidl_array<uint8_t, ANEURALNETWORKS_BYTE_SIZE_OF_CACHE_TOKEN>;
43
44public:
45 Return<void> getCapabilities(V1_0::IDevice::getCapabilities_cb cb) override
46 {
47 ALOGV("hal_1_3::ArmnnDriver::getCapabilities()");
48
49 return hal_1_0::ArmnnDriverImpl::getCapabilities(m_Runtime, cb);
50 }
51
52 Return<void> getSupportedOperations(const V1_0::Model& model,
53 V1_0::IDevice::getSupportedOperations_cb cb) override
54 {
55 ALOGV("hal_1_3::ArmnnDriver::getSupportedOperations()");
56
57 return armnn_driver::ArmnnDriverImpl<hal_1_0::HalPolicy>::getSupportedOperations(m_Runtime,
58 m_Options,
59 model,
60 cb);
61 }
62
63 Return<V1_0::ErrorStatus> prepareModel(const V1_0::Model& model,
64 const android::sp<V1_0::IPreparedModelCallback>& cb) override
65 {
66 ALOGV("hal_1_3::ArmnnDriver::prepareModel()");
67
68 return armnn_driver::ArmnnDriverImpl<hal_1_0::HalPolicy>::prepareModel(m_Runtime,
69 m_ClTunedParameters,
70 m_Options,
71 model,
72 cb);
73 }
74
75 Return<void> getCapabilities_1_1(V1_1::IDevice::getCapabilities_1_1_cb cb) override
76 {
77 ALOGV("hal_1_3::ArmnnDriver::getCapabilities_1_1()");
78
79 return hal_1_1::ArmnnDriverImpl::getCapabilities_1_1(m_Runtime, cb);
80 }
81
82 Return<void> getSupportedOperations_1_1(const V1_1::Model& model,
83 V1_1::IDevice::getSupportedOperations_1_1_cb cb) override
84 {
85 ALOGV("hal_1_3::ArmnnDriver::getSupportedOperations_1_1()");
86 return armnn_driver::ArmnnDriverImpl<hal_1_1::HalPolicy>::getSupportedOperations(m_Runtime,
87 m_Options,
88 model,
89 cb);
90 }
91
92 Return<V1_0::ErrorStatus> prepareModel_1_1(const V1_1::Model& model,
93 V1_1::ExecutionPreference preference,
94 const android::sp<V1_0::IPreparedModelCallback>& cb) override
95 {
96 ALOGV("hal_1_3::ArmnnDriver::prepareModel_1_1()");
97
98 if (!(preference == ExecutionPreference::LOW_POWER ||
99 preference == ExecutionPreference::FAST_SINGLE_ANSWER ||
100 preference == ExecutionPreference::SUSTAINED_SPEED))
101 {
102 ALOGV("hal_1_3::ArmnnDriver::prepareModel_1_1: Invalid execution preference");
103 cb->notify(V1_0::ErrorStatus::INVALID_ARGUMENT, nullptr);
104 return V1_0::ErrorStatus::INVALID_ARGUMENT;
105 }
106
107 return armnn_driver::ArmnnDriverImpl<hal_1_1::HalPolicy>::prepareModel(m_Runtime,
108 m_ClTunedParameters,
109 m_Options,
110 model,
111 cb,
112 model.relaxComputationFloat32toFloat16
113 && m_Options.GetFp16Enabled());
114 }
115
116 Return<void> getCapabilities_1_2(getCapabilities_1_2_cb cb)
117 {
118 ALOGV("hal_1_3::ArmnnDriver::getCapabilities()");
119
120 return hal_1_2::ArmnnDriverImpl::getCapabilities_1_2(m_Runtime, cb);
121 }
122
123 Return<void> getSupportedOperations_1_2(const V1_2::Model& model,
124 getSupportedOperations_1_2_cb cb)
125 {
126 ALOGV("hal_1_3::ArmnnDriver::getSupportedOperations()");
127
128 return armnn_driver::ArmnnDriverImpl<hal_1_2::HalPolicy>::getSupportedOperations(m_Runtime,
129 m_Options,
130 model,
131 cb);
132 }
133
134 Return<V1_0::ErrorStatus> prepareModel_1_2(const V1_2::Model& model, V1_1::ExecutionPreference preference,
135 const android::hardware::hidl_vec<android::hardware::hidl_handle>&,
136 const android::hardware::hidl_vec<android::hardware::hidl_handle>&, const HidlToken&,
137 const android::sp<V1_2::IPreparedModelCallback>& cb)
138 {
139 ALOGV("hal_1_3::ArmnnDriver::prepareModel_1_2()");
140
141 if (!(preference == ExecutionPreference::LOW_POWER ||
142 preference == ExecutionPreference::FAST_SINGLE_ANSWER ||
143 preference == ExecutionPreference::SUSTAINED_SPEED))
144 {
145 ALOGV("hal_1_3::ArmnnDriver::prepareModel_1_2: Invalid execution preference");
146 cb->notify(V1_0::ErrorStatus::INVALID_ARGUMENT, nullptr);
147 return V1_0::ErrorStatus::INVALID_ARGUMENT;
148 }
149
150 return hal_1_2::ArmnnDriverImpl::prepareArmnnModel_1_2(m_Runtime,
151 m_ClTunedParameters,
152 m_Options,
153 model,
154 cb,
155 model.relaxComputationFloat32toFloat16
156 && m_Options.GetFp16Enabled());
157 }
158
159 Return<void> getCapabilities_1_3(getCapabilities_1_3_cb cb)
160 {
161 ALOGV("hal_1_3::ArmnnDriver::getCapabilities()");
162
163 return hal_1_3::ArmnnDriverImpl::getCapabilities_1_3(m_Runtime, cb);
164 }
165
166 Return<void> getSupportedOperations_1_3(const V1_3::Model& model,
167 getSupportedOperations_1_3_cb cb)
168 {
169 ALOGV("hal_1_3::ArmnnDriver::getSupportedOperations()");
170
171 return armnn_driver::ArmnnDriverImpl<hal_1_3::HalPolicy>::getSupportedOperations(m_Runtime,
172 m_Options,
173 model,
174 cb);
175 }
176
177 Return<V1_3::ErrorStatus> prepareModel_1_3(const V1_3::Model& model,
178 V1_1::ExecutionPreference preference,
179 V1_3::Priority priority,
180 const V1_3::OptionalTimePoint&,
181 const android::hardware::hidl_vec<android::hardware::hidl_handle>&,
182 const android::hardware::hidl_vec<android::hardware::hidl_handle>&,
183 const HidlToken&,
184 const android::sp<V1_3::IPreparedModelCallback>& cb)
185 {
186 ALOGV("hal_1_3::ArmnnDriver::prepareModel_1_3()");
187
188 if (!(preference == ExecutionPreference::LOW_POWER ||
189 preference == ExecutionPreference::FAST_SINGLE_ANSWER ||
190 preference == ExecutionPreference::SUSTAINED_SPEED))
191 {
192 ALOGV("hal_1_3::ArmnnDriver::prepareModel_1_3: Invalid execution preference");
193 cb->notify_1_3(V1_3::ErrorStatus::INVALID_ARGUMENT, nullptr);
194 return V1_3::ErrorStatus::INVALID_ARGUMENT;
195 }
196
197 if (!android::nn::validatePriority(priority)) {
198 cb->notify_1_3(V1_3::ErrorStatus::INVALID_ARGUMENT, nullptr);
199 return V1_3::ErrorStatus::INVALID_ARGUMENT;
200 }
201
202
203 return ArmnnDriverImpl::prepareArmnnModel_1_3(m_Runtime,
204 m_ClTunedParameters,
205 m_Options,
206 model,
207 cb,
208 model.relaxComputationFloat32toFloat16
209 && m_Options.GetFp16Enabled());
210 }
211
212 Return<void> getSupportedExtensions(getSupportedExtensions_cb cb)
213 {
214 ALOGV("hal_1_3::ArmnnDriver::getSupportedExtensions()");
215 cb(V1_0::ErrorStatus::NONE, {/* No extensions. */});
216 return Void();
217 }
218
219 Return<void> getNumberOfCacheFilesNeeded(getNumberOfCacheFilesNeeded_cb cb)
220 {
221 ALOGV("hal_1_3::ArmnnDriver::getSupportedExtensions()");
222
223 // Set both numbers to be 0 for cache not supported.
224 cb(V1_0::ErrorStatus::NONE, 0, 0);
225 return Void();
226 }
227
228 Return<DeviceStatus> getStatus() override
229 {
230 ALOGV("hal_1_3::ArmnnDriver::getStatus()");
231
232 return armnn_driver::ArmnnDriverImpl<hal_1_3::HalPolicy>::getStatus();
233 }
234
235 Return<void> getVersionString(getVersionString_cb cb)
236 {
237 ALOGV("hal_1_3::ArmnnDriver::getVersionString()");
238
239 cb(V1_0::ErrorStatus::NONE, "ArmNN");
240 return Void();
241 }
242
243 Return<void> getType(getType_cb cb)
244 {
245 ALOGV("hal_1_3::ArmnnDriver::getType()");
246
247 cb(V1_0::ErrorStatus::NONE, V1_2::DeviceType::CPU);
248 return Void();
249 }
250
251 Return<V1_0::ErrorStatus> prepareModelFromCache(
252 const android::hardware::hidl_vec<android::hardware::hidl_handle>&,
253 const android::hardware::hidl_vec<android::hardware::hidl_handle>&,
254 const HidlToken&,
255 const sp<V1_2::IPreparedModelCallback>& callback)
256 {
257 ALOGV("hal_1_3::ArmnnDriver::prepareModelFromCache()");
258 callback->notify_1_2(V1_0::ErrorStatus::GENERAL_FAILURE, nullptr);
259 return V1_0::ErrorStatus::GENERAL_FAILURE;
260 }
261
262 Return<ErrorStatus> prepareModelFromCache_1_3(
263 V1_3::Priority,
264 const V1_3::OptionalTimePoint&,
265 const android::hardware::hidl_vec<android::hardware::hidl_handle>&,
266 const android::hardware::hidl_vec<android::hardware::hidl_handle>&,
267 const HidlToken&,
268 const sp<V1_3::IPreparedModelCallback>& callback)
269 {
270 ALOGV("hal_1_3::ArmnnDriver::prepareModelFromCache()");
271 callback->notify_1_3(ErrorStatus::GENERAL_FAILURE, nullptr);
272 return ErrorStatus::GENERAL_FAILURE;
273 }
274
275 Return<void> supportsDeadlines(supportsDeadlines_cb cb) {
276 // Set both numbers to be false for deadlines not supported.
277 cb(/*prepareModelDeadline=*/false, /*executionDeadline=*/false);
278 return Void();
279 }
280
281 Return<void> allocate(const V1_3::BufferDesc& /*desc*/,
282 const hidl_vec<sp<V1_3::IPreparedModel>>& /*preparedModels*/,
283 const hidl_vec<V1_3::BufferRole>& /*inputRoles*/,
284 const hidl_vec<V1_3::BufferRole>& /*outputRoles*/,
285 allocate_cb cb) {
286 ALOGV("hal_1_3::ArmnnDriver::allocate()");
287 cb(ErrorStatus::GENERAL_FAILURE, nullptr, 0);
288 return Void();
289 }
290
291};
292
293} // namespace hal_1_3
294} // namespace armnn_driver