SampleDriverAll.cpp revision 47b5916d2c4c5d0e0d4f6b43075a23449c16345b
1/*
2 * Copyright (C) 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#define LOG_TAG "SampleDriverAll"
18
19#include "SampleDriver.h"
20
21#include "HalInterfaces.h"
22#include "Utils.h"
23#include "ValidateHal.h"
24
25#include <android-base/logging.h>
26#include <hidl/LegacySupport.h>
27#include <thread>
28
29namespace android {
30namespace nn {
31namespace sample_driver {
32
33class SampleDriverAll : public SampleDriver {
34public:
35    SampleDriverAll() : SampleDriver("sample-all") {}
36    Return<void> getCapabilities_1_1(getCapabilities_1_1_cb cb) override;
37    Return<void> getSupportedOperations_1_1(const V1_1::Model& model,
38                                            getSupportedOperations_1_1_cb cb) override;
39};
40
41Return<void> SampleDriverAll::getCapabilities_1_1(getCapabilities_1_1_cb cb) {
42    android::nn::initVLogMask();
43    VLOG(DRIVER) << "getCapabilities()";
44    Capabilities capabilities = {.float32Performance = {.execTime = 1.1f, .powerUsage = 1.1f},
45                                 .quantized8Performance = {.execTime = 1.1f, .powerUsage = 1.1f},
46                                 .relaxedFloat32toFloat16Performance =
47                                     {.execTime = 1.1f, .powerUsage = 1.1f}};
48    cb(ErrorStatus::NONE, capabilities);
49    return Void();
50}
51
52Return<void> SampleDriverAll::getSupportedOperations_1_1(const V1_1::Model& model,
53                                                         getSupportedOperations_1_1_cb cb) {
54    VLOG(DRIVER) << "getSupportedOperations()";
55    if (validateModel(model)) {
56        const size_t count = model.operations.size();
57        std::vector<bool> supported(count, true);
58        cb(ErrorStatus::NONE, supported);
59    } else {
60        std::vector<bool> supported;
61        cb(ErrorStatus::INVALID_ARGUMENT, supported);
62    }
63    return Void();
64}
65
66} // namespace sample_driver
67} // namespace nn
68} // namespace android
69
70using android::nn::sample_driver::SampleDriverAll;
71using android::sp;
72
73int main() {
74    sp<SampleDriverAll> driver(new SampleDriverAll());
75    return driver->run();
76}
77