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 #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 SampleDriverFloatFast : public SampleDriver { 34 public: 35 SampleDriverFloatFast() : SampleDriver("sample-float-fast") {} 36 Return<void> getCapabilities_1_2(getCapabilities_1_2_cb cb) override; 37 Return<void> getSupportedOperations_1_2(const V1_2::Model& model, 38 getSupportedOperations_1_2_cb cb) override; 39 }; 40 41 Return<void> SampleDriverFloatFast::getCapabilities_1_2(getCapabilities_1_2_cb cb) { 42 android::nn::initVLogMask(); 43 VLOG(DRIVER) << "getCapabilities()"; 44 45 Capabilities capabilities = { 46 .relaxedFloat32toFloat16PerformanceScalar = {.execTime = 0.7f, .powerUsage = 1.1f}, 47 .relaxedFloat32toFloat16PerformanceTensor = {.execTime = 0.7f, .powerUsage = 1.1f}, 48 .operandPerformance = nonExtensionOperandPerformance({1.0f, 1.0f})}; 49 update(&capabilities.operandPerformance, OperandType::TENSOR_FLOAT32, 50 {.execTime = 0.8f, .powerUsage = 1.2f}); 51 update(&capabilities.operandPerformance, OperandType::FLOAT32, 52 {.execTime = 0.8f, .powerUsage = 1.2f}); 53 54 cb(ErrorStatus::NONE, capabilities); 55 return Void(); 56 } 57 58 Return<void> SampleDriverFloatFast::getSupportedOperations_1_2(const V1_2::Model& model, 59 getSupportedOperations_1_2_cb cb) { 60 VLOG(DRIVER) << "getSupportedOperations()"; 61 if (validateModel(model)) { 62 const size_t count = model.operations.size(); 63 std::vector<bool> supported(count); 64 for (size_t i = 0; i < count; i++) { 65 const Operation& operation = model.operations[i]; 66 if (operation.inputs.size() > 0) { 67 const Operand& firstOperand = model.operands[operation.inputs[0]]; 68 supported[i] = firstOperand.type == OperandType::TENSOR_FLOAT32; 69 } 70 } 71 cb(ErrorStatus::NONE, supported); 72 } else { 73 std::vector<bool> supported; 74 cb(ErrorStatus::INVALID_ARGUMENT, supported); 75 } 76 return Void(); 77 } 78 79 } // namespace sample_driver 80 } // namespace nn 81 } // namespace android 82 83 using android::nn::sample_driver::SampleDriverFloatFast; 84 using android::sp; 85 86 int main() { 87 sp<SampleDriverFloatFast> driver(new SampleDriverFloatFast()); 88 return driver->run(); 89 } 90