This repository has been archived by the owner on Jan 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathdevice.cpp
executable file
·239 lines (194 loc) · 6.12 KB
/
device.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
#include <algorithm>
#include <memory.h>
#include <string.h>
#include <hidl/LegacySupport.h>
#include <thread>
#include "device.h"
#include "prepare_model.h"
#include "executor_manager.h"
#include "ValidateHal.h"
NAME_SPACE_BEGIN
using namespace android::nn;
Return<void> Device::getCapabilities(getCapabilities_cb cb)
{
NN_GPU_ENTRY();
V1_0::Capabilities capabilities;
ExecutorManager::getCapabilities(capabilities);
cb(ErrorStatus::NONE, capabilities);
NN_GPU_EXIT();
return Void();
}
Return<void> Device::getCapabilities_1_1(getCapabilities_1_1_cb cb)
{
NN_GPU_ENTRY();
V1_0::Capabilities capabilities;
ExecutorManager::getCapabilities(capabilities);
cb(ErrorStatus::NONE, convertToV1_1(capabilities));
NN_GPU_EXIT();
return Void();
}
Return<void> Device::getCapabilities_1_2(getCapabilities_1_2_cb cb)
{
NN_GPU_ENTRY();
V1_0::Capabilities capabilities;
ExecutorManager::getCapabilities(capabilities);
cb(ErrorStatus::NONE, convertToV1_2(capabilities));
NN_GPU_EXIT();
return Void();
}
Return<void> Device::getSupportedOperations(const V1_0::Model& model,
getSupportedOperations_cb cb)
{
UNUSED(model);
UNUSED(cb);
NN_GPU_ENTRY();
NN_GPU_EXIT();
return Void();
}
Return<void> Device::getSupportedOperations_1_1(const V1_1::Model& model,
getSupportedOperations_1_1_cb cb)
{
UNUSED(model);
UNUSED(cb);
NN_GPU_ENTRY();
NN_GPU_EXIT();
return Void();
}
Return<void> Device::getSupportedOperations_1_2(const V1_2::Model& model,
getSupportedOperations_1_2_cb cb)
{
NN_GPU_ENTRY();
if (!validateModel(model))
{
std::vector<bool> supported;
cb(ErrorStatus::INVALID_ARGUMENT, supported);
return Void();
}
std::vector<bool> supported = ExecutorManager::getSupportedOperations(model);
cb(ErrorStatus::NONE, supported);
NN_GPU_EXIT();
return Void();
}
Return<ErrorStatus> Device::prepareModel(const V1_0::Model& model,
const sp<V1_0::IPreparedModelCallback>& callback)
{
UNUSED(model);
UNUSED(callback);
NN_GPU_ENTRY();
NN_GPU_EXIT();
return ErrorStatus::NONE;
}
Return<ErrorStatus> Device::prepareModel_1_1(const V1_1::Model& model,
ExecutionPreference preference,
const sp<V1_0::IPreparedModelCallback>& callback)
{
NN_GPU_ENTRY();
if (callback.get() == nullptr)
{
LOGE("invalid callback passed to prepareModel");
return ErrorStatus::INVALID_ARGUMENT;
}
if (!validateModel(model) || !validateExecutionPreference(preference))
{
callback->notify(ErrorStatus::INVALID_ARGUMENT, nullptr);
return ErrorStatus::INVALID_ARGUMENT;
}
sp<PreparedModel> preparedModel = new PreparedModel(convertToV1_2(model));
if (!preparedModel->initialize())
{
callback->notify(ErrorStatus::INVALID_ARGUMENT, nullptr);
return ErrorStatus::INVALID_ARGUMENT;
}
callback->notify(ErrorStatus::NONE, preparedModel);
NN_GPU_EXIT();
return ErrorStatus::NONE;
}
Return<ErrorStatus> Device::prepareModel_1_2(const V1_2::Model& model,
ExecutionPreference preference,
const hidl_vec<hidl_handle>& modelCache,
const hidl_vec<hidl_handle>& dataCache,
const HidlToken& token,
const sp<V1_2::IPreparedModelCallback>& callback)
{
UNUSED(modelCache);
UNUSED(dataCache);
UNUSED(token);
NN_GPU_ENTRY();
if (callback.get() == nullptr)
{
LOGE("invalid callback passed to prepareModel");
return ErrorStatus::INVALID_ARGUMENT;
}
if (!validateModel(model) || !validateExecutionPreference(preference))
{
callback->notify_1_2(ErrorStatus::INVALID_ARGUMENT, nullptr);
return ErrorStatus::INVALID_ARGUMENT;
}
sp<PreparedModel> preparedModel = new PreparedModel(model);
if (!preparedModel->initialize())
{
callback->notify_1_2(ErrorStatus::INVALID_ARGUMENT, nullptr);
return ErrorStatus::INVALID_ARGUMENT;
}
callback->notify_1_2(ErrorStatus::NONE, preparedModel);
NN_GPU_EXIT();
return ErrorStatus::NONE;
}
Return<DeviceStatus> Device::getStatus()
{
NN_GPU_CALL();
return DeviceStatus::AVAILABLE;
}
Return<void> Device::getVersionString(getVersionString_cb cb)
{
NN_GPU_CALL();
cb(ErrorStatus::NONE, "for gpgpu");
return Void();
}
Return<void> Device::getType(getType_cb cb)
{
UNUSED(cb);
NN_GPU_CALL();
return Void();
}
Return<void> Device::getSupportedExtensions(getSupportedExtensions_cb cb)
{
NN_GPU_CALL();
cb(ErrorStatus::NONE, {/* No extensions. */});
return Void();
}
Return<void> Device::getNumberOfCacheFilesNeeded(getNumberOfCacheFilesNeeded_cb cb)
{
NN_GPU_CALL();
cb(ErrorStatus::NONE, /*numModelCache=*/0, /*numDataCache=*/0);
return Void();
}
Return<ErrorStatus> Device::prepareModelFromCache(const hidl_vec<hidl_handle>&,
const hidl_vec<hidl_handle>&,
const HidlToken&,
const sp<V1_2::IPreparedModelCallback>& callback)
{
NN_GPU_CALL();
callback->notify_1_2(ErrorStatus::GENERAL_FAILURE, nullptr);
return ErrorStatus::GENERAL_FAILURE;
}
int Device::run()
{
NN_GPU_CALL();
if (!ExecutorManager::initPerProcess())
{
LOGE("Unable to do ExecutorManager::initPerProcess, service exited!");
return 1;
}
android::hardware::configureRpcThreadpool(4, true);
if (registerAsService(mName) != android::OK)
{
LOGE("Could not register service");
return 1;
}
android::hardware::joinRpcThreadpool();
LOGE("Service exited!");
ExecutorManager::deinitPerProcess();
return 1;
}
NAME_SPACE_STOP