aboutsummaryrefslogtreecommitdiff
path: root/arm_compute/graph
diff options
context:
space:
mode:
authorGian Marco Iodice <gianmarco.iodice@arm.com>2018-09-07 15:32:14 +0100
committerAnthony Barbier <anthony.barbier@arm.com>2018-11-02 16:54:54 +0000
commit23e2479c6e29674a1186465eb6e38b73760c8a91 (patch)
treeddc1c4bc82c7411ea4d7d170ee85d47f42499c7c /arm_compute/graph
parentfd7e8531b1eddf28d4f80d1423ca506ed1b7fa06 (diff)
downloadComputeLibrary-23e2479c6e29674a1186465eb6e38b73760c8a91.tar.gz
COMPMID-1556 - Add ReorgLayer to graph API
Change-Id: I50c13b5808f3cceec36b92e7afc027f47ebbdea4 Reviewed-on: https://eu-gerrit-1.euhpc.arm.com/147369 Reviewed-by: Michele DiGiorgio <michele.digiorgio@arm.com> Reviewed-by: Georgios Pinitas <georgios.pinitas@arm.com> Tested-by: Jenkins <bsgcomp@arm.com>
Diffstat (limited to 'arm_compute/graph')
-rw-r--r--arm_compute/graph/GraphBuilder.h10
-rw-r--r--arm_compute/graph/Types.h1
-rw-r--r--arm_compute/graph/backends/FunctionHelpers.h35
-rw-r--r--arm_compute/graph/backends/ValidateHelpers.h23
-rw-r--r--arm_compute/graph/frontend/Layers.h25
-rw-r--r--arm_compute/graph/nodes/Nodes.h1
-rw-r--r--arm_compute/graph/nodes/ReorgLayerNode.h67
7 files changed, 162 insertions, 0 deletions
diff --git a/arm_compute/graph/GraphBuilder.h b/arm_compute/graph/GraphBuilder.h
index 43670f4022..d7502600a4 100644
--- a/arm_compute/graph/GraphBuilder.h
+++ b/arm_compute/graph/GraphBuilder.h
@@ -261,6 +261,16 @@ public:
* @return Node ID of the created node, EmptyNodeID in case of error
*/
static NodeID add_pooling_node(Graph &g, NodeParams params, NodeIdxPair input, PoolingLayerInfo pool_info);
+ /** Adds a reorg layer node to the graph
+ *
+ * @param[in] g Graph to add the node to
+ * @param[in] params Common node parameters
+ * @param[in] input Input to the reorg layer node as a NodeID-Index pair
+ * @param[in] stride Stride value to use for reorganizing the values in the output tensor.
+ *
+ * @return Node ID of the created node, EmptyNodeID in case of error
+ */
+ static NodeID add_reorg_node(Graph &g, NodeParams params, NodeIdxPair input, int stride);
/** Adds a reshape layer node to the graph
*
* @param[in] g Graph to add the node to
diff --git a/arm_compute/graph/Types.h b/arm_compute/graph/Types.h
index 2df9998fcf..0b9a953531 100644
--- a/arm_compute/graph/Types.h
+++ b/arm_compute/graph/Types.h
@@ -143,6 +143,7 @@ enum class NodeType
NormalizationLayer,
PermuteLayer,
PoolingLayer,
+ ReorgLayer,
ReshapeLayer,
ResizeLayer,
SoftmaxLayer,
diff --git a/arm_compute/graph/backends/FunctionHelpers.h b/arm_compute/graph/backends/FunctionHelpers.h
index bf458ae33f..b1446ea493 100644
--- a/arm_compute/graph/backends/FunctionHelpers.h
+++ b/arm_compute/graph/backends/FunctionHelpers.h
@@ -695,6 +695,41 @@ std::unique_ptr<IFunction> create_pooling_layer(PoolingLayerNode &node)
return std::move(func);
}
+/** Create a backend reorg layer function
+ *
+ * @tparam ReorgLayerFunction Backend reshape function
+ * @tparam TargetInfo Target-specific information
+ *
+ * @param[in] node Node to create the backend function for
+ *
+ * @return Backend reshape layer function
+ */
+template <typename ReorgLayerFunction, typename TargetInfo>
+std::unique_ptr<IFunction> create_reorg_layer(ReorgLayerNode &node)
+{
+ validate_node<TargetInfo>(node, 1 /* expected inputs */, 1 /* expected outputs */);
+
+ // Extract IO and info
+ typename TargetInfo::TensorType *input = get_backing_tensor<TargetInfo>(node.input(0));
+ typename TargetInfo::TensorType *output = get_backing_tensor<TargetInfo>(node.output(0));
+ ARM_COMPUTE_ERROR_ON(input == nullptr);
+ ARM_COMPUTE_ERROR_ON(output == nullptr);
+
+ // Create and configure function
+ auto func = support::cpp14::make_unique<ReorgLayerFunction>();
+ func->configure(input, output, node.stride());
+
+ // Log info
+ ARM_COMPUTE_LOG_GRAPH_INFO("Instantiated " << node.type()
+ << " Target " << TargetInfo::TargetType
+ << " Data Type: " << input->info()->data_type()
+ << " Input shape: " << input->info()->tensor_shape()
+ << " Output shape: " << output->info()->tensor_shape()
+ << std::endl);
+
+ return std::move(func);
+}
+
/** Create a backend reshape layer function
*
* @tparam ReshapeLayerFunction Backend reshape function
diff --git a/arm_compute/graph/backends/ValidateHelpers.h b/arm_compute/graph/backends/ValidateHelpers.h
index 3064db20c3..e8b8af154f 100644
--- a/arm_compute/graph/backends/ValidateHelpers.h
+++ b/arm_compute/graph/backends/ValidateHelpers.h
@@ -201,6 +201,29 @@ Status validate_permute_layer(PermuteLayerNode &node)
return PermuteLayer::validate(input, output, perm);
}
+
+/** Validates a Reorg layer node
+ *
+ * @tparam ReorgLayer Reorg layer type
+ *
+ * @param[in] node Node to validate
+ *
+ * @return Status
+ */
+template <typename ReorgLayer>
+Status validate_reorg_layer(ReorgLayerNode &node)
+{
+ ARM_COMPUTE_LOG_GRAPH_VERBOSE("Validating ReorgLayer node with ID : " << node.id() << " and Name: " << node.name() << std::endl);
+ ARM_COMPUTE_RETURN_ERROR_ON(node.num_inputs() != 1);
+ ARM_COMPUTE_RETURN_ERROR_ON(node.num_outputs() != 1);
+
+ // Extract input and output
+ arm_compute::ITensorInfo *input = detail::get_backing_tensor_info(node.input(0));
+ arm_compute::ITensorInfo *output = get_backing_tensor_info(node.output(0));
+
+ // Validate function
+ return ReorgLayer::validate(input, output, node.stride());
+}
} // namespace detail
} // namespace backends
} // namespace graph
diff --git a/arm_compute/graph/frontend/Layers.h b/arm_compute/graph/frontend/Layers.h
index 054410e4ad..9a268d3d29 100644
--- a/arm_compute/graph/frontend/Layers.h
+++ b/arm_compute/graph/frontend/Layers.h
@@ -589,6 +589,31 @@ private:
PoolingLayerInfo _pool_info;
};
+/** Reorg Layer */
+class ReorgLayer final : public ILayer
+{
+public:
+ /** Construct a reorg layer.
+ *
+ * @param[in] stride Stride value to use for reorganizing the values in the output tensor.
+ * It defines the spatial distance between 2 consecutive pixels in the x and y direction
+ */
+ ReorgLayer(int stride)
+ : _stride(stride)
+ {
+ }
+
+ NodeID create_layer(IStream &s) override
+ {
+ NodeParams common_params = { name(), s.hints().target_hint };
+ NodeIdxPair input = { s.tail_node(), 0 };
+ return GraphBuilder::add_reorg_node(s.graph(), common_params, input, _stride);
+ }
+
+private:
+ int _stride;
+};
+
/** Reshape Layer */
class ReshapeLayer final : public ILayer
{
diff --git a/arm_compute/graph/nodes/Nodes.h b/arm_compute/graph/nodes/Nodes.h
index 8a85159896..438054c4bf 100644
--- a/arm_compute/graph/nodes/Nodes.h
+++ b/arm_compute/graph/nodes/Nodes.h
@@ -41,6 +41,7 @@
#include "arm_compute/graph/nodes/OutputNode.h"
#include "arm_compute/graph/nodes/PermuteLayerNode.h"
#include "arm_compute/graph/nodes/PoolingLayerNode.h"
+#include "arm_compute/graph/nodes/ReorgLayerNode.h"
#include "arm_compute/graph/nodes/ReshapeLayerNode.h"
#include "arm_compute/graph/nodes/ResizeLayerNode.h"
#include "arm_compute/graph/nodes/SoftmaxLayerNode.h"
diff --git a/arm_compute/graph/nodes/ReorgLayerNode.h b/arm_compute/graph/nodes/ReorgLayerNode.h
new file mode 100644
index 0000000000..1cc0698b46
--- /dev/null
+++ b/arm_compute/graph/nodes/ReorgLayerNode.h
@@ -0,0 +1,67 @@
+/*
+ * Copyright (c) 2018 ARM Limited.
+ *
+ * SPDX-License-Identifier: MIT
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+#ifndef __ARM_COMPUTE_GRAPH_REORG_LAYER_NODE_H__
+#define __ARM_COMPUTE_GRAPH_REORG_LAYER_NODE_H__
+
+#include "arm_compute/graph/INode.h"
+
+namespace arm_compute
+{
+namespace graph
+{
+/** Reorg Layer node */
+class ReorgLayerNode final : public INode
+{
+public:
+ /** Constructor
+ *
+ * @param[in] stride Stride value to use for reorganizing the values in the output tensor.
+ */
+ ReorgLayerNode(int stride);
+ /** Stride value to use for reorganizing the values in the output tensor.
+ *
+ * @return Stride value to use for reorganizing the values in the output tensor.
+ */
+ int stride() const;
+ /** Computes reorg output descriptor
+ *
+ * @param[in] input_descriptor Input descriptor
+ * @param[in] stride Stride value to use for reorganizing the values in the output tensor.
+ *
+ * @return Output descriptor
+ */
+ static TensorDescriptor compute_output_descriptor(const TensorDescriptor &input_descriptor, int stride);
+
+ // Inherited overridden methods:
+ NodeType type() const override;
+ bool forward_descriptors() override;
+ TensorDescriptor configure_output(size_t idx) const override;
+ void accept(INodeVisitor &v) override;
+
+private:
+ int _stride;
+};
+} // namespace graph
+} // namespace arm_compute
+#endif /* __ARM_COMPUTE_GRAPH_REORG_LAYER_NODE_H__ */