blob: a73b0d6b0e3f789706de2fb92359d4651c6096e4 [file] [log] [blame]
Georgios Pinitas6f669f02017-09-26 12:32:57 +01001/*
2 * Copyright (c) 2017 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#ifndef __ARM_COMPUTE_GRAPH_SUBTENSOR_H__
25#define __ARM_COMPUTE_GRAPH_SUBTENSOR_H__
26
27#include "arm_compute/graph/ITensorAccessor.h"
28#include "arm_compute/graph/Tensor.h"
29#include "arm_compute/graph/Types.h"
30#include "support/ToolchainSupport.h"
31
32#include <memory>
33
34namespace arm_compute
35{
36namespace graph
37{
38/** SubTensor class */
39class SubTensor final
40{
41public:
42 /** Default Constructor */
43 SubTensor();
44 /** Constructor
45 *
46 * @param[in] parent Parent to create sub-tensor from
47 * @param[in] tensor_shape Sub-tensor shape
48 * @param[in] coords Starting coordinates of the sub-tensor in the parent tensor
49 */
50 SubTensor(Tensor &parent, TensorShape tensor_shape, Coordinates coords);
51 /** Constructor
52 *
53 * @param[in] parent Parent to create sub-tensor from
54 * @param[in] tensor_shape Sub-tensor shape
55 * @param[in] coords Starting coordinates of the sub-tensor in the parent tensor
56 * @param[in] target Execution target
57 */
58 SubTensor(ITensor *parent, TensorShape tensor_shape, Coordinates coords, Hint target);
59 /** Prevent instances of this class from being copied (As this class contains pointers) */
60 SubTensor(const SubTensor &) = delete;
61 /** Prevent instances of this class from being copied (As this class contains pointers) */
62 SubTensor &operator=(const SubTensor &) = delete;
63 /** Allow instances of this class to be moved */
64 SubTensor(SubTensor &&) = default;
65 /** Allow instances of this class to be moved */
66 SubTensor &operator=(SubTensor &&) = default;
67 /** Default Destructor */
68 ~SubTensor() = default;
69
70 /** Sets the given TensorInfo to the tensor
71 *
72 * @param[in] info TensorInfo to set
73 */
74 void set_info(SubTensorInfo &&info);
75 /** Returns tensor's TensorInfo
76 *
77 * @return TensorInfo of the tensor
78 */
79 const SubTensorInfo &info() const;
80 /** Returns a pointer to the internal tensor
81 *
82 * @return Tensor
83 */
84 ITensor *tensor();
85 /** Return the target that this tensor is pinned on
86 *
87 * @return Target of the tensor
88 */
89 Hint target() const;
90
91private:
92 /** Instantiates a sub-tensor */
93 void instantiate_subtensor();
94
95private:
96 Hint _target; /**< Target that this tensor is pinned on */
97 Coordinates _coords; /**< SubTensor Coordinates */
98 SubTensorInfo _info; /**< SubTensor metadata */
99 ITensor *_parent; /**< Parent tensor */
100 std::unique_ptr<ITensor> _subtensor; /**< SubTensor */
101};
102} // namespace graph
103} // namespace arm_compute
104#endif /* __ARM_COMPUTE_GRAPH_SUBTENSOR_H__ */