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