src/armnn/layers/InputLayer.cpp \
src/armnn/layers/InstanceNormalizationLayer.cpp \
src/armnn/layers/L2NormalizationLayer.cpp \
+ src/armnn/layers/LogSoftmaxLayer.cpp \
src/armnn/layers/LstmLayer.cpp \
src/armnn/layers/MaximumLayer.cpp \
src/armnn/layers/MeanLayer.cpp \
src/armnn/layers/InstanceNormalizationLayer.cpp
src/armnn/layers/L2NormalizationLayer.hpp
src/armnn/layers/L2NormalizationLayer.cpp
+ src/armnn/layers/LogSoftmaxLayer.hpp
+ src/armnn/layers/LogSoftmaxLayer.cpp
src/armnn/layers/LstmLayer.cpp
src/armnn/layers/LstmLayer.hpp
src/armnn/layers/MaximumLayer.cpp
int m_Axis;
};
+/// A LogSoftmaxDescriptor for the LogSoftmaxLayer
+using LogSoftmaxDescriptor = SoftmaxDescriptor;
+
/// @brief An OriginsDescriptor for the ConcatLayer.
/// Descriptor to configure the concatenation process. Number of views must be equal to the number of inputs, and
/// their order must match - e.g. first view corresponds to the first input, second view to the second input, etc.
namespace armnn
{
+
struct ActivationDescriptor;
struct ArgMinMaxDescriptor;
struct BatchNormalizationDescriptor;
struct TransposeConvolution2dDescriptor;
struct ViewsDescriptor;
+using ConcatDescriptor = OriginsDescriptor;
using DepthToSpaceDescriptor = SpaceToDepthDescriptor;
+using LogSoftmaxDescriptor = SoftmaxDescriptor;
+// MergerDescriptor is deprecated, use ConcatDescriptor instead
+using MergerDescriptor = OriginsDescriptor;
+using SplitterDescriptor = ViewsDescriptor;
-// MergerDescriptor is deprecated use ConcatDescriptor instead
-using MergerDescriptor = OriginsDescriptor;
-using ConcatDescriptor = OriginsDescriptor;
-using SplitterDescriptor = ViewsDescriptor;
-}
+} // namespace armnn
const L2NormalizationDescriptor& descriptor,
Optional<std::string&> reasonIfUnsupported = EmptyOptional()) const = 0;
+ virtual bool IsLogSoftmaxSupported(const TensorInfo& input,
+ const TensorInfo& output,
+ const LogSoftmaxDescriptor& descriptor,
+ Optional<std::string&> reasonIfUnsupported = EmptyOptional()) const = 0;
+
virtual bool IsLstmSupported(const TensorInfo& input,
const TensorInfo& outputStateIn,
const TensorInfo& cellStateIn,
const L2NormalizationDescriptor& desc,
const char* name = nullptr) = 0;
+ /// Function that a log softmax layer should call back to when its Accept(ILayerVisitor&) function is invoked.
+ /// @param layer - pointer to the layer which is calling back to this visit function.
+ /// @param logSoftmaxDescriptor - LogSoftmaxDescriptor to configure the log softmax.
+ /// @param name - Optional name for the layer.
+ virtual void VisitLogSoftmaxLayer(const IConnectableLayer* layer,
+ const LogSoftmaxDescriptor& logSoftmaxDescriptor,
+ const char* name = nullptr) = 0;
+
/// Function an Lstm layer should call back to when its Accept(ILayerVisitor&) function is invoked.
/// @param layer - pointer to the layer which is calling back to this visit function.
/// @param descriptor - Parameters controlling the operation of the Lstm operation.
virtual IConnectableLayer* AddL2NormalizationLayer(const L2NormalizationDescriptor& desc,
const char* name = nullptr) = 0;
+ /// Adds a log softmax layer to the network.
+ /// @param logSoftmaxDescriptor - LogSoftmaxDescriptor to configure the log softmax.
+ /// @param name - Optional name for the layer.
+ /// @return - Interface for configuring the layer.
+ virtual IConnectableLayer* AddLogSoftmaxLayer(const LogSoftmaxDescriptor& logSoftmaxDescriptor,
+ const char* name = nullptr) = 0;
+
/// Adds a layer with no inputs and a single output, which always corresponds to
/// the passed in constant tensor.
/// @param input - Tensor to be provided as the only output of the layer. The layer will maintain
const L2NormalizationDescriptor&,
const char*) override { DefaultPolicy::Apply(__func__); }
+ void VisitLogSoftmaxLayer(const IConnectableLayer*,
+ const LogSoftmaxDescriptor&,
+ const char*) override { DefaultPolicy::Apply(__func__); }
+
void VisitLstmLayer(const IConnectableLayer*,
const LstmDescriptor&,
const LstmInputParams&,
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";
Input,
InstanceNormalization,
L2Normalization,
+ LogSoftmax,
Lstm,
Maximum,
Mean,
#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"
DECLARE_LAYER(Input)
DECLARE_LAYER(InstanceNormalization)
DECLARE_LAYER(L2Normalization)
+DECLARE_LAYER(LogSoftmax)
DECLARE_LAYER(Lstm)
DECLARE_LAYER(Maximum)
DECLARE_LAYER(Mean)
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);
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,
--- /dev/null
+//
+// 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
--- /dev/null
+//
+// 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
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";
};
};
+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:
CreateAnyLayer(fbLayer.o, serializer::Layer::Layer_L2NormalizationLayer);
}
-void SerializerVisitor::VisitLstmLayer(const armnn::IConnectableLayer* layer, const armnn::LstmDescriptor& descriptor,
- const armnn::LstmInputParams& params, const char* name)
+void SerializerVisitor::VisitLogSoftmaxLayer(const armnn::IConnectableLayer* layer,
+ const armnn::LogSoftmaxDescriptor& logSoftmaxDescriptor,
+ const char* name)
+{
+ throw armnn::UnimplementedException("SerializerVisitor::VisitLogSoftmaxLayer() is not implemented");
+}
+
+void SerializerVisitor::VisitLstmLayer(const armnn::IConnectableLayer* layer,
+ const armnn::LstmDescriptor& descriptor,
+ const armnn::LstmInputParams& params,
+ const char* name)
{
auto fbLstmBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_Lstm);
const armnn::L2NormalizationDescriptor& l2NormalizationDescriptor,
const char* name = nullptr) override;
+ void VisitLogSoftmaxLayer(const armnn::IConnectableLayer* layer,
+ const armnn::LogSoftmaxDescriptor& logSoftmaxDescriptor,
+ const char* name = nullptr) override;
+
void VisitLstmLayer(const armnn::IConnectableLayer* layer,
const armnn::LstmDescriptor& descriptor,
const armnn::LstmInputParams& params,
return DefaultLayerSupport(__func__, __FILE__, __LINE__, reasonIfUnsupported);
}
+bool LayerSupportBase::IsLogSoftmaxSupported(const TensorInfo& input,
+ const TensorInfo& output,
+ const LogSoftmaxDescriptor& descriptor,
+ Optional<std::string&> reasonIfUnsupported) const
+{
+ return DefaultLayerSupport(__func__, __FILE__, __LINE__, reasonIfUnsupported);
+}
+
bool LayerSupportBase::IsLstmSupported(const TensorInfo& input,
const TensorInfo& outputStateIn,
const TensorInfo& cellStateIn,
const L2NormalizationDescriptor& descriptor,
Optional<std::string&> reasonIfUnsupported = EmptyOptional()) const override;
+ bool IsLogSoftmaxSupported(const TensorInfo& input,
+ const TensorInfo& output,
+ const LogSoftmaxDescriptor& descriptor,
+ Optional<std::string&> reasonIfUnsupported = EmptyOptional()) const override;
+
bool IsLstmSupported(const TensorInfo& input,
const TensorInfo& outputStateIn,
const TensorInfo& cellStateIn,
};
ValidateDataTypes(inputTensorInfo, supportedTypes, descriptorName);
- ValidateDataTypes(outputTensorInfo, supportedTypes, descriptorName);
-
ValidateTensorDataTypesMatch(inputTensorInfo, outputTensorInfo, descriptorName, "input", "output");
}
};
ValidateDataTypes(inputTensorInfo, supportedTypes, descriptorName);
- ValidateDataTypes(outputTensorInfo, supportedTypes, descriptorName);
+ ValidateTensorDataTypesMatch(inputTensorInfo, outputTensorInfo, descriptorName, "input", "output");
+}
+
+void LogSoftmaxQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const
+{
+ const std::string descriptorName{"LogSoftmaxQueueDescriptor"};
+
+ ValidateNumInputs(workloadInfo, descriptorName, 1);
+ ValidateNumOutputs(workloadInfo, descriptorName, 1);
+
+ const TensorInfo& inputTensorInfo = workloadInfo.m_InputTensorInfos[0];
+ const TensorInfo& outputTensorInfo = workloadInfo.m_OutputTensorInfos[0];
+
+ ValidateTensorShapesMatch(inputTensorInfo, outputTensorInfo, descriptorName, "input", "output");
+ std::vector<DataType> supportedTypes =
+ {
+ DataType::Float32,
+ DataType::Float16,
+ };
+
+ ValidateDataTypes(inputTensorInfo, supportedTypes, descriptorName);
ValidateTensorDataTypesMatch(inputTensorInfo, outputTensorInfo, descriptorName, "input", "output");
}
void Validate(const WorkloadInfo& workloadInfo) const;
};
+struct LogSoftmaxQueueDescriptor : QueueDescriptorWithParameters<LogSoftmaxDescriptor>
+{
+ void Validate(const WorkloadInfo& workloadInfo) const;
+};
+
struct ConstantQueueDescriptor : QueueDescriptor
{
ConstantQueueDescriptor()
reason);
break;
}
+ case LayerType::LogSoftmax:
+ {
+ auto cLayer = boost::polymorphic_downcast<const LogSoftmaxLayer*>(&layer);
+
+ const TensorInfo& input = layer.GetInputSlot(0).GetConnection()->GetTensorInfo();
+ const TensorInfo& output = layer.GetOutputSlot(0).GetTensorInfo();
+
+ result = layerSupportObject->IsLogSoftmaxSupported(OverrideDataType(input, dataType),
+ OverrideDataType(output, dataType),
+ cLayer->GetParameters(),
+ reason);
+ break;
+ }
case LayerType::Lstm:
{
auto cLayer = boost::polymorphic_downcast<const LstmLayer*>(&layer);
return std::unique_ptr<IWorkload>();
}
+std::unique_ptr<IWorkload> IWorkloadFactory::CreateLogSoftmax(const LogSoftmaxQueueDescriptor& descriptor,
+ const WorkloadInfo& info) const
+{
+ return std::unique_ptr<IWorkload>();
+}
+
std::unique_ptr<IWorkload> IWorkloadFactory::CreateLstm(const LstmQueueDescriptor& descriptor,
const WorkloadInfo& info) const
{
virtual std::unique_ptr<IWorkload> CreateL2Normalization(const L2NormalizationQueueDescriptor& descriptor,
const WorkloadInfo& info) const;
+ virtual std::unique_ptr<IWorkload> CreateLogSoftmax(const LogSoftmaxQueueDescriptor& descriptor,
+ const WorkloadInfo& info) const;
+
virtual std::unique_ptr<IWorkload> CreateLstm(const LstmQueueDescriptor& descriptor,
const WorkloadInfo& info) const;
DECLARE_LAYER_POLICY_2_PARAM(L2Normalization)
+DECLARE_LAYER_POLICY_2_PARAM(LogSoftmax)
+
DECLARE_LAYER_POLICY_2_PARAM(Lstm)
DECLARE_LAYER_POLICY_1_PARAM(Maximum)