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
29 namespace android {
30 namespace nn {
31 namespace sample_driver {
32
33 class SampleDriverAll : public SampleDriver {
34 public:
SampleDriverAll()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
getCapabilities_1_1(getCapabilities_1_1_cb cb)41 Return<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
getSupportedOperations_1_1(const V1_1::Model & model,getSupportedOperations_1_1_cb cb)52 Return<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
70 using android::nn::sample_driver::SampleDriverAll;
71 using android::sp;
72
main()73 int main() {
74 sp<SampleDriverAll> driver(new SampleDriverAll());
75 return driver->run();
76 }
77