diff options
Diffstat (limited to 'src/armnn/layers')
65 files changed, 1431 insertions, 436 deletions
diff --git a/src/armnn/layers/AbsLayer.cpp b/src/armnn/layers/AbsLayer.cpp index 6858b364a6..67654ac8b6 100644 --- a/src/armnn/layers/AbsLayer.cpp +++ b/src/armnn/layers/AbsLayer.cpp @@ -1,5 +1,5 @@ // -// Copyright © 2017,2019-2023 Arm Ltd and Contributors. All rights reserved. +// Copyright © 2017,2019-2024 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // @@ -42,7 +42,12 @@ void AbsLayer::ValidateTensorShapesFromInputs() auto inferredShapes = InferOutputShapes({ GetInputSlot(0).GetTensorInfo().GetShape() }); - ARMNN_ASSERT(inferredShapes.size() == 1); + if (inferredShapes.size() != 1) + { + throw armnn::LayerValidationException("inferredShapes has " + + std::to_string(inferredShapes.size()) + + " elements - should only have 1."); + } ValidateAndCopyShape(outputShape, inferredShapes[0], m_ShapeInferenceMethod, "AbsLayer"); } @@ -52,4 +57,4 @@ void AbsLayer::ExecuteStrategy(IStrategy &strategy) const strategy.ExecuteStrategy(this, GetParameters(), {}, GeName()); } -} // namespace armnn
\ No newline at end of file +} // namespace armnn diff --git a/src/armnn/layers/ActivationLayer.cpp b/src/armnn/layers/ActivationLayer.cpp index fe4aaa766f..999415df4b 100644 --- a/src/armnn/layers/ActivationLayer.cpp +++ b/src/armnn/layers/ActivationLayer.cpp @@ -1,5 +1,5 @@ // -// Copyright © 2017-2023 Arm Ltd and Contributors. All rights reserved. +// Copyright © 2017-2024 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // #include "ActivationLayer.hpp" @@ -40,7 +40,12 @@ void ActivationLayer::ValidateTensorShapesFromInputs() auto inferredShapes = InferOutputShapes({ GetInputSlot(0).GetTensorInfo().GetShape() }); - ARMNN_ASSERT(inferredShapes.size() == 1); + if (inferredShapes.size() != 1) + { + throw armnn::LayerValidationException("inferredShapes has " + + std::to_string(inferredShapes.size()) + + " elements - should only have 1."); + } ValidateAndCopyShape(outputShape, inferredShapes[0], m_ShapeInferenceMethod, "ActivationLayer"); } diff --git a/src/armnn/layers/ArgMinMaxLayer.cpp b/src/armnn/layers/ArgMinMaxLayer.cpp index 37986572a0..537d7d10c5 100644 --- a/src/armnn/layers/ArgMinMaxLayer.cpp +++ b/src/armnn/layers/ArgMinMaxLayer.cpp @@ -1,5 +1,5 @@ // -// Copyright © 2017,2019-2023 Arm Ltd and Contributors. All rights reserved. +// Copyright © 2017,2019-2024 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // @@ -36,7 +36,11 @@ ArgMinMaxLayer* ArgMinMaxLayer::Clone(Graph& graph) const std::vector<TensorShape> ArgMinMaxLayer::InferOutputShapes(const std::vector<TensorShape>& inputShapes) const { - ARMNN_ASSERT(inputShapes.size() == 1); + if (inputShapes.size() != 1) + { + throw armnn::LayerValidationException("inputShapes' size is \"" + std::to_string(inputShapes.size()) + + "\" - should be \"1\"."); + } TensorShape inputShape = inputShapes[0]; auto inputNumDimensions = inputShape.GetNumDimensions(); @@ -44,7 +48,13 @@ std::vector<TensorShape> ArgMinMaxLayer::InferOutputShapes(const std::vector<Ten auto axis = m_Param.m_Axis; auto unsignedAxis = armnnUtils::GetUnsignedAxis(inputNumDimensions, axis); - ARMNN_ASSERT(unsignedAxis <= inputNumDimensions); + if (unsignedAxis > inputNumDimensions) + { + throw armnn::LayerValidationException("Axis must not be greater than number of input dimensions (\"" + + std::to_string(unsignedAxis) + + "\" vs \"" + + std::to_string(inputNumDimensions) + "\")."); + } // 1D input shape results in scalar output if (inputShape.GetNumDimensions() == 1) @@ -81,7 +91,12 @@ void ArgMinMaxLayer::ValidateTensorShapesFromInputs() auto inferredShapes = InferOutputShapes({ GetInputSlot(0).GetTensorInfo().GetShape() }); - ARMNN_ASSERT(inferredShapes.size() == 1); + if (inferredShapes.size() != 1) + { + throw armnn::LayerValidationException("inferredShapes has " + + std::to_string(inferredShapes.size()) + + " elements - should only have 1."); + } ValidateAndCopyShape(outputShape, inferredShapes[0], m_ShapeInferenceMethod, "ArgMinMaxLayer"); } diff --git a/src/armnn/layers/BatchMatMulLayer.cpp b/src/armnn/layers/BatchMatMulLayer.cpp index 8b2629c4ea..cafb051c7b 100644 --- a/src/armnn/layers/BatchMatMulLayer.cpp +++ b/src/armnn/layers/BatchMatMulLayer.cpp @@ -1,5 +1,5 @@ // -// Copyright © 2022-2023 Arm Ltd and Contributors. All rights reserved. +// Copyright © 2022-2024 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // #include "BatchMatMulLayer.hpp" @@ -32,7 +32,11 @@ BatchMatMulLayer* BatchMatMulLayer::Clone(Graph& graph) const std::vector<TensorShape> BatchMatMulLayer::InferOutputShapes(const std::vector<TensorShape>& inputShapes) const { - ARMNN_ASSERT(inputShapes.size() == 2); + if (inputShapes.size() != 2) + { + throw armnn::LayerValidationException("inputShapes' size is \"" + std::to_string(inputShapes.size()) + + "\" - should be \"2\"."); + } TensorShape inputXShape = inputShapes[0]; TensorShape inputYShape = inputShapes[1]; @@ -102,9 +106,14 @@ void BatchMatMulLayer::ValidateTensorShapesFromInputs() GetInputSlot(0).GetTensorInfo().GetShape(), GetInputSlot(1).GetTensorInfo().GetShape() }); - ARMNN_ASSERT(inferredShapes.size() == 1); + if (inferredShapes.size() != 1) + { + throw armnn::LayerValidationException("inferredShapes has " + + std::to_string(inferredShapes.size()) + + " elements - should only have 1."); + } ValidateAndCopyShape(outputShape, inferredShapes[0], m_ShapeInferenceMethod, "BatchMatMulLayer"); } -} // namespace armnn
\ No newline at end of file +} // namespace armnn diff --git a/src/armnn/layers/BatchNormalizationLayer.cpp b/src/armnn/layers/BatchNormalizationLayer.cpp index 17463f8d4f..9936041093 100644 --- a/src/armnn/layers/BatchNormalizationLayer.cpp +++ b/src/armnn/layers/BatchNormalizationLayer.cpp @@ -1,5 +1,5 @@ // -// Copyright © 2017-2023 Arm Ltd and Contributors. All rights reserved. +// Copyright © 2017-2024 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // #include "BatchNormalizationLayer.hpp" @@ -21,10 +21,25 @@ BatchNormalizationLayer::BatchNormalizationLayer(const armnn::BatchNormalization std::unique_ptr<IWorkload> BatchNormalizationLayer::CreateWorkload(const IWorkloadFactory& factory) const { // on this level constant data should not be released.. - ARMNN_ASSERT_MSG(m_Mean != nullptr, "BatchNormalizationLayer: Mean data should not be null."); - ARMNN_ASSERT_MSG(m_Variance != nullptr, "BatchNormalizationLayer: Variance data should not be null."); - ARMNN_ASSERT_MSG(m_Beta != nullptr, "BatchNormalizationLayer: Beta data should not be null."); - ARMNN_ASSERT_MSG(m_Gamma != nullptr, "BatchNormalizationLayer: Gamma data should not be null."); + if (!m_Mean) + { + throw armnn::NullPointerException("BatchNormalizationLayer: Mean data should not be null."); + } + + if (!m_Variance) + { + throw armnn::NullPointerException("BatchNormalizationLayer: Variance data should not be null."); + } + + if (!m_Beta) + { + throw armnn::NullPointerException("BatchNormalizationLayer: Beta data should not be null."); + } + + if (!m_Gamma) + { + throw armnn::NullPointerException("BatchNormalizationLayer: Gamma data should not be null."); + } BatchNormalizationQueueDescriptor descriptor; SetAdditionalInfo(descriptor); @@ -59,7 +74,12 @@ void BatchNormalizationLayer::ValidateTensorShapesFromInputs() auto inferredShapes = InferOutputShapes({ GetInputSlot(0).GetTensorInfo().GetShape() }); - ARMNN_ASSERT(inferredShapes.size() == 1); + if (inferredShapes.size() != 1) + { + throw armnn::LayerValidationException("inferredShapes has " + + std::to_string(inferredShapes.size()) + + " elements - should only have 1."); + } ValidateAndCopyShape(outputShape, inferredShapes[0], m_ShapeInferenceMethod, "BatchNormalizationLayer"); diff --git a/src/armnn/layers/BatchToSpaceNdLayer.cpp b/src/armnn/layers/BatchToSpaceNdLayer.cpp index 63817dde16..9f604503b9 100644 --- a/src/armnn/layers/BatchToSpaceNdLayer.cpp +++ b/src/armnn/layers/BatchToSpaceNdLayer.cpp @@ -1,5 +1,5 @@ // -// Copyright © 2018-2023 Arm Ltd and Contributors. All rights reserved. +// Copyright © 2018-2024 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // @@ -45,7 +45,12 @@ void BatchToSpaceNdLayer::ValidateTensorShapesFromInputs() auto inferredShapes = InferOutputShapes({GetInputSlot(0).GetTensorInfo().GetShape()}); - ARMNN_ASSERT(inferredShapes.size() == 1); + if (inferredShapes.size() != 1) + { + throw armnn::LayerValidationException("inferredShapes has " + + std::to_string(inferredShapes.size()) + + " elements - should only have 1."); + } ValidateAndCopyShape(outputShape, inferredShapes[0], m_ShapeInferenceMethod, "BatchToSpaceNdLayer"); } diff --git a/src/armnn/layers/CastLayer.cpp b/src/armnn/layers/CastLayer.cpp index fc1ab81d4f..8dff6ba5d5 100644 --- a/src/armnn/layers/CastLayer.cpp +++ b/src/armnn/layers/CastLayer.cpp @@ -1,5 +1,5 @@ // -// Copyright © 2021-2023 Arm Ltd and Contributors. All rights reserved. +// Copyright © 2021-2024 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // #include "CastLayer.hpp" @@ -41,7 +41,12 @@ void CastLayer::ValidateTensorShapesFromInputs() auto inferredShapes = InferOutputShapes({ GetInputSlot(0).GetTensorInfo().GetShape() }); - ARMNN_ASSERT(inferredShapes.size() == 1); + if (inferredShapes.size() != 1) + { + throw armnn::LayerValidationException("inferredShapes has " + + std::to_string(inferredShapes.size()) + + " elements - should only have 1."); + } ValidateAndCopyShape(outputShape, inferredShapes[0], m_ShapeInferenceMethod, "CastLayer"); } diff --git a/src/armnn/layers/ChannelShuffleLayer.cpp b/src/armnn/layers/ChannelShuffleLayer.cpp index ce6c0bac11..b05f63cd92 100644 --- a/src/armnn/layers/ChannelShuffleLayer.cpp +++ b/src/armnn/layers/ChannelShuffleLayer.cpp @@ -1,5 +1,5 @@ // -// Copyright © 2021-2023 Arm Ltd and Contributors. All rights reserved. +// Copyright © 2021-2024 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // @@ -42,9 +42,14 @@ void ChannelShuffleLayer::ValidateTensorShapesFromInputs() auto inferredShapes = Layer::InferOutputShapes({GetInputSlot(0).GetTensorInfo().GetShape() }); - ARMNN_ASSERT(inferredShapes.size() == 1); + if (inferredShapes.size() != 1) + { + throw armnn::LayerValidationException("inferredShapes has " + + std::to_string(inferredShapes.size()) + + " elements - should only have 1."); + } ValidateAndCopyShape(outputShape, inferredShapes[0], m_ShapeInferenceMethod, "ChannelShuffleLayer"); } -}
\ No newline at end of file +} diff --git a/src/armnn/layers/ComparisonLayer.cpp b/src/armnn/layers/ComparisonLayer.cpp index 5d18a58f3c..dc5437bb6f 100644 --- a/src/armnn/layers/ComparisonLayer.cpp +++ b/src/armnn/layers/ComparisonLayer.cpp @@ -1,5 +1,5 @@ // -// Copyright © 2019-2023 Arm Ltd and Contributors. All rights reserved. +// Copyright © 2019-2024 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // @@ -35,7 +35,12 @@ ComparisonLayer* ComparisonLayer::Clone(Graph& graph) const std::vector<TensorShape> ComparisonLayer::InferOutputShapes(const std::vector<TensorShape>& inputShapes) const { - ARMNN_ASSERT(inputShapes.size() == 2); + if (inputShapes.size() != 2) + { + throw armnn::Exception("inputShapes' size is \"" + std::to_string(inputShapes.size()) + + "\" - should be \"2\"."); + } + TensorShape input0 = inputShapes[0]; TensorShape input1 = inputShapes[1]; @@ -55,8 +60,10 @@ std::vector<TensorShape> ComparisonLayer::InferOutputShapes(const std::vector<Te unsigned int dim1 = input1[i - shiftedDims]; // Validate inputs are broadcast compatible. - ARMNN_ASSERT_MSG(dim0 == dim1 || dim0 == 1 || dim1 == 1, - "Dimensions should either match or one should be of size 1."); + if (dim0 != dim1 && dim0 != 1 && dim1 != 1) + { + throw armnn::Exception("Dimensions should either match or one should be of size 1."); + } dims[i] = std::max(dim0, dim1); } @@ -82,7 +89,13 @@ void ComparisonLayer::ValidateTensorShapesFromInputs() GetInputSlot(0).GetTensorInfo().GetShape(), GetInputSlot(1).GetTensorInfo().GetShape() }); - ARMNN_ASSERT(inferredShapes.size() == 1); + + if (inferredShapes.size() != 1) + { + throw armnn::LayerValidationException("inferredShapes has " + + std::to_string(inferredShapes.size()) + + " elements - should only have 1."); + } ValidateAndCopyShape(outputShape, inferredShapes[0], m_ShapeInferenceMethod, "ComparisonLayer"); } diff --git a/src/armnn/layers/ConcatLayer.cpp b/src/armnn/layers/ConcatLayer.cpp index 4629bf245e..021e736bb8 100644 --- a/src/armnn/layers/ConcatLayer.cpp +++ b/src/armnn/layers/ConcatLayer.cpp @@ -1,5 +1,5 @@ // -// Copyright © 2017-2023 Arm Ltd and Contributors. All rights reserved. +// Copyright © 2017-2024 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // #include "ConcatLayer.hpp" @@ -164,7 +164,11 @@ void ConcatLayer::CreateTensors(const TensorHandleFactoryRegistry& registry, OutputSlot* slot = currentLayer->GetInputSlot(i).GetConnectedOutputSlot(); OutputHandler& outputHandler = slot->GetOutputHandler(); - ARMNN_ASSERT_MSG(subTensor, "ConcatLayer: Expected a valid sub-tensor for substitution."); + if (!subTensor) + { + throw armnn::Exception("ConcatLayer: Expected a valid sub-tensor for substitution."); + } + outputHandler.SetData(std::move(subTensor)); Layer& inputLayer = slot->GetOwningLayer(); @@ -193,7 +197,10 @@ void ConcatLayer::CreateTensorHandles(const TensorHandleFactoryRegistry& registr else { ITensorHandleFactory* handleFactory = registry.GetFactory(factoryId); - ARMNN_ASSERT(handleFactory); + if (!handleFactory) + { + throw armnn::NullPointerException("handleFactory is returning a nullptr."); + } CreateTensors(registry, *handleFactory, isMemoryManaged); } } @@ -205,7 +212,13 @@ ConcatLayer* ConcatLayer::Clone(Graph& graph) const std::vector<TensorShape> ConcatLayer::InferOutputShapes(const std::vector<TensorShape>& inputShapes) const { - ARMNN_ASSERT(inputShapes.size() == m_Param.GetNumViews()); + if (inputShapes.size() != m_Param.GetNumViews()) + { + throw armnn::Exception("inputShapes' and m_NumViews' sizes do not match (\"" + + std::to_string(inputShapes.size()) + + "\" vs \"" + + std::to_string(m_Param.GetNumViews()) + "\")"); + } unsigned int numDims = m_Param.GetNumDimensions(); for (unsigned int i=0; i< inputShapes.size(); i++) @@ -315,7 +328,12 @@ void ConcatLayer::ValidateTensorShapesFromInputs() auto inferredShapes = InferOutputShapes(inputShapes); - ARMNN_ASSERT(inferredShapes.size() == 1); + if (inferredShapes.size() != 1) + { + throw armnn::Exception("inferredShapes has " + + std::to_string(inferredShapes.size()) + + " elements - should only have 1."); + } ValidateAndCopyShape(outputShape, inferredShapes[0], m_ShapeInferenceMethod, "ConcatLayer"); } diff --git a/src/armnn/layers/ConvertFp16ToFp32Layer.cpp b/src/armnn/layers/ConvertFp16ToFp32Layer.cpp index 9fefe2016a..d0b00cb374 100644 --- a/src/armnn/layers/ConvertFp16ToFp32Layer.cpp +++ b/src/armnn/layers/ConvertFp16ToFp32Layer.cpp @@ -1,5 +1,5 @@ // -// Copyright © 2017-2023 Arm Ltd and Contributors. All rights reserved. +// Copyright © 2017-2024 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // @@ -42,7 +42,12 @@ void ConvertFp16ToFp32Layer::ValidateTensorShapesFromInputs() auto inferredShapes = InferOutputShapes({ GetInputSlot(0).GetTensorInfo().GetShape() }); - ARMNN_ASSERT(inferredShapes.size() == 1); + if (inferredShapes.size() != 1) + { + throw armnn::LayerValidationException("inferredShapes has " + + std::to_string(inferredShapes.size()) + + " elements - should only have 1."); + } ValidateAndCopyShape(outputShape, inferredShapes[0], m_ShapeInferenceMethod, "ConvertFp16ToFp32Layer"); } diff --git a/src/armnn/layers/ConvertFp32ToFp16Layer.cpp b/src/armnn/layers/ConvertFp32ToFp16Layer.cpp index f1abba32c6..898ef3053a 100644 --- a/src/armnn/layers/ConvertFp32ToFp16Layer.cpp +++ b/src/armnn/layers/ConvertFp32ToFp16Layer.cpp @@ -1,5 +1,5 @@ // -// Copyright © 2017-2023 Arm Ltd and Contributors. All rights reserved. +// Copyright © 2017-2024 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // #include "ConvertFp32ToFp16Layer.hpp" @@ -42,7 +42,12 @@ void ConvertFp32ToFp16Layer::ValidateTensorShapesFromInputs() auto inferredShapes = InferOutputShapes({ GetInputSlot(0).GetTensorInfo().GetShape() }); - ARMNN_ASSERT(inferredShapes.size() == 1); + if (inferredShapes.size() != 1) + { + throw armnn::LayerValidationException("inferredShapes has " + + std::to_string(inferredShapes.size()) + + " elements - should only have 1."); + } ValidateAndCopyShape(outputShape, inferredShapes[0], m_ShapeInferenceMethod, "LayerName"); } diff --git a/src/armnn/layers/Convolution2dLayer.cpp b/src/armnn/layers/Convolution2dLayer.cpp index df971a517d..2fcc4aa755 100644 --- a/src/armnn/layers/Convolution2dLayer.cpp +++ b/src/armnn/layers/Convolution2dLayer.cpp @@ -1,5 +1,5 @@ // -// Copyright © 2017-2023 Arm Ltd and Contributors. All rights reserved. +// Copyright © 2017-2024 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // @@ -63,15 +63,30 @@ Convolution2dLayer* Convolution2dLayer::Clone(Graph& graph) const std::vector<TensorShape> Convolution2dLayer::InferOutputShapes(const std::vector<TensorShape>& inputShapes) const { - ARMNN_ASSERT(inputShapes.size() == 2); + if (inputShapes.size() != 2) + { + throw armnn::Exception("inputShapes' size is \"" + std::to_string(inputShapes.size()) + + "\" - should be \"2\"."); + } + const TensorShape& inputShape = inputShapes[0]; const TensorShape filterShape = inputShapes[1]; // If we support multiple batch dimensions in the future, then this assert will need to change. - ARMNN_ASSERT_MSG(inputShape.GetNumDimensions() == 4, "Convolutions will always have 4D input."); + if (inputShape.GetNumDimensions() != 4) + { + throw armnn::Exception("Convolutions will always have 4D input."); + } + + if (m_Param.m_StrideX == 0) + { + throw armnn::Exception("m_StrideX cannot be 0."); + } - ARMNN_ASSERT( m_Param.m_StrideX > 0); - ARMNN_ASSERT( m_Param.m_StrideY > 0); + if (m_Param.m_StrideY == 0) + { + throw armnn::Exception("m_StrideY cannot be 0."); + } DataLayoutIndexed dataLayoutIndex(m_Param.m_DataLayout); @@ -107,14 +122,21 @@ void Convolution2dLayer::ValidateTensorShapesFromInputs() VerifyShapeInferenceType(outputShape, m_ShapeInferenceMethod); - ARMNN_ASSERT_MSG(GetInputSlot(1).GetConnection(), - "Convolution2dLayer: Weights should be connected to input slot 1."); + if (!GetInputSlot(1).GetConnection()) + { + throw armnn::NullPointerException("Convolution2dLayer: Weights should be connected to input slot 1."); + } std::vector<TensorShape> inferredShapes = InferOutputShapes({ GetInputSlot(0).GetTensorInfo().GetShape(), GetInputSlot(1).GetTensorInfo().GetShape() }); - ARMNN_ASSERT(inferredShapes.size() == 1); + if (inferredShapes.size() != 1) + { + throw armnn::Exception("inferredShapes has " + + std::to_string(inferredShapes.size()) + + " elements - should only have 1."); + } ValidateAndCopyShape(outputShape, inferredShapes[0], m_ShapeInferenceMethod, "Convolution2dLayer"); } diff --git a/src/armnn/layers/Convolution3dLayer.cpp b/src/armnn/layers/Convolution3dLayer.cpp index 2d697beb1f..89ea0042ce 100644 --- a/src/armnn/layers/Convolution3dLayer.cpp +++ b/src/armnn/layers/Convolution3dLayer.cpp @@ -1,5 +1,5 @@ // -// Copyright © 2021-2023 Arm Ltd and Contributors. All rights reserved. +// Copyright © 2021-2024 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // @@ -61,15 +61,34 @@ Convolution3dLayer* Convolution3dLayer::Clone(Graph& graph) const std::vector<TensorShape> Convolution3dLayer::InferOutputShapes(const std::vector<TensorShape>& inputShapes) const { - ARMNN_ASSERT(inputShapes.size() == 2); + if (inputShapes.size() != 2) + { + throw armnn::Exception("inputShapes' size is \"" + std::to_string(inputShapes.size()) + + "\" - should be \"2\"."); + } + const TensorShape& inputShape = inputShapes[0]; const TensorShape& filterShape = inputShapes[1]; - ARMNN_ASSERT_MSG(inputShape.GetNumDimensions() == 5, "Convolutions will always have 5D input."); + if (inputShape.GetNumDimensions() != 5) + { + throw armnn::Exception("Convolutions will always have 5D input."); + } + + if (m_Param.m_StrideX == 0) + { + throw armnn::Exception("m_StrideX cannot be 0."); + } + + if (m_Param.m_StrideY == 0) + { + throw armnn::Exception("m_StrideY cannot be 0."); + } - ARMNN_ASSERT( m_Param.m_StrideX > 0); - ARMNN_ASSERT( m_Param.m_StrideY > 0); - ARMNN_ASSERT( m_Param.m_StrideZ > 0); + if (m_Param.m_StrideZ == 0) + { + throw armnn::Exception("m_StrideZ cannot be 0."); + } DataLayoutIndexed dataLayoutIndex(m_Param.m_DataLayout); @@ -112,14 +131,21 @@ void Convolution3dLayer::ValidateTensorShapesFromInputs() VerifyShapeInferenceType(outputShape, m_ShapeInferenceMethod); - ARMNN_ASSERT_MSG(GetInputSlot(1).GetConnection(), - "Convolution3dLayer: Weights should be connected to input slot 1."); + if (!GetInputSlot(1).GetConnection()) + { + throw armnn::LayerValidationException("Convolution3dLayer: Weights should be connected to input slot 1."); + } auto inferredShapes = InferOutputShapes({ GetInputSlot(0).GetTensorInfo().GetShape(), GetInputSlot(1).GetTensorInfo().GetShape() }); - ARMNN_ASSERT(inferredShapes.size() == 1); + if (inferredShapes.size() != 1) + { + throw armnn::LayerValidationException("inferredShapes has " + + std::to_string(inferredShapes.size()) + + " elements - should only have 1."); + } ValidateAndCopyShape(outputShape, inferredShapes[0], m_ShapeInferenceMethod, "Convolution3dLayer"); } diff --git a/src/armnn/layers/DebugLayer.cpp b/src/armnn/layers/DebugLayer.cpp index 01c1c7be6b..ca8215ddb4 100644 --- a/src/armnn/layers/DebugLayer.cpp +++ b/src/armnn/layers/DebugLayer.cpp @@ -1,5 +1,5 @@ // -// Copyright © 2017-2023 Arm Ltd and Contributors. All rights reserved. +// Copyright © 2017-2024 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // #include "DebugLayer.hpp" @@ -53,7 +53,12 @@ void DebugLayer::ValidateTensorShapesFromInputs() std::vector<TensorShape> inferredShapes = InferOutputShapes({ GetInputSlot(0).GetTensorInfo().GetShape() }); - ARMNN_ASSERT(inferredShapes.size() == 1); + if (inferredShapes.size() != 1) + { + throw armnn::Exception("inferredShapes has " + + std::to_string(inferredShapes.size()) + + " elements - should only have 1."); + } ValidateAndCopyShape(outputShape, inferredShapes[0], m_ShapeInferenceMethod, "DebugLayer"); } diff --git a/src/armnn/layers/DepthToSpaceLayer.cpp b/src/armnn/layers/DepthToSpaceLayer.cpp index b94eccc1ee..b303474ab4 100644 --- a/src/armnn/layers/DepthToSpaceLayer.cpp +++ b/src/armnn/layers/DepthToSpaceLayer.cpp @@ -1,5 +1,5 @@ // -// Copyright © 2019-2023 Arm Ltd and Contributors. All rights reserved. +// Copyright © 2019-2024 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // @@ -40,7 +40,11 @@ DepthToSpaceLayer* DepthToSpaceLayer::Clone(Graph& graph) const std::vector<TensorShape> DepthToSpaceLayer::InferOutputShapes(const std::vector<TensorShape>& inputShapes) const { - ARMNN_ASSERT(inputShapes.size() == 1); + if (inputShapes.size() != 1) + { + throw armnn::Exception("inputShapes' size is \"" + std::to_string(inputShapes.size()) + + "\" - should be \"1\"."); + } TensorShape inputShape = inputShapes[0]; TensorShape outputShape(inputShape); @@ -70,7 +74,12 @@ void DepthToSpaceLayer::ValidateTensorShapesFromInputs() std::vector<TensorShape> inferredShapes = InferOutputShapes({ GetInputSlot(0).GetTensorInfo().GetShape() }); - ARMNN_ASSERT(inferredShapes.size() == 1); + if (inferredShapes.size() != 1) + { + throw armnn::LayerValidationException("inferredShapes has " + + std::to_string(inferredShapes.size()) + + " elements - should only have 1."); + } ValidateAndCopyShape(outputShape, inferredShapes[0], m_ShapeInferenceMethod, "DepthToSpaceLayer"); } diff --git a/src/armnn/layers/DepthwiseConvolution2dLayer.cpp b/src/armnn/layers/DepthwiseConvolution2dLayer.cpp index 4f08b2324e..69c3d380af 100644 --- a/src/armnn/layers/DepthwiseConvolution2dLayer.cpp +++ b/src/armnn/layers/DepthwiseConvolution2dLayer.cpp @@ -1,5 +1,5 @@ // -// Copyright © 2017-2023 Arm Ltd and Contributors. All rights reserved. +// Copyright © 2017-2024 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // @@ -64,14 +64,30 @@ DepthwiseConvolution2dLayer* DepthwiseConvolution2dLayer::Clone(Graph& graph) co std::vector<TensorShape> DepthwiseConvolution2dLayer::InferOutputShapes(const std::vector<TensorShape>& inputShapes) const { - ARMNN_ASSERT(inputShapes.size() == 2); + if (inputShapes.size() != 2) + { + throw armnn::Exception("inputShapes' size is \"" + std::to_string(inputShapes.size()) + + "\" - should be \"2\"."); + } + const TensorShape& inputShape = inputShapes[0]; const TensorShape& filterShape = inputShapes[1]; - ARMNN_ASSERT_MSG(inputShape.GetNumDimensions() == 4, "Convolutions will always have 4D input."); + if (inputShape.GetNumDimensions() != 4) + { + throw armnn::Exception("Convolutions will always have 4D input."); + } + + if (m_Param.m_StrideX == 0) + { + throw armnn::Exception("m_StrideX cannot be 0."); + } + + if (m_Param.m_StrideY == 0) + { + throw armnn::Exception("m_StrideY cannot be 0."); + } - ARMNN_ASSERT( m_Param.m_StrideX > 0); - ARMNN_ASSERT( m_Param.m_StrideY > 0); DataLayoutIndexed dataLayoutIndex(m_Param.m_DataLayout); @@ -110,15 +126,22 @@ void DepthwiseConvolution2dLayer::ValidateTensorShapesFromInputs() VerifyShapeInferenceType(outputShape, m_ShapeInferenceMethod); - ARMNN_ASSERT_MSG(GetInputSlot(1).GetConnection(), - "DepthwiseConvolution2dLayer: Weights data should not be null."); + if (!GetInputSlot(1).GetConnection()) + { + throw armnn::LayerValidationException("DepthwiseConvolution2dLayer: Weights data should not be null."); + } auto inferredShapes = InferOutputShapes({ GetInputSlot(0).GetTensorInfo().GetShape(), GetInputSlot(1).GetTensorInfo().GetShape() }); - ARMNN_ASSERT(inferredShapes.size() == 1); + if (inferredShapes.size() != 1) + { + throw armnn::LayerValidationException("inferredShapes has " + + std::to_string(inferredShapes.size()) + + " elements - should only have 1."); + } ValidateAndCopyShape(outputShape, inferredShapes[0], m_ShapeInferenceMethod, "DepthwiseConvolution2dLayer"); } diff --git a/src/armnn/layers/DequantizeLayer.cpp b/src/armnn/layers/DequantizeLayer.cpp index b398cf6e0d..79ab969719 100644 --- a/src/armnn/layers/DequantizeLayer.cpp +++ b/src/armnn/layers/DequantizeLayer.cpp @@ -1,5 +1,5 @@ // -// Copyright © 2017,2019-2023 Arm Ltd and Contributors. All rights reserved. +// Copyright © 2017,2019-2024 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // #include "DequantizeLayer.hpp" @@ -41,7 +41,12 @@ void DequantizeLayer::ValidateTensorShapesFromInputs() std::vector<TensorShape> inferredShapes = InferOutputShapes({ GetInputSlot(0).GetTensorInfo().GetShape() }); - ARMNN_ASSERT(inferredShapes.size() == 1); + if (inferredShapes.size() != 1) + { + throw armnn::LayerValidationException("inferredShapes has " + + std::to_string(inferredShapes.size()) + + " elements - should only have 1."); + } ValidateAndCopyShape(outputShape, inferredShapes[0], m_ShapeInferenceMethod, "DequantizeLayer"); } diff --git a/src/armnn/layers/DetectionPostProcessLayer.cpp b/src/armnn/layers/DetectionPostProcessLayer.cpp index 6bddf51551..f71f72af3a 100644 --- a/src/armnn/layers/DetectionPostProcessLayer.cpp +++ b/src/armnn/layers/DetectionPostProcessLayer.cpp @@ -1,5 +1,5 @@ // -// Copyright © 2017-2023 Arm Ltd and Contributors. All rights reserved. +// Copyright © 2017-2024 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // @@ -45,19 +45,33 @@ void DetectionPostProcessLayer::ValidateTensorShapesFromInputs() VerifyShapeInferenceType(outputShape, m_ShapeInferenceMethod); // on this level constant data should not be released. - ARMNN_ASSERT_MSG(m_Anchors != nullptr, "DetectionPostProcessLayer: Anchors data should not be null."); + if (!m_Anchors) + { + throw armnn::LayerValidationException("DetectionPostProcessLayer: Anchors data should not be null."); + } - ARMNN_ASSERT_MSG(GetNumOutputSlots() == 4, "DetectionPostProcessLayer: The layer should return 4 outputs."); + if (GetNumOutputSlots() != 4) + { + throw armnn::LayerValidationException("DetectionPostProcessLayer: The layer should return 4 outputs."); + } std::vector<TensorShape> inferredShapes = InferOutputShapes( { GetInputSlot(0).GetTensorInfo().GetShape(), GetInputSlot(1).GetTensorInfo().GetShape() }); - ARMNN_ASSERT(inferredShapes.size() == 4); - ARMNN_ASSERT(inferredShapes[0].GetDimensionality() == Dimensionality::Specified); - ARMNN_ASSERT(inferredShapes[1].GetDimensionality() == Dimensionality::Specified); - ARMNN_ASSERT(inferredShapes[2].GetDimensionality() == Dimensionality::Specified); - ARMNN_ASSERT(inferredShapes[3].GetDimensionality() == Dimensionality::Specified); + if (inferredShapes.size() != 4) + { + throw armnn::LayerValidationException("inferredShapes has " + + std::to_string(inferredShapes.size()) + + " element(s) - should only have 4."); + } + + if (std::any_of(inferredShapes.begin(), inferredShapes.end(), [] (auto&& inferredShape) { + return inferredShape.GetDimensionality() != Dimensionality::Specified; + })) + { + throw armnn::Exception("One of inferredShapes' dimensionalities is not specified."); + } ValidateAndCopyShape(outputShape, inferredShapes[0], m_ShapeInferenceMethod, "DetectionPostProcessLayer"); diff --git a/src/armnn/layers/ElementwiseBaseLayer.cpp b/src/armnn/layers/ElementwiseBaseLayer.cpp index 3cbddfa5db..e813f48daf 100644 --- a/src/armnn/layers/ElementwiseBaseLayer.cpp +++ b/src/armnn/layers/ElementwiseBaseLayer.cpp @@ -1,5 +1,5 @@ // -// Copyright © 2017-2018,2020-2021,2023 Arm Ltd and Contributors. All rights reserved. +// Copyright © 2017-2018,2020-2021,2023-2024 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // @@ -22,7 +22,12 @@ ElementwiseBaseLayer::ElementwiseBaseLayer(unsigned int numInputSlots, std::vector<TensorShape> ElementwiseBaseLayer::InferOutputShapes(const std::vector<TensorShape>& inputShapes) const { - ARMNN_ASSERT(inputShapes.size() == 2); + if (inputShapes.size() != 2) + { + throw armnn::Exception("inputShapes' size is \"" + std::to_string(inputShapes.size()) + + "\" - should be \"2\"."); + } + TensorShape input0 = inputShapes[0]; TensorShape input1 = inputShapes[1]; @@ -43,8 +48,10 @@ std::vector<TensorShape> ElementwiseBaseLayer::InferOutputShapes(const std::vect unsigned int dim1 = input1[i - shiftedDims]; // Validate inputs are broadcast compatible. - ARMNN_ASSERT_MSG(dim0 == dim1 || dim0 == 1 || dim1 == 1, - "Dimensions should either match or one should be of size 1."); + if (dim0 != dim1 && dim0 != 1 && dim1 != 1) + { + throw armnn::Exception("Dimensions should either match or one should be of size 1."); + } dims[i] = std::max(dim0, dim1); } @@ -69,7 +76,12 @@ void ElementwiseBaseLayer::ValidateTensorShapesFromInputs() auto inferredShapes = InferOutputShapes({ GetInputSlot(0).GetTensorInfo().GetShape(), GetInputSlot(1).GetTensorInfo().GetShape() }); - ARMNN_ASSERT(inferredShapes.size() == 1); + if (inferredShapes.size() != 1) + { + throw armnn::LayerValidationException("inferredShapes has " + + std::to_string(inferredShapes.size()) + + " elements - should only have 1."); + } ValidateAndCopyShape(outputShape, inferredShapes[0], m_ShapeInferenceMethod, GetLayerTypeAsCString(GetType())); } diff --git a/src/armnn/layers/ElementwiseBinaryLayer.cpp b/src/armnn/layers/ElementwiseBinaryLayer.cpp index 67619fc463..5459aafbca 100644 --- a/src/armnn/layers/ElementwiseBinaryLayer.cpp +++ b/src/armnn/layers/ElementwiseBinaryLayer.cpp @@ -1,5 +1,5 @@ // -// Copyright © 2023 Arm Ltd and Contributors. All rights reserved. +// Copyright © 2024 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // @@ -30,7 +30,12 @@ ElementwiseBinaryLayer* ElementwiseBinaryLayer::Clone(Graph& graph) const std::vector<TensorShape> ElementwiseBinaryLayer::InferOutputShapes(const std::vector<TensorShape>& inputShapes) const { - ARMNN_ASSERT(inputShapes.size() == 2); + if (inputShapes.size() != 2) + { + throw armnn::Exception("inputShapes' size is \"" + std::to_string(inputShapes.size()) + + "\" - should be \"2\"."); + } + TensorShape input0 = inputShapes[0]; TensorShape input1 = inputShapes[1]; @@ -51,8 +56,10 @@ std::vector<TensorShape> ElementwiseBinaryLayer::InferOutputShapes(const std::ve unsigned int dim1 = input1[i - shiftedDims]; // Validate inputs are broadcast compatible. - ARMNN_ASSERT_MSG(dim0 == dim1 || dim0 == 1 || dim1 == 1, - "Dimensions should either match or one should be of size 1."); + if (dim0 != dim1 && dim0 != 1 && dim1 != 1) + { + throw armnn::Exception("Dimensions should either match or one should be of size 1."); + } dims[i] = std::max(dim0, dim1); } @@ -77,7 +84,12 @@ void ElementwiseBinaryLayer::ValidateTensorShapesFromInputs() auto inferredShapes = InferOutputShapes({ GetInputSlot(0).GetTensorInfo().GetShape(), GetInputSlot(1).GetTensorInfo().GetShape() }); - ARMNN_ASSERT(inferredShapes.size() == 1); + if (inferredShapes.size() != 1) + { + throw armnn::LayerValidationException("inferredShapes has " + + std::to_string(inferredShapes.size()) + + " elements - should only have 1."); + } ValidateAndCopyShape(outputShape, inferredShapes[0], m_ShapeInferenceMethod, GetLayerTypeAsCString(GetType())); } diff --git a/src/armnn/layers/ElementwiseUnaryLayer.cpp b/src/armnn/layers/ElementwiseUnaryLayer.cpp index c648f9b863..791a3d5d89 100644 --- a/src/armnn/layers/ElementwiseUnaryLayer.cpp +++ b/src/armnn/layers/ElementwiseUnaryLayer.cpp @@ -1,5 +1,5 @@ // -// Copyright © 2020-2023 Arm Ltd and Contributors. All rights reserved. +// Copyright © 2020-2024 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // @@ -34,7 +34,12 @@ ElementwiseUnaryLayer* ElementwiseUnaryLayer::Clone(Graph& graph) const std::vector<TensorShape> ElementwiseUnaryLayer::InferOutputShapes(const std::vector<TensorShape>& inputShapes) const { // Should return the shape of the input tensor - ARMNN_ASSERT(inputShapes.size() == 1); + if (inputShapes.size() != 1) + { + throw armnn::Exception("inputShapes' size is \"" + std::to_string(inputShapes.size()) + + "\" - should be \"1\"."); + } + const TensorShape& input = inputShapes[0]; return std::vector<TensorShape>({ input }); @@ -50,7 +55,13 @@ void ElementwiseUnaryLayer::ValidateTensorShapesFromInputs() std::vector<TensorShape> inferredShapes = InferOutputShapes({ GetInputSlot(0).GetTensorInfo().GetShape()}); - ARMNN_ASSERT(inferredShapes.size() == 1); + + if (inferredShapes.size() != 1) + { + throw armnn::Exception("inferredShapes has " + + std::to_string(inferredShapes.size()) + + " elements - should only have 1."); + } ValidateAndCopyShape(outputShape, inferredShapes[0], m_ShapeInferenceMethod, GetLayerTypeAsCString(GetType())); } diff --git a/src/armnn/layers/FakeQuantizationLayer.cpp b/src/armnn/layers/FakeQuantizationLayer.cpp index a612b5a4ec..bb9e6a4a7a 100644 --- a/src/armnn/layers/FakeQuantizationLayer.cpp +++ b/src/armnn/layers/FakeQuantizationLayer.cpp @@ -1,5 +1,5 @@ // -// Copyright © 2017-2023 Arm Ltd and Contributors. All rights reserved. +// Copyright © 2017-2024 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // #include "FakeQuantizationLayer.hpp" @@ -41,7 +41,12 @@ void FakeQuantizationLayer::ValidateTensorShapesFromInputs() auto inferredShapes = InferOutputShapes({ GetInputSlot(0).GetTensorInfo().GetShape() }); - ARMNN_ASSERT(inferredShapes.size() == 1); + if (inferredShapes.size() != 1) + { + throw armnn::Exception("inferredShapes has " + + std::to_string(inferredShapes.size()) + + " elements - should only have 1."); + } ValidateAndCopyShape(outputShape, inferredShapes[0], m_ShapeInferenceMethod, "FakeQuantizationLayer"); } diff --git a/src/armnn/layers/FillLayer.cpp b/src/armnn/layers/FillLayer.cpp index af01b99847..c40efb33fb 100644 --- a/src/armnn/layers/FillLayer.cpp +++ b/src/armnn/layers/FillLayer.cpp @@ -1,5 +1,5 @@ // -// Copyright © 2020-2023 Arm Ltd and Contributors. All rights reserved. +// Copyright © 2020-2024 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // #include "FillLayer.hpp" @@ -41,7 +41,12 @@ void FillLayer::ValidateTensorShapesFromInputs() auto inferredShapes = InferOutputShapes({ GetInputSlot(0).GetTensorInfo().GetShape() }); - ARMNN_ASSERT(inferredShapes.size() == 1); + if (inferredShapes.size() != 1) + { + throw armnn::Exception("inferredShapes has " + + std::to_string(inferredShapes.size()) + + " elements - should only have 1."); + } // Cannot validate the output shape from the input shape. but we can validate that the correct dims have been // inferred diff --git a/src/armnn/layers/FloorLayer.cpp b/src/armnn/layers/FloorLayer.cpp index 2db8d91b4b..1177b93054 100644 --- a/src/armnn/layers/FloorLayer.cpp +++ b/src/armnn/layers/FloorLayer.cpp @@ -1,5 +1,5 @@ // -// Copyright © 2017-2023 Arm Ltd and Contributors. All rights reserved. +// Copyright © 2017-2024 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // #include "FloorLayer.hpp" @@ -40,7 +40,13 @@ void FloorLayer::ValidateTensorShapesFromInputs() VerifyShapeInferenceType(outputShape, m_ShapeInferenceMethod); auto inferredShapes = InferOutputShapes({ GetInputSlot(0).GetTensorInfo().GetShape() }); - ARMNN_ASSERT(inferredShapes.size() == 1); + + if (inferredShapes.size() != 1) + { + throw armnn::Exception("inferredShapes has " + + std::to_string(inferredShapes.size()) + + " elements - should only have 1."); + } ValidateAndCopyShape(outputShape, inferredShapes[0], m_ShapeInferenceMethod, "FloorLayer"); } diff --git a/src/armnn/layers/FullyConnectedLayer.cpp b/src/armnn/layers/FullyConnectedLayer.cpp index 87a8adacaa..5b6b2a34d0 100644 --- a/src/armnn/layers/FullyConnectedLayer.cpp +++ b/src/armnn/layers/FullyConnectedLayer.cpp @@ -1,5 +1,5 @@ // -// Copyright © 2017-2023 Arm Ltd and Contributors. All rights reserved. +// Copyright © 2017-2024 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // #include "FullyConnectedLayer.hpp" @@ -34,7 +34,12 @@ FullyConnectedLayer* FullyConnectedLayer::Clone(Graph& graph) const std::vector<TensorShape> FullyConnectedLayer::InferOutputShapes(const std::vector<TensorShape>& inputShapes) const { - ARMNN_ASSERT(inputShapes.size() == 2); + if (inputShapes.size() != 2) + { + throw armnn::Exception("inputShapes' size is \"" + std::to_string(inputShapes.size()) + + "\" - should be \"2\"."); + } + const TensorShape& inputShape = inputShapes[0]; const TensorShape weightShape = inputShapes[1]; @@ -55,8 +60,17 @@ void FullyConnectedLayer::ValidateTensorShapesFromInputs() {GetInputSlot(0).GetTensorInfo().GetShape(), GetInputSlot(1).GetTensorInfo().GetShape()}); - ARMNN_ASSERT(inferredShapes.size() == 1); - ARMNN_ASSERT(inferredShapes[0].GetDimensionality() == Dimensionality::Specified); + if (inferredShapes.size() != 1) + { + throw armnn::LayerValidationException("inferredShapes has " + + std::to_string(inferredShapes.size()) + + " elements - should only have 1."); + } + + if (inferredShapes[0].GetDimensionality() != Dimensionality::Specified) + { + throw armnn::LayerValidationException("inferredShapes' dimensionality has not been specified."); + } ValidateAndCopyShape(outputShape, inferredShapes[0], m_ShapeInferenceMethod, "FullyConnectedLayer"); } diff --git a/src/armnn/layers/GatherLayer.cpp b/src/armnn/layers/GatherLayer.cpp index ae5ecd6cb6..359f3118dd 100644 --- a/src/armnn/layers/GatherLayer.cpp +++ b/src/armnn/layers/GatherLayer.cpp @@ -1,5 +1,5 @@ // -// Copyright © 2017,2019-2023 Arm Ltd and Contributors. All rights reserved. +// Copyright © 2017,2019-2024 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // @@ -33,7 +33,12 @@ GatherLayer* GatherLayer::Clone(Graph& graph) const std::vector<TensorShape> GatherLayer::InferOutputShapes(const std::vector<TensorShape>& inputShapes) const { - ARMNN_ASSERT(inputShapes.size() == 2); + if (inputShapes.size() != 2) + { + throw armnn::Exception("inputShapes' size is \"" + std::to_string(inputShapes.size()) + + "\" - should be \"2\"."); + } + const TensorShape& params = inputShapes[0]; const TensorShape& indices = inputShapes[1]; @@ -82,9 +87,19 @@ void GatherLayer::ValidateTensorShapesFromInputs() std::vector<TensorShape> inferredShapes = InferOutputShapes( {GetInputSlot(0).GetTensorInfo().GetShape(), GetInputSlot(1).GetTensorInfo().GetShape()}); - ARMNN_ASSERT(inferredShapes.size() == 1); - ARMNN_ASSERT(inferredShapes[0].GetDimensionality() == Dimensionality::Specified || - inferredShapes[0].GetDimensionality() == Dimensionality::Scalar); + + if (inferredShapes.size() != 1) + { + throw armnn::LayerValidationException("inferredShapes has " + + std::to_string(inferredShapes.size()) + + " elements - should only have 1."); + } + + if (inferredShapes[0].GetDimensionality() != Dimensionality::Specified && + inferredShapes[0].GetDimensionality() != Dimensionality::Scalar) + { + throw armnn::LayerValidationException("inferredShapes' dimensionality is neither specified nor scalar."); + } ValidateAndCopyShape(outputShape, inferredShapes[0], m_ShapeInferenceMethod, "GatherLayer"); } diff --git a/src/armnn/layers/GatherNdLayer.cpp b/src/armnn/layers/GatherNdLayer.cpp index 0f06946634..56e1500aa6 100644 --- a/src/armnn/layers/GatherNdLayer.cpp +++ b/src/armnn/layers/GatherNdLayer.cpp @@ -1,5 +1,5 @@ // -// Copyright © 2022-2023 Arm Ltd and Contributors. All rights reserved. +// Copyright © 2022-2024 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // @@ -33,7 +33,12 @@ GatherNdLayer* GatherNdLayer::Clone(Graph& graph) const std::vector<TensorShape> GatherNdLayer::InferOutputShapes(const std::vector<TensorShape>& inputShapes) const { - ARMNN_ASSERT(inputShapes.size() == 2); + if (inputShapes.size() != 2) + { + throw armnn::Exception("inputShapes' size is \"" + std::to_string(inputShapes.size()) + + "\" - should be \"2\"."); + } + const TensorShape& params = inputShapes[0]; const TensorShape& indices = inputShapes[1]; @@ -47,7 +52,13 @@ std::vector<TensorShape> GatherNdLayer::InferOutputShapes(const std::vector<Tens // last dimension of indices unsigned int index_depth = indices[indicesDim - 1]; - ARMNN_ASSERT(index_depth <= paramsDim); + if (index_depth > paramsDim) + { + throw armnn::Exception("index_depth must not be greater than paramsDim (\"" + + std::to_string(index_depth) + + "\" vs \"" + + std::to_string(paramsDim) + "\")"); + } // all but the last dimension of indices std::vector<unsigned int> outer_shape; @@ -86,9 +97,19 @@ void GatherNdLayer::ValidateTensorShapesFromInputs() std::vector<TensorShape> inferredShapes = InferOutputShapes( {GetInputSlot(0).GetTensorInfo().GetShape(), GetInputSlot(1).GetTensorInfo().GetShape()}); - ARMNN_ASSERT(inferredShapes.size() == 1); - ARMNN_ASSERT(inferredShapes[0].GetDimensionality() == Dimensionality::Specified || - inferredShapes[0].GetDimensionality() == Dimensionality::Scalar); + + if (inferredShapes.size() != 1) + { + throw armnn::LayerValidationException("inferredShapes has " + + std::to_string(inferredShapes.size()) + + " elements - should only have 1."); + } + + if (inferredShapes[0].GetDimensionality() != Dimensionality::Specified && + inferredShapes[0].GetDimensionality() != Dimensionality::Scalar) + { + throw armnn::LayerValidationException("inferredShapes' dimensionality is neither specified nor scalar."); + } ValidateAndCopyShape(outputShape, inferredShapes[0], m_ShapeInferenceMethod, "GatherNdLayer"); } diff --git a/src/armnn/layers/InstanceNormalizationLayer.cpp b/src/armnn/layers/InstanceNormalizationLayer.cpp index db6cd206cc..9cc9745ea3 100644 --- a/src/armnn/layers/InstanceNormalizationLayer.cpp +++ b/src/armnn/layers/InstanceNormalizationLayer.cpp @@ -1,5 +1,5 @@ // -// Copyright © 2019-2023 Arm Ltd and Contributors. All rights reserved. +// Copyright © 2019-2024 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // #include "InstanceNormalizationLayer.hpp" @@ -41,7 +41,12 @@ void InstanceNormalizationLayer::ValidateTensorShapesFromInputs() auto inferredShapes = InferOutputShapes({ GetInputSlot(0).GetTensorInfo().GetShape() }); - ARMNN_ASSERT(inferredShapes.size() == 1); + if (inferredShapes.size() != 1) + { + throw armnn::LayerValidationException("inferredShapes has " + + std::to_string(inferredShapes.size()) + + " elements - should only have 1."); + } ValidateAndCopyShape(outputShape, inferredShapes[0], m_ShapeInferenceMethod, "InstanceNormalizationLayer"); } diff --git a/src/armnn/layers/L2NormalizationLayer.cpp b/src/armnn/layers/L2NormalizationLayer.cpp index 2d268dddef..14a5f90d06 100644 --- a/src/armnn/layers/L2NormalizationLayer.cpp +++ b/src/armnn/layers/L2NormalizationLayer.cpp @@ -1,5 +1,5 @@ // -// Copyright © 2017-2023 Arm Ltd and Contributors. All rights reserved. +// Copyright © 2017-2024 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // #include "L2NormalizationLayer.hpp" @@ -41,7 +41,12 @@ void L2NormalizationLayer::ValidateTensorShapesFromInputs() auto inferredShapes = InferOutputShapes({ GetInputSlot(0).GetTensorInfo().GetShape() }); - ARMNN_ASSERT(inferredShapes.size() == 1); + if (inferredShapes.size() != 1) + { + throw armnn::LayerValidationException("inferredShapes has " + + std::to_string(inferredShapes.size()) + + " elements - should only have 1."); + } ValidateAndCopyShape(outputShape, inferredShapes[0], m_ShapeInferenceMethod, "L2NormalizationLayer"); } diff --git a/src/armnn/layers/LogSoftmaxLayer.cpp b/src/armnn/layers/LogSoftmaxLayer.cpp index 872d42297f..da82dfe658 100644 --- a/src/armnn/layers/LogSoftmaxLayer.cpp +++ b/src/armnn/layers/LogSoftmaxLayer.cpp @@ -1,5 +1,5 @@ // -// Copyright © 2019-2023 Arm Ltd and Contributors. All rights reserved. +// Copyright © 2019-2024 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // @@ -40,7 +40,13 @@ void LogSoftmaxLayer::ValidateTensorShapesFromInputs() VerifyShapeInferenceType(outputShape, m_ShapeInferenceMethod); auto inferredShapes = InferOutputShapes({ GetInputSlot(0).GetTensorInfo().GetShape() }); - ARMNN_ASSERT(inferredShapes.size() == 1); + + if (inferredShapes.size() != 1) + { + throw armnn::LayerValidationException("inferredShapes has " + + std::to_string(inferredShapes.size()) + + " elements - should only have 1."); + } ValidateAndCopyShape(outputShape, inferredShapes[0], m_ShapeInferenceMethod, "LogSoftmaxLayer"); } diff --git a/src/armnn/layers/LogicalBinaryLayer.cpp b/src/armnn/layers/LogicalBinaryLayer.cpp index 84a6e8e812..a781d6e283 100644 --- a/src/armnn/layers/LogicalBinaryLayer.cpp +++ b/src/armnn/layers/LogicalBinaryLayer.cpp @@ -1,5 +1,5 @@ // -// Copyright © 2020-2023 Arm Ltd and Contributors. All rights reserved. +// Copyright © 2020-2024 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // @@ -33,11 +33,23 @@ LogicalBinaryLayer* LogicalBinaryLayer::Clone(Graph& graph) const std::vector<TensorShape> LogicalBinaryLayer::InferOutputShapes(const std::vector<TensorShape>& inputShapes) const { - ARMNN_ASSERT(inputShapes.size() == 2); + if (inputShapes.size() != 2) + { + throw armnn::Exception("inputShapes' size is \"" + std::to_string(inputShapes.size()) + + "\" - should be \"2\"."); + } + const TensorShape& input0 = inputShapes[0]; const TensorShape& input1 = inputShapes[1]; - ARMNN_ASSERT(input0.GetNumDimensions() == input1.GetNumDimensions()); + if (input0.GetNumDimensions() != input1.GetNumDimensions()) + { + throw armnn::Exception("Input dimensions do not match (\"" + + std::to_string(input0.GetNumDimensions()) + + "\" vs \"" + + std::to_string(input1.GetNumDimensions()) + "\")."); + } + unsigned int numDims = input0.GetNumDimensions(); std::vector<unsigned int> dims(numDims); @@ -46,8 +58,10 @@ std::vector<TensorShape> LogicalBinaryLayer::InferOutputShapes(const std::vector unsigned int dim0 = input0[i]; unsigned int dim1 = input1[i]; - ARMNN_ASSERT_MSG(dim0 == dim1 || dim0 == 1 || dim1 == 1, - "Dimensions should either match or one should be of size 1."); + if (dim0 != dim1 && dim0 != 1 && dim1 != 1) + { + throw armnn::Exception("Dimensions should either match or one should be of size 1."); + } dims[i] = std::max(dim0, dim1); } @@ -67,7 +81,13 @@ void LogicalBinaryLayer::ValidateTensorShapesFromInputs() GetInputSlot(0).GetTensorInfo().GetShape(), GetInputSlot(1).GetTensorInfo().GetShape() }); - ARMNN_ASSERT(inferredShapes.size() == 1); + + if (inferredShapes.size() != 1) + { + throw armnn::LayerValidationException("inferredShapes has " + + std::to_string(inferredShapes.size()) + + " elements - should only have 1."); + } ValidateAndCopyShape(outputShape, inferredShapes[0], m_ShapeInferenceMethod, "LogicalBinaryLayer"); } diff --git a/src/armnn/layers/LstmLayer.cpp b/src/armnn/layers/LstmLayer.cpp index 0e6f3d882b..d87ad6461e 100644 --- a/src/armnn/layers/LstmLayer.cpp +++ b/src/armnn/layers/LstmLayer.cpp @@ -1,5 +1,5 @@ // -// Copyright © 2017-2023 Arm Ltd and Contributors. All rights reserved. +// Copyright © 2017-2024 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // #include "LstmLayer.hpp" @@ -149,7 +149,11 @@ LstmLayer* LstmLayer::Clone(Graph& graph) const std::vector<TensorShape> LstmLayer::InferOutputShapes(const std::vector<TensorShape>& inputShapes) const { - ARMNN_ASSERT(inputShapes.size() == 3); + if (inputShapes.size() != 3) + { + throw armnn::Exception("inputShapes' size is \"" + std::to_string(inputShapes.size()) + + "\" - should be \"3\"."); + } // Get input values for validation unsigned int batchSize = inputShapes[0][0]; @@ -179,69 +183,148 @@ void LstmLayer::ValidateTensorShapesFromInputs() GetInputSlot(2).GetTensorInfo().GetShape() }); - ARMNN_ASSERT(inferredShapes.size() == 4); + if (inferredShapes.size() != 4) + { + throw armnn::Exception("inferredShapes has " + + std::to_string(inferredShapes.size()) + + " element(s) - should only have 4."); + } // Check if the weights are nullptr - ARMNN_ASSERT_MSG(m_BasicParameters.m_InputToForgetWeights != nullptr, - "LstmLayer: m_BasicParameters.m_InputToForgetWeights should not be null."); - ARMNN_ASSERT_MSG(m_BasicParameters.m_InputToCellWeights != nullptr, - "LstmLayer: m_BasicParameters.m_InputToCellWeights should not be null."); - ARMNN_ASSERT_MSG(m_BasicParameters.m_InputToOutputWeights != nullptr, - "LstmLayer: m_BasicParameters.m_InputToOutputWeights should not be null."); - ARMNN_ASSERT_MSG(m_BasicParameters.m_RecurrentToForgetWeights != nullptr, - "LstmLayer: m_BasicParameters.m_RecurrentToForgetWeights should not be null."); - ARMNN_ASSERT_MSG(m_BasicParameters.m_RecurrentToCellWeights != nullptr, - "LstmLayer: m_BasicParameters.m_RecurrentToCellWeights should not be null."); - ARMNN_ASSERT_MSG(m_BasicParameters.m_RecurrentToOutputWeights != nullptr, - "LstmLayer: m_BasicParameters.m_RecurrentToOutputWeights should not be null."); - ARMNN_ASSERT_MSG(m_BasicParameters.m_ForgetGateBias != nullptr, - "LstmLayer: m_BasicParameters.m_ForgetGateBias should not be null."); - ARMNN_ASSERT_MSG(m_BasicParameters.m_CellBias != nullptr, - "LstmLayer: m_BasicParameters.m_CellBias should not be null."); - ARMNN_ASSERT_MSG(m_BasicParameters.m_OutputGateBias != nullptr, - "LstmLayer: m_BasicParameters.m_OutputGateBias should not be null."); + if (!m_BasicParameters.m_InputToForgetWeights) + { + throw armnn::NullPointerException("LstmLayer: " + "m_BasicParameters.m_InputToForgetWeights should not be null."); + } + + if (!m_BasicParameters.m_InputToCellWeights) + { + throw armnn::NullPointerException("LstmLayer: " + "m_BasicParameters.m_InputToCellWeights should not be null."); + } + + if (!m_BasicParameters.m_InputToOutputWeights) + { + throw armnn::NullPointerException("LstmLayer: " + "m_BasicParameters.m_InputToOutputWeights should not be null."); + } + + if (!m_BasicParameters.m_RecurrentToForgetWeights) + { + throw armnn::NullPointerException("LstmLayer: " + "m_BasicParameters.m_RecurrentToForgetWeights should not be null."); + } + + if (!m_BasicParameters.m_RecurrentToCellWeights) + { + throw armnn::NullPointerException("LstmLayer: " + "m_BasicParameters.m_RecurrentToCellWeights should not be null."); + } + + if (!m_BasicParameters.m_RecurrentToOutputWeights) + { + throw armnn::NullPointerException("LstmLayer: " + "m_BasicParameters.m_RecurrentToOutputWeights should not be null."); + } + + if (!m_BasicParameters.m_ForgetGateBias) + { + throw armnn::NullPointerException("LstmLayer: " + "m_BasicParameters.m_ForgetGateBias should not be null."); + } + + if (!m_BasicParameters.m_CellBias) + { + throw armnn::NullPointerException("LstmLayer: " + "m_BasicParameters.m_CellBias should not be null."); + } + + if (!m_BasicParameters.m_OutputGateBias) + { + throw armnn::NullPointerException("LstmLayer: " + "m_BasicParameters.m_OutputGateBias should not be null."); + } if (!m_Param.m_CifgEnabled) { - ARMNN_ASSERT_MSG(m_CifgParameters.m_InputToInputWeights != nullptr, - "LstmLayer: m_CifgParameters.m_InputToInputWeights should not be null."); - ARMNN_ASSERT_MSG(m_CifgParameters.m_RecurrentToInputWeights != nullptr, - "LstmLayer: m_CifgParameters.m_RecurrentToInputWeights should not be null."); - ARMNN_ASSERT_MSG(m_CifgParameters.m_InputGateBias != nullptr, - "LstmLayer: m_CifgParameters.m_InputGateBias should not be null."); + if (!m_CifgParameters.m_InputToInputWeights) + { + throw armnn::NullPointerException("LstmLayer: " + "m_CifgParameters.m_InputToInputWeights should not be null."); + } + + if (!m_CifgParameters.m_RecurrentToInputWeights) + { + throw armnn::NullPointerException("LstmLayer: " + "m_CifgParameters.m_RecurrentToInputWeights should not be null."); + } + + if (!m_CifgParameters.m_InputGateBias) + { + throw armnn::NullPointerException("LstmLayer: " + "m_CifgParameters.m_InputGateBias should not be null."); + } ValidateAndCopyShape(outputShape, inferredShapes[0], m_ShapeInferenceMethod, "LstmLayer"); } else { - ARMNN_ASSERT_MSG(m_CifgParameters.m_InputToInputWeights == nullptr, - "LstmLayer: m_CifgParameters.m_InputToInputWeights should not have a value when CIFG is enabled."); - ARMNN_ASSERT_MSG(m_CifgParameters.m_RecurrentToInputWeights == nullptr, - "LstmLayer: m_CifgParameters.m_RecurrentToInputWeights should not have a value when CIFG is enabled."); - ARMNN_ASSERT_MSG(m_CifgParameters.m_InputGateBias == nullptr, - "LstmLayer: m_CifgParameters.m_InputGateBias should not have a value when CIFG is enabled."); + if (m_CifgParameters.m_InputToInputWeights) + { + throw armnn::Exception("LstmLayer: " + "m_CifgParameters.m_InputToInputWeights should not have a value " + "when CIFG is enabled."); + } + + if (m_CifgParameters.m_RecurrentToInputWeights) + { + throw armnn::Exception("LstmLayer: " + "m_CifgParameters.m_RecurrentToInputWeights should not have a value " + "when CIFG is enabled."); + } + + if (m_CifgParameters.m_InputGateBias) + { + throw armnn::Exception("LstmLayer: " + "m_CifgParameters.m_InputGateBias should not have a value " + "when CIFG is enabled."); + } ValidateAndCopyShape(outputShape, inferredShapes[0], m_ShapeInferenceMethod, "LstmLayer"); } if (m_Param.m_ProjectionEnabled) { - ARMNN_ASSERT_MSG(m_ProjectionParameters.m_ProjectionWeights != nullptr, - "LstmLayer: m_ProjectionParameters.m_ProjectionWeights should not be null."); + if (!m_ProjectionParameters.m_ProjectionWeights) + { + throw armnn::NullPointerException("LstmLayer: " + "m_ProjectionParameters.m_ProjectionWeights should not be null."); + } } if (m_Param.m_PeepholeEnabled) { if (!m_Param.m_CifgEnabled) { - ARMNN_ASSERT_MSG(m_PeepholeParameters.m_CellToInputWeights != nullptr, - "LstmLayer: m_PeepholeParameters.m_CellToInputWeights should not be null " - "when Peephole is enabled and CIFG is disabled."); + if (!m_PeepholeParameters.m_CellToInputWeights) + { + throw armnn::NullPointerException("LstmLayer: " + "m_PeepholeParameters.m_CellToInputWeights should not be null " + "when Peephole is enabled and CIFG is disabled."); + } + } + + if (!m_PeepholeParameters.m_CellToForgetWeights) + { + throw armnn::NullPointerException("LstmLayer: " + "m_PeepholeParameters.m_CellToForgetWeights should not be null."); + } + + if (!m_PeepholeParameters.m_CellToOutputWeights) + { + throw armnn::NullPointerException("LstmLayer: " + "m_PeepholeParameters.m_CellToOutputWeights should not be null."); } - ARMNN_ASSERT_MSG(m_PeepholeParameters.m_CellToForgetWeights != nullptr, - "LstmLayer: m_PeepholeParameters.m_CellToForgetWeights should not be null."); - ARMNN_ASSERT_MSG(m_PeepholeParameters.m_CellToOutputWeights != nullptr, - "LstmLayer: m_PeepholeParameters.m_CellToOutputWeights should not be null."); } ValidateAndCopyShape( @@ -255,15 +338,30 @@ void LstmLayer::ValidateTensorShapesFromInputs() { if(!m_Param.m_CifgEnabled) { - ARMNN_ASSERT_MSG(m_LayerNormParameters.m_InputLayerNormWeights != nullptr, - "LstmLayer: m_LayerNormParameters.m_inputLayerNormWeights should not be null."); + if (!m_LayerNormParameters.m_InputLayerNormWeights) + { + throw armnn::NullPointerException("LstmLayer: " + "m_LayerNormParameters.m_inputLayerNormWeights should not be null."); + } + } + + if (!m_LayerNormParameters.m_ForgetLayerNormWeights) + { + throw armnn::NullPointerException("LstmLayer: " + "m_LayerNormParameters.m_forgetLayerNormWeights should not be null."); + } + + if (!m_LayerNormParameters.m_CellLayerNormWeights) + { + throw armnn::NullPointerException("LstmLayer: " + "m_LayerNormParameters.m_cellLayerNormWeights should not be null."); + } + + if (!m_LayerNormParameters.m_OutputLayerNormWeights) + { + throw armnn::NullPointerException("LstmLayer: " + "m_LayerNormParameters.m_outputLayerNormWeights should not be null."); } - ARMNN_ASSERT_MSG(m_LayerNormParameters.m_ForgetLayerNormWeights != nullptr, - "LstmLayer: m_LayerNormParameters.m_forgetLayerNormWeights should not be null."); - ARMNN_ASSERT_MSG(m_LayerNormParameters.m_CellLayerNormWeights != nullptr, - "LstmLayer: m_LayerNormParameters.m_cellLayerNormWeights should not be null."); - ARMNN_ASSERT_MSG(m_LayerNormParameters.m_OutputLayerNormWeights != nullptr, - "LstmLayer: m_LayerNormParameters.m_outputLayerNormWeights should not be null."); } } diff --git a/src/armnn/layers/MapLayer.cpp b/src/armnn/layers/MapLayer.cpp index 6141974122..71814a24de 100644 --- a/src/armnn/layers/MapLayer.cpp +++ b/src/armnn/layers/MapLayer.cpp @@ -1,5 +1,5 @@ // -// Copyright © 2020 Arm Ltd and Contributors. All rights reserved. +// Copyright © 2020,2024 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // #include "MapLayer.hpp" @@ -38,7 +38,11 @@ void MapLayer::ValidateTensorShapesFromInputs() { // validates that the input is connected. VerifyLayerConnections(1, CHECK_LOCATION()); - ARMNN_ASSERT(GetNumOutputSlots() == 0); + if (GetNumOutputSlots() != 0) + { + throw armnn::LayerValidationException("Output slots must be \"0\" - currently \"" + + std::to_string(GetNumOutputSlots()) + "\"."); + } } void MapLayer::ExecuteStrategy(IStrategy& strategy) const diff --git a/src/armnn/layers/MeanLayer.cpp b/src/armnn/layers/MeanLayer.cpp index bd49f509a0..62a3923750 100644 --- a/src/armnn/layers/MeanLayer.cpp +++ b/src/armnn/layers/MeanLayer.cpp @@ -1,5 +1,5 @@ // -// Copyright © 2017-2023 Arm Ltd and Contributors. All rights reserved. +// Copyright © 2017-2024 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // @@ -52,19 +52,35 @@ void MeanLayer::ValidateTensorShapesFromInputs() std::vector<TensorShape> inferredShapes = InferOutputShapes( { GetInputSlot(0).GetTensorInfo().GetShape() }); - ARMNN_ASSERT(inferredShapes.size() == 1); - ARMNN_ASSERT(inferredShapes[0].GetDimensionality() == Dimensionality::Specified); + if (inferredShapes.size() != 1) + { + throw armnn::LayerValidationException("inferredShapes has " + + std::to_string(inferredShapes.size()) + + " elements - should only have 1."); + } + + if (inferredShapes[0].GetDimensionality() != Dimensionality::Specified) + { + throw armnn::LayerValidationException("inferredShapes' dimensionality has not been specified."); + } ValidateAndCopyShape(outputShape, inferredShapes[0], m_ShapeInferenceMethod, "MeanLayer"); } std::vector<TensorShape> MeanLayer::InferOutputShapes(const std::vector<TensorShape>& inputShapes) const { - ARMNN_ASSERT(inputShapes.size() == 1); + if (inputShapes.size() != 1) + { + throw armnn::Exception("inputShapes' size is \"" + std::to_string(inputShapes.size()) + + "\" - should be \"1\"."); + } + const TensorShape& input = inputShapes[0]; - ARMNN_ASSERT_MSG(input.GetNumDimensions() > 0 && input.GetNumDimensions() <= 4, - "MeanLayer: Mean supports up to 4D input."); + if (auto inputDims = input.GetNumDimensions(); inputDims != std::clamp(inputDims, 1u, 4u)) + { + throw armnn::Exception("ReduceLayer: Reduce supports up to 4D input."); + } unsigned int rank = input.GetNumDimensions(); unsigned int outputRank = 0; diff --git a/src/armnn/layers/MemCopyLayer.cpp b/src/armnn/layers/MemCopyLayer.cpp index 6dd203448d..6fc7d73dd9 100644 --- a/src/armnn/layers/MemCopyLayer.cpp +++ b/src/armnn/layers/MemCopyLayer.cpp @@ -1,5 +1,5 @@ // -// Copyright © 2017-2023 Arm Ltd and Contributors. All rights reserved. +// Copyright © 2017-2024 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // #include "MemCopyLayer.hpp" @@ -44,7 +44,12 @@ void MemCopyLayer::ValidateTensorShapesFromInputs() auto inferredShapes = InferOutputShapes({ GetInputSlot(0).GetTensorInfo().GetShape() }); - ARMNN_ASSERT(inferredShapes.size() == 1); + if (inferredShapes.size() != 1) + { + throw armnn::LayerValidationException("inferredShapes has " + + std::to_string(inferredShapes.size()) + + " elements - should only have 1."); + } ValidateAndCopyShape(outputShape, inferredShapes[0], m_ShapeInferenceMethod, "MemCopyLayer"); } diff --git a/src/armnn/layers/MemImportLayer.cpp b/src/armnn/layers/MemImportLayer.cpp index a1c92f676e..10e6cd44c2 100644 --- a/src/armnn/layers/MemImportLayer.cpp +++ b/src/armnn/layers/MemImportLayer.cpp @@ -1,5 +1,5 @@ // -// Copyright © 2019-2023 Arm Ltd and Contributors. All rights reserved. +// Copyright © 2019-2024 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // #include "MemImportLayer.hpp" @@ -44,7 +44,12 @@ void MemImportLayer::ValidateTensorShapesFromInputs() auto inferredShapes = InferOutputShapes({ GetInputSlot(0).GetTensorInfo().GetShape() }); - ARMNN_ASSERT(inferredShapes.size() == 1); + if (inferredShapes.size() != 1) + { + throw armnn::LayerValidationException("inferredShapes has " + + std::to_string(inferredShapes.size()) + + " elements - should only have 1."); + } ValidateAndCopyShape(outputShape, inferredShapes[0], m_ShapeInferenceMethod, "MemImportLayer"); } diff --git a/src/armnn/layers/MergeLayer.cpp b/src/armnn/layers/MergeLayer.cpp index a3b098ae00..e8f92177eb 100644 --- a/src/armnn/layers/MergeLayer.cpp +++ b/src/armnn/layers/MergeLayer.cpp @@ -1,5 +1,5 @@ // -// Copyright © 2019-2023 Arm Ltd and Contributors. All rights reserved. +// Copyright © 2019-2024 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // #include "MergeLayer.hpp" @@ -40,14 +40,23 @@ void MergeLayer::ValidateTensorShapesFromInputs() GetInputSlot(1).GetTensorInfo().GetShape(), }); - ARMNN_ASSERT(inferredShapes.size() == 1); + if (inferredShapes.size() != 1) + { + throw armnn::LayerValidationException("inferredShapes has " + + std::to_string(inferredShapes.size()) + + " elements - should only have 1."); + } ValidateAndCopyShape(outputShape, inferredShapes[0], m_ShapeInferenceMethod, "MergeLayer"); } std::vector<TensorShape> MergeLayer::InferOutputShapes(const std::vector<TensorShape>& inputShapes) const { - ARMNN_ASSERT(inputShapes.size() == 2); + if (inputShapes.size() != 2) + { + throw armnn::Exception("inputShapes' size is \"" + std::to_string(inputShapes.size()) + + "\" - should be \"2\"."); + } ConditionalThrowIfNotEqual<LayerValidationException>( "MergeLayer: TensorShapes set on inputs do not match", diff --git a/src/armnn/layers/NormalizationLayer.cpp b/src/armnn/layers/NormalizationLayer.cpp index 24b6788ee6..b604b05d0f 100644 --- a/src/armnn/layers/NormalizationLayer.cpp +++ b/src/armnn/layers/NormalizationLayer.cpp @@ -1,5 +1,5 @@ // -// Copyright © 2017-2023 Arm Ltd and Contributors. All rights reserved. +// Copyright © 2017-2024 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // #include "NormalizationLayer.hpp" @@ -41,7 +41,12 @@ void NormalizationLayer::ValidateTensorShapesFromInputs() auto inferredShapes = InferOutputShapes({ GetInputSlot(0).GetTensorInfo().GetShape() }); - ARMNN_ASSERT(inferredShapes.size() == 1); + if (inferredShapes.size() != 1) + { + throw armnn::LayerValidationException("inferredShapes has " + + std::to_string(inferredShapes.size()) + + " elements - should only have 1."); + } ValidateAndCopyShape(outputShape, inferredShapes[0], m_ShapeInferenceMethod, "NormalizationLayer"); } diff --git a/src/armnn/layers/PadLayer.cpp b/src/armnn/layers/PadLayer.cpp index 0024ba5541..4b0b0e1d49 100644 --- a/src/armnn/layers/PadLayer.cpp +++ b/src/armnn/layers/PadLayer.cpp @@ -1,5 +1,5 @@ // -// Copyright © 2017-2023 Arm Ltd and Contributors. All rights reserved. +// Copyright © 2017-2024 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // @@ -41,12 +41,28 @@ PadLayer* PadLayer::Clone(Graph& graph) const std::vector<TensorShape> PadLayer::InferOutputShapes(const std::vector<TensorShape>& inputShapes) const { - ARMNN_ASSERT(inputShapes.size() == 1); + if (inputShapes.size() != 1) + { + throw armnn::Exception("inputShapes' size is \"" + std::to_string(inputShapes.size()) + + "\" - should be \"1\"."); + } + const TensorShape& inputShape = inputShapes[0]; unsigned int rank = inputShape.GetNumDimensions(); - ARMNN_ASSERT(m_Param.m_PadList.size() == rank); - ARMNN_ASSERT(rank != 0); + + if (m_Param.m_PadList.size() != rank) + { + throw armnn::Exception("Mismatch in size of mPadList and rank (\"" + + std::to_string(m_Param.m_PadList.size()) + + "\" vs " + + std::to_string(rank) + ")"); + } + + if (rank == 0) + { + throw armnn::Exception("rank must not equal 0."); + } std::vector<unsigned int> outputDimensionSizes(rank); for (unsigned int i = 0; i < rank; ++i) @@ -68,7 +84,12 @@ void PadLayer::ValidateTensorShapesFromInputs() auto inferredShapes = InferOutputShapes({ GetInputSlot(0).GetTensorInfo().GetShape() }); - ARMNN_ASSERT(inferredShapes.size() == 1); + if (inferredShapes.size() != 1) + { + throw armnn::LayerValidationException("inferredShapes has " + + std::to_string(inferredShapes.size()) + + " elements - should only have 1."); + } ValidateAndCopyShape(outputShape, inferredShapes[0], m_ShapeInferenceMethod, "PadLayer"); } diff --git a/src/armnn/layers/PermuteLayer.cpp b/src/armnn/layers/PermuteLayer.cpp index f8803a167e..3d3efc3209 100644 --- a/src/armnn/layers/PermuteLayer.cpp +++ b/src/armnn/layers/PermuteLayer.cpp @@ -1,5 +1,5 @@ // -// Copyright © 2017-2023 Arm Ltd and Contributors. All rights reserved. +// Copyright © 2017-2024 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // @@ -37,7 +37,12 @@ PermuteLayer* PermuteLayer::Clone(Graph& graph) const std::vector<TensorShape> PermuteLayer::InferOutputShapes(const std::vector<TensorShape>& inputShapes) const { - ARMNN_ASSERT(inputShapes.size() == 1); + if (inputShapes.size() != 1) + { + throw armnn::Exception("inputShapes' size is \"" + std::to_string(inputShapes.size()) + + "\" - should be \"1\"."); + } + const TensorShape& inShape = inputShapes[0]; return std::vector<TensorShape> ({armnnUtils::Permuted(inShape, m_Param.m_DimMappings)}); } @@ -52,7 +57,12 @@ void PermuteLayer::ValidateTensorShapesFromInputs() auto inferredShapes = InferOutputShapes({ GetInputSlot(0).GetTensorInfo().GetShape() }); - ARMNN_ASSERT(inferredShapes.size() == 1); + if (inferredShapes.size() != 1) + { + throw armnn::LayerValidationException("inferredShapes has " + + std::to_string(inferredShapes.size()) + + " elements - should only have 1."); + } ValidateAndCopyShape(outputShape, inferredShapes[0], m_ShapeInferenceMethod, "PermuteLayer"); } diff --git a/src/armnn/layers/Pooling2dLayer.cpp b/src/armnn/layers/Pooling2dLayer.cpp index e423b8bf38..1003867705 100644 --- a/src/armnn/layers/Pooling2dLayer.cpp +++ b/src/armnn/layers/Pooling2dLayer.cpp @@ -1,5 +1,5 @@ // -// Copyright © 2017-2023 Arm Ltd and Contributors. All rights reserved. +// Copyright © 2017-2024 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // @@ -39,12 +39,20 @@ Pooling2dLayer* Pooling2dLayer::Clone(Graph& graph) const std::vector<TensorShape> Pooling2dLayer::InferOutputShapes(const std::vector<TensorShape>& inputShapes) const { - ARMNN_ASSERT(inputShapes.size() == 1); + if (inputShapes.size() != 1) + { + throw armnn::Exception("inputShapes' size is \"" + std::to_string(inputShapes.size()) + + "\" - should be \"1\"."); + } + const TensorShape& inputShape = inputShapes[0]; const DataLayoutIndexed dimensionIndices = m_Param.m_DataLayout; // If we support multiple batch dimensions in the future, then this assert will need to change. - ARMNN_ASSERT_MSG(inputShape.GetNumDimensions() == 4, "Pooling2dLayer will always have 4D input."); + if (inputShape.GetNumDimensions() != 4) + { + throw armnn::Exception("Pooling2dLayer will always have 4D input."); + } unsigned int inWidth = inputShape[dimensionIndices.GetWidthIndex()]; unsigned int inHeight = inputShape[dimensionIndices.GetHeightIndex()]; @@ -56,8 +64,10 @@ std::vector<TensorShape> Pooling2dLayer::InferOutputShapes(const std::vector<Ten unsigned int outHeight = 1; if (!isGlobalPooling) { - ARMNN_ASSERT_MSG(m_Param.m_StrideX!=0 && m_Param.m_StrideY!=0, - "Stride can only be zero when performing global pooling"); + if (!m_Param.m_StrideX || !m_Param.m_StrideY) + { + throw armnn::Exception("Stride can only be zero when performing global pooling"); + } auto CalcSize = [](auto inSize, auto lowPad, auto highPad, auto poolSize, auto stride, auto outputShapeRounding) { @@ -74,7 +84,7 @@ std::vector<TensorShape> Pooling2dLayer::InferOutputShapes(const std::vector<Ten size = static_cast<unsigned int>(floor(div)) + 1; break; default: - ARMNN_ASSERT_MSG(false, "Unsupported Output Shape Rounding"); + throw armnn::Exception("Unsupported Output Shape Rounding"); } // MakeS sure that border operations will start from inside the input and not the padded area. @@ -112,7 +122,12 @@ void Pooling2dLayer::ValidateTensorShapesFromInputs() auto inferredShapes = InferOutputShapes({ GetInputSlot(0).GetTensorInfo().GetShape() }); - ARMNN_ASSERT(inferredShapes.size() == 1); + if (inferredShapes.size() != 1) + { + throw armnn::LayerValidationException("inferredShapes has " + + std::to_string(inferredShapes.size()) + + " elements - should only have 1."); + } ValidateAndCopyShape(outputShape, inferredShapes[0], m_ShapeInferenceMethod, "Pooling2dLayer"); } diff --git a/src/armnn/layers/Pooling3dLayer.cpp b/src/armnn/layers/Pooling3dLayer.cpp index ec1ec80f0e..0506efa7d3 100644 --- a/src/armnn/layers/Pooling3dLayer.cpp +++ b/src/armnn/layers/Pooling3dLayer.cpp @@ -1,5 +1,5 @@ // -// Copyright © 2021-2023 Arm Ltd and Contributors. All rights reserved. +// Copyright © 2021-2024 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // @@ -39,12 +39,20 @@ Pooling3dLayer* Pooling3dLayer::Clone(Graph& graph) const std::vector<TensorShape> Pooling3dLayer::InferOutputShapes(const std::vector<TensorShape>& inputShapes) const { - ARMNN_ASSERT(inputShapes.size() == 1); + if (inputShapes.size() != 1) + { + throw armnn::Exception("inputShapes' size is \"" + std::to_string(inputShapes.size()) + + "\" - should be \"1\"."); + } + const TensorShape& inputShape = inputShapes[0]; const DataLayoutIndexed dimensionIndices = m_Param.m_DataLayout; // If we support multiple batch dimensions in the future, then this assert will need to change. - ARMNN_ASSERT_MSG(inputShape.GetNumDimensions() == 5, "Pooling3dLayer will always have 5D input."); + if (inputShape.GetNumDimensions() != 5) + { + throw armnn::Exception("Pooling3dLayer will always have 5D input."); + } unsigned int inWidth = inputShape[dimensionIndices.GetWidthIndex()]; unsigned int inHeight = inputShape[dimensionIndices.GetHeightIndex()]; @@ -58,8 +66,10 @@ std::vector<TensorShape> Pooling3dLayer::InferOutputShapes(const std::vector<Ten unsigned int outDepth = 1; if (!isGlobalPooling) { - ARMNN_ASSERT_MSG(m_Param.m_StrideX!=0 && m_Param.m_StrideY!=0 && m_Param.m_StrideZ!=0, - "Stride can only be zero when performing global pooling"); + if (!m_Param.m_StrideX || !m_Param.m_StrideY || !m_Param.m_StrideZ) + { + throw armnn::Exception("Stride can only be zero when performing global pooling"); + } auto CalcSize = [](auto inSize, auto lowPad, auto highPad, auto poolSize, auto stride, auto outputShapeRounding) { @@ -76,7 +86,7 @@ std::vector<TensorShape> Pooling3dLayer::InferOutputShapes(const std::vector<Ten size = static_cast<unsigned int>(floor(div)) + 1; break; default: - ARMNN_ASSERT_MSG(false, "Unsupported Output Shape Rounding"); + throw armnn::Exception("Unsupported Output Shape Rounding"); } // Makes sure that border operations will start from inside the input and not the padded area. @@ -116,7 +126,12 @@ void Pooling3dLayer::ValidateTensorShapesFromInputs() auto inferredShapes = InferOutputShapes({ GetInputSlot(0).GetTensorInfo().GetShape() }); - ARMNN_ASSERT(inferredShapes.size() == 1); + if (inferredShapes.size() != 1) + { + throw armnn::LayerValidationException("inferredShapes has " + + std::to_string(inferredShapes.size()) + + " elements - should only have 1."); + } ValidateAndCopyShape(outputShape, inferredShapes[0], m_ShapeInferenceMethod, "Pooling3dLayer"); } diff --git a/src/armnn/layers/PreluLayer.cpp b/src/armnn/layers/PreluLayer.cpp index a302640434..874ee6b152 100644 --- a/src/armnn/layers/PreluLayer.cpp +++ b/src/armnn/layers/PreluLayer.cpp @@ -1,5 +1,5 @@ // -// Copyright © 2017,2019-2023 Arm Ltd and Contributors. All rights reserved. +// Copyright © 2017,2019-2024 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // @@ -37,7 +37,11 @@ PreluLayer* PreluLayer::Clone(Graph& graph) const std::vector<TensorShape> PreluLayer::InferOutputShapes(const std::vector<TensorShape>& inputShapes) const { - ARMNN_ASSERT(inputShapes.size() == 2); + if (inputShapes.size() != 2) + { + throw armnn::Exception("inputShapes' size is \"" + std::to_string(inputShapes.size()) + + "\" - should be \"2\"."); + } const TensorShape& inputShape = inputShapes[0]; const TensorShape& alphaShape = inputShapes[1]; @@ -45,8 +49,16 @@ std::vector<TensorShape> PreluLayer::InferOutputShapes(const std::vector<TensorS const unsigned int inputShapeDimensions = inputShape.GetNumDimensions(); const unsigned int alphaShapeDimensions = alphaShape.GetNumDimensions(); - ARMNN_ASSERT(inputShapeDimensions > 0); - ARMNN_ASSERT(alphaShapeDimensions > 0); + if (inputShapeDimensions == 0) + { + throw armnn::Exception("inputShapeDimensions must be greater than 0."); + } + + if (alphaShapeDimensions == 0) + { + throw armnn::Exception("alphaShapeDimensions must be not be zero (\"" + + std::to_string(alphaShapeDimensions) + "\")"); + } // The size of the output is the maximum size along each dimension of the input operands, // it starts with the trailing dimensions, and works its way forward @@ -66,8 +78,10 @@ std::vector<TensorShape> PreluLayer::InferOutputShapes(const std::vector<TensorS unsigned int alphaDimension = alphaShape[armnn::numeric_cast<unsigned int>(alphaShapeIndex)]; // Check that the inputs are broadcast compatible - ARMNN_ASSERT_MSG(inputDimension == alphaDimension || inputDimension == 1 || alphaDimension == 1, - "PreluLayer: Dimensions should either match or one should be of size 1"); + if (inputDimension != alphaDimension && inputDimension != 1 && alphaDimension != 1) + { + throw armnn::Exception("PreluLayer: Dimensions should either match or one should be of size 1"); + } outputShape[outputShapeIndex] = std::max(inputDimension, alphaDimension); @@ -111,7 +125,12 @@ void PreluLayer::ValidateTensorShapesFromInputs() GetInputSlot(1).GetTensorInfo().GetShape() }); - ARMNN_ASSERT(inferredShapes.size() == 1); + if (inferredShapes.size() != 1) + { + throw armnn::LayerValidationException("inferredShapes has " + + std::to_string(inferredShapes.size()) + + " elements - should only have 1."); + } ValidateAndCopyShape(outputShape, inferredShapes[0], m_ShapeInferenceMethod, "PreluLayer"); } diff --git a/src/armnn/layers/QLstmLayer.cpp b/src/armnn/layers/QLstmLayer.cpp index eeb01db51d..e98deb6a88 100644 --- a/src/armnn/layers/QLstmLayer.cpp +++ b/src/armnn/layers/QLstmLayer.cpp @@ -1,5 +1,5 @@ // -// Copyright © 2020-2023 Arm Ltd and Contributors. All rights reserved. +// Copyright © 2020-2024 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // #include "QLstmLayer.hpp" @@ -152,7 +152,11 @@ QLstmLayer* QLstmLayer::Clone(Graph& graph) const std::vector<TensorShape> QLstmLayer::InferOutputShapes(const std::vector<TensorShape>& inputShapes) const { - ARMNN_ASSERT(inputShapes.size() == 3); + if (inputShapes.size() != 3) + { + throw armnn::Exception("inputShapes' size is \"" + std::to_string(inputShapes.size()) + + "\" - should be \"3\"."); + } // Get input values for validation unsigned int batchSize = inputShapes[0][0]; @@ -182,70 +186,147 @@ void QLstmLayer::ValidateTensorShapesFromInputs() GetInputSlot(2).GetTensorInfo().GetShape() // previousCellStateIn }); - ARMNN_ASSERT(inferredShapes.size() == 3); + if (inferredShapes.size() != 3) + { + throw armnn::LayerValidationException("inferredShapes has " + + std::to_string(inferredShapes.size()) + + " element(s) - should only have 3."); + } // Check if the weights are nullptr for basic params - ARMNN_ASSERT_MSG(m_BasicParameters.m_InputToForgetWeights != nullptr, - "QLstmLayer: m_BasicParameters.m_InputToForgetWeights should not be null."); - ARMNN_ASSERT_MSG(m_BasicParameters.m_InputToCellWeights != nullptr, - "QLstmLayer: m_BasicParameters.m_InputToCellWeights should not be null."); - ARMNN_ASSERT_MSG(m_BasicParameters.m_InputToOutputWeights != nullptr, - "QLstmLayer: m_BasicParameters.m_InputToOutputWeights should not be null."); - ARMNN_ASSERT_MSG(m_BasicParameters.m_RecurrentToForgetWeights != nullptr, - "QLstmLayer: m_BasicParameters.m_RecurrentToForgetWeights should not be null."); - ARMNN_ASSERT_MSG(m_BasicParameters.m_RecurrentToCellWeights != nullptr, - "QLstmLayer: m_BasicParameters.m_RecurrentToCellWeights should not be null."); - ARMNN_ASSERT_MSG(m_BasicParameters.m_RecurrentToOutputWeights != nullptr, - "QLstmLayer: m_BasicParameters.m_RecurrentToOutputWeights should not be null."); - ARMNN_ASSERT_MSG(m_BasicParameters.m_ForgetGateBias != nullptr, - "QLstmLayer: m_BasicParameters.m_ForgetGateBias should not be null."); - ARMNN_ASSERT_MSG(m_BasicParameters.m_CellBias != nullptr, - "QLstmLayer: m_BasicParameters.m_CellBias should not be null."); - ARMNN_ASSERT_MSG(m_BasicParameters.m_OutputGateBias != nullptr, - "QLstmLayer: m_BasicParameters.m_OutputGateBias should not be null."); + if (!m_BasicParameters.m_InputToForgetWeights) + { + throw armnn::LayerValidationException("QLstmLayer: " + "m_BasicParameters.m_InputToForgetWeights should not be null."); + } + + if (!m_BasicParameters.m_InputToCellWeights) + { + throw armnn::LayerValidationException("QLstmLayer: " + "m_BasicParameters.m_InputToCellWeights should not be null."); + } + + if (!m_BasicParameters.m_InputToOutputWeights) + { + throw armnn::LayerValidationException("QLstmLayer: " + "m_BasicParameters.m_InputToOutputWeights should not be null."); + } + + if (!m_BasicParameters.m_RecurrentToForgetWeights) + { + throw armnn::LayerValidationException("QLstmLayer: " + "m_BasicParameters.m_RecurrentToForgetWeights should not be null."); + } + + if (!m_BasicParameters.m_RecurrentToCellWeights) + { + throw armnn::LayerValidationException("QLstmLayer: " + "m_BasicParameters.m_RecurrentToCellWeights should not be null."); + } + + if (!m_BasicParameters.m_RecurrentToOutputWeights) + { + throw armnn::LayerValidationException("QLstmLayer: " + "m_BasicParameters.m_RecurrentToOutputWeights should not be null."); + } + + if (!m_BasicParameters.m_ForgetGateBias) + { + throw armnn::LayerValidationException("QLstmLayer: " + "m_BasicParameters.m_ForgetGateBias should not be null."); + } + + if (!m_BasicParameters.m_CellBias) + { + throw armnn::LayerValidationException("QLstmLayer: " + "m_BasicParameters.m_CellBias should not be null."); + } + + if (!m_BasicParameters.m_OutputGateBias) + { + throw armnn::LayerValidationException("QLstmLayer: " + "m_BasicParameters.m_OutputGateBias should not be null."); + } if (!m_Param.m_CifgEnabled) { - ARMNN_ASSERT_MSG(m_CifgParameters.m_InputToInputWeights != nullptr, - "QLstmLayer: m_CifgParameters.m_InputToInputWeights should not be null."); - ARMNN_ASSERT_MSG(m_CifgParameters.m_RecurrentToInputWeights != nullptr, - "QLstmLayer: m_CifgParameters.m_RecurrentToInputWeights should not be null."); - ARMNN_ASSERT_MSG(m_CifgParameters.m_InputGateBias != nullptr, - "QLstmLayer: m_CifgParameters.m_InputGateBias should not be null."); + if (!m_CifgParameters.m_InputToInputWeights) + { + throw armnn::LayerValidationException("QLstmLayer: " + "m_CifgParameters.m_InputToInputWeights should not be null."); + } + + if (!m_CifgParameters.m_RecurrentToInputWeights) + { + throw armnn::LayerValidationException("QLstmLayer: " + "m_CifgParameters.m_RecurrentToInputWeights should not be null."); + } + + if (!m_CifgParameters.m_InputGateBias) + { + throw armnn::LayerValidationException("QLstmLayer: " + "m_CifgParameters.m_InputGateBias should not be null."); + } ValidateAndCopyShape(outputShape, inferredShapes[0], m_ShapeInferenceMethod, "QLstmLayer"); } else { - ARMNN_ASSERT_MSG(m_CifgParameters.m_InputToInputWeights == nullptr, - "QLstmLayer: m_CifgParameters.m_InputToInputWeights should not have a value when CIFG is enabled."); - ARMNN_ASSERT_MSG(m_CifgParameters.m_RecurrentToInputWeights == nullptr, - "QLstmLayer: m_CifgParameters.m_RecurrentToInputWeights should " - "not have a value when CIFG is enabled."); - ARMNN_ASSERT_MSG(m_CifgParameters.m_InputGateBias == nullptr, - "QLstmLayer: m_CifgParameters.m_InputGateBias should not have a value when CIFG is enabled."); + if (m_CifgParameters.m_InputToInputWeights) + { + throw armnn::LayerValidationException("QLstmLayer: " + "m_CifgParameters.m_InputToInputWeights " + "should not have a value when CIFG is enabled."); + } + + if (m_CifgParameters.m_RecurrentToInputWeights) + { + throw armnn::LayerValidationException("QLstmLayer: " + "m_CifgParameters.m_RecurrentToInputWeights " + "should not have a value when CIFG is enabled."); + } + + if (m_CifgParameters.m_InputGateBias) + { + throw armnn::LayerValidationException("QLstmLayer: " + "m_CifgParameters.m_InputGateBias " + "should not have a value when CIFG is enabled."); + } ValidateAndCopyShape(outputShape, inferredShapes[0], m_ShapeInferenceMethod, "QLstmLayer"); } if (m_Param.m_ProjectionEnabled) { - ARMNN_ASSERT_MSG(m_ProjectionParameters.m_ProjectionWeights != nullptr, - "QLstmLayer: m_ProjectionParameters.m_ProjectionWeights should not be null."); + if (!m_ProjectionParameters.m_ProjectionWeights) + { + throw armnn::LayerValidationException("QLstmLayer: " + "m_ProjectionParameters.m_ProjectionWeights should not be null."); + } } if (m_Param.m_PeepholeEnabled) { if (!m_Param.m_CifgEnabled) { - ARMNN_ASSERT_MSG(m_PeepholeParameters.m_CellToInputWeights != nullptr, - "QLstmLayer: m_PeepholeParameters.m_CellToInputWeights should not be null " - "when Peephole is enabled and CIFG is disabled."); + if (!m_PeepholeParameters.m_CellToInputWeights) + { + throw armnn::LayerValidationException("QLstmLayer: " + "m_PeepholeParameters.m_CellToInputWeights should not be null " + "when Peephole is enabled and CIFG is disabled."); + } } - ARMNN_ASSERT_MSG(m_PeepholeParameters.m_CellToForgetWeights != nullptr, - "QLstmLayer: m_PeepholeParameters.m_CellToForgetWeights should not be null."); - ARMNN_ASSERT_MSG(m_PeepholeParameters.m_CellToOutputWeights != nullptr, - "QLstmLayer: m_PeepholeParameters.m_CellToOutputWeights should not be null."); + if (!m_PeepholeParameters.m_CellToForgetWeights) + { + throw armnn::LayerValidationException("QLstmLayer: " + "m_PeepholeParameters.m_CellToForgetWeights should not be null."); + } + + if (!m_PeepholeParameters.m_CellToOutputWeights) + { + throw armnn::LayerValidationException("QLstmLayer: " + "m_PeepholeParameters.m_CellToOutputWeights should not be null."); + } } ValidateAndCopyShape( @@ -255,17 +336,32 @@ void QLstmLayer::ValidateTensorShapesFromInputs() if (m_Param.m_LayerNormEnabled) { - if(!m_Param.m_CifgEnabled) + if (!m_Param.m_CifgEnabled) + { + if (!m_LayerNormParameters.m_InputLayerNormWeights) + { + throw armnn::LayerValidationException("QLstmLayer: m_LayerNormParameters.m_InputLayerNormWeights " + "should not be null."); + } + } + + if (!m_LayerNormParameters.m_ForgetLayerNormWeights) + { + throw armnn::LayerValidationException("QLstmLayer: " + "m_LayerNormParameters.m_ForgetLayerNormWeights should not be null."); + } + + if (!m_LayerNormParameters.m_CellLayerNormWeights) + { + throw armnn::LayerValidationException("QLstmLayer: " + "m_LayerNormParameters.m_CellLayerNormWeights should not be null."); + } + + if (!m_LayerNormParameters.m_OutputLayerNormWeights) { - ARMNN_ASSERT_MSG(m_LayerNormParameters.m_InputLayerNormWeights != nullptr, - "QLstmLayer: m_LayerNormParameters.m_InputLayerNormWeights should not be null."); + throw armnn::LayerValidationException("QLstmLayer: " + "m_LayerNormParameters.m_UutputLayerNormWeights should not be null."); } - ARMNN_ASSERT_MSG(m_LayerNormParameters.m_ForgetLayerNormWeights != nullptr, - "QLstmLayer: m_LayerNormParameters.m_ForgetLayerNormWeights should not be null."); - ARMNN_ASSERT_MSG(m_LayerNormParameters.m_CellLayerNormWeights != nullptr, - "QLstmLayer: m_LayerNormParameters.m_CellLayerNormWeights should not be null."); - ARMNN_ASSERT_MSG(m_LayerNormParameters.m_OutputLayerNormWeights != nullptr, - "QLstmLayer: m_LayerNormParameters.m_UutputLayerNormWeights should not be null."); } } diff --git a/src/armnn/layers/QuantizedLstmLayer.cpp b/src/armnn/layers/QuantizedLstmLayer.cpp index c82e34f983..ebe320718c 100644 --- a/src/armnn/layers/QuantizedLstmLayer.cpp +++ b/src/armnn/layers/QuantizedLstmLayer.cpp @@ -1,5 +1,5 @@ // -// Copyright © 2017,2019-2023 Arm Ltd and Contributors. All rights reserved. +// Copyright © 2017,2019-2024 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // #include "QuantizedLstmLayer.hpp" @@ -80,7 +80,11 @@ QuantizedLstmLayer* QuantizedLstmLayer::Clone(Graph& graph) const std::vector<TensorShape> QuantizedLstmLayer::InferOutputShapes(const std::vector<TensorShape>& inputShapes) const { - ARMNN_ASSERT(inputShapes.size() == 3); + if (inputShapes.size() != 3) + { + throw armnn::Exception("inputShapes' size is \"" + std::to_string(inputShapes.size()) + + "\" - should be \"3\"."); + } // Get input values for validation unsigned int numBatches = inputShapes[0][0]; @@ -108,35 +112,97 @@ void QuantizedLstmLayer::ValidateTensorShapesFromInputs() GetInputSlot(2).GetTensorInfo().GetShape() // previousOutputIn }); - ARMNN_ASSERT(inferredShapes.size() == 2); + if (inferredShapes.size() != 2) + { + throw armnn::LayerValidationException("inferredShapes has " + + std::to_string(inferredShapes.size()) + + " element(s) - should only have 2."); + } // Check weights and bias for nullptr - ARMNN_ASSERT_MSG(m_QuantizedLstmParameters.m_InputToInputWeights != nullptr, - "QuantizedLstmLayer: m_QuantizedLstmParameters.m_InputToInputWeights should not be null."); - ARMNN_ASSERT_MSG(m_QuantizedLstmParameters.m_InputToForgetWeights != nullptr, - "QuantizedLstmLayer: m_QuantizedLstmParameters.m_InputToForgetWeights should not be null."); - ARMNN_ASSERT_MSG(m_QuantizedLstmParameters.m_InputToCellWeights != nullptr, - "QuantizedLstmLayer: m_QuantizedLstmParameters.m_InputToCellWeights should not be null."); - ARMNN_ASSERT_MSG(m_QuantizedLstmParameters.m_InputToOutputWeights != nullptr, - "QuantizedLstmLayer: m_QuantizedLstmParameters.m_InputToOutputWeights should not be null."); - - ARMNN_ASSERT_MSG(m_QuantizedLstmParameters.m_RecurrentToInputWeights != nullptr, - "QuantizedLstmLayer: m_QuantizedLstmParameters.m_RecurrentToInputWeights should not be null."); - ARMNN_ASSERT_MSG(m_QuantizedLstmParameters.m_RecurrentToForgetWeights != nullptr, - "QuantizedLstmLayer: m_QuantizedLstmParameters.m_RecurrentToForgetWeights should not be null."); - ARMNN_ASSERT_MSG(m_QuantizedLstmParameters.m_RecurrentToCellWeights != nullptr, - "QuantizedLstmLayer: m_QuantizedLstmParameters.m_RecurrentToCellWeights should not be null."); - ARMNN_ASSERT_MSG(m_QuantizedLstmParameters.m_RecurrentToOutputWeights != nullptr, - "QuantizedLstmLayer: m_QuantizedLstmParameters.m_RecurrentToOutputWeights should not be null."); - - ARMNN_ASSERT_MSG(m_QuantizedLstmParameters.m_InputGateBias != nullptr, - "QuantizedLstmLayer: m_QuantizedLstmParameters.m_InputGateBias should not be null."); - ARMNN_ASSERT_MSG(m_QuantizedLstmParameters.m_ForgetGateBias != nullptr, - "QuantizedLstmLayer: m_QuantizedLstmParameters.m_ForgetGateBias should not be null."); - ARMNN_ASSERT_MSG(m_QuantizedLstmParameters.m_CellBias != nullptr, - "QuantizedLstmLayer: m_QuantizedLstmParameters.m_CellBias should not be null."); - ARMNN_ASSERT_MSG(m_QuantizedLstmParameters.m_OutputGateBias != nullptr, - "QuantizedLstmLayer: m_QuantizedLstmParameters.m_OutputGateBias should not be null."); + if (!m_QuantizedLstmParameters.m_InputToInputWeights) + { + throw armnn::LayerValidationException("QuantizedLstmLayer: " + "m_QuantizedLstmParameters.m_InputToInputWeights " + "should not be null."); + } + + if (!m_QuantizedLstmParameters.m_InputToForgetWeights) + { + throw armnn::LayerValidationException("QuantizedLstmLayer: " + "m_QuantizedLstmParameters.m_InputToForgetWeights " + "should not be null."); + } + + if (!m_QuantizedLstmParameters.m_InputToCellWeights) + { + throw armnn::LayerValidationException("QuantizedLstmLayer: " + "m_QuantizedLstmParameters.m_InputToCellWeights " + "should not be null."); + } + + if (!m_QuantizedLstmParameters.m_InputToOutputWeights) + { + throw armnn::LayerValidationException("QuantizedLstmLayer: " + "m_QuantizedLstmParameters.m_InputToOutputWeights " + "should not be null."); + } + + if (!m_QuantizedLstmParameters.m_RecurrentToInputWeights) + { + throw armnn::LayerValidationException("QuantizedLstmLayer: " + "m_QuantizedLstmParameters.m_RecurrentToInputWeights " + "should not be null."); + } + + if (!m_QuantizedLstmParameters.m_RecurrentToForgetWeights) + { + throw armnn::LayerValidationException("QuantizedLstmLayer: " + "m_QuantizedLstmParameters.m_RecurrentToForgetWeights " + "should not be null."); + } + + if (!m_QuantizedLstmParameters.m_RecurrentToCellWeights) + { + throw armnn::LayerValidationException("QuantizedLstmLayer: " + "m_QuantizedLstmParameters.m_RecurrentToCellWeights " + "should not be null."); + } + + if (!m_QuantizedLstmParameters.m_RecurrentToOutputWeights) + { + throw armnn::LayerValidationException("QuantizedLstmLayer: " + "m_QuantizedLstmParameters.m_RecurrentToOutputWeights " + "should not be null."); + } + + if (!m_QuantizedLstmParameters.m_InputGateBias) + { + throw armnn::LayerValidationException("QuantizedLstmLayer: " + "m_QuantizedLstmParameters.m_InputGateBias " + "should not be null."); + } + + if (!m_QuantizedLstmParameters.m_ForgetGateBias) + { + throw armnn::LayerValidationException("QuantizedLstmLayer: " + "m_QuantizedLstmParameters.m_ForgetGateBias " + "should not be null."); + } + + if (!m_QuantizedLstmParameters.m_CellBias) + { + throw armnn::LayerValidationException("QuantizedLstmLayer: " + "m_QuantizedLstmParameters.m_CellBias " + "should not be null."); + } + + if (!m_QuantizedLstmParameters.m_OutputGateBias) + { + throw armnn::LayerValidationException("QuantizedLstmLayer: " + "m_QuantizedLstmParameters.m_OutputGateBias " + "should not be null."); + } // Check output TensorShape(s) match inferred shape ValidateAndCopyShape(outputShape, inferredShapes[0], m_ShapeInferenceMethod, "QuantizedLstmLayer"); diff --git a/src/armnn/layers/ReduceLayer.cpp b/src/armnn/layers/ReduceLayer.cpp index 21095dda74..bebd043e9b 100644 --- a/src/armnn/layers/ReduceLayer.cpp +++ b/src/armnn/layers/ReduceLayer.cpp @@ -1,6 +1,6 @@ // // Copyright © 2020 Samsung Electronics Co Ltd and Contributors. All rights reserved. -// Copyright © 2023 Arm Ltd and Contributors. All rights reserved. +// Copyright © 2023-2024 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // @@ -51,8 +51,10 @@ void ReduceLayer::ValidateTensorShapesFromInputs() const TensorInfo& input = GetInputSlot(0).GetTensorInfo(); - ARMNN_ASSERT_MSG(input.GetNumDimensions() > 0 && input.GetNumDimensions() <= 4, - "ReduceLayer: Reduce supports up to 4D input."); + if (auto inputDims = input.GetNumDimensions(); inputDims != std::clamp(inputDims, 1u, 4u)) + { + throw armnn::LayerValidationException("ReduceLayer: Reduce supports up to 4D input."); + } std::vector<TensorShape> inferredShapes = InferOutputShapes( {input.GetShape() }); @@ -61,11 +63,18 @@ void ReduceLayer::ValidateTensorShapesFromInputs() std::vector<TensorShape> ReduceLayer::InferOutputShapes(const std::vector<TensorShape>& inputShapes) const { - ARMNN_ASSERT(inputShapes.size() == 1); + if (inputShapes.size() != 1) + { + throw armnn::Exception("inputShapes' size is \"" + std::to_string(inputShapes.size()) + + "\" - should be \"1\"."); + } + const TensorShape& input = inputShapes[0]; - ARMNN_ASSERT_MSG(input.GetNumDimensions() > 0 && input.GetNumDimensions() <= 4, - "ReduceLayer: Reduce supports up to 4D input."); + if (auto inputDims = input.GetNumDimensions(); inputDims != std::clamp(inputDims, 1u, 4u)) + { + throw armnn::Exception("ReduceLayer: Reduce supports up to 4D input."); + } unsigned int rank = input.GetNumDimensions(); unsigned int outputRank = 0; diff --git a/src/armnn/layers/ReshapeLayer.cpp b/src/armnn/layers/ReshapeLayer.cpp index b786f54fe3..f6480b0ff5 100644 --- a/src/armnn/layers/ReshapeLayer.cpp +++ b/src/armnn/layers/ReshapeLayer.cpp @@ -1,5 +1,5 @@ // -// Copyright © 2017-2023 Arm Ltd and Contributors. All rights reserved. +// Copyright © 2017-2024 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // #include "ReshapeLayer.hpp" @@ -48,8 +48,17 @@ void ReshapeLayer::ValidateTensorShapesFromInputs() auto inferredShapes = InferOutputShapes({ GetInputSlot(0).GetTensorInfo().GetShape() }); - ARMNN_ASSERT(inferredShapes.size() == 1); - ARMNN_ASSERT(inferredShapes[0].GetDimensionality() == Dimensionality::Specified); + if (inferredShapes.size() != 1) + { + throw armnn::LayerValidationException("inferredShapes has " + + std::to_string(inferredShapes.size()) + + " elements - should only have 1."); + } + + if (inferredShapes[0].GetDimensionality() != Dimensionality::Specified) + { + throw armnn::LayerValidationException("inferredShapes' dimensionality has not been specified."); + } ValidateAndCopyShape(outputShape, inferredShapes[0], m_ShapeInferenceMethod, "ReshapeLayer"); } diff --git a/src/armnn/layers/ResizeLayer.cpp b/src/armnn/layers/ResizeLayer.cpp index 734df0a9a2..0b60db28ee 100644 --- a/src/armnn/layers/ResizeLayer.cpp +++ b/src/armnn/layers/ResizeLayer.cpp @@ -1,5 +1,5 @@ // -// Copyright © 2019-2023 Arm Ltd and Contributors. All rights reserved. +// Copyright © 2019-2024 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // @@ -38,7 +38,11 @@ ResizeLayer* ResizeLayer::Clone(Graph& graph) const std::vector<TensorShape> ResizeLayer::InferOutputShapes(const std::vector<TensorShape>& inputShapes) const { - ARMNN_ASSERT(inputShapes.size() == 1); + if (inputShapes.size() != 1) + { + throw armnn::Exception("inputShapes' size is \"" + std::to_string(inputShapes.size()) + + "\" - should be \"1\"."); + } const TensorShape& inputShape = inputShapes[0]; const DataLayoutIndexed dimensionIndices = m_Param.m_DataLayout; @@ -70,7 +74,12 @@ void ResizeLayer::ValidateTensorShapesFromInputs() auto inferredShapes = InferOutputShapes({ GetInputSlot(0).GetTensorInfo().GetShape() }); - ARMNN_ASSERT(inferredShapes.size() == 1); + if (inferredShapes.size() != 1) + { + throw armnn::LayerValidationException("inferredShapes has " + + std::to_string(inferredShapes.size()) + + " elements - should only have 1."); + } ValidateAndCopyShape(outputShape, inferredShapes[0], m_ShapeInferenceMethod, "ResizeLayer"); } diff --git a/src/armnn/layers/ReverseV2Layer.cpp b/src/armnn/layers/ReverseV2Layer.cpp index e1160b6e16..1c46b79875 100644 --- a/src/armnn/layers/ReverseV2Layer.cpp +++ b/src/armnn/layers/ReverseV2Layer.cpp @@ -1,5 +1,5 @@ // -// Copyright © 2023 Arm Ltd and Contributors. All rights reserved. +// Copyright © 2024 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // @@ -32,7 +32,11 @@ ReverseV2Layer* ReverseV2Layer::Clone(armnn::Graph &graph) const std::vector<TensorShape> ReverseV2Layer::InferOutputShapes(const std::vector<TensorShape>& inputShapes) const { - ARMNN_ASSERT(inputShapes.size() == 2); + if (inputShapes.size() != 2) + { + throw armnn::Exception("inputShapes' size is \"" + std::to_string(inputShapes.size()) + + "\" - should be \"2\"."); + } const auto inputDims = inputShapes[0].GetNumDimensions(); @@ -59,7 +63,12 @@ void ReverseV2Layer::ValidateTensorShapesFromInputs() GetInputSlot(0).GetTensorInfo().GetShape(), GetInputSlot(1).GetTensorInfo().GetShape()}); - ARMNN_ASSERT(inferredShapes.size() == 1); + if (inferredShapes.size() != 1) + { + throw armnn::LayerValidationException("inferredShapes has " + + std::to_string(inferredShapes.size()) + + " elements - should only have 1."); + } ValidateAndCopyShape(outputShape, inferredShapes[0], m_ShapeInferenceMethod, "ReverseV2Layer"); } diff --git a/src/armnn/layers/RsqrtLayer.cpp b/src/armnn/layers/RsqrtLayer.cpp index 91f6d10a69..10c05c4d22 100644 --- a/src/armnn/layers/RsqrtLayer.cpp +++ b/src/armnn/layers/RsqrtLayer.cpp @@ -1,5 +1,5 @@ // -// Copyright © 2017-2023 Arm Ltd and Contributors. All rights reserved. +// Copyright © 2017-2024 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // @@ -43,7 +43,12 @@ void RsqrtLayer::ValidateTensorShapesFromInputs() auto inferredShapes = InferOutputShapes({ GetInputSlot(0).GetTensorInfo().GetShape() }); - ARMNN_ASSERT(inferredShapes.size() == 1); + if (inferredShapes.size() != 1) + { + throw armnn::LayerValidationException("inferredShapes has " + + std::to_string(inferredShapes.size()) + + " elements - should only have 1."); + } ValidateAndCopyShape(outputShape, inferredShapes[0], m_ShapeInferenceMethod, "RsqrtLayer"); } @@ -53,4 +58,4 @@ void RsqrtLayer::ExecuteStrategy(IStrategy& strategy) const strategy.ExecuteStrategy(this, GetParameters(), {}, GetName()); } -} // namespace armnn
\ No newline at end of file +} // namespace armnn diff --git a/src/armnn/layers/ShapeLayer.cpp b/src/armnn/layers/ShapeLayer.cpp index e7e343c707..d810bef9dd 100644 --- a/src/armnn/layers/ShapeLayer.cpp +++ b/src/armnn/layers/ShapeLayer.cpp @@ -1,5 +1,5 @@ // -// Copyright © 2021-2023 Arm Ltd and Contributors. All rights reserved. +// Copyright © 2021-2024 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // @@ -44,15 +44,23 @@ void ShapeLayer::ValidateTensorShapesFromInputs() auto inferredShape = InferOutputShapes({ GetInputSlot(0).GetTensorInfo().GetShape() }); - ARMNN_ASSERT(inferredShape.size() == 1); + if (inferredShape.size() != 1) + { + throw armnn::LayerValidationException("inferredShape has " + + std::to_string(inferredShape.size()) + + " elements - should only have 1."); + } ValidateAndCopyShape(outputShape, inferredShape[0], m_ShapeInferenceMethod, "ShapeLayer"); } std::vector<TensorShape> ShapeLayer::InferOutputShapes(const std::vector<TensorShape>& inputShapes) const { - IgnoreUnused(inputShapes); - ARMNN_ASSERT(inputShapes.size() == 1); + if (inputShapes.size() != 1) + { + throw armnn::Exception("inputShapes' size is \"" + std::to_string(inputShapes.size()) + + "\" - should be \"1\"."); + } TensorShape outputShape({ inputShapes[0].GetNumDimensions()} ); diff --git a/src/armnn/layers/SliceLayer.cpp b/src/armnn/layers/SliceLayer.cpp index a9327c6111..428e672adb 100644 --- a/src/armnn/layers/SliceLayer.cpp +++ b/src/armnn/layers/SliceLayer.cpp @@ -1,5 +1,5 @@ // -// Copyright © 2019-2023 Arm Ltd and Contributors. All rights reserved. +// Copyright © 2019-2024 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // @@ -44,7 +44,12 @@ void SliceLayer::ValidateTensorShapesFromInputs() auto inferredShapes = InferOutputShapes({ GetInputSlot(0).GetTensorInfo().GetShape() }); - ARMNN_ASSERT(inferredShapes.size() == 1); + if (inferredShapes.size() != 1) + { + throw armnn::LayerValidationException("inferredShapes has " + + std::to_string(inferredShapes.size()) + + " elements - should only have 1."); + } ValidateAndCopyShape(outputShape, inferredShapes[0], m_ShapeInferenceMethod, "SliceLayer"); } @@ -52,7 +57,12 @@ void SliceLayer::ValidateTensorShapesFromInputs() std::vector<TensorShape> SliceLayer::InferOutputShapes(const std::vector<TensorShape>& inputShapes) const { IgnoreUnused(inputShapes); - ARMNN_ASSERT(inputShapes.size() == 1); + + if (inputShapes.size() != 1) + { + throw armnn::Exception("inputShapes' size is \"" + std::to_string(inputShapes.size()) + + "\" - should be \"1\"."); + } TensorShape outputShape(armnn::numeric_cast<unsigned int>(m_Param.m_Size.size()), m_Param.m_Size.data()); diff --git a/src/armnn/layers/SoftmaxLayer.cpp b/src/armnn/layers/SoftmaxLayer.cpp index 5f68278454..f0d5e4a1da 100644 --- a/src/armnn/layers/SoftmaxLayer.cpp +++ b/src/armnn/layers/SoftmaxLayer.cpp @@ -1,5 +1,5 @@ // -// Copyright © 2017-2023 Arm Ltd and Contributors. All rights reserved. +// Copyright © 2017-2024 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // #include "SoftmaxLayer.hpp" @@ -41,7 +41,12 @@ void SoftmaxLayer::ValidateTensorShapesFromInputs() auto inferredShapes = InferOutputShapes({ GetInputSlot(0).GetTensorInfo().GetShape() }); - ARMNN_ASSERT(inferredShapes.size() == 1); + if (inferredShapes.size() != 1) + { + throw armnn::LayerValidationException("inferredShapes has " + + std::to_string(inferredShapes.size()) + + " elements - should only have 1."); + } ValidateAndCopyShape(outputShape, inferredShapes[0], m_ShapeInferenceMethod, "SoftmaxLayer"); } diff --git a/src/armnn/layers/SpaceToBatchNdLayer.cpp b/src/armnn/layers/SpaceToBatchNdLayer.cpp index 277fc4479d..80728d0503 100644 --- a/src/armnn/layers/SpaceToBatchNdLayer.cpp +++ b/src/armnn/layers/SpaceToBatchNdLayer.cpp @@ -1,5 +1,5 @@ // -// Copyright © 2018-2023 Arm Ltd and Contributors. All rights reserved. +// Copyright © 2018-2024 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // @@ -71,7 +71,12 @@ void SpaceToBatchNdLayer::ValidateTensorShapesFromInputs() std::vector<TensorShape> inferredShapes = InferOutputShapes({ GetInputSlot(0).GetTensorInfo().GetShape() }); - ARMNN_ASSERT(inferredShapes.size() == 1); + if (inferredShapes.size() != 1) + { + throw armnn::LayerValidationException("inferredShapes has " + + std::to_string(inferredShapes.size()) + + " elements - should only have 1."); + } ValidateAndCopyShape(outputShape, inferredShapes[0], m_ShapeInferenceMethod, "SpaceToBatchNdLayer"); } diff --git a/src/armnn/layers/SpaceToDepthLayer.cpp b/src/armnn/layers/SpaceToDepthLayer.cpp index c86758f67f..0083ad91c9 100644 --- a/src/armnn/layers/SpaceToDepthLayer.cpp +++ b/src/armnn/layers/SpaceToDepthLayer.cpp @@ -1,5 +1,5 @@ // -// Copyright © 2019-2023 Arm Ltd and Contributors. All rights reserved. +// Copyright © 2019-2024 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // @@ -43,7 +43,11 @@ SpaceToDepthLayer* SpaceToDepthLayer::Clone(Graph& graph) const std::vector<TensorShape> SpaceToDepthLayer::InferOutputShapes(const std::vector<TensorShape>& inputShapes) const { - ARMNN_ASSERT(inputShapes.size() == 1); + if (inputShapes.size() != 1) + { + throw armnn::Exception("inputShapes' size is \"" + std::to_string(inputShapes.size()) + + "\" - should be \"1\"."); + } TensorShape inputShape = inputShapes[0]; TensorShape outputShape(inputShape); @@ -72,7 +76,12 @@ void SpaceToDepthLayer::ValidateTensorShapesFromInputs() std::vector<TensorShape> inferredShapes = InferOutputShapes({ GetInputSlot(0).GetTensorInfo().GetShape() }); - ARMNN_ASSERT(inferredShapes.size() == 1); + if (inferredShapes.size() != 1) + { + throw armnn::LayerValidationException("inferredShapes has " + + std::to_string(inferredShapes.size()) + + " elements - should only have 1."); + } ValidateAndCopyShape(outputShape, inferredShapes[0], m_ShapeInferenceMethod, "SpaceToDepthLayer"); } diff --git a/src/armnn/layers/SplitterLayer.cpp b/src/armnn/layers/SplitterLayer.cpp index f8a2ae0e62..8a24e0df1f 100644 --- a/src/armnn/layers/SplitterLayer.cpp +++ b/src/armnn/layers/SplitterLayer.cpp @@ -1,5 +1,5 @@ // -// Copyright © 2017-2023 Arm Ltd and Contributors. All rights reserved. +// Copyright © 2017-2024 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // #include "SplitterLayer.hpp" @@ -188,7 +188,10 @@ void SplitterLayer::CreateTensorHandles(const TensorHandleFactoryRegistry& regis else { ITensorHandleFactory* handleFactory = registry.GetFactory(factoryId); - ARMNN_ASSERT(handleFactory); + if (!handleFactory) + { + throw armnn::NullPointerException("handleFactory is returning a nullptr."); + } CreateTensors(registry, *handleFactory, isMemoryManaged); } } @@ -200,8 +203,14 @@ SplitterLayer* SplitterLayer::Clone(Graph& graph) const std::vector<TensorShape> SplitterLayer::InferOutputShapes(const std::vector<TensorShape>& inputShapes) const { - IgnoreUnused(inputShapes); - ARMNN_ASSERT(inputShapes.size() == m_Param.GetNumViews()); + if (inputShapes.size() != m_Param.GetNumViews()) + { + throw armnn::Exception("inputShapes' and m_NumViews' sizes do not match (\"" + + std::to_string(inputShapes.size()) + + "\" vs \"" + + std::to_string(m_Param.GetNumViews()) + "\")"); + } + std::vector<TensorShape> outShapes; //Output shapes must match View shapes. for (unsigned int viewIdx = 0; viewIdx < m_Param.GetNumViews(); viewIdx++) @@ -228,7 +237,13 @@ void SplitterLayer::ValidateTensorShapesFromInputs() auto inferredShapes = InferOutputShapes(views); - ARMNN_ASSERT(inferredShapes.size() == m_Param.GetNumViews()); + if (inferredShapes.size() != m_Param.GetNumViews()) + { + throw armnn::LayerValidationException("inferredShapes' size and m_NumViews do not match (\"" + + std::to_string(inferredShapes.size()) + + "\" vs \"" + + std::to_string(m_Param.GetNumViews()) + "\")"); + } for (unsigned int viewIdx = 0; viewIdx < m_Param.GetNumViews(); viewIdx++) { diff --git a/src/armnn/layers/StackLayer.cpp b/src/armnn/layers/StackLayer.cpp index 3c5a216eb3..ea49949b69 100644 --- a/src/armnn/layers/StackLayer.cpp +++ b/src/armnn/layers/StackLayer.cpp @@ -1,5 +1,5 @@ // -// Copyright © 2019-2023 Arm Ltd and Contributors. All rights reserved. +// Copyright © 2019-2024 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // #include "StackLayer.hpp" @@ -32,15 +32,19 @@ StackLayer* StackLayer::Clone(Graph& graph) const return CloneBase<StackLayer>(graph, m_Param, GetName()); } -std::vector<TensorShape> StackLayer::InferOutputShapes(const std::vector<TensorShape>& inputShapes) const +std::vector<TensorShape> StackLayer::InferOutputShapes(const std::vector<TensorShape>&) const { - IgnoreUnused(inputShapes); - const TensorShape& inputShape = m_Param.m_InputShape; const unsigned int inputNumDimensions = inputShape.GetNumDimensions(); const unsigned int axis = m_Param.m_Axis; - ARMNN_ASSERT(axis <= inputNumDimensions); + if (axis > inputNumDimensions) + { + throw armnn::Exception("axis must not be greater than input dimensions (\"" + + std::to_string(axis) + + "\" vs \"" + + std::to_string(inputNumDimensions) + "\")."); + } std::vector<unsigned int> dimensionSizes(inputNumDimensions + 1, 0); for (unsigned int i = 0; i < axis; ++i) @@ -90,7 +94,12 @@ void StackLayer::ValidateTensorShapesFromInputs() auto inferredShapes = InferOutputShapes(inputShapes); - ARMNN_ASSERT(inferredShapes.size() == 1); + if (inferredShapes.size() != 1) + { + throw armnn::LayerValidationException("inferredShapes has " + + std::to_string(inferredShapes.size()) + + " elements - should only have 1."); + } ValidateAndCopyShape(outputShape, inferredShapes[0], m_ShapeInferenceMethod, "StackLayer"); } diff --git a/src/armnn/layers/StridedSliceLayer.cpp b/src/armnn/layers/StridedSliceLayer.cpp index 16aeab5f5a..c348951178 100644 --- a/src/armnn/layers/StridedSliceLayer.cpp +++ b/src/armnn/layers/StridedSliceLayer.cpp @@ -1,5 +1,5 @@ // -// Copyright © 2018-2023 Arm Ltd and Contributors. All rights reserved. +// Copyright © 2018-2024 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // #include "StridedSliceLayer.hpp" @@ -47,7 +47,11 @@ StridedSliceLayer* StridedSliceLayer::Clone(Graph& graph) const std::vector<TensorShape> StridedSliceLayer::InferOutputShapes( const std::vector<TensorShape>& inputShapes) const { - ARMNN_ASSERT(inputShapes.size() == 1); + if (inputShapes.size() != 1) + { + throw armnn::Exception("inputShapes' size is \"" + std::to_string(inputShapes.size()) + + "\" - should be \"1\"."); + } TensorShape inputShape = inputShapes[0]; std::vector<unsigned int> outputShape; @@ -106,7 +110,12 @@ void StridedSliceLayer::ValidateTensorShapesFromInputs() auto inferredShapes = InferOutputShapes({GetInputSlot(0).GetTensorInfo().GetShape()}); - ARMNN_ASSERT(inferredShapes.size() == 1); + if (inferredShapes.size() != 1) + { + throw armnn::LayerValidationException("inferredShapes has " + + std::to_string(inferredShapes.size()) + + " elements - should only have 1."); + } ValidateAndCopyShape(outputShape, inferredShapes[0], m_ShapeInferenceMethod, "StridedSliceLayer"); } diff --git a/src/armnn/layers/SwitchLayer.cpp b/src/armnn/layers/SwitchLayer.cpp index 031dcec29a..afb2753e96 100644 --- a/src/armnn/layers/SwitchLayer.cpp +++ b/src/armnn/layers/SwitchLayer.cpp @@ -1,5 +1,5 @@ // -// Copyright © 2019-2023 Arm Ltd and Contributors. All rights reserved. +// Copyright © 2019-2024 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // #include "SwitchLayer.hpp" @@ -37,14 +37,22 @@ void SwitchLayer::ValidateTensorShapesFromInputs() VerifyShapeInferenceType(outputShape, m_ShapeInferenceMethod); - ARMNN_ASSERT_MSG(GetNumOutputSlots() == 2, "SwitchLayer: The layer should return 2 outputs."); + if (GetNumOutputSlots() != 2) + { + throw armnn::LayerValidationException("SwitchLayer: The layer should return 2 outputs."); + } // Assuming first input is the Input and second input is the Constant std::vector<TensorShape> inferredShapes = InferOutputShapes({ GetInputSlot(0).GetTensorInfo().GetShape(), GetInputSlot(1).GetTensorInfo().GetShape()}); - ARMNN_ASSERT(inferredShapes.size() == 2); + if (inferredShapes.size() != 2) + { + throw armnn::LayerValidationException("inferredShapes has " + + std::to_string(inferredShapes.size()) + + " element(s) - should only have 2."); + } ValidateAndCopyShape(outputShape, inferredShapes[0], m_ShapeInferenceMethod, "SwitchLayer"); diff --git a/src/armnn/layers/TileLayer.cpp b/src/armnn/layers/TileLayer.cpp index d3629002e0..8e07478a54 100644 --- a/src/armnn/layers/TileLayer.cpp +++ b/src/armnn/layers/TileLayer.cpp @@ -1,5 +1,5 @@ // -// Copyright © 2023 Arm Ltd and Contributors. All rights reserved. +// Copyright © 2023-2024 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // @@ -31,7 +31,12 @@ TileLayer* TileLayer::Clone(armnn::Graph &graph) const std::vector<TensorShape> TileLayer::InferOutputShapes(const std::vector<TensorShape>& inputShapes) const { - ARMNN_ASSERT(inputShapes.size() == 1); + if (inputShapes.size() != 1) + { + throw armnn::Exception("inputShapes' size is \"" + std::to_string(inputShapes.size()) + + "\" - should be \"1\"."); + } + const TensorShape& inputShape = inputShapes[0]; uint32_t numberOfDimensions = inputShape.GetNumDimensions(); @@ -64,9 +69,14 @@ void TileLayer::ValidateTensorShapesFromInputs() auto inferredShapes = InferOutputShapes({ GetInputSlot(0).GetTensorInfo().GetShape() }); - ARMNN_ASSERT(inferredShapes.size() == 1); + if (inferredShapes.size() != 1) + { + throw armnn::LayerValidationException("inferredShapes has " + + std::to_string(inferredShapes.size()) + + " elements - should only have 1."); + } ValidateAndCopyShape(outputShape, inferredShapes[0], m_ShapeInferenceMethod, "TileLayer"); } -}
\ No newline at end of file +} diff --git a/src/armnn/layers/TransposeConvolution2dLayer.cpp b/src/armnn/layers/TransposeConvolution2dLayer.cpp index 3a7e8b889e..21dcf1f1d6 100644 --- a/src/armnn/layers/TransposeConvolution2dLayer.cpp +++ b/src/armnn/layers/TransposeConvolution2dLayer.cpp @@ -1,5 +1,5 @@ // -// Copyright © 2019-2023 Arm Ltd and Contributors. All rights reserved. +// Copyright © 2019-2024 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // @@ -24,14 +24,20 @@ TransposeConvolution2dLayer::TransposeConvolution2dLayer(const TransposeConvolut std::unique_ptr<IWorkload> TransposeConvolution2dLayer::CreateWorkload(const IWorkloadFactory& factory) const { - ARMNN_ASSERT_MSG(m_Weight != nullptr, "TransposeConvolution2dLayer: Weights data should not be null."); + if (!m_Weight) + { + throw armnn::NullPointerException("TransposeConvolution2dLayer: Weights data should not be null."); + } TransposeConvolution2dQueueDescriptor descriptor; descriptor.m_Weight = m_Weight.get(); if (m_Param.m_BiasEnabled) { - ARMNN_ASSERT_MSG(m_Bias != nullptr, "TransposeConvolution2dLayer: Bias data should not be null."); + if (!m_Bias) + { + throw armnn::NullPointerException("TransposeConvolution2dLayer: Bias data should not be null."); + } descriptor.m_Bias = m_Bias.get(); } @@ -57,11 +63,19 @@ TransposeConvolution2dLayer* TransposeConvolution2dLayer::Clone(Graph& graph) co std::vector<TensorShape> TransposeConvolution2dLayer::InferOutputShapes( const std::vector<TensorShape>& inputShapes) const { - ARMNN_ASSERT(inputShapes.size() == 2); + if (inputShapes.size() != 2) + { + throw armnn::Exception("inputShapes' size is \"" + std::to_string(inputShapes.size()) + + "\" - should be \"2\"."); + } + const TensorShape& inputShape = inputShapes[0]; const TensorShape& kernelShape = inputShapes[1]; - ARMNN_ASSERT_MSG(inputShape.GetNumDimensions() == 4, "Transpose convolutions will always have 4D input"); + if (inputShape.GetNumDimensions() != 4) + { + throw armnn::Exception("Transpose convolutions will always have 4D input"); + } DataLayoutIndexed dataLayoutIndex(m_Param.m_DataLayout); @@ -95,7 +109,10 @@ void TransposeConvolution2dLayer::ValidateTensorShapesFromInputs() VerifyShapeInferenceType(outputShape, m_ShapeInferenceMethod); - ARMNN_ASSERT_MSG(m_Weight != nullptr, "TransposeConvolution2dLayer: Weight data cannot be null."); + if (!m_Weight) + { + throw armnn::LayerValidationException("TransposeConvolution2dLayer: Weight data cannot be null."); + } std::vector<TensorShape> expectedOutputShape; std::vector<TensorShape> outputShapeGivenAsInput; @@ -103,7 +120,12 @@ void TransposeConvolution2dLayer::ValidateTensorShapesFromInputs() expectedOutputShape = InferOutputShapes({GetInputSlot(0).GetTensorInfo().GetShape(), m_Weight->GetTensorInfo().GetShape() }); - ARMNN_ASSERT(expectedOutputShape.size() == 1); + if (expectedOutputShape.size() != 1) + { + throw armnn::LayerValidationException("expectedOutputShape' size is " + + std::to_string(expectedOutputShape.size()) + + " - should be \"1\"."); + } // If output_shape was specified then use it rather than calculate an inferred output shape. if (m_Param.m_OutputShapeEnabled) @@ -112,10 +134,19 @@ void TransposeConvolution2dLayer::ValidateTensorShapesFromInputs() m_Param.m_OutputShape.data()); outputShapeGivenAsInput.push_back(shapeAsTensorShape); - ARMNN_ASSERT(outputShapeGivenAsInput.size() == 1); - ARMNN_ASSERT_MSG(expectedOutputShape == outputShapeGivenAsInput, - "TransposeConvolution2dLayer: output calculated by InferOutputShapes and " - "the output given as an input parameter to the layer are not matching"); + if (outputShapeGivenAsInput.size() != 1) + { + throw armnn::LayerValidationException("outputShapeGivenAsInput' size is " + + std::to_string(outputShapeGivenAsInput.size()) + + " - should be \"1\"."); + } + + if (expectedOutputShape != outputShapeGivenAsInput) + { + throw armnn::LayerValidationException("TransposeConvolution2dLayer: " + "output calculated by InferOutputShapes and the output given " + "as an input parameter to the layer are not matching"); + } } ValidateAndCopyShape(outputShape, expectedOutputShape[0], m_ShapeInferenceMethod, "TransposeConvolution2dLayer"); diff --git a/src/armnn/layers/TransposeLayer.cpp b/src/armnn/layers/TransposeLayer.cpp index 58e570ab38..f0b7139b26 100644 --- a/src/armnn/layers/TransposeLayer.cpp +++ b/src/armnn/layers/TransposeLayer.cpp @@ -1,5 +1,5 @@ // -// Copyright © 2020-2023 Arm Ltd and Contributors. All rights reserved. +// Copyright © 2020-2024 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // @@ -37,7 +37,12 @@ TransposeLayer* TransposeLayer::Clone(Graph& graph) const std::vector<TensorShape> TransposeLayer::InferOutputShapes(const std::vector<TensorShape>& inputShapes) const { - ARMNN_ASSERT(inputShapes.size() == 1); + if (inputShapes.size() != 1) + { + throw armnn::Exception("inputShapes' size is \"" + std::to_string(inputShapes.size()) + + "\" - should be \"1\"."); + } + const TensorShape& inShape = inputShapes[0]; return std::vector<TensorShape> ({armnnUtils::TransposeTensorShape(inShape, m_Param.m_DimMappings)}); } @@ -52,7 +57,12 @@ void TransposeLayer::ValidateTensorShapesFromInputs() auto inferredShapes = InferOutputShapes({ GetInputSlot(0).GetTensorInfo().GetShape() }); - ARMNN_ASSERT(inferredShapes.size() == 1); + if (inferredShapes.size() != 1) + { + throw armnn::LayerValidationException("inferredShapes has " + + std::to_string(inferredShapes.size()) + + " elements - should only have 1."); + } ValidateAndCopyShape(outputShape, inferredShapes[0], m_ShapeInferenceMethod, "TransposeLayer"); } diff --git a/src/armnn/layers/UnidirectionalSequenceLstmLayer.cpp b/src/armnn/layers/UnidirectionalSequenceLstmLayer.cpp index 75f027e32d..68a0d8e2c2 100644 --- a/src/armnn/layers/UnidirectionalSequenceLstmLayer.cpp +++ b/src/armnn/layers/UnidirectionalSequenceLstmLayer.cpp @@ -1,5 +1,5 @@ // -// Copyright © 2021-2023 Arm Ltd and Contributors. All rights reserved. +// Copyright © 2021-2024 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // #include "UnidirectionalSequenceLstmLayer.hpp" @@ -150,7 +150,9 @@ UnidirectionalSequenceLstmLayer* UnidirectionalSequenceLstmLayer::Clone(Graph& g std::vector<TensorShape> UnidirectionalSequenceLstmLayer::InferOutputShapes( const std::vector<TensorShape>& inputShapes) const { - ARMNN_ASSERT(inputShapes.size() == 3); + ARMNN_THROW_INVALIDARG_MSG_IF_FALSE(inputShapes.size() == 3, + "inputShapes' size is \"" + std::to_string(inputShapes.size()) + + "\" - should be \"3\"."); // Get input values for validation unsigned int outputSize = inputShapes[1][1]; @@ -181,94 +183,178 @@ void UnidirectionalSequenceLstmLayer::ValidateTensorShapesFromInputs() GetInputSlot(2).GetTensorInfo().GetShape() }); - ARMNN_ASSERT(inferredShapes.size() == 1); + if (inferredShapes.size() != 1) + { + throw armnn::LayerValidationException("inferredShapes has " + + std::to_string(inferredShapes.size()) + + " elements - should only have 1."); + } // Check if the weights are nullptr - ARMNN_ASSERT_MSG(m_BasicParameters.m_InputToForgetWeights != nullptr, - "UnidirectionalSequenceLstmLayer: m_BasicParameters.m_InputToForgetWeights should not be null."); - ARMNN_ASSERT_MSG(m_BasicParameters.m_InputToCellWeights != nullptr, - "UnidirectionalSequenceLstmLayer: m_BasicParameters.m_InputToCellWeights should not be null."); - ARMNN_ASSERT_MSG(m_BasicParameters.m_InputToOutputWeights != nullptr, - "UnidirectionalSequenceLstmLayer: m_BasicParameters.m_InputToOutputWeights should not be null."); - ARMNN_ASSERT_MSG(m_BasicParameters.m_RecurrentToForgetWeights != nullptr, - "UnidirectionalSequenceLstmLayer: m_BasicParameters.m_RecurrentToForgetWeights " - "should not be null."); - ARMNN_ASSERT_MSG(m_BasicParameters.m_RecurrentToCellWeights != nullptr, - "UnidirectionalSequenceLstmLayer: m_BasicParameters.m_RecurrentToCellWeights should not be null."); - ARMNN_ASSERT_MSG(m_BasicParameters.m_RecurrentToOutputWeights != nullptr, - "UnidirectionalSequenceLstmLayer: m_BasicParameters.m_RecurrentToOutputWeights " - "should not be null."); - ARMNN_ASSERT_MSG(m_BasicParameters.m_ForgetGateBias != nullptr, - "UnidirectionalSequenceLstmLayer: m_BasicParameters.m_ForgetGateBias should not be null."); - ARMNN_ASSERT_MSG(m_BasicParameters.m_CellBias != nullptr, - "UnidirectionalSequenceLstmLayer: m_BasicParameters.m_CellBias should not be null."); - ARMNN_ASSERT_MSG(m_BasicParameters.m_OutputGateBias != nullptr, - "UnidirectionalSequenceLstmLayer: m_BasicParameters.m_OutputGateBias should not be null."); + if (!m_BasicParameters.m_InputToForgetWeights) + { + throw armnn::LayerValidationException("UnidirectionalSequenceLstmLayer: " + "m_BasicParameters.m_InputToForgetWeights should not be null."); + } + + if (!m_BasicParameters.m_InputToCellWeights) + { + throw armnn::LayerValidationException("UnidirectionalSequenceLstmLayer: " + "m_BasicParameters.m_InputToCellWeights should not be null."); + } + + if (!m_BasicParameters.m_InputToOutputWeights) + { + throw armnn::LayerValidationException("UnidirectionalSequenceLstmLayer: " + "m_BasicParameters.m_InputToOutputWeights should not be null."); + } + + if (!m_BasicParameters.m_RecurrentToForgetWeights) + { + throw armnn::LayerValidationException("UnidirectionalSequenceLstmLayer: " + "m_BasicParameters.m_RecurrentToForgetWeights should not be null."); + } + + if (!m_BasicParameters.m_RecurrentToCellWeights) + { + throw armnn::LayerValidationException("UnidirectionalSequenceLstmLayer: " + "m_BasicParameters.m_RecurrentToCellWeights should not be null."); + } + + if (!m_BasicParameters.m_RecurrentToOutputWeights) + { + throw armnn::LayerValidationException("UnidirectionalSequenceLstmLayer: " + "m_BasicParameters.m_RecurrentToOutputWeights should not be null."); + } + + if (!m_BasicParameters.m_ForgetGateBias) + { + throw armnn::LayerValidationException("UnidirectionalSequenceLstmLayer: " + "m_BasicParameters.m_ForgetGateBias should not be null."); + } + + if (!m_BasicParameters.m_CellBias) + { + throw armnn::LayerValidationException("UnidirectionalSequenceLstmLayer: " + "m_BasicParameters.m_CellBias should not be null."); + } + + if (!m_BasicParameters.m_OutputGateBias) + { + throw armnn::LayerValidationException("UnidirectionalSequenceLstmLayer: " + "m_BasicParameters.m_OutputGateBias should not be null."); + } if (!m_Param.m_CifgEnabled) { - ARMNN_ASSERT_MSG(m_CifgParameters.m_InputToInputWeights != nullptr, - "UnidirectionalSequenceLstmLayer: m_CifgParameters.m_InputToInputWeights should not be null."); - ARMNN_ASSERT_MSG(m_CifgParameters.m_RecurrentToInputWeights != nullptr, - "UnidirectionalSequenceLstmLayer: m_CifgParameters.m_RecurrentToInputWeights " - "should not be null."); - ARMNN_ASSERT_MSG(m_CifgParameters.m_InputGateBias != nullptr, - "UnidirectionalSequenceLstmLayer: m_CifgParameters.m_InputGateBias should not be null."); + if (!m_CifgParameters.m_InputToInputWeights) + { + throw armnn::LayerValidationException("UnidirectionalSequenceLstmLayer: " + "m_CifgParameters.m_InputToInputWeights should not be null."); + } + + if (!m_CifgParameters.m_RecurrentToInputWeights) + { + throw armnn::LayerValidationException("UnidirectionalSequenceLstmLayer: " + "m_CifgParameters.m_RecurrentToInputWeights should not be null."); + } + + if (!m_CifgParameters.m_InputGateBias) + { + throw armnn::LayerValidationException("UnidirectionalSequenceLstmLayer: " + "m_CifgParameters.m_InputGateBias should not be null."); + } } else { - ARMNN_ASSERT_MSG(m_CifgParameters.m_InputToInputWeights == nullptr, - "UnidirectionalSequenceLstmLayer: m_CifgParameters.m_InputToInputWeights should not have a value " - "when CIFG is enabled."); - ARMNN_ASSERT_MSG(m_CifgParameters.m_RecurrentToInputWeights == nullptr, - "UnidirectionalSequenceLstmLayer: m_CifgParameters.m_RecurrentToInputWeights should not have a value " - "when CIFG is enabled."); - ARMNN_ASSERT_MSG(m_CifgParameters.m_InputGateBias == nullptr, - "UnidirectionalSequenceLstmLayer: m_CifgParameters.m_InputGateBias should not have a value " - "when CIFG is enabled."); + if (m_CifgParameters.m_InputToInputWeights) + { + throw armnn::LayerValidationException("UnidirectionalSequenceLstmLayer: " + "m_CifgParameters.m_InputToInputWeights should not have a value " + "when CIFG is enabled."); + } + + if (m_CifgParameters.m_RecurrentToInputWeights) + { + throw armnn::LayerValidationException("UnidirectionalSequenceLstmLayer: " + "m_CifgParameters.m_RecurrentToInputWeights should not have a value " + "when CIFG is enabled."); + } + + if (m_CifgParameters.m_InputGateBias) + { + throw armnn::LayerValidationException("UnidirectionalSequenceLstmLayer: " + "m_CifgParameters.m_InputGateBias should not have a value " + "when CIFG is enabled."); + } } if (m_Param.m_ProjectionEnabled) { - ARMNN_ASSERT_MSG(m_ProjectionParameters.m_ProjectionWeights != nullptr, - "UnidirectionalSequenceLstmLayer: m_ProjectionParameters.m_ProjectionWeights " - "should not be null."); + if (!m_ProjectionParameters.m_ProjectionWeights) + { + throw armnn::LayerValidationException("UnidirectionalSequenceLstmLayer: " + "m_ProjectionParameters.m_ProjectionWeights should not be null."); + } } if (m_Param.m_PeepholeEnabled) { if (!m_Param.m_CifgEnabled) { - ARMNN_ASSERT_MSG(m_PeepholeParameters.m_CellToInputWeights != nullptr, - "UnidirectionalSequenceLstmLayer: m_PeepholeParameters.m_CellToInputWeights " - "should not be null " - "when Peephole is enabled and CIFG is disabled."); + if (!m_PeepholeParameters.m_CellToInputWeights) + { + throw armnn::LayerValidationException("UnidirectionalSequenceLstmLayer: " + "m_PeepholeParameters.m_CellToInputWeights should not be null " + "when Peephole is enabled and CIFG is disabled."); + } + } + + if (!m_PeepholeParameters.m_CellToForgetWeights) + { + throw armnn::LayerValidationException("UnidirectionalSequenceLstmLayer: " + "m_PeepholeParameters.m_CellToForgetWeights should not be null."); + } + + if (!m_PeepholeParameters.m_CellToOutputWeights) + { + throw armnn::LayerValidationException("UnidirectionalSequenceLstmLayer: " + "m_PeepholeParameters.m_CellToOutputWeights should not be null."); } - ARMNN_ASSERT_MSG(m_PeepholeParameters.m_CellToForgetWeights != nullptr, - "UnidirectionalSequenceLstmLayer: m_PeepholeParameters.m_CellToForgetWeights " - "should not be null."); - ARMNN_ASSERT_MSG(m_PeepholeParameters.m_CellToOutputWeights != nullptr, - "UnidirectionalSequenceLstmLayer: m_PeepholeParameters.m_CellToOutputWeights " - "should not be null."); } if (m_Param.m_LayerNormEnabled) { if(!m_Param.m_CifgEnabled) { - ARMNN_ASSERT_MSG(m_LayerNormParameters.m_InputLayerNormWeights != nullptr, - "UnidirectionalSequenceLstmLayer: m_LayerNormParameters.m_inputLayerNormWeights " - "should not be null."); + if (!m_LayerNormParameters.m_InputLayerNormWeights) + { + throw armnn::LayerValidationException("UnidirectionalSequenceLstmLayer: " + "m_LayerNormParameters.m_inputLayerNormWeights " + "should not be null."); + } + } + + if (!m_LayerNormParameters.m_ForgetLayerNormWeights) + { + throw armnn::LayerValidationException("UnidirectionalSequenceLstmLayer: " + "m_LayerNormParameters.m_forgetLayerNormWeights " + "should not be null."); + } + + if (!m_LayerNormParameters.m_CellLayerNormWeights) + { + throw armnn::LayerValidationException("UnidirectionalSequenceLstmLayer: " + "m_LayerNormParameters.m_cellLayerNormWeights " + "should not be null."); + } + + if (!m_LayerNormParameters.m_OutputLayerNormWeights) + { + throw armnn::LayerValidationException("UnidirectionalSequenceLstmLayer: " + "m_LayerNormParameters.m_outputLayerNormWeights " + "should not be null."); } - ARMNN_ASSERT_MSG(m_LayerNormParameters.m_ForgetLayerNormWeights != nullptr, - "UnidirectionalSequenceLstmLayer: m_LayerNormParameters.m_forgetLayerNormWeights " - "should not be null."); - ARMNN_ASSERT_MSG(m_LayerNormParameters.m_CellLayerNormWeights != nullptr, - "UnidirectionalSequenceLstmLayer: m_LayerNormParameters.m_cellLayerNormWeights " - "should not be null."); - ARMNN_ASSERT_MSG(m_LayerNormParameters.m_OutputLayerNormWeights != nullptr, - "UnidirectionalSequenceLstmLayer: m_LayerNormParameters.m_outputLayerNormWeights " - "should not be null."); } ValidateAndCopyShape(outputShape, inferredShapes[0], m_ShapeInferenceMethod, "UnidirectionalSequenceLstmLayer"); diff --git a/src/armnn/layers/UnmapLayer.cpp b/src/armnn/layers/UnmapLayer.cpp index cfbde211ba..a62536f3bc 100644 --- a/src/armnn/layers/UnmapLayer.cpp +++ b/src/armnn/layers/UnmapLayer.cpp @@ -1,5 +1,5 @@ // -// Copyright © 2020 Arm Ltd and Contributors. All rights reserved. +// Copyright © 2020,2024 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // #include "UnmapLayer.hpp" @@ -38,7 +38,11 @@ void UnmapLayer::ValidateTensorShapesFromInputs() { // validates that the input is connected. VerifyLayerConnections(1, CHECK_LOCATION()); - ARMNN_ASSERT(GetNumOutputSlots() == 0); + if (GetNumOutputSlots() != 0) + { + throw armnn::LayerValidationException("Output slots must be \"0\" - currently \"" + + std::to_string(GetNumOutputSlots()) + "\"."); + } } void UnmapLayer::ExecuteStrategy(IStrategy& strategy) const |