aboutsummaryrefslogtreecommitdiff
path: root/src/armnn
diff options
context:
space:
mode:
authorAron Virginas-Tar <Aron.Virginas-Tar@arm.com>2019-09-19 14:31:17 +0100
committerÁron Virginás-Tar <aron.virginas-tar@arm.com>2019-09-20 14:18:22 +0000
commitdd6247f52dcb33bd03391b7ee573d7082e18cca7 (patch)
treefb849d8afc6ffd74c1f6334d1f81b92a367fd024 /src/armnn
parenta2f4b4be6adbd8b53e4e860c4d7c3a704e343395 (diff)
downloadarmnn-dd6247f52dcb33bd03391b7ee573d7082e18cca7.tar.gz
IVGCVSW-3883 Add frontend for DepthToSpace layer
Signed-off-by: Aron Virginas-Tar <Aron.Virginas-Tar@arm.com> Change-Id: I18d957af6e988ffb6b9ee46ac836d1f38600e10b
Diffstat (limited to 'src/armnn')
-rw-r--r--src/armnn/InternalTypes.cpp1
-rw-r--r--src/armnn/InternalTypes.hpp1
-rw-r--r--src/armnn/LayersFwd.hpp2
-rw-r--r--src/armnn/Network.cpp6
-rw-r--r--src/armnn/Network.hpp3
-rw-r--r--src/armnn/layers/DepthToSpaceLayer.cpp84
-rw-r--r--src/armnn/layers/DepthToSpaceLayer.hpp50
-rw-r--r--src/armnn/test/TestNameOnlyLayerVisitor.cpp1
-rw-r--r--src/armnn/test/TestNameOnlyLayerVisitor.hpp1
9 files changed, 149 insertions, 0 deletions
diff --git a/src/armnn/InternalTypes.cpp b/src/armnn/InternalTypes.cpp
index 600d80023f..e6f7367ab5 100644
--- a/src/armnn/InternalTypes.cpp
+++ b/src/armnn/InternalTypes.cpp
@@ -26,6 +26,7 @@ char const* GetLayerTypeAsCString(LayerType type)
case LayerType::ConvertFp32ToFp16: return "ConvertFp32ToFp16";
case LayerType::Convolution2d: return "Convolution2d";
case LayerType::Debug: return "Debug";
+ case LayerType::DepthToSpace: return "DepthToSpace";
case LayerType::DepthwiseConvolution2d: return "DepthwiseConvolution2d";
case LayerType::Dequantize: return "Dequantize";
case LayerType::DetectionPostProcess: return "DetectionPostProcess";
diff --git a/src/armnn/InternalTypes.hpp b/src/armnn/InternalTypes.hpp
index 1e05fff769..fbca9bcbcb 100644
--- a/src/armnn/InternalTypes.hpp
+++ b/src/armnn/InternalTypes.hpp
@@ -26,6 +26,7 @@ enum class LayerType
ConvertFp32ToFp16,
Convolution2d,
Debug,
+ DepthToSpace,
DepthwiseConvolution2d,
Dequantize,
DetectionPostProcess,
diff --git a/src/armnn/LayersFwd.hpp b/src/armnn/LayersFwd.hpp
index a98c104f85..3599eacf7d 100644
--- a/src/armnn/LayersFwd.hpp
+++ b/src/armnn/LayersFwd.hpp
@@ -18,6 +18,7 @@
#include "layers/ConvertFp32ToFp16Layer.hpp"
#include "layers/Convolution2dLayer.hpp"
#include "layers/DebugLayer.hpp"
+#include "layers/DepthToSpaceLayer.hpp"
#include "layers/DepthwiseConvolution2dLayer.hpp"
#include "layers/DequantizeLayer.hpp"
#include "layers/DetectionPostProcessLayer.hpp"
@@ -100,6 +101,7 @@ DECLARE_LAYER(ConvertFp16ToFp32)
DECLARE_LAYER(ConvertFp32ToFp16)
DECLARE_LAYER(Convolution2d)
DECLARE_LAYER(Debug)
+DECLARE_LAYER(DepthToSpace)
DECLARE_LAYER(DepthwiseConvolution2d)
DECLARE_LAYER(Dequantize)
DECLARE_LAYER(DetectionPostProcess)
diff --git a/src/armnn/Network.cpp b/src/armnn/Network.cpp
index c055407b3a..a668274c4d 100644
--- a/src/armnn/Network.cpp
+++ b/src/armnn/Network.cpp
@@ -1060,6 +1060,12 @@ IConnectableLayer* Network::AddDepthwiseConvolution2dLayerImpl(
return layer;
}
+IConnectableLayer* Network::AddDepthToSpaceLayer(const DepthToSpaceDescriptor& depthToSpaceDescriptor,
+ const char* name)
+{
+ return m_Graph->AddLayer<DepthToSpaceLayer>(depthToSpaceDescriptor, name);
+}
+
IConnectableLayer* Network::AddDepthwiseConvolution2dLayer(
const DepthwiseConvolution2dDescriptor& convolution2dDescriptor,
const ConstTensor& weights,
diff --git a/src/armnn/Network.hpp b/src/armnn/Network.hpp
index 274cc1ab7c..4a8bfbc9f2 100644
--- a/src/armnn/Network.hpp
+++ b/src/armnn/Network.hpp
@@ -61,6 +61,9 @@ public:
const ConstTensor& biases,
const char* name = nullptr) override;
+ IConnectableLayer* AddDepthToSpaceLayer(const DepthToSpaceDescriptor& depthToSpaceDescriptor,
+ const char* name = nullptr) override;
+
IConnectableLayer* AddDepthwiseConvolution2dLayer(
const DepthwiseConvolution2dDescriptor& convolution2dDescriptor,
const ConstTensor& weights,
diff --git a/src/armnn/layers/DepthToSpaceLayer.cpp b/src/armnn/layers/DepthToSpaceLayer.cpp
new file mode 100644
index 0000000000..e964c32865
--- /dev/null
+++ b/src/armnn/layers/DepthToSpaceLayer.cpp
@@ -0,0 +1,84 @@
+//
+// Copyright © 2019 Arm Ltd. All rights reserved.
+// SPDX-License-Identifier: MIT
+//
+
+#include "DepthToSpaceLayer.hpp"
+
+#include "LayerCloneBase.hpp"
+
+#include <armnn/TypesUtils.hpp>
+
+#include <backendsCommon/WorkloadData.hpp>
+#include <backendsCommon/WorkloadFactory.hpp>
+
+#include <DataLayoutIndexed.hpp>
+
+#include <numeric>
+
+namespace armnn
+{
+
+DepthToSpaceLayer::DepthToSpaceLayer(const DepthToSpaceDescriptor& param, const char* name)
+ : LayerWithParameters(1, 1, LayerType::DepthToSpace, param, name)
+{}
+
+std::unique_ptr<IWorkload> DepthToSpaceLayer::CreateWorkload(const Graph& graph,
+ const IWorkloadFactory& factory) const
+{
+ DepthToSpaceQueueDescriptor descriptor;
+ descriptor.m_Parameters.m_BlockSize = m_Param.m_BlockSize;
+ descriptor.m_Parameters.m_DataLayout = m_Param.m_DataLayout;
+
+ return factory.CreateDepthToSpace(descriptor, PrepInfoAndDesc(descriptor, graph));
+}
+
+DepthToSpaceLayer* DepthToSpaceLayer::Clone(Graph& graph) const
+{
+ return CloneBase<DepthToSpaceLayer>(graph, m_Param, GetName());
+}
+
+std::vector<TensorShape> DepthToSpaceLayer::InferOutputShapes(const std::vector<TensorShape>& inputShapes) const
+{
+ throw UnimplementedException("DepthToSpaceLayer::InferOutputShapes is not implemented");
+
+ BOOST_ASSERT(inputShapes.size() == 1);
+
+ TensorShape inputShape = inputShapes[0];
+ TensorShape outputShape(inputShape);
+
+ armnnUtils::DataLayoutIndexed dimensionIndices(m_Param.m_DataLayout);
+
+ unsigned int hIndex = dimensionIndices.GetHeightIndex();
+ unsigned int wIndex = dimensionIndices.GetWidthIndex();
+ unsigned int cIndex = dimensionIndices.GetChannelsIndex();
+
+ outputShape[hIndex] = inputShape[hIndex] * m_Param.m_BlockSize;
+ outputShape[wIndex] = inputShape[wIndex] * m_Param.m_BlockSize;
+
+ outputShape[cIndex] = inputShape[cIndex] / (m_Param.m_BlockSize * m_Param.m_BlockSize);
+
+ return std::vector<TensorShape>({ outputShape });
+}
+
+void DepthToSpaceLayer::ValidateTensorShapesFromInputs()
+{
+ VerifyLayerConnections(1, CHECK_LOCATION());
+
+ std::vector<TensorShape> inferredShapes = InferOutputShapes({
+ GetInputSlot(0).GetConnection()->GetTensorInfo().GetShape() });
+
+ BOOST_ASSERT(inferredShapes.size() == 1);
+
+ ConditionalThrowIfNotEqual<LayerValidationException>(
+ "DepthToSpaceLayer: TensorShape set on OutputSlot[0] does not match the inferred shape.",
+ GetOutputSlot(0).GetTensorInfo().GetShape(),
+ inferredShapes[0]);
+}
+
+void DepthToSpaceLayer::Accept(ILayerVisitor& visitor) const
+{
+ visitor.VisitDepthToSpaceLayer(this, GetParameters(), GetName());
+}
+
+} // namespace armnn
diff --git a/src/armnn/layers/DepthToSpaceLayer.hpp b/src/armnn/layers/DepthToSpaceLayer.hpp
new file mode 100644
index 0000000000..cc5abe4cc9
--- /dev/null
+++ b/src/armnn/layers/DepthToSpaceLayer.hpp
@@ -0,0 +1,50 @@
+//
+// Copyright © 2019 Arm Ltd. All rights reserved.
+// SPDX-License-Identifier: MIT
+//
+
+#pragma once
+
+#include "LayerWithParameters.hpp"
+
+namespace armnn
+{
+
+/// This layer represents a DepthToSpace operation.
+class DepthToSpaceLayer : public LayerWithParameters<DepthToSpaceDescriptor>
+{
+public:
+ /// Makes a workload for the DepthToSpace 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.
+ DepthToSpaceLayer* Clone(Graph& graph) const override;
+
+ /// By default returns inputShapes if the number of inputs are equal to number of outputs,
+ /// otherwise infers the output shapes from given input shapes and layer properties.
+ /// @param [in] inputShapes The input shapes layer has.
+ /// @return A vector to the inferred output shape.
+ std::vector<TensorShape> InferOutputShapes(const std::vector<TensorShape>& inputShapes) const override;
+
+ /// Check if the input tensor shape(s)
+ /// will lead to a valid configuration of @ref DepthToSpaceLayer.
+ void ValidateTensorShapesFromInputs() override;
+
+ void Accept(ILayerVisitor& visitor) const override;
+
+protected:
+ /// Constructor to create a DepthToSpaceLayer.
+ /// @param [in] param DepthToSpaceDescriptor to configure the DepthToSpaceLayer operation.
+ /// @param [in] name Optional name for the layer.
+ DepthToSpaceLayer(const DepthToSpaceDescriptor& param, const char* name);
+
+ /// Default destructor
+ ~DepthToSpaceLayer() = default;
+};
+
+} // namespace armnn
diff --git a/src/armnn/test/TestNameOnlyLayerVisitor.cpp b/src/armnn/test/TestNameOnlyLayerVisitor.cpp
index c738caeb1f..2217a32edf 100644
--- a/src/armnn/test/TestNameOnlyLayerVisitor.cpp
+++ b/src/armnn/test/TestNameOnlyLayerVisitor.cpp
@@ -49,6 +49,7 @@ TEST_CASE_CHECK_LAYER_VISITOR_NAME_NULLPTR(name, 2)
BOOST_AUTO_TEST_SUITE(TestNameOnlyLayerVisitor)
TEST_SUITE_NAME_ONLY_LAYER_VISITOR_1_PARAM(Addition)
+TEST_SUITE_NAME_ONLY_LAYER_VISITOR_2_PARAM(DepthToSpace)
TEST_SUITE_NAME_ONLY_LAYER_VISITOR_1_PARAM(Division)
TEST_SUITE_NAME_ONLY_LAYER_VISITOR_1_PARAM(Equal)
TEST_SUITE_NAME_ONLY_LAYER_VISITOR_1_PARAM(Floor)
diff --git a/src/armnn/test/TestNameOnlyLayerVisitor.hpp b/src/armnn/test/TestNameOnlyLayerVisitor.hpp
index 1c5ede0802..4e0aa2f989 100644
--- a/src/armnn/test/TestNameOnlyLayerVisitor.hpp
+++ b/src/armnn/test/TestNameOnlyLayerVisitor.hpp
@@ -45,6 +45,7 @@ public: \
} // anonymous namespace
TEST_LAYER_VISITOR_1_PARAM(Addition)
+TEST_LAYER_VISITOR_2_PARAM(DepthToSpace)
TEST_LAYER_VISITOR_1_PARAM(Division)
TEST_LAYER_VISITOR_1_PARAM(Equal)
TEST_LAYER_VISITOR_1_PARAM(Floor)