1 /*
2 * Copyright (C) 2021 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 #include <nnapi/hal/aidl/Conversions.h>
22
23 #include <memory>
24 #include <thread>
25 #include <vector>
26
27 #include "AidlHalUtils.h"
28 #include "SampleDriverPartial.h"
29
30 namespace android {
31 namespace nn {
32 namespace sample_driver {
33
34 class SampleDriverFloatSlow : public SampleDriverPartial {
35 public:
SampleDriverFloatSlow()36 SampleDriverFloatSlow() : SampleDriverPartial("nnapi-sample_float_slow") {}
37 ndk::ScopedAStatus getCapabilities(aidl_hal::Capabilities* capabilities) override;
38
39 private:
40 std::vector<bool> getSupportedOperationsImpl(const Model& model) const override;
41 };
42
getCapabilities(aidl_hal::Capabilities * capabilities)43 ndk::ScopedAStatus SampleDriverFloatSlow::getCapabilities(aidl_hal::Capabilities* capabilities) {
44 android::nn::initVLogMask();
45 VLOG(DRIVER) << "getCapabilities()";
46
47 *capabilities = {
48 .relaxedFloat32toFloat16PerformanceScalar = {.execTime = 1.2f, .powerUsage = 0.6f},
49 .relaxedFloat32toFloat16PerformanceTensor = {.execTime = 1.2f, .powerUsage = 0.6f},
50 .operandPerformance = nonExtensionOperandPerformance({1.0f, 1.0f}),
51 .ifPerformance = {.execTime = 1.0f, .powerUsage = 1.0f},
52 .whilePerformance = {.execTime = 1.0f, .powerUsage = 1.0f}};
53 update(&capabilities->operandPerformance, aidl_hal::OperandType::TENSOR_FLOAT32,
54 {.execTime = 1.3f, .powerUsage = 0.7f});
55 update(&capabilities->operandPerformance, aidl_hal::OperandType::FLOAT32,
56 {.execTime = 1.3f, .powerUsage = 0.7f});
57
58 return ndk::ScopedAStatus::ok();
59 }
60
getSupportedOperationsImpl(const Model & model) const61 std::vector<bool> SampleDriverFloatSlow::getSupportedOperationsImpl(const Model& model) const {
62 const size_t count = model.main.operations.size();
63 std::vector<bool> supported(count);
64 for (size_t i = 0; i < count; i++) {
65 const Operation& operation = model.main.operations[i];
66 if (!isExtensionOperationType(operation.type) && operation.inputs.size() > 0) {
67 const Operand& firstOperand = model.main.operands[operation.inputs[0]];
68 supported[i] = firstOperand.type == OperandType::TENSOR_FLOAT32;
69 }
70 }
71 return supported;
72 }
73
74 } // namespace sample_driver
75 } // namespace nn
76 } // namespace android
77
78 using android::nn::sample_driver::SampleDriverFloatSlow;
79
main()80 int main() {
81 std::shared_ptr<SampleDriverFloatSlow> driver =
82 ndk::SharedRefBase::make<SampleDriverFloatSlow>();
83 return driver->run();
84 }
85