blob: 1c0539744fca2aaa42a0498d55dfab85ed8ce918 [file] [log] [blame]
Georgios Pinitasd8734b52017-12-22 15:27:52 +00001/*
2 * Copyright (c) 2018 ARM Limited.
3 *
4 * SPDX-License-Identifier: MIT
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to
8 * deal in the Software without restriction, including without limitation the
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010024#include "arm_compute/graph/nodes/DepthConcatenateLayerNode.h"
Georgios Pinitasd8734b52017-12-22 15:27:52 +000025
26#include "arm_compute/core/Utils.h"
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010027#include "arm_compute/graph/Graph.h"
28#include "arm_compute/graph/INodeVisitor.h"
Georgios Pinitasd8734b52017-12-22 15:27:52 +000029
30namespace arm_compute
31{
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010032namespace graph
Georgios Pinitasd8734b52017-12-22 15:27:52 +000033{
34DepthConcatenateLayerNode::DepthConcatenateLayerNode(unsigned int total_nodes)
35 : _total_nodes(total_nodes), _is_enabled(true)
36{
37 _input_edges.resize(total_nodes, EmptyEdgeID);
38 _outputs.resize(1, NullTensorID);
39}
40
41void DepthConcatenateLayerNode::set_enabled(bool is_enabled)
42{
43 _is_enabled = is_enabled;
44}
45
46bool DepthConcatenateLayerNode::is_enabled() const
47{
48 return _is_enabled;
49}
50
51TensorShape DepthConcatenateLayerNode::compute_output_shape(const std::vector<TensorShape> &input_shapes)
52{
53 ARM_COMPUTE_ERROR_ON(input_shapes.size() == 0);
54
55 TensorShape output_shape = input_shapes[0];
56
57 size_t max_x = 0;
58 size_t max_y = 0;
59 size_t depth = 0;
60
61 for(const auto &shape : input_shapes)
62 {
63 max_x = std::max(shape.x(), max_x);
64 max_y = std::max(shape.y(), max_y);
65 depth += shape.z();
66 }
67
68 output_shape.set(0, max_x);
69 output_shape.set(1, max_y);
70 output_shape.set(2, depth);
71
72 return output_shape;
73}
74
75bool DepthConcatenateLayerNode::forward_descriptors()
76{
77 if(_outputs[0] != NullTensorID)
78 {
79 Tensor *dst = output(0);
80 ARM_COMPUTE_ERROR_ON(dst == nullptr);
81 dst->desc() = configure_output(0);
82 return true;
83 }
84 return false;
85}
86
87TensorDescriptor DepthConcatenateLayerNode::configure_output(size_t idx) const
88{
89 ARM_COMPUTE_UNUSED(idx);
90 ARM_COMPUTE_ERROR_ON(idx >= _outputs.size());
91
92 // Check if all input tensors are set
93 bool are_all_inputs_set = std::all_of(std::begin(_input_edges), std::end(_input_edges), [](const EdgeID & eid)
94 {
95 return eid != EmptyEdgeID;
96 });
97
98 TensorDescriptor output_info = {};
99
100 if(are_all_inputs_set)
101 {
102 std::vector<TensorShape> inputs_shapes;
103 for(unsigned int i = 0; i < _input_edges.size(); ++i)
104 {
105 const Tensor *t = _graph->tensor(input_id(i));
106 ARM_COMPUTE_ERROR_ON(t == nullptr);
107 inputs_shapes.push_back(t->desc().shape);
108 }
109 output_info = input(0)->desc();
110 TensorShape output_shape = compute_output_shape(inputs_shapes);
111 output_info.shape = output_shape;
112 }
113
114 return output_info;
115}
116
117Status DepthConcatenateLayerNode::validate()
118{
119 ARM_COMPUTE_UNUSED(_total_nodes);
120 return Status{};
121}
122
123NodeType DepthConcatenateLayerNode::type() const
124{
125 return NodeType::DepthConcatenateLayer;
126}
127
128void DepthConcatenateLayerNode::accept(INodeVisitor &v)
129{
130 v.visit(*this);
131}
Georgios Pinitasd9eb2752018-04-03 13:44:29 +0100132} // namespace graph
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000133} // namespace arm_compute