• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "SampleDriverMinimal"
18 
19 #include "SampleDriver.h"
20 
21 #include "HalInterfaces.h"
22 #include "NeuralNetworksOEM.h"
23 #include "Utils.h"
24 #include "ValidateHal.h"
25 
26 #include <android-base/logging.h>
27 #include <hidl/LegacySupport.h>
28 #include <thread>
29 
30 namespace android {
31 namespace nn {
32 namespace sample_driver {
33 
34 class SampleDriverMinimal : public SampleDriver {
35 public:
SampleDriverMinimal()36     SampleDriverMinimal() : SampleDriver("sample-minimal") {}
37     Return<void> getCapabilities_1_1(getCapabilities_1_1_cb cb) override;
38     Return<void> getSupportedOperations_1_1(const V1_1::Model& model,
39                                             getSupportedOperations_1_1_cb cb) override;
40 };
41 
getCapabilities_1_1(getCapabilities_1_1_cb cb)42 Return<void> SampleDriverMinimal::getCapabilities_1_1(getCapabilities_1_1_cb cb) {
43     android::nn::initVLogMask();
44     VLOG(DRIVER) << "getCapabilities()";
45     Capabilities capabilities = {.float32Performance = {.execTime = 0.4f, .powerUsage = 0.5f},
46                                  .quantized8Performance = {.execTime = 1.0f, .powerUsage = 1.0f},
47                                  .relaxedFloat32toFloat16Performance =
48                                      {.execTime = 0.4f, .powerUsage = 0.5f}};
49     cb(ErrorStatus::NONE, capabilities);
50     return Void();
51 }
52 
getSupportedOperations_1_1(const V1_1::Model & model,getSupportedOperations_1_1_cb cb)53 Return<void> SampleDriverMinimal::getSupportedOperations_1_1(const V1_1::Model& model,
54                                                              getSupportedOperations_1_1_cb cb) {
55     VLOG(DRIVER) << "getSupportedOperations()";
56     if (validateModel(model)) {
57         const size_t count = model.operations.size();
58         std::vector<bool> supported(count);
59         // Simulate supporting just a few ops
60         for (size_t i = 0; i < count; i++) {
61             supported[i] = false;
62             const Operation& operation = model.operations[i];
63             switch (operation.type) {
64                 case OperationType::ADD:
65                 case OperationType::CONCATENATION:
66                 case OperationType::CONV_2D: {
67                     const Operand& firstOperand = model.operands[operation.inputs[0]];
68                     if (firstOperand.type == OperandType::TENSOR_FLOAT32) {
69                         supported[i] = true;
70                     }
71                     break;
72                 }
73                 default:
74                     break;
75             }
76         }
77         cb(ErrorStatus::NONE, supported);
78     } else {
79         std::vector<bool> supported;
80         cb(ErrorStatus::INVALID_ARGUMENT, supported);
81     }
82     return Void();
83 }
84 
85 } // namespace sample_driver
86 } // namespace nn
87 } // namespace android
88 
89 using android::nn::sample_driver::SampleDriverMinimal;
90 using android::sp;
91 
main()92 int main() {
93     sp<SampleDriverMinimal> driver(new SampleDriverMinimal());
94     return driver->run();
95 }
96