From aeec3ce5c8f936fb1220a9de8c84cceef88d4080 Mon Sep 17 00:00:00 2001 From: Matthew Bentham Date: Thu, 23 Feb 2023 13:03:46 +0000 Subject: Add constant version of IConnectableLayer::GetConstantTensorsByRef This makes it easier to use, particularly in backends where it is common to pass around const pointers to IConnectableLayer. The non-constant version is rewritten to use the constant version. Signed-off-by: Matthew Bentham Change-Id: Id3a8384447e93c213299a85ade9a667df5960534 --- src/armnn/layers/BatchNormalizationLayer.cpp | 2 +- src/armnn/layers/BatchNormalizationLayer.hpp | 2 +- src/armnn/layers/ConstantLayer.hpp | 2 +- src/armnn/layers/Convolution2dLayer.cpp | 4 ++-- src/armnn/layers/Convolution2dLayer.hpp | 2 +- src/armnn/layers/DepthwiseConvolution2dLayer.cpp | 4 ++-- src/armnn/layers/DepthwiseConvolution2dLayer.hpp | 2 +- src/armnn/layers/DetectionPostProcessLayer.cpp | 2 +- src/armnn/layers/DetectionPostProcessLayer.hpp | 2 +- src/armnn/layers/FullyConnectedLayer.cpp | 4 ++-- src/armnn/layers/FullyConnectedLayer.hpp | 2 +- src/armnn/layers/LayerWithParameters.hpp | 4 ++-- src/armnn/layers/LstmLayer.cpp | 2 +- src/armnn/layers/LstmLayer.hpp | 2 +- src/armnn/layers/QLstmLayer.cpp | 2 +- src/armnn/layers/QLstmLayer.hpp | 2 +- src/armnn/layers/QuantizedLstmLayer.cpp | 2 +- src/armnn/layers/QuantizedLstmLayer.hpp | 2 +- src/armnn/layers/TransposeConvolution2dLayer.cpp | 2 +- src/armnn/layers/TransposeConvolution2dLayer.hpp | 2 +- src/armnn/layers/UnidirectionalSequenceLstmLayer.cpp | 2 +- src/armnn/layers/UnidirectionalSequenceLstmLayer.hpp | 2 +- 22 files changed, 26 insertions(+), 26 deletions(-) (limited to 'src/armnn/layers') diff --git a/src/armnn/layers/BatchNormalizationLayer.cpp b/src/armnn/layers/BatchNormalizationLayer.cpp index 6f0e1a82a8..b5e9f2c413 100644 --- a/src/armnn/layers/BatchNormalizationLayer.cpp +++ b/src/armnn/layers/BatchNormalizationLayer.cpp @@ -65,7 +65,7 @@ void BatchNormalizationLayer::ValidateTensorShapesFromInputs() } -Layer::ConstantTensors BatchNormalizationLayer::GetConstantTensorsByRef() +Layer::ImmutableConstantTensors BatchNormalizationLayer::GetConstantTensorsByRef() const { // For API stability DO NOT ALTER order and add new members to the end of vector return {m_Mean, m_Variance, m_Beta, m_Gamma}; diff --git a/src/armnn/layers/BatchNormalizationLayer.hpp b/src/armnn/layers/BatchNormalizationLayer.hpp index 9715c56094..1b61c78130 100644 --- a/src/armnn/layers/BatchNormalizationLayer.hpp +++ b/src/armnn/layers/BatchNormalizationLayer.hpp @@ -52,7 +52,7 @@ protected: /// Retrieve the handles to the constant values stored by the layer. /// @return A vector of the constant tensors stored by this layer. - ConstantTensors GetConstantTensorsByRef() override; + ImmutableConstantTensors GetConstantTensorsByRef() const override; }; } // namespace diff --git a/src/armnn/layers/ConstantLayer.hpp b/src/armnn/layers/ConstantLayer.hpp index f5ab5464f2..08b9c24273 100644 --- a/src/armnn/layers/ConstantLayer.hpp +++ b/src/armnn/layers/ConstantLayer.hpp @@ -53,7 +53,7 @@ protected: /// Retrieve the handles to the constant values stored by the layer. // For API stability DO NOT ALTER order and add new members to the end of vector - ConstantTensors GetConstantTensorsByRef() override { return {m_LayerOutput}; } + ImmutableConstantTensors GetConstantTensorsByRef() const override { return {m_LayerOutput}; } }; } // namespace diff --git a/src/armnn/layers/Convolution2dLayer.cpp b/src/armnn/layers/Convolution2dLayer.cpp index e06b45acb0..f6a5583aad 100644 --- a/src/armnn/layers/Convolution2dLayer.cpp +++ b/src/armnn/layers/Convolution2dLayer.cpp @@ -119,9 +119,9 @@ void Convolution2dLayer::ValidateTensorShapesFromInputs() ValidateAndCopyShape(outputShape, inferredShapes[0], m_ShapeInferenceMethod, "Convolution2dLayer"); } -Layer::ConstantTensors Convolution2dLayer::GetConstantTensorsByRef() +Layer::ImmutableConstantTensors Convolution2dLayer::GetConstantTensorsByRef() const { - Layer::ConstantTensors tensors = GetConnectedConstantAsInputTensors(); + Layer::ImmutableConstantTensors tensors = GetConnectedConstantAsInputTensors(); return tensors; } diff --git a/src/armnn/layers/Convolution2dLayer.hpp b/src/armnn/layers/Convolution2dLayer.hpp index f7e4dec72f..519d8c43be 100644 --- a/src/armnn/layers/Convolution2dLayer.hpp +++ b/src/armnn/layers/Convolution2dLayer.hpp @@ -56,7 +56,7 @@ protected: /// Retrieve the handles to the constant values connected to the layer. /// @return A vector of the constant tensors connected to the layer. - ConstantTensors GetConstantTensorsByRef() override; + ImmutableConstantTensors GetConstantTensorsByRef() const override; }; } // namespace diff --git a/src/armnn/layers/DepthwiseConvolution2dLayer.cpp b/src/armnn/layers/DepthwiseConvolution2dLayer.cpp index 4c97437a1c..1e5a998119 100644 --- a/src/armnn/layers/DepthwiseConvolution2dLayer.cpp +++ b/src/armnn/layers/DepthwiseConvolution2dLayer.cpp @@ -123,9 +123,9 @@ void DepthwiseConvolution2dLayer::ValidateTensorShapesFromInputs() ValidateAndCopyShape(outputShape, inferredShapes[0], m_ShapeInferenceMethod, "DepthwiseConvolution2dLayer"); } -Layer::ConstantTensors DepthwiseConvolution2dLayer::GetConstantTensorsByRef() +Layer::ImmutableConstantTensors DepthwiseConvolution2dLayer::GetConstantTensorsByRef() const { - Layer::ConstantTensors tensors = GetConnectedConstantAsInputTensors(); + Layer::ImmutableConstantTensors tensors = GetConnectedConstantAsInputTensors(); return tensors; } diff --git a/src/armnn/layers/DepthwiseConvolution2dLayer.hpp b/src/armnn/layers/DepthwiseConvolution2dLayer.hpp index ef7410f1d3..d69d779721 100644 --- a/src/armnn/layers/DepthwiseConvolution2dLayer.hpp +++ b/src/armnn/layers/DepthwiseConvolution2dLayer.hpp @@ -56,7 +56,7 @@ protected: /// Retrieve the handles to the constant values connected to the layer. /// @return A vector of the constant tensors connected to the layer. - ConstantTensors GetConstantTensorsByRef() override; + ImmutableConstantTensors GetConstantTensorsByRef() const override; }; } // namespace diff --git a/src/armnn/layers/DetectionPostProcessLayer.cpp b/src/armnn/layers/DetectionPostProcessLayer.cpp index 33f894414a..27e459b0ce 100644 --- a/src/armnn/layers/DetectionPostProcessLayer.cpp +++ b/src/armnn/layers/DetectionPostProcessLayer.cpp @@ -89,7 +89,7 @@ std::vector DetectionPostProcessLayer::InferOutputShapes(const std: return results; } -Layer::ConstantTensors DetectionPostProcessLayer::GetConstantTensorsByRef() +Layer::ImmutableConstantTensors DetectionPostProcessLayer::GetConstantTensorsByRef() const { // For API stability DO NOT ALTER order and add new members to the end of vector return { m_Anchors }; diff --git a/src/armnn/layers/DetectionPostProcessLayer.hpp b/src/armnn/layers/DetectionPostProcessLayer.hpp index e203032db0..93939bf3e3 100644 --- a/src/armnn/layers/DetectionPostProcessLayer.hpp +++ b/src/armnn/layers/DetectionPostProcessLayer.hpp @@ -53,7 +53,7 @@ protected: /// Retrieve the handles to the constant values stored by the layer. /// @return A vector of the constant tensors stored by this layer. - ConstantTensors GetConstantTensorsByRef() override; + ImmutableConstantTensors GetConstantTensorsByRef() const override; }; } // namespace armnn diff --git a/src/armnn/layers/FullyConnectedLayer.cpp b/src/armnn/layers/FullyConnectedLayer.cpp index 05c53961e3..f86f58443f 100644 --- a/src/armnn/layers/FullyConnectedLayer.cpp +++ b/src/armnn/layers/FullyConnectedLayer.cpp @@ -61,9 +61,9 @@ void FullyConnectedLayer::ValidateTensorShapesFromInputs() ValidateAndCopyShape(outputShape, inferredShapes[0], m_ShapeInferenceMethod, "FullyConnectedLayer"); } -Layer::ConstantTensors FullyConnectedLayer::GetConstantTensorsByRef() +Layer::ImmutableConstantTensors FullyConnectedLayer::GetConstantTensorsByRef() const { - Layer::ConstantTensors tensors = GetConnectedConstantAsInputTensors(); + Layer::ImmutableConstantTensors tensors = GetConnectedConstantAsInputTensors(); return tensors; } diff --git a/src/armnn/layers/FullyConnectedLayer.hpp b/src/armnn/layers/FullyConnectedLayer.hpp index f3ca696b62..e133def144 100644 --- a/src/armnn/layers/FullyConnectedLayer.hpp +++ b/src/armnn/layers/FullyConnectedLayer.hpp @@ -54,7 +54,7 @@ protected: /// Retrieve the handles to the constant values stored by the layer. /// @return A vector of the constant tensors stored by this layer. - ConstantTensors GetConstantTensorsByRef() override; + ImmutableConstantTensors GetConstantTensorsByRef() const override; }; } // namespace diff --git a/src/armnn/layers/LayerWithParameters.hpp b/src/armnn/layers/LayerWithParameters.hpp index 40ade95d5c..0a1dbf363c 100644 --- a/src/armnn/layers/LayerWithParameters.hpp +++ b/src/armnn/layers/LayerWithParameters.hpp @@ -56,9 +56,9 @@ protected: strategy.ExecuteStrategy(this, GetParameters(), {}, GetName()); } - Layer::ConstantTensors GetConnectedConstantAsInputTensors() + Layer::ImmutableConstantTensors GetConnectedConstantAsInputTensors() const { - Layer::ConstantTensors tensors; + Layer::ImmutableConstantTensors tensors; for (unsigned int i = 0; i < GetNumInputSlots(); ++i) { if (GetInputSlot(i).GetConnection() && GetInputSlot(i).GetConnection()->GetTensorInfo().IsConstant()) diff --git a/src/armnn/layers/LstmLayer.cpp b/src/armnn/layers/LstmLayer.cpp index 8e6bfdba3e..2c9604396b 100644 --- a/src/armnn/layers/LstmLayer.cpp +++ b/src/armnn/layers/LstmLayer.cpp @@ -267,7 +267,7 @@ void LstmLayer::ValidateTensorShapesFromInputs() } } -Layer::ConstantTensors LstmLayer::GetConstantTensorsByRef() +Layer::ImmutableConstantTensors LstmLayer::GetConstantTensorsByRef() const { // For API stability DO NOT ALTER order and add new members to the end of vector return {m_BasicParameters.m_InputToForgetWeights, diff --git a/src/armnn/layers/LstmLayer.hpp b/src/armnn/layers/LstmLayer.hpp index 7310d41238..0462403051 100644 --- a/src/armnn/layers/LstmLayer.hpp +++ b/src/armnn/layers/LstmLayer.hpp @@ -57,7 +57,7 @@ protected: /// Retrieve the handles to the constant values stored by the layer. /// @return A vector of the constant tensors stored by this layer. - Layer::ConstantTensors GetConstantTensorsByRef() override; + Layer::ImmutableConstantTensors GetConstantTensorsByRef() const override; }; } // namespace diff --git a/src/armnn/layers/QLstmLayer.cpp b/src/armnn/layers/QLstmLayer.cpp index 5d44c8f12d..bfdbe16155 100644 --- a/src/armnn/layers/QLstmLayer.cpp +++ b/src/armnn/layers/QLstmLayer.cpp @@ -269,7 +269,7 @@ void QLstmLayer::ValidateTensorShapesFromInputs() } } -Layer::ConstantTensors QLstmLayer::GetConstantTensorsByRef() +Layer::ImmutableConstantTensors QLstmLayer::GetConstantTensorsByRef() const { // For API stability DO NOT ALTER order and add new members to the end of vector return {m_BasicParameters.m_InputToForgetWeights, diff --git a/src/armnn/layers/QLstmLayer.hpp b/src/armnn/layers/QLstmLayer.hpp index 115c47bddb..a269d562f6 100644 --- a/src/armnn/layers/QLstmLayer.hpp +++ b/src/armnn/layers/QLstmLayer.hpp @@ -119,7 +119,7 @@ protected: /// Retrieve the handles to the constant values stored by the layer. /// @return A vector of the constant tensors stored by this layer. - Layer::ConstantTensors GetConstantTensorsByRef() override; + Layer::ImmutableConstantTensors GetConstantTensorsByRef() const override; }; } // namespace armnn diff --git a/src/armnn/layers/QuantizedLstmLayer.cpp b/src/armnn/layers/QuantizedLstmLayer.cpp index 9d58d25f60..a213a1b5b0 100644 --- a/src/armnn/layers/QuantizedLstmLayer.cpp +++ b/src/armnn/layers/QuantizedLstmLayer.cpp @@ -148,7 +148,7 @@ void QuantizedLstmLayer::ValidateTensorShapesFromInputs() 1); } -Layer::ConstantTensors QuantizedLstmLayer::GetConstantTensorsByRef() +Layer::ImmutableConstantTensors QuantizedLstmLayer::GetConstantTensorsByRef() const { // For API stability DO NOT ALTER order and add new members to the end of vector return diff --git a/src/armnn/layers/QuantizedLstmLayer.hpp b/src/armnn/layers/QuantizedLstmLayer.hpp index 8def0f3f10..1bca70cab9 100644 --- a/src/armnn/layers/QuantizedLstmLayer.hpp +++ b/src/armnn/layers/QuantizedLstmLayer.hpp @@ -81,7 +81,7 @@ protected: /// Retrieve the handles to the constant values stored by the layer. /// @return A vector of the constant tensors stored by this layer. - Layer::ConstantTensors GetConstantTensorsByRef() override; + Layer::ImmutableConstantTensors GetConstantTensorsByRef() const override; }; } // namespace armnn diff --git a/src/armnn/layers/TransposeConvolution2dLayer.cpp b/src/armnn/layers/TransposeConvolution2dLayer.cpp index eec42fbb78..f79c5887fb 100644 --- a/src/armnn/layers/TransposeConvolution2dLayer.cpp +++ b/src/armnn/layers/TransposeConvolution2dLayer.cpp @@ -116,7 +116,7 @@ void TransposeConvolution2dLayer::ValidateTensorShapesFromInputs() ValidateAndCopyShape(outputShape, expectedOutputShape[0], m_ShapeInferenceMethod, "TransposeConvolution2dLayer"); } -Layer::ConstantTensors TransposeConvolution2dLayer::GetConstantTensorsByRef() +Layer::ImmutableConstantTensors TransposeConvolution2dLayer::GetConstantTensorsByRef() const { // For API stability DO NOT ALTER order and add new members to the end of vector return {m_Weight, m_Bias}; diff --git a/src/armnn/layers/TransposeConvolution2dLayer.hpp b/src/armnn/layers/TransposeConvolution2dLayer.hpp index 1fa2902dfe..04889d9dda 100644 --- a/src/armnn/layers/TransposeConvolution2dLayer.hpp +++ b/src/armnn/layers/TransposeConvolution2dLayer.hpp @@ -54,7 +54,7 @@ protected: /// Retrieve the handles to the constant values stored by the layer. /// @return A vector of the constant tensors stored by this layer. - ConstantTensors GetConstantTensorsByRef() override; + ImmutableConstantTensors GetConstantTensorsByRef() const override; }; } // namespace armnn diff --git a/src/armnn/layers/UnidirectionalSequenceLstmLayer.cpp b/src/armnn/layers/UnidirectionalSequenceLstmLayer.cpp index 857f369cb6..7ae08834e6 100644 --- a/src/armnn/layers/UnidirectionalSequenceLstmLayer.cpp +++ b/src/armnn/layers/UnidirectionalSequenceLstmLayer.cpp @@ -274,7 +274,7 @@ void UnidirectionalSequenceLstmLayer::ValidateTensorShapesFromInputs() ValidateAndCopyShape(outputShape, inferredShapes[0], m_ShapeInferenceMethod, "UnidirectionalSequenceLstmLayer"); } -Layer::ConstantTensors UnidirectionalSequenceLstmLayer::GetConstantTensorsByRef() +Layer::ImmutableConstantTensors UnidirectionalSequenceLstmLayer::GetConstantTensorsByRef() const { // For API stability DO NOT ALTER order and add new members to the end of vector return {m_BasicParameters.m_InputToForgetWeights, diff --git a/src/armnn/layers/UnidirectionalSequenceLstmLayer.hpp b/src/armnn/layers/UnidirectionalSequenceLstmLayer.hpp index 60b6893627..d7e95140ff 100644 --- a/src/armnn/layers/UnidirectionalSequenceLstmLayer.hpp +++ b/src/armnn/layers/UnidirectionalSequenceLstmLayer.hpp @@ -58,7 +58,7 @@ protected: /// Retrieve the handles to the constant values stored by the layer. /// @return A vector of the constant tensors stored by this layer. - Layer::ConstantTensors GetConstantTensorsByRef() override; + Layer::ImmutableConstantTensors GetConstantTensorsByRef() const override; }; } // namespace -- cgit v1.2.1