blob: bdd39e8ebde61f738bffb75bbc45c41dea84bc8d [file] [log] [blame]
Michalis Spyrou4e1c3f32018-09-20 17:14:03 +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/UpsampleLayerNode.h"
25
26#include "arm_compute/graph/Graph.h"
27#include "arm_compute/graph/INodeVisitor.h"
28#include "arm_compute/graph/Utils.h"
29
30namespace arm_compute
31{
32namespace graph
33{
34UpsampleLayerNode::UpsampleLayerNode(Size2D info, InterpolationPolicy upsampling_policy)
35 : _info(info), _upsampling_policy(upsampling_policy)
36{
37 _input_edges.resize(1, EmptyEdgeID);
38 _outputs.resize(1, NullTensorID);
39}
40
41Size2D UpsampleLayerNode::info() const
42{
43 return _info;
44}
45
46InterpolationPolicy UpsampleLayerNode::upsampling_policy() const
47{
48 return _upsampling_policy;
49}
50
51TensorDescriptor UpsampleLayerNode::compute_output_descriptor(const TensorDescriptor &input_descriptor,
52 Size2D info)
53{
54 const unsigned int input_width = get_dimension_size(input_descriptor, DataLayoutDimension::WIDTH);
55 const unsigned int input_height = get_dimension_size(input_descriptor, DataLayoutDimension::HEIGHT);
56
57 TensorDescriptor output_descriptor = input_descriptor;
58 output_descriptor.shape.set(get_dimension_idx(output_descriptor, DataLayoutDimension::WIDTH), input_width * info.x());
59 output_descriptor.shape.set(get_dimension_idx(output_descriptor, DataLayoutDimension::HEIGHT), input_height * info.y());
60
61 return output_descriptor;
62}
63
64bool UpsampleLayerNode::forward_descriptors()
65{
66 if((input_id(0) != NullTensorID) && (output_id(0) != NullTensorID))
67 {
68 Tensor *dst = output(0);
69 ARM_COMPUTE_ERROR_ON(dst == nullptr);
70 dst->desc() = configure_output(0);
71 return true;
72 }
73 return false;
74}
75
76TensorDescriptor UpsampleLayerNode::configure_output(size_t idx) const
77{
78 ARM_COMPUTE_UNUSED(idx);
79 ARM_COMPUTE_ERROR_ON(idx >= _outputs.size());
80
81 const Tensor *src = input(0);
82 ARM_COMPUTE_ERROR_ON(src == nullptr);
83
84 return compute_output_descriptor(src->desc(), _info);
85}
86
87NodeType UpsampleLayerNode::type() const
88{
89 return NodeType::UpsampleLayer;
90}
91
92void UpsampleLayerNode::accept(INodeVisitor &v)
93{
94 v.visit(*this);
95}
96} // namespace graph
97} // namespace arm_compute