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 "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 29namespace android { 30namespace nn { 31namespace sample_driver { 32 33class SampleDriverFloatSlow : public SampleDriver { 34public: 35 SampleDriverFloatSlow() : SampleDriver("sample-float-slow") {} 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 41Return<void> SampleDriverFloatSlow::getCapabilities_1_1(getCapabilities_1_1_cb cb) { 42 android::nn::initVLogMask(); 43 VLOG(DRIVER) << "getCapabilities()"; 44 Capabilities capabilities = {.float32Performance = {.execTime = 1.3f, .powerUsage = 0.7f}, 45 .quantized8Performance = {.execTime = 1.0f, .powerUsage = 1.0f}, 46 .relaxedFloat32toFloat16Performance = 47 {.execTime = 1.2f, .powerUsage = 0.6f}}; 48 cb(ErrorStatus::NONE, capabilities); 49 return Void(); 50} 51 52Return<void> SampleDriverFloatSlow::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); 58 for (size_t i = 0; i < count; i++) { 59 const Operation& operation = model.operations[i]; 60 if (operation.inputs.size() > 0) { 61 const Operand& firstOperand = model.operands[operation.inputs[0]]; 62 supported[i] = firstOperand.type == OperandType::TENSOR_FLOAT32; 63 } 64 } 65 cb(ErrorStatus::NONE, supported); 66 } else { 67 std::vector<bool> supported; 68 cb(ErrorStatus::INVALID_ARGUMENT, supported); 69 } 70 return Void(); 71} 72 73} // namespace sample_driver 74} // namespace nn 75} // namespace android 76 77using android::nn::sample_driver::SampleDriverFloatSlow; 78using android::sp; 79 80int main() { 81 sp<SampleDriverFloatSlow> driver(new SampleDriverFloatSlow()); 82 return driver->run(); 83} 84