From 44cfd848c1913f87a77c0427450dba93ba47fb94 Mon Sep 17 00:00:00 2001 From: Aron Virginas-Tar Date: Fri, 14 Jun 2019 15:45:03 +0100 Subject: IVGCVSW-3283 Add test for converting CONV2D and DEPTHWISE_CONV2D operators with dilation params Signed-off-by: Aron Virginas-Tar Change-Id: I51a9c71d7a277ab530ac35faea2e8a069c134f45 --- test/DriverTestHelpers.hpp | 127 +++++++++++++++++++++++++++++++-------------- 1 file changed, 88 insertions(+), 39 deletions(-) (limited to 'test/DriverTestHelpers.hpp') diff --git a/test/DriverTestHelpers.hpp b/test/DriverTestHelpers.hpp index 4a8f607e..428359e2 100644 --- a/test/DriverTestHelpers.hpp +++ b/test/DriverTestHelpers.hpp @@ -73,29 +73,58 @@ android::sp AddPoolAndGetData(uint32_t size, Request& request); void AddPoolAndSetData(uint32_t size, Request& request, const float* data); -template -void AddOperand(HalModel& model, const V1_0::Operand& op) +template +void AddOperand(HalModel& model, const HalOperand& op) { model.operands.resize(model.operands.size() + 1); model.operands[model.operands.size() - 1] = op; } -template +template void AddIntOperand(HalModel& model, int32_t value) { + using HalOperand = typename HalPolicy::Operand; + using HalOperandType = typename HalPolicy::OperandType; + using HalOperandLifeTime = typename HalPolicy::OperandLifeTime; + DataLocation location = {}; location.offset = model.operandValues.size(); location.length = sizeof(int32_t); - V1_0::Operand op = {}; - op.type = V1_0::OperandType::INT32; - op.dimensions = hidl_vec{}; - op.lifetime = V1_0::OperandLifeTime::CONSTANT_COPY; - op.location = location; + HalOperand op = {}; + op.type = HalOperandType::INT32; + op.dimensions = hidl_vec{}; + op.lifetime = HalOperandLifeTime::CONSTANT_COPY; + op.location = location; model.operandValues.resize(model.operandValues.size() + location.length); *reinterpret_cast(&model.operandValues[location.offset]) = value; + AddOperand(model, op); +} + +template +void AddBoolOperand(HalModel& model, bool value) +{ + using HalOperand = typename HalPolicy::Operand; + using HalOperandType = typename HalPolicy::OperandType; + using HalOperandLifeTime = typename HalPolicy::OperandLifeTime; + + DataLocation location = {}; + location.offset = model.operandValues.size(); + location.length = sizeof(uint8_t); + + HalOperand op = {}; + op.type = HalOperandType::BOOL; + op.dimensions = hidl_vec{}; + op.lifetime = HalOperandLifeTime::CONSTANT_COPY; + op.location = location; + + model.operandValues.resize(model.operandValues.size() + location.length); + *reinterpret_cast(&model.operandValues[location.offset]) = static_cast(value); + AddOperand(model, op); } @@ -108,13 +137,19 @@ OperandType TypeToOperandType(); template<> OperandType TypeToOperandType(); -template +template void AddTensorOperand(HalModel& model, const hidl_vec& dimensions, const T* values, - V1_0::OperandType operandType = V1_0::OperandType::TENSOR_FLOAT32, - V1_0::OperandLifeTime operandLifeTime = V1_0::OperandLifeTime::CONSTANT_COPY) + HalOperandType operandType = HalOperandType::TENSOR_FLOAT32, + HalOperandLifeTime operandLifeTime = HalOperandLifeTime::CONSTANT_COPY) { + using HalOperand = typename HalPolicy::Operand; + uint32_t totalElements = 1; for (uint32_t dim : dimensions) { @@ -124,16 +159,16 @@ void AddTensorOperand(HalModel& model, DataLocation location = {}; location.length = totalElements * sizeof(T); - if(operandLifeTime == V1_0::OperandLifeTime::CONSTANT_COPY) + if(operandLifeTime == HalOperandLifeTime::CONSTANT_COPY) { location.offset = model.operandValues.size(); } - V1_0::Operand op = {}; - op.type = operandType; - op.dimensions = dimensions; - op.lifetime = V1_0::OperandLifeTime::CONSTANT_COPY; - op.location = location; + HalOperand op = {}; + op.type = operandType; + op.dimensions = dimensions; + op.lifetime = HalOperandLifeTime::CONSTANT_COPY; + op.location = location; model.operandValues.resize(model.operandValues.size() + location.length); for (uint32_t i = 0; i < totalElements; i++) @@ -141,48 +176,62 @@ void AddTensorOperand(HalModel& model, *(reinterpret_cast(&model.operandValues[location.offset]) + i) = values[i]; } - AddOperand(model, op); + AddOperand(model, op); } -template +template void AddTensorOperand(HalModel& model, const hidl_vec& dimensions, const std::vector& values, - V1_0::OperandType operandType = V1_0::OperandType::TENSOR_FLOAT32, - V1_0::OperandLifeTime operandLifeTime = V1_0::OperandLifeTime::CONSTANT_COPY) + HalOperandType operandType = HalPolicy::OperandType::TENSOR_FLOAT32, + HalOperandLifeTime operandLifeTime = HalOperandLifeTime::CONSTANT_COPY) { - AddTensorOperand(model, dimensions, values.data(), operandType, operandLifeTime); + AddTensorOperand(model, dimensions, values.data(), operandType, operandLifeTime); } -template +template void AddInputOperand(HalModel& model, const hidl_vec& dimensions, - V1_0::OperandType operandType = V1_0::OperandType::TENSOR_FLOAT32) + HalOperandType operandType = HalOperandType::TENSOR_FLOAT32) { - V1_0::Operand op = {}; - op.type = operandType; - op.scale = operandType == V1_0::OperandType::TENSOR_QUANT8_ASYMM ? 1.f / 255.f : 0.f; - op.dimensions = dimensions; - op.lifetime = V1_0::OperandLifeTime::MODEL_INPUT; + using HalOperand = typename HalPolicy::Operand; + using HalOperandLifeTime = typename HalPolicy::OperandLifeTime; - AddOperand(model, op); + HalOperand op = {}; + op.type = operandType; + op.scale = operandType == HalOperandType::TENSOR_QUANT8_ASYMM ? 1.f / 255.f : 0.f; + op.dimensions = dimensions; + op.lifetime = HalOperandLifeTime::MODEL_INPUT; + + AddOperand(model, op); model.inputIndexes.resize(model.inputIndexes.size() + 1); model.inputIndexes[model.inputIndexes.size() - 1] = model.operands.size() - 1; } -template +template void AddOutputOperand(HalModel& model, const hidl_vec& dimensions, - V1_0::OperandType operandType = V1_0::OperandType::TENSOR_FLOAT32) + HalOperandType operandType = HalOperandType::TENSOR_FLOAT32) { - V1_0::Operand op = {}; - op.type = operandType; - op.scale = operandType == V1_0::OperandType::TENSOR_QUANT8_ASYMM ? 1.f / 255.f : 0.f; - op.dimensions = dimensions; - op.lifetime = V1_0::OperandLifeTime::MODEL_OUTPUT; + using HalOperand = typename HalPolicy::Operand; + using HalOperandLifeTime = typename HalPolicy::OperandLifeTime; - AddOperand(model, op); + HalOperand op = {}; + op.type = operandType; + op.scale = operandType == HalOperandType::TENSOR_QUANT8_ASYMM ? 1.f / 255.f : 0.f; + op.dimensions = dimensions; + op.lifetime = HalOperandLifeTime::MODEL_OUTPUT; + + AddOperand(model, op); model.outputIndexes.resize(model.outputIndexes.size() + 1); model.outputIndexes[model.outputIndexes.size() - 1] = model.operands.size() - 1; @@ -204,7 +253,7 @@ android::sp PrepareModelWithStatus(const V1_1::Model& mode template android::sp PrepareModel(const HalModel& model, - armnn_driver::ArmnnDriver& driver) + armnn_driver::ArmnnDriver& driver) { ErrorStatus prepareStatus = ErrorStatus::NONE; return PrepareModelWithStatus(model, driver, prepareStatus); -- cgit v1.2.1