diff options
author | Mike Kelly <mike.kelly@arm.com> | 2022-11-25 13:55:24 +0000 |
---|---|---|
committer | mike.kelly <mike.kelly@arm.com> | 2022-12-12 15:58:21 +0000 |
commit | ec67a0f08e0f96a5aebf3cac65331c67f6649f5e (patch) | |
tree | 94146a1f43c74d89d83fd5da54688ae0fc19cf85 /src/armnn | |
parent | 5383767a7a759c867235ab66bd71f88281e3bd06 (diff) | |
download | armnn-ec67a0f08e0f96a5aebf3cac65331c67f6649f5e.tar.gz |
IVGCVSW-7209 Remove deprecated code due to be removed in 23.02
* Removed weights and bias from Convolution, DepthwiseConv & FullyConnected
layers
* Removed the weight and bias ConstTensorHandles from the QueueDescriptors
* Updated Workloads to take tensors from WorkloadInfo rather than the
QueueDescriptors
* Removed unused RedirectMembersToConstantInputs optimization and tests.
Signed-off-by: Teresa Charlin <teresa.charlinreyes@arm.com>
Signed-off-by: Mike Kelly <mike.kelly@arm.com>
Change-Id: I9ffcdc4a1c0dff725539dd69fc435b700bd98a56
Diffstat (limited to 'src/armnn')
19 files changed, 102 insertions, 529 deletions
diff --git a/src/armnn/LoadedNetwork.cpp b/src/armnn/LoadedNetwork.cpp index 40fbde8ac8..7b24fd77b8 100644 --- a/src/armnn/LoadedNetwork.cpp +++ b/src/armnn/LoadedNetwork.cpp @@ -421,7 +421,7 @@ LoadedNetwork::LoadedNetwork(std::unique_ptr<IOptimizedNetwork> net, ConstWorkloads.push_back(m_WorkloadQueue.back().get()); } } - // release the constant data in the layer.. + // release the constant data in the layer. layer->ReleaseConstantData(); break; } diff --git a/src/armnn/Network.cpp b/src/armnn/Network.cpp index a61624fb0a..158142f48e 100644 --- a/src/armnn/Network.cpp +++ b/src/armnn/Network.cpp @@ -1,5 +1,5 @@ // -// Copyright © 2022 Arm Ltd and Contributors. All rights reserved. +// Copyright © 2017,2022 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // @@ -1714,9 +1714,6 @@ IOptimizedNetworkPtr Optimize(const Graph& inGraph, ARMNN_SCOPED_PROFILING_EVENT(Compute::Undefined, "Optimizer_ConvertConstants"); Optimizer::Pass(optGraph, MakeOptimizations(ConvertConstantsFloatToHalf())); Optimizer::Pass(optGraph, MakeOptimizations(ConvertConstantsHalfToFloat())); - - // Once the constants are converted we can now safely call RedirectMembersToConstantInputs - Optimizer::Pass(optGraph, MakeOptimizations(RedirectMembersToConstantInputs())); } // This must occur after all topological changes to the graph and any redirection of variables @@ -1860,82 +1857,6 @@ IConnectableLayer* NetworkImpl::AddFullyConnectedLayer(const FullyConnectedDescr return m_Graph->AddLayer<FullyConnectedLayer>(fullyConnectedDescriptor, name); } -IConnectableLayer* NetworkImpl::AddFullyConnectedLayer(const FullyConnectedDescriptor& fullyConnectedDescriptor, - const Optional<ConstTensor>& weights, - const Optional<ConstTensor>& biases, - const char* name) -{ - ConstantLayer* weightsLayer = nullptr; - ConstantLayer* biasLayer = nullptr; - unsigned int numInputs = fullyConnectedDescriptor.GetNumInputs(); - - // Add a constant layer for weights - if (weights.has_value()) - { - weightsLayer = m_Graph->AddLayer<ConstantLayer>("Weights"); - weightsLayer->m_LayerOutput = std::make_shared<ScopedTensorHandle>(weights.value()); - - TensorInfo weightsInfo = weightsLayer->m_LayerOutput->GetTensorInfo(); - weightsInfo.SetConstant(); - - weightsLayer->GetOutputSlot(0).SetTensorInfo(weightsInfo); - } - else if (fullyConnectedDescriptor.m_ConstantWeights) - { - throw InvalidArgumentException("AddFullyConnectedLayer: Constant weights tensor is empty."); - } - - // Add a constant layer for biases - if (biases.has_value() && fullyConnectedDescriptor.m_BiasEnabled) - { - biasLayer = m_Graph->AddLayer<ConstantLayer>("Biases"); - biasLayer->m_LayerOutput = std::make_shared<ScopedTensorHandle>(biases.value()); - - TensorInfo biasInfo = biasLayer->m_LayerOutput->GetTensorInfo(); - biasInfo.SetConstant(); - - biasLayer->GetOutputSlot(0).SetTensorInfo(biasInfo); - } - - if (numInputs < 2) - { - throw InvalidArgumentException("AddFullyConnectedLayer: Requires at least 2 input tensors: Input, Weights"); - } - - auto layer = m_Graph->AddLayer<FullyConnectedLayer>(fullyConnectedDescriptor, name); - - if (weightsLayer) - { - // Connect weights layer - weightsLayer->GetOutputSlot(0).Connect(layer->GetInputSlot(1)); - } - - if ( fullyConnectedDescriptor.m_BiasEnabled && numInputs == 3 ) - { - if (biasLayer) - { - // Connect bias layer - biasLayer->GetOutputSlot(0).Connect(layer->GetInputSlot(2)); - } - } - else if ( !fullyConnectedDescriptor.m_BiasEnabled && numInputs == 2 ) - { - // Bias is disabled - layer->m_Bias = nullptr; - } - else - { - throw InvalidArgumentException(fmt::format( - "AddFullyConnectedLayer: Value mismatch. When bias is enabled in the " - "descriptor the number of inputs is expected to be 3 otherwise 2. " - "BiasEnabled={}, numInputs={}", - fullyConnectedDescriptor.m_BiasEnabled, - numInputs)); - } - - return layer; -} - IConnectableLayer* NetworkImpl::AddConcatLayer(const ConcatDescriptor& concatDescriptor, const char* name) { @@ -1948,32 +1869,6 @@ IConnectableLayer* NetworkImpl::AddConvolution2dLayer(const Convolution2dDescrip return m_Graph->AddLayer<Convolution2dLayer>(convolution2dDescriptor, name); } -IConnectableLayer* NetworkImpl::AddConvolution2dLayer(const Convolution2dDescriptor& convolution2dDescriptor, - const ConstTensor& weights, - const Optional<ConstTensor>& biases, - const char* name) -{ - auto layer = m_Graph->AddLayer<Convolution2dLayer>(convolution2dDescriptor, name); - // Add a constant layer for weights - ConstantLayer* weightsLayer = m_Graph->AddLayer<ConstantLayer>("Weights"); - auto weightsTensorHandle = std::make_shared<ScopedTensorHandle>(weights); - weightsLayer->m_LayerOutput = weightsTensorHandle; - layer->m_Weight = weightsTensorHandle; - weightsLayer->GetOutputSlot(0).SetTensorInfo(weightsLayer->m_LayerOutput->GetTensorInfo()); - weightsLayer->GetOutputSlot(0).Connect(layer->GetInputSlot(1)); - // Add a constant layer for biases - if (biases.has_value() && convolution2dDescriptor.m_BiasEnabled) - { - ConstantLayer* biasLayer = m_Graph->AddLayer<ConstantLayer>("Bias"); - auto biasTensorHandle = std::make_shared<ScopedTensorHandle>(biases.value()); - biasLayer->m_LayerOutput = biasTensorHandle; - layer->m_Bias = biasTensorHandle; - biasLayer->GetOutputSlot(0).SetTensorInfo(biasLayer->m_LayerOutput->GetTensorInfo()); - biasLayer->GetOutputSlot(0).Connect(layer->GetInputSlot(2)); - } - return layer; -} - IConnectableLayer* NetworkImpl::AddConvertFp16ToFp32Layer(const char* name) { return m_Graph->AddLayer<ConvertFp16ToFp32Layer>(name); @@ -2003,38 +1898,6 @@ IConnectableLayer* NetworkImpl::AddDepthwiseConvolution2dLayer( return m_Graph->AddLayer<DepthwiseConvolution2dLayer>(convolution2dDescriptor, name); } -IConnectableLayer* NetworkImpl::AddDepthwiseConvolution2dLayer( - const DepthwiseConvolution2dDescriptor& convolution2dDescriptor, - const ConstTensor& weights, - const Optional<ConstTensor>& biases, - const char* name) -{ - auto layer = m_Graph->AddLayer<DepthwiseConvolution2dLayer>(convolution2dDescriptor, name); - - // Add a constant layer for weights - ConstantLayer* weightsLayer = m_Graph->AddLayer<ConstantLayer>("Weights"); - auto weightsTensorHandle = std::make_shared<ScopedTensorHandle>(weights); - weightsLayer->m_LayerOutput = weightsTensorHandle; - layer->m_Weight = weightsTensorHandle; - - weightsLayer->GetOutputSlot(0).SetTensorInfo(weightsLayer->m_LayerOutput->GetTensorInfo()); - weightsLayer->GetOutputSlot(0).Connect(layer->GetInputSlot(1)); - - // Add a constant layer for biases - if (biases.has_value() && convolution2dDescriptor.m_BiasEnabled) - { - ConstantLayer* biasLayer = m_Graph->AddLayer<ConstantLayer>("Bias"); - auto biasTensorHandle = std::make_shared<ScopedTensorHandle>(biases.value()); - biasLayer->m_LayerOutput = biasTensorHandle; - layer->m_Bias = biasTensorHandle; - - biasLayer->GetOutputSlot(0).SetTensorInfo(biasLayer->m_LayerOutput->GetTensorInfo()); - biasLayer->GetOutputSlot(0).Connect(layer->GetInputSlot(2)); - } - - return layer; -} - IConnectableLayer* NetworkImpl::AddDetectionPostProcessLayer(const armnn::DetectionPostProcessDescriptor& descriptor, const ConstTensor& anchors, const char* name) { diff --git a/src/armnn/Network.hpp b/src/armnn/Network.hpp index 5ca16e2968..a37a4be218 100644 --- a/src/armnn/Network.hpp +++ b/src/armnn/Network.hpp @@ -1,5 +1,5 @@ // -// Copyright © 2017 Arm Ltd and Contributors. All rights reserved. +// Copyright © 2017,2022 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // #pragma once @@ -76,23 +76,6 @@ public: IConnectableLayer* AddConvolution2dLayer(const Convolution2dDescriptor& convolution2dDescriptor, const char* name = nullptr); - ARMNN_DEPRECATED_MSG_REMOVAL_DATE("This AddConvolution2dLayer overload is deprecated", "23.02") - IConnectableLayer* AddConvolution2dLayer(const Convolution2dDescriptor& convolution2dDescriptor, - const ConstTensor& weights, - const Optional<ConstTensor>& biases, - const char* name = nullptr); - - ARMNN_DEPRECATED_MSG_REMOVAL_DATE("This AddConvolution2dLayer overload is deprecated", "23.02") - IConnectableLayer* AddConvolution2dLayer(const Convolution2dDescriptor& convolution2dDescriptor, - const ConstTensor& weights, - const char* name = nullptr); - - ARMNN_DEPRECATED_MSG_REMOVAL_DATE("This AddConvolution2dLayer overload is deprecated", "23.02") - IConnectableLayer* AddConvolution2dLayer(const Convolution2dDescriptor& convolution2dDescriptor, - const ConstTensor& weights, - const ConstTensor& biases, - const char* name = nullptr); - IConnectableLayer* AddConvolution3dLayer(const Convolution3dDescriptor& convolution3dDescriptor, const char* name = nullptr); @@ -101,23 +84,14 @@ public: IConnectableLayer* AddDepthToSpaceLayer(const DepthToSpaceDescriptor& depthToSpaceDescriptor, const char* name = nullptr); - IConnectableLayer* AddDepthwiseConvolution2dLayer( - const DepthwiseConvolution2dDescriptor& convolution2dDescriptor, - const char* name = nullptr); - - ARMNN_DEPRECATED_MSG("This AddDepthwiseConvolution2dLayer overload is deprecated") - IConnectableLayer* AddDepthwiseConvolution2dLayer( - const DepthwiseConvolution2dDescriptor& convolution2dDescriptor, - const ConstTensor& weights, - const Optional<ConstTensor>& biases, - const char* name = nullptr); + IConnectableLayer* AddDepthwiseConvolution2dLayer(const DepthwiseConvolution2dDescriptor& convolution2dDescriptor, + const char* name = nullptr); IConnectableLayer* AddDequantizeLayer(const char* name = nullptr); - IConnectableLayer* AddDetectionPostProcessLayer( - const DetectionPostProcessDescriptor& descriptor, - const ConstTensor& anchors, - const char* name = nullptr); + IConnectableLayer* AddDetectionPostProcessLayer(const DetectionPostProcessDescriptor& descriptor, + const ConstTensor& anchors, + const char* name = nullptr); IConnectableLayer* AddDivisionLayer(const char* name = nullptr); @@ -134,11 +108,6 @@ public: IConnectableLayer* AddFullyConnectedLayer(const FullyConnectedDescriptor& fullyConnectedDescriptor, const char* name = nullptr); - IConnectableLayer* AddFullyConnectedLayer(const FullyConnectedDescriptor& fullyConnectedDescriptor, - const Optional<ConstTensor>& weights, - const Optional<ConstTensor>& biases, - const char* name = nullptr); - IConnectableLayer* AddGatherLayer(const GatherDescriptor& gatherDescriptor, const char* name = nullptr); diff --git a/src/armnn/layers/Convolution2dLayer.cpp b/src/armnn/layers/Convolution2dLayer.cpp index d0233976c4..e06b45acb0 100644 --- a/src/armnn/layers/Convolution2dLayer.cpp +++ b/src/armnn/layers/Convolution2dLayer.cpp @@ -1,5 +1,5 @@ // -// Copyright © 2017 Arm Ltd and Contributors. All rights reserved. +// Copyright © 2017,2022 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // @@ -48,18 +48,8 @@ void Convolution2dLayer::SerializeLayerParameters(ParameterStringifyFunction& fn std::unique_ptr<IWorkload> Convolution2dLayer::CreateWorkload(const IWorkloadFactory& factory) const { - // on this level constant data should not be released.. ARMNN_SCOPED_PROFILING_EVENT(Compute::Undefined, "Convolution2dLayer_CreateWorkload"); Convolution2dQueueDescriptor descriptor; - if (m_Weight) - { - descriptor.m_Weight = m_Weight.get(); - } - if (m_Param.m_BiasEnabled && m_Bias) - { - descriptor.m_Bias = m_Bias.get(); - } - SetAdditionalInfo(descriptor); return factory.CreateWorkload(LayerType::Convolution2d, descriptor, PrepInfoAndDesc(descriptor)); @@ -68,14 +58,6 @@ std::unique_ptr<IWorkload> Convolution2dLayer::CreateWorkload(const IWorkloadFac Convolution2dLayer* Convolution2dLayer::Clone(Graph& graph) const { auto layer = CloneBase<Convolution2dLayer>(graph, m_Param, GetName()); - - layer->m_Weight = m_Weight ? m_Weight : nullptr; - - if (layer->m_Param.m_BiasEnabled) - { - layer->m_Bias = m_Bias ? m_Bias : nullptr; - } - return std::move(layer); } @@ -140,14 +122,7 @@ 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}; + return tensors; } void Convolution2dLayer::ExecuteStrategy(IStrategy& strategy) const diff --git a/src/armnn/layers/Convolution2dLayer.hpp b/src/armnn/layers/Convolution2dLayer.hpp index 02ae05f83b..f7e4dec72f 100644 --- a/src/armnn/layers/Convolution2dLayer.hpp +++ b/src/armnn/layers/Convolution2dLayer.hpp @@ -1,5 +1,5 @@ // -// Copyright © 2017 Arm Ltd and Contributors. All rights reserved. +// Copyright © 2017,2022 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // #pragma once @@ -16,13 +16,6 @@ class Convolution2dLayer : public LayerWithParameters<Convolution2dDescriptor> { public: - /// A unique pointer to store Weight values. - /// @Note: Deprecated. Removal date is 23.02. Weights are stored in ConstantLayers now. - std::shared_ptr<ConstTensorHandle> m_Weight; - /// A unique pointer to store Bias values. - /// @Note: Deprecated. Removal date is 23.02. Bias are stored in ConstantLayers now. - std::shared_ptr<ConstTensorHandle> m_Bias; - /// Makes a workload for the Convolution2d type. /// @param [in] graph The graph where this layer can be found. /// @param [in] factory The workload factory which will create the workload. @@ -48,6 +41,10 @@ public: void SerializeLayerParameters(ParameterStringifyFunction& fn) const override; + /// This layer does not have any data stored, weights and bias are now stored in constant layers. + /// We do not want to release the data in the constant layer, that is why we override with an empty function. + void ReleaseConstantData() override {} + protected: /// Constructor to create a Convolution2dLayer. /// @param [in] param Convolution2dDescriptor to configure the convolution2d operation. @@ -57,8 +54,8 @@ protected: /// Default destructor ~Convolution2dLayer() = default; - /// @Note Deprecated. GetConstantTensorsByRef is deprecated. m_Weights and m_Bias - /// should be connected to layer as Constant Layers instead." + /// 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; }; diff --git a/src/armnn/layers/DepthwiseConvolution2dLayer.cpp b/src/armnn/layers/DepthwiseConvolution2dLayer.cpp index dcd800e367..4c97437a1c 100644 --- a/src/armnn/layers/DepthwiseConvolution2dLayer.cpp +++ b/src/armnn/layers/DepthwiseConvolution2dLayer.cpp @@ -1,5 +1,5 @@ // -// Copyright © 2017 Arm Ltd and Contributors. All rights reserved. +// Copyright © 2017,2022 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // @@ -50,16 +50,6 @@ void DepthwiseConvolution2dLayer::SerializeLayerParameters(ParameterStringifyFun std::unique_ptr<IWorkload> DepthwiseConvolution2dLayer::CreateWorkload(const IWorkloadFactory& factory) const { DepthwiseConvolution2dQueueDescriptor descriptor; - - if (m_Weight) - { - descriptor.m_Weight = m_Weight.get(); - } - if (m_Param.m_BiasEnabled && m_Bias) - { - descriptor.m_Bias = m_Bias.get(); - } - SetAdditionalInfo(descriptor); return factory.CreateWorkload(LayerType::DepthwiseConvolution2d, descriptor, PrepInfoAndDesc(descriptor)); @@ -68,13 +58,6 @@ std::unique_ptr<IWorkload> DepthwiseConvolution2dLayer::CreateWorkload(const IWo DepthwiseConvolution2dLayer* DepthwiseConvolution2dLayer::Clone(Graph& graph) const { auto layer = CloneBase<DepthwiseConvolution2dLayer>(graph, m_Param, GetName()); - layer->m_Weight = m_Weight ? m_Weight : nullptr; - - if (layer->m_Param.m_BiasEnabled) - { - layer->m_Bias = m_Bias ? m_Bias : nullptr; - } - return std::move(layer); } @@ -143,14 +126,7 @@ 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}; + return tensors; } void DepthwiseConvolution2dLayer::ExecuteStrategy(IStrategy& strategy) const diff --git a/src/armnn/layers/DepthwiseConvolution2dLayer.hpp b/src/armnn/layers/DepthwiseConvolution2dLayer.hpp index baae7f122a..ef7410f1d3 100644 --- a/src/armnn/layers/DepthwiseConvolution2dLayer.hpp +++ b/src/armnn/layers/DepthwiseConvolution2dLayer.hpp @@ -1,5 +1,5 @@ // -// Copyright © 2017 Arm Ltd and Contributors. All rights reserved. +// Copyright © 2017,2022 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // #pragma once @@ -15,12 +15,6 @@ class ScopedTensorHandle; class DepthwiseConvolution2dLayer : public LayerWithParameters<DepthwiseConvolution2dDescriptor> { public: - /// A unique pointer to store Weight values. - /// @Note Deprecated. Removal date is 23.02. Weights are stored in ConstantLayers now. - std::shared_ptr<ConstTensorHandle> m_Weight; - /// A unique pointer to store Bias values. - /// @Note Deprecated. Removal date is 23.02. Bias are stored in ConstantLayers now. - std::shared_ptr<ConstTensorHandle> m_Bias; /// Makes a workload for the DepthwiseConvolution2d type. /// @param [in] graph The graph where this layer can be found. @@ -47,6 +41,10 @@ public: void SerializeLayerParameters(ParameterStringifyFunction& fn) const override; + /// This layer does not have any data stored, weights and bias are now stored in constant layers. + /// We do not want to release the data in the constant layer, that is why we override with an empty function. + void ReleaseConstantData() override {} + protected: /// Constructor to create a DepthwiseConvolution2dLayer. /// @param [in] param DepthwiseConvolution2dDescriptor to configure the depthwise convolution2d. @@ -56,10 +54,8 @@ protected: /// Default destructor ~DepthwiseConvolution2dLayer() = default; - /// Retrieve the handles to the constant values stored by the layer. - /// @return A vector of the constant tensors stored by this layer. - /// @Note Deprecated. GetConstantTensorsByRef is deprecated. m_Weights and m_Bias - /// should be connected to layer as Constant Layers instead." + /// 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; }; diff --git a/src/armnn/layers/FullyConnectedLayer.cpp b/src/armnn/layers/FullyConnectedLayer.cpp index c20bc8d167..05c53961e3 100644 --- a/src/armnn/layers/FullyConnectedLayer.cpp +++ b/src/armnn/layers/FullyConnectedLayer.cpp @@ -1,5 +1,5 @@ // -// Copyright © 2017 Arm Ltd and Contributors. All rights reserved. +// Copyright © 2017,2022 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // #include "FullyConnectedLayer.hpp" @@ -22,27 +22,13 @@ FullyConnectedLayer::FullyConnectedLayer(const FullyConnectedDescriptor& param, std::unique_ptr<IWorkload> FullyConnectedLayer::CreateWorkload(const IWorkloadFactory& factory) const { FullyConnectedQueueDescriptor descriptor; - if (m_Weight) - { - descriptor.m_Weight = m_Weight.get(); - } - if (m_Param.m_BiasEnabled && m_Bias) - { - descriptor.m_Bias = m_Bias.get(); - } SetAdditionalInfo(descriptor); - return factory.CreateWorkload(LayerType::FullyConnected, descriptor, PrepInfoAndDesc(descriptor)); } FullyConnectedLayer* FullyConnectedLayer::Clone(Graph& graph) const { auto layer = CloneBase<FullyConnectedLayer>(graph, m_Param, GetName()); - layer->m_Weight = m_Weight ? m_Weight : nullptr; - if (layer->m_Param.m_BiasEnabled) - { - layer->m_Bias = m_Bias ? m_Bias : nullptr; - } return std::move(layer); } @@ -78,14 +64,7 @@ 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}; + return tensors; } void FullyConnectedLayer::ExecuteStrategy(IStrategy& strategy) const diff --git a/src/armnn/layers/FullyConnectedLayer.hpp b/src/armnn/layers/FullyConnectedLayer.hpp index 07f4a936f9..f3ca696b62 100644 --- a/src/armnn/layers/FullyConnectedLayer.hpp +++ b/src/armnn/layers/FullyConnectedLayer.hpp @@ -1,5 +1,5 @@ // -// Copyright © 2017 Arm Ltd and Contributors. All rights reserved. +// Copyright © 2017,2022 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // #pragma once @@ -15,12 +15,6 @@ class ScopedTensorHandle; class FullyConnectedLayer : public LayerWithParameters<FullyConnectedDescriptor> { public: - /// A unique pointer to store Weight values. - /// @Note: Deprecated. Removal date is 23.02. Weights are stored in ConstantLayers now. - std::shared_ptr<ConstTensorHandle> m_Weight; - /// A unique pointer to store Bias values. - /// @Note: Deprecated. Removal date is 23.02. Bias are stored in ConstantLayers now. - std::shared_ptr<ConstTensorHandle> m_Bias; /// Makes a workload for the FullyConnected type. /// @param [in] graph The graph where this layer can be found. @@ -45,6 +39,10 @@ public: void ExecuteStrategy(IStrategy& strategy) const override; + /// This layer does not have any data stored, weights and bias are now stored in constant layers. + /// We do not want to release the data in the constant layer, that is why we override with an empty function. + void ReleaseConstantData() override {} + protected: /// Constructor to create a FullyConnectedLayer. /// @param [in] param FullyConnectedDescriptor to configure the fully connected operation. diff --git a/src/armnn/optimizations/All.hpp b/src/armnn/optimizations/All.hpp index a11dec9446..0e67516193 100644 --- a/src/armnn/optimizations/All.hpp +++ b/src/armnn/optimizations/All.hpp @@ -20,6 +20,5 @@ #include "PermuteAsReshape.hpp" #include "PermuteAndBatchToSpaceAsDepthToSpace.hpp" #include "PermuteDepthwiseConv2dWeights.hpp" -#include "RedirectMembersToConstantInputs.hpp" #include "SquashEqualSiblings.hpp" #include "TransposeAsReshape.hpp"
\ No newline at end of file diff --git a/src/armnn/optimizations/FoldPadIntoLayer2d.hpp b/src/armnn/optimizations/FoldPadIntoLayer2d.hpp index 7a50c4ac06..874749fda9 100644 --- a/src/armnn/optimizations/FoldPadIntoLayer2d.hpp +++ b/src/armnn/optimizations/FoldPadIntoLayer2d.hpp @@ -1,5 +1,5 @@ // -// Copyright © 2022 Arm Ltd and Contributors. All rights reserved. +// Copyright © 2017,2022 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // @@ -196,21 +196,14 @@ public: if (newConv2dLayer != nullptr) { const auto conv2dLayer = PolymorphicDowncast<Convolution2dLayer*>(&connection.GetOwningLayer()); - // Copy weights and bias to the new convolution layer ARMNN_ASSERT_MSG(newConv2dLayer->GetInputSlot(1).GetConnection() != nullptr, "FoldPadIntoConvolution2d: New convolution layer is missing connection to weights layer"); - // Deprecated. Removal date is 23.02. - newConv2dLayer->m_Weight = std::move(conv2dLayer->m_Weight); - if (conv2dLayer->GetParameters().m_BiasEnabled) { ARMNN_ASSERT_MSG(newConv2dLayer->GetInputSlot(2).GetConnection() != nullptr, "FoldPadIntoConvolution2d: New convolution layer is missing " "connection to bias layer."); - - // Deprecated. Removal date is 23.02. - newConv2dLayer->m_Bias = std::move(conv2dLayer->m_Bias); } } } @@ -230,24 +223,18 @@ public: if (newConv2dLayer != nullptr) { const auto conv2dLayer = PolymorphicDowncast<DepthwiseConvolution2dLayer*>(&connection.GetOwningLayer()); - // Copy weights and bias to the new convolution layer ARMNN_ASSERT_MSG(newConv2dLayer->GetInputSlot(1).GetConnection() != nullptr, - "FoldPadIntoDepthwiseConvolution2d: New convolution layer is missing connection to weights layer"); - - // Deprecated. Removal date is 23.02. - newConv2dLayer->m_Weight = std::move(conv2dLayer->m_Weight); + "FoldPadIntoDepthwiseConvolution2d: New convolution layer is missing " + "connection to weights layer"); if (conv2dLayer->GetParameters().m_BiasEnabled) { ARMNN_ASSERT_MSG(newConv2dLayer->GetInputSlot(2).GetConnection() != nullptr, "FoldPadIntoConvolution2d: New convolution layer is missing " "connection to bias layer."); - // Deprecated. Removal date is 23.02. - newConv2dLayer->m_Bias = std::move(conv2dLayer->m_Bias); } } } - protected: FoldPadIntoDepthwiseConvolution2dImpl() = default; ~FoldPadIntoDepthwiseConvolution2dImpl() = default; diff --git a/src/armnn/optimizations/FuseBatchNorm.hpp b/src/armnn/optimizations/FuseBatchNorm.hpp index bca0c7d00a..88ac97cd0c 100644 --- a/src/armnn/optimizations/FuseBatchNorm.hpp +++ b/src/armnn/optimizations/FuseBatchNorm.hpp @@ -1,5 +1,5 @@ // -// Copyright © 2020 Arm Ltd and Contributors. All rights reserved. +// Copyright © 2020,2022 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // @@ -167,8 +167,6 @@ public: auto& newConv2dLayer = *graph.InsertNewLayer<ConvLayer>(base.GetInputSlot(0), convDescriptor, name.c_str()); - newConv2dLayer.m_Weight = std::make_unique<ScopedTensorHandle>(fusedWeightsTensor); - newConv2dLayer.m_Bias = std::make_unique<ScopedTensorHandle>(ConstTensor(fusedBiasTensor)); // Connect weights and bias from old to new Conv2d layer // This optimization will always have 3 input slots on the Conv2d base layer @@ -177,7 +175,7 @@ public: // Remove old connection and connect to new layer2d weightLayer->GetOutputSlot(0).Disconnect(base.GetInputSlot(1)); weightLayer->GetOutputSlot(0).Connect(newConv2dLayer.GetInputSlot(1)); - weightLayer->m_LayerOutput = newConv2dLayer.m_Weight; + weightLayer->m_LayerOutput = std::make_unique<ScopedTensorHandle>(fusedWeightsTensor); // Move bias const layers as normal if it was enabled before the optimisation ConstantLayer* biasLayer; @@ -198,7 +196,7 @@ public: biasLayer->GetOutputSlot(0).SetTensorInfo(fusedBiasTensor.GetInfo()); biasLayer->GetOutputSlot(0).Connect(newConv2dLayer.GetInputSlot(2)); } - biasLayer->m_LayerOutput = newConv2dLayer.m_Bias; + biasLayer->m_LayerOutput = std::make_unique<ScopedTensorHandle>(ConstTensor(fusedBiasTensor)); } diff --git a/src/armnn/optimizations/RedirectMembersToConstantInputs.hpp b/src/armnn/optimizations/RedirectMembersToConstantInputs.hpp deleted file mode 100644 index a2bad710e6..0000000000 --- a/src/armnn/optimizations/RedirectMembersToConstantInputs.hpp +++ /dev/null @@ -1,90 +0,0 @@ -// -// Copyright © 2021 Arm Ltd and Contributors. All rights reserved. -// SPDX-License-Identifier: MIT -// - -#pragma once - -#include "Optimization.hpp" - -#include <armnn/utility/IgnoreUnused.hpp> -#include <armnn/utility/PolymorphicDowncast.hpp> - -namespace armnn -{ -namespace optimizations -{ - -class RedirectMembersToConstantInputsImpl -{ -public: - /// Search for layers with ConstantLayers as inputs. If the inputs are constant redirect the layers member - /// variable for ConstTensors (e.g. m_weights) to the data stored in the ConstantLayer it is connected to. - void Run(Graph& graph, Layer& layer) const - { - IgnoreUnused(graph); - - switch (layer.GetType()) - { - case LayerType::BatchNormalization: - break; - case LayerType::Convolution2d: - RedirectWeightsAndBiases<Convolution2dLayer>(&layer); - break; - case LayerType::DepthwiseConvolution2d: - RedirectWeightsAndBiases<DepthwiseConvolution2dLayer>(&layer); - break; - case LayerType::DetectionPostProcess: - break; - case LayerType::FullyConnected: - RedirectWeightsAndBiases<FullyConnectedLayer>(&layer); - break; - case LayerType::Lstm: - break; - case LayerType::TransposeConvolution2d: - break; - default: - break; - } - } - -protected: - RedirectMembersToConstantInputsImpl() = default; - ~RedirectMembersToConstantInputsImpl() = default; - -private: - template <typename LayerT> - static LayerT* RedirectWeightsAndBiases(Layer* layer) - { - LayerT* layerPtr = PolymorphicDowncast<LayerT*>(layer); - - // Loop through input slots to check for constant weights and biases layers. - // Weights index = 1, Biases index = 2. - for (unsigned int inputSlotIndex = 1; inputSlotIndex != layerPtr->GetNumInputSlots(); ++inputSlotIndex) - { - OutputSlot* outputSlot = layerPtr->GetInputSlot(inputSlotIndex).GetConnectedOutputSlot(); - // Debug layers should not be inserted in optimize process yet - ARMNN_ASSERT(outputSlot->GetOwningLayer().GetType() != LayerType::Debug); - if (outputSlot->GetOwningLayer().GetType() == LayerType::Constant) - { - // Get constant layer and redirect base layer member variables. - ConstantLayer& constantLayer = dynamic_cast<ConstantLayer&>(outputSlot->GetOwningLayer()); - if (inputSlotIndex == 1) - { - layerPtr->m_Weight = constantLayer.m_LayerOutput; - } - else if (inputSlotIndex == 2) - { - layerPtr->m_Bias = constantLayer.m_LayerOutput; - } - } - } - - return layerPtr; - } -}; - -using RedirectMembersToConstantInputs = OptimizeForType<Layer, RedirectMembersToConstantInputsImpl>; - -} // namespace optimizations -} // namespace armnn diff --git a/src/armnn/test/OptimizerTests.cpp b/src/armnn/test/OptimizerTests.cpp index b78863dddc..f83900404b 100644 --- a/src/armnn/test/OptimizerTests.cpp +++ b/src/armnn/test/OptimizerTests.cpp @@ -1,5 +1,5 @@ // -// Copyright © 2017 Arm Ltd and Contributors. All rights reserved. +// Copyright © 2017,2022 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // @@ -441,16 +441,15 @@ void CreateConvolution2dGraph(Graph &graph, const unsigned int* inputShape, Layer* input = graph.AddLayer<InputLayer>(0, "input"); input->GetOutputSlot().SetTensorInfo(inputInfo); - ConstantLayer* weightsLayer = nullptr; - weightsLayer = graph.AddLayer<ConstantLayer>("Weights"); + ConstantLayer* weightsLayer = graph.AddLayer<ConstantLayer>("Weights"); weightsLayer->m_LayerOutput = std::make_shared<ScopedTensorHandle>(weights); weightsLayer->GetOutputSlot(0).SetTensorInfo(weightsLayer->m_LayerOutput->GetTensorInfo()); Convolution2dLayer* layer = graph.AddLayer<Convolution2dLayer>(desc, "conv2d"); - layer->m_Weight = std::make_unique<armnn::ScopedTensorHandle>(weights); layer->GetOutputSlot().SetTensorInfo(outputInfo); Layer* output = graph.AddLayer<OutputLayer>(0, "output"); + input->GetOutputSlot().Connect(layer->GetInputSlot(0)); layer->GetOutputSlot().Connect(output->GetInputSlot(0)); weightsLayer->GetOutputSlot(0).Connect(layer->GetInputSlot(1)); @@ -908,11 +907,10 @@ TEST_CASE("OptimizeForExclusiveConnectionsFuseTest") { std::vector<float> biasVector = { 11 }; ConstTensor bias(TensorInfo(1, outputChannelSize, DataType::Float32, 0.0f, 0, true), biasVector); - biasLayer =graph.AddLayer<ConstantLayer>("Bias"); + biasLayer = graph.AddLayer<ConstantLayer>("Bias"); biasLayer->m_LayerOutput = std::make_shared<ScopedTensorHandle>(bias); biasLayer->GetOutputSlot(0).SetTensorInfo(biasLayer->m_LayerOutput->GetTensorInfo()); biasLayer->GetOutputSlot(0).Connect(conv->GetInputSlot(2)); - conv->m_Bias = biasLayer->m_LayerOutput; } // Connect layers @@ -921,9 +919,6 @@ TEST_CASE("OptimizeForExclusiveConnectionsFuseTest") conv->GetOutputSlot(0).Connect(batchNorm->GetInputSlot(0)); batchNorm->GetOutputSlot(0).Connect(output->GetInputSlot(0)); - // Temporary workaround to ensure the descriptor weights are populated - conv->m_Weight = weightsLayer->m_LayerOutput; - if (convolution2dDescriptor.m_BiasEnabled) { CHECK(6 == graph.GetNumLayers()); @@ -983,22 +978,22 @@ TEST_CASE("OptimizeForExclusiveConnectionsWithoutFuseTest") batchNorm->GetOutputSlot(0).Connect(output->GetInputSlot(0)); conv->GetOutputSlot(0).Connect(output2->GetInputSlot(0)); - CHECK(5 == graph.GetNumLayers()); + CHECK((5 == graph.GetNumLayers())); CHECK(CheckSequence(graph.cbegin(), graph.cend(), - &IsLayerOfType<armnn::InputLayer>, - &IsLayerOfType<armnn::Convolution2dLayer>, - &IsLayerOfType<armnn::BatchNormalizationLayer>, - &IsLayerOfType<armnn::OutputLayer>, - &IsLayerOfType<armnn::OutputLayer>)); + &IsLayerOfType<armnn::InputLayer>, + &IsLayerOfType<armnn::Convolution2dLayer>, + &IsLayerOfType<armnn::BatchNormalizationLayer>, + &IsLayerOfType<armnn::OutputLayer>, + &IsLayerOfType<armnn::OutputLayer>)); // Optimize graph armnn::Optimizer::Pass(graph, armnn::MakeOptimizations(FuseBatchNormIntoConvolution2DFloat32())); CHECK(5 == graph.GetNumLayers()); CHECK(CheckSequence(graph.cbegin(), graph.cend(), - &IsLayerOfType<armnn::InputLayer>, - &IsLayerOfType<armnn::Convolution2dLayer>, - &IsLayerOfType<armnn::BatchNormalizationLayer>, - &IsLayerOfType<armnn::OutputLayer>, - &IsLayerOfType<armnn::OutputLayer>)); + &IsLayerOfType<armnn::InputLayer>, + &IsLayerOfType<armnn::Convolution2dLayer>, + &IsLayerOfType<armnn::BatchNormalizationLayer>, + &IsLayerOfType<armnn::OutputLayer>, + &IsLayerOfType<armnn::OutputLayer>)); } } // Optimizer TestSuite diff --git a/src/armnn/test/optimizations/ConvertConstantsFloatToHalfTests.cpp b/src/armnn/test/optimizations/ConvertConstantsFloatToHalfTests.cpp index 34e5f6d3b6..118907e703 100644 --- a/src/armnn/test/optimizations/ConvertConstantsFloatToHalfTests.cpp +++ b/src/armnn/test/optimizations/ConvertConstantsFloatToHalfTests.cpp @@ -1,12 +1,12 @@ // -// Copyright © 2017 Arm Ltd. All rights reserved. +// Copyright © 2022 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // #include <TestUtils.hpp> -#include <Optimizer.hpp> #include <Half.hpp> +#include <Optimizer.hpp> #include <doctest/doctest.h> @@ -25,33 +25,38 @@ TEST_CASE("ConvertConstantsFloatToHalfTest") // Create const tensor from fp32 data unsigned int dims[] = { 4, 1, 1, 1 }; std::vector<float> floatWeights{ 1.0f, 2.0f, 3.0f, 4.0f }; - armnn::ConstTensor weights(armnn::TensorInfo(4, dims, armnn::DataType::Float32, 0.0f, 0, true), floatWeights); + armnn::TensorInfo weightsInfo = armnn::TensorInfo(4, dims, armnn::DataType::Float32, 0.0f, 0, true); + armnn::ConstTensor weights(weightsInfo, floatWeights); // Create simple test network auto input = graph.AddLayer<armnn::InputLayer>(0, "input"); input->GetOutputSlot().SetTensorInfo(info); auto fc = graph.AddLayer<armnn::FullyConnectedLayer>(armnn::FullyConnectedDescriptor(), "fc"); - fc->m_Weight = std::make_unique<armnn::ScopedTensorHandle>(weights); fc->GetOutputSlot().SetTensorInfo(info); + auto weightsLayer = graph.AddLayer<armnn::ConstantLayer>("weights"); + weightsLayer->m_LayerOutput = std::make_unique<armnn::ScopedTensorHandle>(weights); + weightsLayer->GetOutputSlot().SetTensorInfo(weightsInfo); + auto output = graph.AddLayer<armnn::OutputLayer>(1, "output"); // Connect up the layers input->GetOutputSlot().Connect(fc->GetInputSlot(0)); + weightsLayer->GetOutputSlot().Connect(fc->GetInputSlot(1)); fc->GetOutputSlot().Connect(output->GetInputSlot(0)); // Check tensor data type before conversion - CHECK(fc->m_Weight->GetTensorInfo().GetDataType() == armnn::DataType::Float32); + CHECK(weightsLayer->m_LayerOutput->GetTensorInfo().GetDataType() == armnn::DataType::Float32); // Run the optimizer armnn::Optimizer::Pass(graph, armnn::MakeOptimizations(ConvertConstantsFloatToHalf())); // Check tensor data type after conversion - CHECK(fc->m_Weight->GetTensorInfo().GetDataType() == armnn::DataType::Float16); + CHECK(weightsLayer->m_LayerOutput->GetTensorInfo().GetDataType() == armnn::DataType::Float16); // Check whether data matches expected fp16 data - const Half* data = fc->m_Weight->GetConstTensor<Half>(); + const Half* data = weightsLayer->m_LayerOutput->GetConstTensor<Half>(); CHECK(data[0] == Half(1.0f)); CHECK(data[1] == Half(2.0f)); CHECK(data[2] == Half(3.0f)); @@ -100,12 +105,14 @@ TEST_CASE("ConvertConstantsFloatToHalfTest_constant") fcLayer->GetOutputSlot(0).Connect(output->GetInputSlot(0)); // Check tensor data type before conversion + CHECK(5 == graph.GetNumLayers()); CHECK(weights->m_LayerOutput->GetTensorInfo().GetDataType() == armnn::DataType::Float32); // Run the optimizer armnn::Optimizer::Pass(graph, armnn::MakeOptimizations(ConvertConstantsFloatToHalf())); // Check tensor data type after conversion + CHECK(5 == graph.GetNumLayers()); CHECK(weights->m_LayerOutput->GetTensorInfo().GetDataType() == armnn::DataType::Float16); // Check whether weights data matches expected fp16 data diff --git a/src/armnn/test/optimizations/ConvertConstantsHalfToFloatTests.cpp b/src/armnn/test/optimizations/ConvertConstantsHalfToFloatTests.cpp index 4c453cc799..778d7b0814 100644 --- a/src/armnn/test/optimizations/ConvertConstantsHalfToFloatTests.cpp +++ b/src/armnn/test/optimizations/ConvertConstantsHalfToFloatTests.cpp @@ -1,5 +1,5 @@ // -// Copyright © 2017 Arm Ltd. All rights reserved. +// Copyright © 2022 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // @@ -25,33 +25,38 @@ TEST_CASE("ConvertConstantsHalfToFloatTest") std::vector<uint16_t> halfWeights(4); armnnUtils::FloatingPointConverter::ConvertFloat32To16(convWeightsData.data(), convWeightsData.size(), halfWeights.data()); - armnn::ConstTensor weights(armnn::TensorInfo(4, dims, armnn::DataType::Float16, 0.0f, 0, true), halfWeights); + armnn::TensorInfo weightInfo = armnn::TensorInfo(4, dims, armnn::DataType::Float16, 0.0f, 0, true); + armnn::ConstTensor weights(weightInfo, halfWeights); //Create the simple test network auto input = graph.AddLayer<armnn::InputLayer>(0, "input"); input->GetOutputSlot().SetTensorInfo(info); auto fc = graph.AddLayer<armnn::FullyConnectedLayer>(armnn::FullyConnectedDescriptor(), "fc"); - fc->m_Weight = std::make_unique<armnn::ScopedTensorHandle>(weights); fc->GetOutputSlot().SetTensorInfo(info); + auto weightsLayer = graph.AddLayer<armnn::ConstantLayer>("weights"); + weightsLayer->m_LayerOutput = std::make_unique<armnn::ScopedTensorHandle>(weights); + weightsLayer->GetOutputSlot(0).SetTensorInfo(weightInfo); + auto output = graph.AddLayer<armnn::OutputLayer>(1, "output"); //Connect up the layers input->GetOutputSlot().Connect(fc->GetInputSlot(0)); + weightsLayer->GetOutputSlot().Connect(fc->GetInputSlot(1)); fc->GetOutputSlot().Connect(output->GetInputSlot(0)); //Test the tensor info is correct. - CHECK(fc->m_Weight->GetTensorInfo().GetDataType() == armnn::DataType::Float16); + CHECK(weightsLayer->m_LayerOutput->GetTensorInfo().GetDataType() == armnn::DataType::Float16); // Run the optimizer armnn::Optimizer::Pass(graph, armnn::MakeOptimizations(ConvertConstantsHalfToFloat())); //Test the tensor info is correct. - CHECK(fc->m_Weight->GetTensorInfo().GetDataType() == armnn::DataType::Float32); + CHECK(weightsLayer->m_LayerOutput->GetTensorInfo().GetDataType() == armnn::DataType::Float32); // Now test the data matches float32 data - const float* data = fc->m_Weight->GetConstTensor<float>(); + const float* data = weightsLayer->m_LayerOutput->GetConstTensor<float>(); CHECK(1.0f == data[0]); CHECK(2.0f == data[1]); CHECK(3.0f == data[2]); diff --git a/src/armnn/test/optimizations/Fp32NetworkToFp16ConverterTests.cpp b/src/armnn/test/optimizations/Fp32NetworkToFp16ConverterTests.cpp index bc8839948b..0a4a4fafde 100644 --- a/src/armnn/test/optimizations/Fp32NetworkToFp16ConverterTests.cpp +++ b/src/armnn/test/optimizations/Fp32NetworkToFp16ConverterTests.cpp @@ -1,5 +1,5 @@ // -// Copyright © 2017 Arm Ltd. All rights reserved. +// Copyright © 2022 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // @@ -33,14 +33,21 @@ TEST_CASE("Fp32NetworkToFp16OptimizationTest") floor->GetOutputSlot().Connect(output->GetInputSlot(0)); CHECK(CheckSequence(graph.cbegin(), graph.cend(), &IsLayerOfType<armnn::InputLayer>, - &IsLayerOfType<armnn::FloorLayer>, &IsLayerOfType<armnn::OutputLayer>)); + &IsLayerOfType<armnn::FloorLayer>, + &IsLayerOfType<armnn::OutputLayer>)); // Run the optimizer armnn::Optimizer::Pass(graph, armnn::MakeOptimizations(Fp32NetworkToFp16Converter())); CHECK(CheckSequence(graph.cbegin(), graph.cend(), &IsLayerOfType<armnn::InputLayer>, - &IsLayerOfType<armnn::ConvertFp32ToFp16Layer>, &IsLayerOfType<armnn::FloorLayer>, - &IsLayerOfType<armnn::ConvertFp16ToFp32Layer>, &IsLayerOfType<armnn::OutputLayer>)); + &IsLayerOfType<armnn::ConvertFp32ToFp16Layer>, + &IsLayerOfType<armnn::FloorLayer>, + &IsLayerOfType<armnn::ConvertFp16ToFp32Layer>, + &IsLayerOfType<armnn::OutputLayer>)); + + CHECK(floor->GetDataType() == armnn::DataType::Float16); + CHECK(floor->GetInputSlot(0).GetConnectedOutputSlot()->GetTensorInfo().GetDataType() == armnn::DataType::Float16); + CHECK(floor->GetOutputSlot(0).GetTensorInfo().GetDataType() == armnn::DataType::Float16); } }
\ No newline at end of file diff --git a/src/armnn/test/optimizations/FuseBatchNormTests.cpp b/src/armnn/test/optimizations/FuseBatchNormTests.cpp index 54cbbce89f..5cbd17fb6a 100644 --- a/src/armnn/test/optimizations/FuseBatchNormTests.cpp +++ b/src/armnn/test/optimizations/FuseBatchNormTests.cpp @@ -1,5 +1,5 @@ // -// Copyright © 2020 Arm Ltd and Contributors. All rights reserved. +// Copyright © 2022 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // @@ -27,13 +27,8 @@ public: static IConnectableLayer *AddConvolution(INetwork *network, const Convolution2dDescriptor &descriptor, - const ConstTensor &weights, - const Optional<ConstTensor> &biases, const char *name) { - IgnoreUnused(weights); - IgnoreUnused(biases); - return network->AddConvolution2dLayer(descriptor, name); } @@ -65,12 +60,8 @@ public: static IConnectableLayer* AddConvolution(INetwork* network, const DepthwiseConvolution2dDescriptor& descriptor, - const ConstTensor& weights, - const Optional<ConstTensor>& biases, const char* name) { - IgnoreUnused(weights); - IgnoreUnused(biases); return network->AddDepthwiseConvolution2dLayer(descriptor, name); } @@ -171,8 +162,6 @@ INetworkPtr CreateNetwork(bool depthwise, bool preventFusing) IConnectableLayer* convLayer = Conv2dTest::AddConvolution(network.get(), convolution2dDescriptor, - weights, - Optional<ConstTensor>(), "convolution"); IConnectableLayer* batchNormLayer = network->AddBatchNormalizationLayer(batchNormDescriptor, @@ -243,13 +232,21 @@ void FuseBatchNormIntoConvTest(bool depthwise, float tolerance, armnn::Compute b return IsLayerOfType<ConvLayerType>(layer) && (layer->GetNameStr() == "fused-batchNorm-into-convolution"); }; - + auto checkConstant = [ ](const armnn::Layer* const layer) -> bool + { + const ConstantLayer* constLayer = PolymorphicDowncast<const ConstantLayer*>(layer); + auto tensor = ConstTensor(constLayer->m_LayerOutput->GetTensorInfo(), + constLayer->m_LayerOutput->Map(true)); + const auto* buffer = static_cast<const T*>(tensor.GetMemoryArea()); + std::vector<T> vector(buffer, buffer + tensor.GetNumElements()); + return IsLayerOfType<ConstantLayer>(layer); + }; CHECK(5 == graphFused.GetNumLayers()); CHECK(CheckSequence(graphFused.cbegin(), graphFused.cend(), &IsLayerOfType<InputLayer>, - &IsLayerOfType<ConstantLayer>, - &IsLayerOfType<ConstantLayer>, + checkConstant, + checkConstant, checkFusedConv2d, &IsLayerOfType<OutputLayer>)); diff --git a/src/armnn/test/optimizations/RedirectMembersToConstantInputsTests.cpp b/src/armnn/test/optimizations/RedirectMembersToConstantInputsTests.cpp deleted file mode 100644 index b3f9ed8780..0000000000 --- a/src/armnn/test/optimizations/RedirectMembersToConstantInputsTests.cpp +++ /dev/null @@ -1,85 +0,0 @@ -// -// Copyright © 2021 Arm Ltd and Contributors. All rights reserved. -// SPDX-License-Identifier: MIT -// - -#include <TestUtils.hpp> - -#include <Optimizer.hpp> - -#include <doctest/doctest.h> - -TEST_SUITE("Optimizer") -{ -using namespace armnn::optimizations; - -TEST_CASE("RedirectMembersToConstantInputsFullyConnectedTest") -{ - armnn::Graph graph; - - const armnn::TensorInfo inputInfo ({ 1, 2, 2, 3 }, armnn::DataType::Float32); - const armnn::TensorInfo outputInfo ({ 1, 2, 2, 3 }, armnn::DataType::Float32); - const armnn::TensorInfo weightsInfo({ 4 }, armnn::DataType::Float32, 0.0f, 0, true); - const armnn::TensorInfo biasesInfo ({ 2 }, armnn::DataType::Float32, 0.0f, 0, true); - - // Check if isConstant is enabled for weights and biases tensor info. - CHECK(weightsInfo.IsConstant()); - CHECK(biasesInfo.IsConstant()); - - armnn::FullyConnectedDescriptor desc; - desc.m_BiasEnabled = true; - desc.m_ConstantWeights = false; - - // Create the simple test network with Weights and Biases as inputs to a FullyConnected layer. - auto input = graph.AddLayer<armnn::InputLayer>(0, "Input"); - auto weights = graph.AddLayer<armnn::ConstantLayer>("Weights"); - auto biases = graph.AddLayer<armnn::ConstantLayer>("Biases"); - auto fcLayer = graph.AddLayer<armnn::FullyConnectedLayer>(desc, "FullyConnected"); - auto output = graph.AddLayer<armnn::OutputLayer>(1, "Output"); - - float expectedWeightsData[] = { 1.0f, 1.0f, 1.0f, 1.0f }; - float expectedBiasesData[] = { 2.0f, 2.0f }; - - // Set the m_LayerOutput for the optimizer to point to. - armnn::ConstTensor weightsTensor(weightsInfo, &expectedWeightsData); - armnn::ConstTensor biasesTensor(biasesInfo, &expectedBiasesData); - weights->m_LayerOutput = std::make_unique<armnn::ScopedTensorHandle>(weightsTensor); - biases->m_LayerOutput = std::make_unique<armnn::ScopedTensorHandle>(biasesTensor); - - input->GetOutputSlot().SetTensorInfo(inputInfo); - weights->GetOutputSlot().SetTensorInfo(weightsInfo); - biases->GetOutputSlot().SetTensorInfo(biasesInfo); - fcLayer->GetOutputSlot().SetTensorInfo(outputInfo); - - // Connect up the layers - input->GetOutputSlot(0).Connect(fcLayer->GetInputSlot(0)); - weights->GetOutputSlot(0).Connect(fcLayer->GetInputSlot(1)); - biases->GetOutputSlot(0).Connect(fcLayer->GetInputSlot(2)); - fcLayer->GetOutputSlot(0).Connect(output->GetInputSlot(0)); - - // Member variables should be null before optimization. - CHECK(fcLayer->m_Weight == nullptr); - CHECK(fcLayer->m_Bias == nullptr); - - // Run the optimizer - armnn::Optimizer::Pass(graph, armnn::MakeOptimizations(RedirectMembersToConstantInputs())); - - // Check if member variables are not null and shape is set correctly. - CHECK(fcLayer->m_Weight != nullptr); - CHECK(fcLayer->m_Bias != nullptr); - CHECK(fcLayer->m_Weight->GetTensorInfo().GetShape() == weightsInfo.GetShape()); - CHECK(fcLayer->m_Bias->GetTensorInfo().GetShape() == biasesInfo.GetShape()); - - // Check whether data matches expected float data - const float* weightsData = fcLayer->m_Weight->GetConstTensor<float>(); - CHECK(weightsData[0] == expectedWeightsData[0]); - CHECK(weightsData[1] == expectedWeightsData[1]); - CHECK(weightsData[2] == expectedWeightsData[2]); - CHECK(weightsData[3] == expectedWeightsData[3]); - - const float* biasesData = fcLayer->m_Bias->GetConstTensor<float>(); - CHECK(biasesData[0] == expectedBiasesData[0]); - CHECK(biasesData[1] == expectedBiasesData[1]); -} - -}
\ No newline at end of file |