forked from projectceladon/nn_gpu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
device.cpp
executable file
·96 lines (81 loc) · 2.34 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
#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 "validate.h"
NAME_SPACE_BEGIN
Return<void> Device::getCapabilities(getCapabilities_cb cb)
{
NN_GPU_ENTRY();
Capabilities capabilities;
ExecutorManager::getCapabilities(capabilities);
cb(ErrorStatus::NONE, capabilities);
NN_GPU_EXIT();
return Void();
}
Return<void> Device::getSupportedOperations(const Model& model,
getSupportedOperations_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 Model& model,
const sp<IPreparedModelCallback>& callback)
{
NN_GPU_ENTRY();
if (callback.get() == nullptr) {
LOGE("invalid callback passed to prepareModel");
return ErrorStatus::INVALID_ARGUMENT;
}
if (!validateModel(model)) {
callback->notify(ErrorStatus::INVALID_ARGUMENT, nullptr);
return ErrorStatus::INVALID_ARGUMENT;
}
sp<PreparedModel> preparedModel = new PreparedModel(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<DeviceStatus> Device::getStatus()
{
NN_GPU_CALL();
return DeviceStatus::AVAILABLE;
}
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