blob: 08cccc1ff106b3b68b4ede5e2ec8ef87c374ed69 [file] [log] [blame]
Jenkinsb3a371b2018-05-23 11:36:53 +01001/*
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 */
24#include "arm_compute/graph/nodes/DepthConcatenateLayerNode.h"
25
26#include "arm_compute/core/Utils.h"
27#include "arm_compute/graph/Graph.h"
28#include "arm_compute/graph/INodeVisitor.h"
29
30namespace arm_compute
31{
32namespace graph
33{
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
51TensorDescriptor DepthConcatenateLayerNode::compute_output_descriptor(const std::vector<TensorDescriptor> &input_descriptors)
52{
53 ARM_COMPUTE_ERROR_ON(input_descriptors.size() == 0);
54
55 TensorDescriptor output_descriptor = input_descriptors[0];
56
57 size_t max_x = 0;
58 size_t max_y = 0;
59 size_t depth = 0;
60
61 for(const auto &input_descriptor : input_descriptors)
62 {
63 max_x = std::max(input_descriptor.shape.x(), max_x);
64 max_y = std::max(input_descriptor.shape.y(), max_y);
65 depth += input_descriptor.shape.z();
66 }
67
68 output_descriptor.shape.set(0, max_x);
69 output_descriptor.shape.set(1, max_y);
70 output_descriptor.shape.set(2, depth);
71
72 return output_descriptor;
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<TensorDescriptor> inputs_descriptors;
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_descriptors.push_back(t->desc());
108 }
109 output_info = compute_output_descriptor(inputs_descriptors);
110 }
111
112 return output_info;
113}
114
115NodeType DepthConcatenateLayerNode::type() const
116{
117 return NodeType::DepthConcatenateLayer;
118}
119
120void DepthConcatenateLayerNode::accept(INodeVisitor &v)
121{
122 v.visit(*this);
123}
124} // namespace graph
125} // namespace arm_compute