forked from projectceladon/nn_gpu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdevice.cpp
executable file
·84 lines (73 loc) · 2.15 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
#include <algorithm>
#include <memory.h>
#include <string.h>
#include <android/log.h>
#include <android-base/logging.h>
#include <hidl/LegacySupport.h>
#include <thread>
#include "device.h"
#include "prepare_model.h"
#include "executor_manager.h"
namespace android {
namespace hardware {
namespace neuralnetworks {
namespace V1_0 {
namespace implementation {
Return<void> Device::getCapabilities(getCapabilities_cb cb)
{
ALOGV("Device::getCapabilities");
Capabilities capabilities;
ExecutorManager::getCapabilities(capabilities);
cb(ErrorStatus::NONE, capabilities);
return Void();
}
Return<void> Device::getSupportedOperations(const Model& model,
getSupportedOperations_cb cb)
{
ALOGV("Device::getSupportedOperations");
std::vector<bool> supported = ExecutorManager::getSupportedOperations(model);
cb(ErrorStatus::NONE, supported);
return Void();
}
Return<ErrorStatus> Device::prepareModel(const Model& model,
const sp<IPreparedModelCallback>& callback)
{
ALOGV("Device::prepareModel");
sp<PreparedModel> preparedModel = new PreparedModel(model);
if (!preparedModel->initialize())
{
callback->notify(ErrorStatus::INVALID_ARGUMENT, nullptr);
return ErrorStatus::INVALID_ARGUMENT;
}
callback->notify(ErrorStatus::NONE, preparedModel);
return ErrorStatus::NONE;
}
Return<DeviceStatus> Device::getStatus()
{
ALOGV("Device::getStatus");
return DeviceStatus::AVAILABLE;
}
int Device::run()
{
ALOGV("Device::run");
if (!ExecutorManager::initPerProcess())
{
ALOGE("Unable to do ExecutorManager::initPerProcess, service exited!");
return 1;
}
android::hardware::configureRpcThreadpool(4, true);
if (registerAsService(mName) != android::OK)
{
ALOGE("Could not register service");
return 1;
}
android::hardware::joinRpcThreadpool();
ALOGE("Service exited!");
ExecutorManager::deinitPerProcess();
return 1;
}
}// namespace implementation
} // namespace V1_0
} // namespace neuralnetworks
} // namespace hardware
} // namespace android