blob: 43b835d49cf170df1292aeb4307d274d259e4a51 [file] [log] [blame]
Georgios Pinitas6f669f02017-09-26 12:32:57 +01001/*
Georgios Pinitas652bde52018-01-10 15:33:28 +00002 * Copyright (c) 2017-2018 ARM Limited.
Georgios Pinitas6f669f02017-09-26 12:32:57 +01003 *
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"
Georgios Pinitase2c82fe2017-10-02 18:51:47 +010028#include "arm_compute/graph/ITensorObject.h"
Georgios Pinitas6f669f02017-09-26 12:32:57 +010029#include "arm_compute/graph/Tensor.h"
30#include "arm_compute/graph/Types.h"
31#include "support/ToolchainSupport.h"
32
33#include <memory>
34
35namespace arm_compute
36{
37namespace graph
38{
39/** SubTensor class */
Georgios Pinitase2c82fe2017-10-02 18:51:47 +010040class SubTensor final : public ITensorObject
Georgios Pinitas6f669f02017-09-26 12:32:57 +010041{
42public:
43 /** Default Constructor */
44 SubTensor();
45 /** Constructor
46 *
Georgios Pinitas652bde52018-01-10 15:33:28 +000047 * @param[in] parent Parent to create sub-tensor from
48 * @param[in] tensor_shape Sub-tensor shape
49 * @param[in] coords Starting coordinates of the sub-tensor in the parent tensor
50 * @param[in] extend_parent (Optional) Extend parent with subtensor shape if subtensor indexes out of bounds
Georgios Pinitas6f669f02017-09-26 12:32:57 +010051 */
Georgios Pinitas652bde52018-01-10 15:33:28 +000052 SubTensor(Tensor &parent, TensorShape tensor_shape, Coordinates coords, bool extend_parent = false);
Georgios Pinitas6f669f02017-09-26 12:32:57 +010053 /** Constructor
54 *
Georgios Pinitas652bde52018-01-10 15:33:28 +000055 * @param[in] parent Parent to create sub-tensor from
56 * @param[in] tensor_shape Sub-tensor shape
57 * @param[in] coords Starting coordinates of the sub-tensor in the parent tensor
58 * @param[in] target Execution target
59 * @param[in] extend_parent (Optional) Extend parent with subtensor shape if subtensor indexes out of bounds
Georgios Pinitas6f669f02017-09-26 12:32:57 +010060 */
Georgios Pinitas652bde52018-01-10 15:33:28 +000061 SubTensor(arm_compute::ITensor *parent, TensorShape tensor_shape, Coordinates coords, TargetHint target, bool extend_parent = false);
Georgios Pinitas6f669f02017-09-26 12:32:57 +010062 /** Prevent instances of this class from being copied (As this class contains pointers) */
63 SubTensor(const SubTensor &) = delete;
64 /** Prevent instances of this class from being copied (As this class contains pointers) */
65 SubTensor &operator=(const SubTensor &) = delete;
66 /** Allow instances of this class to be moved */
67 SubTensor(SubTensor &&) = default;
68 /** Allow instances of this class to be moved */
69 SubTensor &operator=(SubTensor &&) = default;
70 /** Default Destructor */
71 ~SubTensor() = default;
72
Georgios Pinitase2c82fe2017-10-02 18:51:47 +010073 // Inherited methods overriden:
74 bool call_accessor() override;
75 bool has_accessor() const override;
76 arm_compute::ITensor *set_target(TargetHint target) override;
Michalis Spyroued194b12017-10-31 15:04:34 +000077 arm_compute::ITensor *tensor() override;
78 const arm_compute::ITensor *tensor() const override;
79 TargetHint target() const override;
80 void allocate() override;
Georgios Pinitas6f669f02017-09-26 12:32:57 +010081
82private:
83 /** Instantiates a sub-tensor */
84 void instantiate_subtensor();
85
86private:
Georgios Pinitas652bde52018-01-10 15:33:28 +000087 TargetHint _target; /**< Target that this tensor is pinned on */
88 TensorShape _tensor_shape; /**< SubTensor shape */
89 Coordinates _coords; /**< SubTensor Coordinates */
90 arm_compute::ITensor *_parent; /**< Parent tensor */
91 std::unique_ptr<arm_compute::ITensor> _subtensor; /**< SubTensor */
92 bool _extend_parent; /**< Parent extension flag */
Georgios Pinitas6f669f02017-09-26 12:32:57 +010093};
94} // namespace graph
95} // namespace arm_compute
96#endif /* __ARM_COMPUTE_GRAPH_SUBTENSOR_H__ */