aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin May <kevin.may@arm.com>2023-08-18 14:01:51 +0100
committerKevin May <kevin.may@arm.com>2023-08-22 15:38:44 +0100
commitf762b8391cdb6064fcca4c269fb582e5534bbc7f (patch)
tree6fd01833123e424aab9f469004d33ca8648be994
parent693c5adc14d1e2038e759ddffcb1d89cb77d0b71 (diff)
downloadandroid-nn-driver-f762b8391cdb6064fcca4c269fb582e5534bbc7f.tar.gz
IVGCVSW-7957 Fix weights checking when converting Conv2d/DepthwiseConv2d
* An Operand can only have NO_VALUE if it is an optional argument of an operation * Add a check to see if the operand is optional to IsWeightsValid Signed-off-by: Kevin May <kevin.may@arm.com> Change-Id: I6321934dbfa41dd2bd28d8871c135f3694d9674d
-rw-r--r--ConversionUtils_1_2.hpp23
1 files changed, 16 insertions, 7 deletions
diff --git a/ConversionUtils_1_2.hpp b/ConversionUtils_1_2.hpp
index 7a629e5a..e5840468 100644
--- a/ConversionUtils_1_2.hpp
+++ b/ConversionUtils_1_2.hpp
@@ -27,7 +27,8 @@ template<typename HalPolicy,
typename HalModel = typename HalPolicy::Model>
bool IsWeightsValid(const HalOperation& operation,
uint32_t inputIndex,
- const HalModel& model)
+ const HalModel& model,
+ const bool isOptional = true)
{
using HalOperand = typename HalPolicy::Operand;
using HalOperandLifeTime = typename HalPolicy::OperandLifeTime;
@@ -38,12 +39,19 @@ bool IsWeightsValid(const HalOperation& operation,
return false;
}
+ // If the operand is not an optional operand it cannot have a NO_VALUE lifetime
+ if (!isOptional && operand->lifetime == HalOperandLifeTime::NO_VALUE)
+ {
+ return false;
+ }
+
if (operand->lifetime != HalOperandLifeTime::CONSTANT_COPY
&& operand->lifetime != HalOperandLifeTime::CONSTANT_REFERENCE
&& operand->lifetime != HalOperandLifeTime::NO_VALUE)
{
return false;
}
+
return true;
}
@@ -415,11 +423,10 @@ bool ConvertConv2d_1_2(const HalOperation& operation, const HalModel& model, Con
// the DataLayout is NCHW
- if (!IsWeightsValid<HalPolicy>(operation, 1, model) && desc.m_DataLayout == DataLayout::NCHW)
+ if (!IsWeightsValid<HalPolicy>(operation, 1, model, false) && desc.m_DataLayout == DataLayout::NCHW)
{
return Fail("%s: Operation has unsupported weights HalOperandLifeTime", __func__);
}
-
LayerInputHandle weightsInput = (desc.m_DataLayout == DataLayout::NCHW) ?
ConvertToLayerInputHandle<HalPolicy>(operation, 1, model, data, OHWIToOIHW) :
ConvertToLayerInputHandle<HalPolicy>(operation, 1, model, data);
@@ -562,12 +569,14 @@ bool ConvertDepthwiseConv2d_1_2(const HalOperation& operation, const HalModel& m
const TensorInfo& outputInfo = GetTensorInfoForOperand(*output);
// ArmNN does not currently support non-fixed weights or bias
- // Find the shape of the weights tensor. In AndroidNN this will be [ 1, H, W, I * M ]
- const HalOperand* weightsOperand = GetInputOperand<HalPolicy>(operation, 1, model);
- if (!weightsOperand)
+ if (!IsWeightsValid<HalPolicy>(operation, 1, model, false))
{
- return Fail("%s: Could not read weights", __func__);
+ return Fail("%s: This Operation has unsupported weights HalOperandLifeTime", __func__);
}
+
+ // Find the shape of the weights tensor. In AndroidNN this will be [ 1, H, W, I * M ]
+ const HalOperand* weightsOperand = GetInputOperand<HalPolicy>(operation, 1, model);
+
if (weightsOperand->dimensions[0] != 1)
{
return Fail("%s: Invalid weights; for depthwise convolution, dimension 0 must be 1 but it is %i",