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 "SampleDriverFloatFast"
18
19#include "SampleDriver.h"
20
21#include "HalInterfaces.h"
22#include "Utils.h"
23
24#include <android-base/logging.h>
25#include <hidl/LegacySupport.h>
26#include <thread>
27
28namespace android {
29namespace nn {
30namespace sample_driver {
31
32class SampleDriverFloatFast : public SampleDriver {
33public:
34    SampleDriverFloatFast() : SampleDriver("sample-float-fast") {}
35    Return<void> getCapabilities(getCapabilities_cb _hidl_cb) override;
36    Return<void> getSupportedOperations(const Model& model, getSupportedOperations_cb cb) override;
37};
38
39Return<void> SampleDriverFloatFast::getCapabilities(getCapabilities_cb cb) {
40    android::nn::initVLogMask();
41    VLOG(DRIVER) << "getCapabilities()";
42    Capabilities capabilities = {.float32Performance = {.execTime = 0.8f, .powerUsage = 1.2f},
43                                 .quantized8Performance = {.execTime = 1.0f, .powerUsage = 1.0f}};
44    cb(ErrorStatus::NONE, capabilities);
45    return Void();
46}
47
48Return<void> SampleDriverFloatFast::getSupportedOperations(const Model& model,
49                                                           getSupportedOperations_cb cb) {
50    VLOG(DRIVER) << "getSupportedOperations()";
51    if (validateModel(model)) {
52        const size_t count = model.operations.size();
53        std::vector<bool> supported(count);
54        for (size_t i = 0; i < count; i++) {
55            const Operation& operation = model.operations[i];
56            if (operation.inputs.size() > 0) {
57                const Operand& firstOperand = model.operands[operation.inputs[0]];
58                supported[i] = firstOperand.type == OperandType::TENSOR_FLOAT32;
59            }
60        }
61        cb(ErrorStatus::NONE, supported);
62    } else {
63        std::vector<bool> supported;
64        cb(ErrorStatus::INVALID_ARGUMENT, supported);
65    }
66    return Void();
67}
68
69} // namespace sample_driver
70} // namespace nn
71} // namespace android
72
73using android::nn::sample_driver::SampleDriverFloatFast;
74using android::sp;
75
76int main() {
77    sp<SampleDriverFloatFast> driver(new SampleDriverFloatFast());
78    return driver->run();
79}
80