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 "SampleDriverFloatSlow"
18
19 #include <android-base/logging.h>
20 #include <hidl/LegacySupport.h>
21
22 #include <thread>
23 #include <vector>
24
25 #include "HalInterfaces.h"
26 #include "SampleDriverPartial.h"
27 #include "Utils.h"
28 #include "ValidateHal.h"
29
30 namespace android {
31 namespace nn {
32 namespace sample_driver {
33
34 using namespace hal;
35
36 class SampleDriverFloatSlow : public SampleDriverPartial {
37 public:
SampleDriverFloatSlow()38 SampleDriverFloatSlow() : SampleDriverPartial("nnapi-sample_float_slow") {}
39 Return<void> getCapabilities_1_3(getCapabilities_1_3_cb cb) override;
40
41 private:
42 std::vector<bool> getSupportedOperationsImpl(const V1_3::Model& model) const override;
43 };
44
getCapabilities_1_3(getCapabilities_1_3_cb cb)45 Return<void> SampleDriverFloatSlow::getCapabilities_1_3(getCapabilities_1_3_cb cb) {
46 android::nn::initVLogMask();
47 VLOG(DRIVER) << "getCapabilities()";
48
49 Capabilities capabilities = {
50 .relaxedFloat32toFloat16PerformanceScalar = {.execTime = 1.2f, .powerUsage = 0.6f},
51 .relaxedFloat32toFloat16PerformanceTensor = {.execTime = 1.2f, .powerUsage = 0.6f},
52 .operandPerformance = nonExtensionOperandPerformance<HalVersion::V1_3>({1.0f, 1.0f}),
53 .ifPerformance = {.execTime = 1.0f, .powerUsage = 1.0f},
54 .whilePerformance = {.execTime = 1.0f, .powerUsage = 1.0f}};
55 update(&capabilities.operandPerformance, OperandType::TENSOR_FLOAT32,
56 {.execTime = 1.3f, .powerUsage = 0.7f});
57 update(&capabilities.operandPerformance, OperandType::FLOAT32,
58 {.execTime = 1.3f, .powerUsage = 0.7f});
59
60 cb(ErrorStatus::NONE, capabilities);
61 return Void();
62 }
63
getSupportedOperationsImpl(const V1_3::Model & model) const64 std::vector<bool> SampleDriverFloatSlow::getSupportedOperationsImpl(
65 const V1_3::Model& model) const {
66 const size_t count = model.main.operations.size();
67 std::vector<bool> supported(count);
68 for (size_t i = 0; i < count; i++) {
69 const Operation& operation = model.main.operations[i];
70 if (operation.inputs.size() > 0) {
71 const Operand& firstOperand = model.main.operands[operation.inputs[0]];
72 supported[i] = firstOperand.type == OperandType::TENSOR_FLOAT32;
73 }
74 }
75 return supported;
76 }
77
78 } // namespace sample_driver
79 } // namespace nn
80 } // namespace android
81
82 using android::sp;
83 using android::nn::sample_driver::SampleDriverFloatSlow;
84
main()85 int main() {
86 sp<SampleDriverFloatSlow> driver(new SampleDriverFloatSlow());
87 return driver->run();
88 }
89