aboutsummaryrefslogtreecommitdiff
path: root/src/armnn/layers
diff options
context:
space:
mode:
authorFrancis Murtagh <francis.murtagh@arm.com>2022-05-09 17:00:21 +0100
committerFrancis Murtagh <francis.murtagh@arm.com>2022-05-19 18:16:47 +0100
commitd86f6c4697e0c1511c553e76e0e59b72a5730fac (patch)
tree8e4ccf043457732d20892f980389f97bc3332c95 /src/armnn/layers
parent541880fcf4572887e57658a508623fb5f95ac554 (diff)
downloadarmnn-d86f6c4697e0c1511c553e76e0e59b72a5730fac.tar.gz
IVGCVSW-6145 ConstTensorsAsInput: Optimizer Fix - GetConstantTensorsByRef
* Add functionality to check for ConstantTensorsAsInputs to GetConstantTensorsByRef * Reorder optimizations so RedirectMembersToConstantInputs occurs after Conversion of Constants * Ensure graph is in topological order after loading in OptimizedNet * Fixed test to check release of m_LayerOutputs. Signed-off-by: Francis Murtagh <francis.murtagh@arm.com> Change-Id: I7cff50798d7217e8ea0d2f9b153eabd10174a566
Diffstat (limited to 'src/armnn/layers')
-rw-r--r--src/armnn/layers/Convolution2dLayer.cpp7
-rw-r--r--src/armnn/layers/DepthwiseConvolution2dLayer.cpp7
-rw-r--r--src/armnn/layers/FullyConnectedLayer.cpp7
-rw-r--r--src/armnn/layers/LayerWithParameters.hpp29
4 files changed, 50 insertions, 0 deletions
diff --git a/src/armnn/layers/Convolution2dLayer.cpp b/src/armnn/layers/Convolution2dLayer.cpp
index 7b3382bf93..dbbd009716 100644
--- a/src/armnn/layers/Convolution2dLayer.cpp
+++ b/src/armnn/layers/Convolution2dLayer.cpp
@@ -139,6 +139,13 @@ void Convolution2dLayer::ValidateTensorShapesFromInputs()
Layer::ConstantTensors Convolution2dLayer::GetConstantTensorsByRef()
{
+ Layer::ConstantTensors tensors = GetConnectedConstantAsInputTensors();
+
+ if (!tensors.empty())
+ {
+ return tensors;
+ }
+
// 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/DepthwiseConvolution2dLayer.cpp b/src/armnn/layers/DepthwiseConvolution2dLayer.cpp
index 08f6fafa1b..4fd280485a 100644
--- a/src/armnn/layers/DepthwiseConvolution2dLayer.cpp
+++ b/src/armnn/layers/DepthwiseConvolution2dLayer.cpp
@@ -142,6 +142,13 @@ void DepthwiseConvolution2dLayer::ValidateTensorShapesFromInputs()
Layer::ConstantTensors DepthwiseConvolution2dLayer::GetConstantTensorsByRef()
{
+ Layer::ConstantTensors tensors = GetConnectedConstantAsInputTensors();
+
+ if (!tensors.empty())
+ {
+ return tensors;
+ }
+
// 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/FullyConnectedLayer.cpp b/src/armnn/layers/FullyConnectedLayer.cpp
index b1ae974cd6..1f006c9d80 100644
--- a/src/armnn/layers/FullyConnectedLayer.cpp
+++ b/src/armnn/layers/FullyConnectedLayer.cpp
@@ -77,6 +77,13 @@ void FullyConnectedLayer::ValidateTensorShapesFromInputs()
Layer::ConstantTensors FullyConnectedLayer::GetConstantTensorsByRef()
{
+ Layer::ConstantTensors tensors = GetConnectedConstantAsInputTensors();
+
+ if (!tensors.empty())
+ {
+ return tensors;
+ }
+
// 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/LayerWithParameters.hpp b/src/armnn/layers/LayerWithParameters.hpp
index 8d9ddffc24..40ade95d5c 100644
--- a/src/armnn/layers/LayerWithParameters.hpp
+++ b/src/armnn/layers/LayerWithParameters.hpp
@@ -4,6 +4,7 @@
//
#pragma once
+#include "ConstantLayer.hpp"
#include <Layer.hpp>
namespace armnn
@@ -54,6 +55,34 @@ protected:
{
strategy.ExecuteStrategy(this, GetParameters(), {}, GetName());
}
+
+ Layer::ConstantTensors GetConnectedConstantAsInputTensors()
+ {
+ Layer::ConstantTensors tensors;
+ for (unsigned int i = 0; i < GetNumInputSlots(); ++i)
+ {
+ if (GetInputSlot(i).GetConnection() && GetInputSlot(i).GetConnection()->GetTensorInfo().IsConstant())
+ {
+ auto &inputLayer = GetInputSlot(i).GetConnectedOutputSlot()->GetOwningLayer();
+ if (inputLayer.GetType() == armnn::LayerType::Constant)
+ {
+ auto &constantLayer = static_cast<ConstantLayer&>(inputLayer);
+
+ tensors.push_back(constantLayer.m_LayerOutput);
+ }
+ }
+ }
+ if (tensors.empty())
+ {
+ const std::string warningMessage{"GetConnectedConstantAsInputTensors() called on Layer with no "
+ "connected Constants as Input Tensors."};
+ ARMNN_LOG(warning) << warningMessage;
+ }
+ return tensors;
+ }
};
+
+
+
} // namespace