diff options
Diffstat (limited to 'src/armnn')
-rw-r--r-- | src/armnn/InternalTypes.cpp | 1 | ||||
-rw-r--r-- | src/armnn/InternalTypes.hpp | 1 | ||||
-rw-r--r-- | src/armnn/LayersFwd.hpp | 2 | ||||
-rw-r--r-- | src/armnn/Network.cpp | 6 | ||||
-rw-r--r-- | src/armnn/Network.hpp | 3 | ||||
-rw-r--r-- | src/armnn/layers/LogSoftmaxLayer.cpp | 50 | ||||
-rw-r--r-- | src/armnn/layers/LogSoftmaxLayer.hpp | 44 | ||||
-rw-r--r-- | src/armnn/test/TestNameAndDescriptorLayerVisitor.cpp | 28 | ||||
-rw-r--r-- | src/armnn/test/TestNameAndDescriptorLayerVisitor.hpp | 26 |
9 files changed, 161 insertions, 0 deletions
diff --git a/src/armnn/InternalTypes.cpp b/src/armnn/InternalTypes.cpp index 612d00be5f..7c39128bec 100644 --- a/src/armnn/InternalTypes.cpp +++ b/src/armnn/InternalTypes.cpp @@ -40,6 +40,7 @@ char const* GetLayerTypeAsCString(LayerType type) case LayerType::Input: return "Input"; case LayerType::InstanceNormalization: return "InstanceNormalization"; case LayerType::L2Normalization: return "L2Normalization"; + case LayerType::LogSoftmax: return "LogSoftmax"; case LayerType::Lstm: return "Lstm"; case LayerType::Maximum: return "Maximum"; case LayerType::Mean: return "Mean"; diff --git a/src/armnn/InternalTypes.hpp b/src/armnn/InternalTypes.hpp index 039d0f8ac8..895fe3235d 100644 --- a/src/armnn/InternalTypes.hpp +++ b/src/armnn/InternalTypes.hpp @@ -40,6 +40,7 @@ enum class LayerType Input, InstanceNormalization, L2Normalization, + LogSoftmax, Lstm, Maximum, Mean, diff --git a/src/armnn/LayersFwd.hpp b/src/armnn/LayersFwd.hpp index 1f539f3076..7bb9c64818 100644 --- a/src/armnn/LayersFwd.hpp +++ b/src/armnn/LayersFwd.hpp @@ -32,6 +32,7 @@ #include "layers/InputLayer.hpp" #include "layers/InstanceNormalizationLayer.hpp" #include "layers/L2NormalizationLayer.hpp" +#include "layers/LogSoftmaxLayer.hpp" #include "layers/LstmLayer.hpp" #include "layers/MaximumLayer.hpp" #include "layers/MeanLayer.hpp" @@ -116,6 +117,7 @@ DECLARE_LAYER(Greater) DECLARE_LAYER(Input) DECLARE_LAYER(InstanceNormalization) DECLARE_LAYER(L2Normalization) +DECLARE_LAYER(LogSoftmax) DECLARE_LAYER(Lstm) DECLARE_LAYER(Maximum) DECLARE_LAYER(Mean) diff --git a/src/armnn/Network.cpp b/src/armnn/Network.cpp index 9d10b9ace1..b2fc1a6389 100644 --- a/src/armnn/Network.cpp +++ b/src/armnn/Network.cpp @@ -1236,6 +1236,12 @@ IConnectableLayer* Network::AddL2NormalizationLayer(const L2NormalizationDescrip return m_Graph->AddLayer<L2NormalizationLayer>(desc, name); } +IConnectableLayer* Network::AddLogSoftmaxLayer(const LogSoftmaxDescriptor& desc, + const char* name) +{ + return m_Graph->AddLayer<LogSoftmaxLayer>(desc, name); +} + IConnectableLayer* Network::AddConstantLayer(const ConstTensor& input, const char* name) { auto layer = m_Graph->AddLayer<ConstantLayer>(name); diff --git a/src/armnn/Network.hpp b/src/armnn/Network.hpp index e11f3d2185..ad1e7c456e 100644 --- a/src/armnn/Network.hpp +++ b/src/armnn/Network.hpp @@ -158,6 +158,9 @@ public: IConnectableLayer* AddL2NormalizationLayer(const L2NormalizationDescriptor& desc, const char* name = nullptr) override; + IConnectableLayer* AddLogSoftmaxLayer(const LogSoftmaxDescriptor& logSoftmaxDescriptor, + const char* name = nullptr) override; + IConnectableLayer* AddConstantLayer(const ConstTensor& input, const char* name = nullptr) override; IConnectableLayer* AddReshapeLayer(const ReshapeDescriptor& reshapeDescriptor, diff --git a/src/armnn/layers/LogSoftmaxLayer.cpp b/src/armnn/layers/LogSoftmaxLayer.cpp new file mode 100644 index 0000000000..6ca15b2d6f --- /dev/null +++ b/src/armnn/layers/LogSoftmaxLayer.cpp @@ -0,0 +1,50 @@ +// +// Copyright © 2019 Arm Ltd. All rights reserved. +// SPDX-License-Identifier: MIT +// + +#include "LogSoftmaxLayer.hpp" + +#include "LayerCloneBase.hpp" + +#include <armnn/TypesUtils.hpp> + +#include <backendsCommon/WorkloadData.hpp> +#include <backendsCommon/WorkloadFactory.hpp> + +namespace armnn +{ + +LogSoftmaxLayer::LogSoftmaxLayer(const LogSoftmaxDescriptor ¶m, const char* name) + : LayerWithParameters(1, 1, LayerType::LogSoftmax, param, name) {} + +std::unique_ptr<IWorkload> LogSoftmaxLayer::CreateWorkload(const Graph& graph, const IWorkloadFactory& factory) const +{ + LogSoftmaxQueueDescriptor descriptor; + return factory.CreateLogSoftmax(descriptor, PrepInfoAndDesc(descriptor, graph)); +} + +LogSoftmaxLayer* LogSoftmaxLayer::Clone(Graph& graph) const +{ + return CloneBase<LogSoftmaxLayer>(graph, m_Param, GetName()); +} + +void LogSoftmaxLayer::ValidateTensorShapesFromInputs() +{ + VerifyLayerConnections(1, CHECK_LOCATION()); + + auto inferredShapes = InferOutputShapes({ GetInputSlot(0).GetConnection()->GetTensorInfo().GetShape() }); + BOOST_ASSERT(inferredShapes.size() == 1); + + ConditionalThrowIfNotEqual<LayerValidationException>( + "LogSoftmaxLayer: TensorShape set on OutputSlot[0] does not match the inferred shape.", + GetOutputSlot(0).GetTensorInfo().GetShape(), + inferredShapes[0]); +} + +void LogSoftmaxLayer::Accept(ILayerVisitor& visitor) const +{ + visitor.VisitLogSoftmaxLayer(this, GetParameters(), GetName()); +} + +} // namespace armnn diff --git a/src/armnn/layers/LogSoftmaxLayer.hpp b/src/armnn/layers/LogSoftmaxLayer.hpp new file mode 100644 index 0000000000..13da542139 --- /dev/null +++ b/src/armnn/layers/LogSoftmaxLayer.hpp @@ -0,0 +1,44 @@ +// +// Copyright © 2019 Arm Ltd. All rights reserved. +// SPDX-License-Identifier: MIT +// + +#pragma once + +#include "LayerWithParameters.hpp" + +namespace armnn +{ + +/// This layer represents a log softmax operation. +class LogSoftmaxLayer : public LayerWithParameters<LogSoftmaxDescriptor> +{ +public: + /// Makes a workload for the LogSoftmax type. + /// @param [in] graph The graph where this layer can be found. + /// @param [in] factory The workload factory which will create the workload. + /// @return A pointer to the created workload, or nullptr if not created. + virtual std::unique_ptr<IWorkload> CreateWorkload(const Graph& graph, + const IWorkloadFactory& factory) const override; + + /// Creates a dynamically-allocated copy of this layer. + /// @param [in] graph The graph into which this layer is being cloned. + LogSoftmaxLayer* Clone(Graph& graph) const override; + + /// Check if the input tensor shape(s) + /// will lead to a valid configuration of @ref LogSoftmaxLayer. + void ValidateTensorShapesFromInputs() override; + + void Accept(ILayerVisitor& visitor) const override; + +protected: + /// Constructor to create a LogSoftmaxLayer. + /// @param [in] param LogSoftmaxDescriptor to configure the log softmax operation. + /// @param [in] name Optional name for the layer. + LogSoftmaxLayer(const LogSoftmaxDescriptor& param, const char* name); + + /// Default destructor + ~LogSoftmaxLayer() = default; +}; + +} // namespace diff --git a/src/armnn/test/TestNameAndDescriptorLayerVisitor.cpp b/src/armnn/test/TestNameAndDescriptorLayerVisitor.cpp index dcc5dc4cfb..e2bfb01733 100644 --- a/src/armnn/test/TestNameAndDescriptorLayerVisitor.cpp +++ b/src/armnn/test/TestNameAndDescriptorLayerVisitor.cpp @@ -328,6 +328,34 @@ BOOST_AUTO_TEST_CASE(CheckL2NormalizationLayerVisitorNameNullAndDescriptor) layer->Accept(visitor); } +BOOST_AUTO_TEST_CASE(CheckLogSoftmaxLayerVisitorNameAndDescriptor) +{ + const char* layerName = "LogSoftmaxLayer"; + + LogSoftmaxDescriptor descriptor; + descriptor.m_Beta = 2.0f; + descriptor.m_Axis = 1; + + TestLogSoftmaxLayerVisitor visitor(descriptor, layerName); + Network net; + + IConnectableLayer *const layer = net.AddLogSoftmaxLayer(descriptor, layerName); + layer->Accept(visitor); +} + +BOOST_AUTO_TEST_CASE(CheckLogSoftmaxLayerVisitorNameNullAndDescriptor) +{ + LogSoftmaxDescriptor descriptor; + descriptor.m_Beta = 2.0f; + descriptor.m_Axis = 1; + + TestLogSoftmaxLayerVisitor visitor(descriptor); + Network net; + + IConnectableLayer *const layer = net.AddLogSoftmaxLayer(descriptor); + layer->Accept(visitor); +} + BOOST_AUTO_TEST_CASE(CheckReshapeLayerVisitorNameAndDescriptor) { const char* layerName = "ReshapeLayer"; diff --git a/src/armnn/test/TestNameAndDescriptorLayerVisitor.hpp b/src/armnn/test/TestNameAndDescriptorLayerVisitor.hpp index aa0b3597fa..e46aa34e29 100644 --- a/src/armnn/test/TestNameAndDescriptorLayerVisitor.hpp +++ b/src/armnn/test/TestNameAndDescriptorLayerVisitor.hpp @@ -479,6 +479,32 @@ public: }; }; +class TestLogSoftmaxLayerVisitor : public TestLayerVisitor +{ +private: + LogSoftmaxDescriptor m_VisitorDescriptor; + +public: + explicit TestLogSoftmaxLayerVisitor(const LogSoftmaxDescriptor& descriptor, const char* name = nullptr) + : TestLayerVisitor(name) + , m_VisitorDescriptor(descriptor) {} + + void CheckDescriptor(const LogSoftmaxDescriptor& descriptor) + { + BOOST_CHECK_EQUAL(descriptor.m_Beta, m_VisitorDescriptor.m_Beta); + BOOST_CHECK_EQUAL(descriptor.m_Axis, m_VisitorDescriptor.m_Axis); + } + + void VisitLogSoftmaxLayer(const IConnectableLayer* layer, + const LogSoftmaxDescriptor& descriptor, + const char* name = nullptr) override + { + CheckLayerPointer(layer); + CheckDescriptor(descriptor); + CheckLayerName(name); + }; +}; + class TestReshapeLayerVisitor : public TestLayerVisitor { private: |