diff options
Diffstat (limited to 'src/armnn/layers')
-rw-r--r-- | src/armnn/layers/Convolution2dLayer.cpp | 7 | ||||
-rw-r--r-- | src/armnn/layers/DepthwiseConvolution2dLayer.cpp | 7 | ||||
-rw-r--r-- | src/armnn/layers/FullyConnectedLayer.cpp | 7 | ||||
-rw-r--r-- | src/armnn/layers/LayerWithParameters.hpp | 29 |
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 |