blob: b6b55fae151973322d4af8783f2247e8fba29b7d [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
Narumol Prangnawaratcad4e912020-06-02 12:07:43 +0100209 && m_Options.GetFp16Enabled(),
210 priority);
Kevin May42477c12020-03-26 13:34:14 +0000211 }
212
213 Return<void> getSupportedExtensions(getSupportedExtensions_cb cb)
214 {
215 ALOGV("hal_1_3::ArmnnDriver::getSupportedExtensions()");
216 cb(V1_0::ErrorStatus::NONE, {/* No extensions. */});
217 return Void();
218 }
219
220 Return<void> getNumberOfCacheFilesNeeded(getNumberOfCacheFilesNeeded_cb cb)
221 {
222 ALOGV("hal_1_3::ArmnnDriver::getSupportedExtensions()");
223
224 // Set both numbers to be 0 for cache not supported.
225 cb(V1_0::ErrorStatus::NONE, 0, 0);
226 return Void();
227 }
228
229 Return<DeviceStatus> getStatus() override
230 {
231 ALOGV("hal_1_3::ArmnnDriver::getStatus()");
232
233 return armnn_driver::ArmnnDriverImpl<hal_1_3::HalPolicy>::getStatus();
234 }
235
236 Return<void> getVersionString(getVersionString_cb cb)
237 {
238 ALOGV("hal_1_3::ArmnnDriver::getVersionString()");
239
240 cb(V1_0::ErrorStatus::NONE, "ArmNN");
241 return Void();
242 }
243
244 Return<void> getType(getType_cb cb)
245 {
246 ALOGV("hal_1_3::ArmnnDriver::getType()");
247
248 cb(V1_0::ErrorStatus::NONE, V1_2::DeviceType::CPU);
249 return Void();
250 }
251
252 Return<V1_0::ErrorStatus> prepareModelFromCache(
253 const android::hardware::hidl_vec<android::hardware::hidl_handle>&,
254 const android::hardware::hidl_vec<android::hardware::hidl_handle>&,
255 const HidlToken&,
256 const sp<V1_2::IPreparedModelCallback>& callback)
257 {
258 ALOGV("hal_1_3::ArmnnDriver::prepareModelFromCache()");
259 callback->notify_1_2(V1_0::ErrorStatus::GENERAL_FAILURE, nullptr);
260 return V1_0::ErrorStatus::GENERAL_FAILURE;
261 }
262
263 Return<ErrorStatus> prepareModelFromCache_1_3(
Kevin May42477c12020-03-26 13:34:14 +0000264 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
Kevin May42477c12020-03-26 13:34:14 +0000275 Return<void> allocate(const V1_3::BufferDesc& /*desc*/,
276 const hidl_vec<sp<V1_3::IPreparedModel>>& /*preparedModels*/,
277 const hidl_vec<V1_3::BufferRole>& /*inputRoles*/,
278 const hidl_vec<V1_3::BufferRole>& /*outputRoles*/,
279 allocate_cb cb) {
280 ALOGV("hal_1_3::ArmnnDriver::allocate()");
281 cb(ErrorStatus::GENERAL_FAILURE, nullptr, 0);
282 return Void();
283 }
284
285};
286
287} // namespace hal_1_3
288} // namespace armnn_driver