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 <matthew.bentham@arm.com>
Change-Id: Id3a8384447e93c213299a85ade9a667df5960534
diff --git a/delegate/src/MultiLayerFacade.hpp b/delegate/src/MultiLayerFacade.hpp
index aa00be8..31a7354 100644
--- a/delegate/src/MultiLayerFacade.hpp
+++ b/delegate/src/MultiLayerFacade.hpp
@@ -123,6 +123,7 @@
     /// 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 { return {}; }
+    ImmutableConstantTensors GetConstantTensorsByRef() const override { return {}; }
 
 private:
     armnn::IConnectableLayer* m_FirstLayer;
diff --git a/include/armnn/INetwork.hpp b/include/armnn/INetwork.hpp
index c9c8a04..c944d09 100644
--- a/include/armnn/INetwork.hpp
+++ b/include/armnn/INetwork.hpp
@@ -126,6 +126,11 @@
     // Returns ConstantTensors of this Layer if it has any, otherwise returns empty vector.
     virtual ConstantTensors GetConstantTensorsByRef() = 0;
 
+    using ImmutableConstantTensors = std::vector<std::reference_wrapper<const std::shared_ptr<ConstTensorHandle>>>;
+
+    // Returns ConstantTensors of this Layer if it has any, otherwise returns empty vector.
+    virtual ImmutableConstantTensors GetConstantTensorsByRef() const = 0;
+
 protected:
       /// Objects are not deletable via the handle
     ~IConnectableLayer() {}
diff --git a/include/armnn/Version.hpp b/include/armnn/Version.hpp
index aedd4a0..82d546a 100644
--- a/include/armnn/Version.hpp
+++ b/include/armnn/Version.hpp
@@ -11,7 +11,7 @@
 
 // ArmNN version components
 #define ARMNN_MAJOR_VERSION 32
-#define ARMNN_MINOR_VERSION 0
+#define ARMNN_MINOR_VERSION 1
 #define ARMNN_PATCH_VERSION 0
 
 /// ARMNN_VERSION: "X.Y.Z"
diff --git a/python/pyarmnn/src/pyarmnn/_version.py b/python/pyarmnn/src/pyarmnn/_version.py
index 4501f88..f7decd3 100644
--- a/python/pyarmnn/src/pyarmnn/_version.py
+++ b/python/pyarmnn/src/pyarmnn/_version.py
@@ -3,7 +3,7 @@
 # SPDX-License-Identifier: MIT
 import os
 
-version_info = (32, 0, 0)
+version_info = (32, 1, 0)
 
 __dev_version_env = os.getenv("PYARMNN_DEV_VER", "")
 
diff --git a/python/pyarmnn/test/test_version.py b/python/pyarmnn/test/test_version.py
index 145fc3b..8ba93ef 100644
--- a/python/pyarmnn/test/test_version.py
+++ b/python/pyarmnn/test/test_version.py
@@ -18,7 +18,7 @@
 
     importlib.reload(v)
 
-    assert "32.0.0.dev1" == v.__version__
+    assert "32.1.0.dev1" == v.__version__
 
     del os.environ["PYARMNN_DEV_VER"]
     del v
@@ -30,7 +30,7 @@
 
     importlib.reload(v)
 
-    assert "32.0.0" == v.__arm_ml_version__
+    assert "32.1.0" == v.__arm_ml_version__
 
     del os.environ["PYARMNN_DEV_VER"]
     del v
diff --git a/src/armnn/Layer.cpp b/src/armnn/Layer.cpp
index 19337dc..3ccce40 100644
--- a/src/armnn/Layer.cpp
+++ b/src/armnn/Layer.cpp
@@ -538,6 +538,19 @@
     strategy.ExecuteStrategy(this, BaseDescriptor(), {}, GetName());
 }
 
+Layer::ConstantTensors Layer::GetConstantTensorsByRef()
+{
+    const Layer *constThis = const_cast<const Layer*>(this);
+    ConstantTensors res;
+
+    ImmutableConstantTensors immutableData = constThis->GetConstantTensorsByRef();
+    for (auto i : immutableData)
+    {
+        res.push_back(const_cast<std::shared_ptr<ConstTensorHandle>&>(i.get()));
+    }
+    return res;
+}
+
 const IConnectableLayer& OutputSlot::GetOwningIConnectableLayer() const
 {
     return m_OwningLayer;
diff --git a/src/armnn/Layer.hpp b/src/armnn/Layer.hpp
index aab5227..ad6c9b2 100644
--- a/src/armnn/Layer.hpp
+++ b/src/armnn/Layer.hpp
@@ -406,7 +406,11 @@
 
     // Retrieve the Handles to the constants
     // Marking this as override and having this here keeps IConnectable abstract with only pure virtual function
-    virtual ConstantTensors GetConstantTensorsByRef() override {return ConstantTensors(); };
+    virtual ConstantTensors GetConstantTensorsByRef() override final;
+
+    // Retrieve the Handles to the constants
+    // Marking this as override and having this here keeps IConnectable abstract with only pure virtual function
+    virtual ImmutableConstantTensors GetConstantTensorsByRef() const override { return ImmutableConstantTensors(); };
 
     // "Blob"
     AdditionalInfoObjectPtr m_AdditionalInfoObject;
diff --git a/src/armnn/layers/BatchNormalizationLayer.cpp b/src/armnn/layers/BatchNormalizationLayer.cpp
index 6f0e1a8..b5e9f2c 100644
--- a/src/armnn/layers/BatchNormalizationLayer.cpp
+++ b/src/armnn/layers/BatchNormalizationLayer.cpp
@@ -65,7 +65,7 @@
 
 }
 
-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 9715c56..1b61c78 100644
--- a/src/armnn/layers/BatchNormalizationLayer.hpp
+++ b/src/armnn/layers/BatchNormalizationLayer.hpp
@@ -52,7 +52,7 @@
 
     /// 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 f5ab546..08b9c24 100644
--- a/src/armnn/layers/ConstantLayer.hpp
+++ b/src/armnn/layers/ConstantLayer.hpp
@@ -53,7 +53,7 @@
 
     /// 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 e06b45a..f6a5583 100644
--- a/src/armnn/layers/Convolution2dLayer.cpp
+++ b/src/armnn/layers/Convolution2dLayer.cpp
@@ -119,9 +119,9 @@
     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 f7e4dec..519d8c4 100644
--- a/src/armnn/layers/Convolution2dLayer.hpp
+++ b/src/armnn/layers/Convolution2dLayer.hpp
@@ -56,7 +56,7 @@
 
     /// 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 4c97437..1e5a998 100644
--- a/src/armnn/layers/DepthwiseConvolution2dLayer.cpp
+++ b/src/armnn/layers/DepthwiseConvolution2dLayer.cpp
@@ -123,9 +123,9 @@
     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 ef7410f..d69d779 100644
--- a/src/armnn/layers/DepthwiseConvolution2dLayer.hpp
+++ b/src/armnn/layers/DepthwiseConvolution2dLayer.hpp
@@ -56,7 +56,7 @@
 
     /// 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 33f8944..27e459b 100644
--- a/src/armnn/layers/DetectionPostProcessLayer.cpp
+++ b/src/armnn/layers/DetectionPostProcessLayer.cpp
@@ -89,7 +89,7 @@
     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 e203032..93939bf 100644
--- a/src/armnn/layers/DetectionPostProcessLayer.hpp
+++ b/src/armnn/layers/DetectionPostProcessLayer.hpp
@@ -53,7 +53,7 @@
 
     /// 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 05c5396..f86f584 100644
--- a/src/armnn/layers/FullyConnectedLayer.cpp
+++ b/src/armnn/layers/FullyConnectedLayer.cpp
@@ -61,9 +61,9 @@
     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 f3ca696..e133def 100644
--- a/src/armnn/layers/FullyConnectedLayer.hpp
+++ b/src/armnn/layers/FullyConnectedLayer.hpp
@@ -54,7 +54,7 @@
 
     /// 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 40ade95..0a1dbf3 100644
--- a/src/armnn/layers/LayerWithParameters.hpp
+++ b/src/armnn/layers/LayerWithParameters.hpp
@@ -56,9 +56,9 @@
         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 8e6bfdb..2c96043 100644
--- a/src/armnn/layers/LstmLayer.cpp
+++ b/src/armnn/layers/LstmLayer.cpp
@@ -267,7 +267,7 @@
     }
 }
 
-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 7310d41..0462403 100644
--- a/src/armnn/layers/LstmLayer.hpp
+++ b/src/armnn/layers/LstmLayer.hpp
@@ -57,7 +57,7 @@
 
     /// 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 5d44c8f..bfdbe16 100644
--- a/src/armnn/layers/QLstmLayer.cpp
+++ b/src/armnn/layers/QLstmLayer.cpp
@@ -269,7 +269,7 @@
     }
 }
 
-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 115c47b..a269d56 100644
--- a/src/armnn/layers/QLstmLayer.hpp
+++ b/src/armnn/layers/QLstmLayer.hpp
@@ -119,7 +119,7 @@
 
     /// 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 9d58d25..a213a1b 100644
--- a/src/armnn/layers/QuantizedLstmLayer.cpp
+++ b/src/armnn/layers/QuantizedLstmLayer.cpp
@@ -148,7 +148,7 @@
                          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 8def0f3..1bca70c 100644
--- a/src/armnn/layers/QuantizedLstmLayer.hpp
+++ b/src/armnn/layers/QuantizedLstmLayer.hpp
@@ -81,7 +81,7 @@
 
     /// 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 eec42fb..f79c588 100644
--- a/src/armnn/layers/TransposeConvolution2dLayer.cpp
+++ b/src/armnn/layers/TransposeConvolution2dLayer.cpp
@@ -116,7 +116,7 @@
     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 1fa2902..04889d9 100644
--- a/src/armnn/layers/TransposeConvolution2dLayer.hpp
+++ b/src/armnn/layers/TransposeConvolution2dLayer.hpp
@@ -54,7 +54,7 @@
 
     /// 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 857f369..7ae0883 100644
--- a/src/armnn/layers/UnidirectionalSequenceLstmLayer.cpp
+++ b/src/armnn/layers/UnidirectionalSequenceLstmLayer.cpp
@@ -274,7 +274,7 @@
     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 60b6893..d7e9514 100644
--- a/src/armnn/layers/UnidirectionalSequenceLstmLayer.hpp
+++ b/src/armnn/layers/UnidirectionalSequenceLstmLayer.hpp
@@ -58,7 +58,7 @@
 
     /// 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