blob: e5821dc812a5cb32fd3da4b9712fd00d3d4005d7 [file] [log] [blame]
Anthony Barbier2a07e182017-08-04 18:20:27 +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_TENSOR_H__
25#define __ARM_COMPUTE_GRAPH_TENSOR_H__
26
27#include "arm_compute/graph/ITensorAccessor.h"
Georgios Pinitase2c82fe2017-10-02 18:51:47 +010028#include "arm_compute/graph/ITensorObject.h"
Anthony Barbier2a07e182017-08-04 18:20:27 +010029#include "arm_compute/graph/Types.h"
30#include "support/ToolchainSupport.h"
31
32#include <memory>
33
34namespace arm_compute
35{
36namespace graph
37{
38/** Tensor class */
Georgios Pinitase2c82fe2017-10-02 18:51:47 +010039class Tensor final : public ITensorObject
Anthony Barbier2a07e182017-08-04 18:20:27 +010040{
41public:
42 /** Constructor
43 *
44 * @param[in] info Tensor info to use
45 */
46 Tensor(TensorInfo &&info);
47 /** Constructor
48 *
49 * @param[in] accessor Tensor accessor
50 */
51 template <typename AccessorType>
52 Tensor(std::unique_ptr<AccessorType> accessor)
Georgios Pinitasff421f22017-10-04 16:53:58 +010053 : _target(TargetHint::DONT_CARE), _info(), _accessor(std::move(accessor)), _tensor(nullptr)
Anthony Barbier2a07e182017-08-04 18:20:27 +010054 {
55 }
56 /** Constructor
57 *
58 * @param[in] accessor Tensor accessor
59 */
60 template <typename AccessorType>
61 Tensor(AccessorType &&accessor)
Georgios Pinitasff421f22017-10-04 16:53:58 +010062 : _target(TargetHint::DONT_CARE), _info(), _accessor(arm_compute::support::cpp14::make_unique<AccessorType>(std::forward<AccessorType>(accessor))), _tensor(nullptr)
Anthony Barbier2a07e182017-08-04 18:20:27 +010063 {
64 }
65 /** Constructor
66 *
67 * @param[in] info Tensor info to use
68 * @param[in] accessor Tensor accessor
69 */
70 template <typename AccessorType>
Gian Marco44ec2e72017-10-19 14:13:38 +010071 Tensor(TensorInfo &&info, std::unique_ptr<AccessorType> &&accessor)
72 : _target(TargetHint::DONT_CARE), _info(info), _accessor(std::move(accessor)), _tensor(nullptr)
73 {
74 }
75 /** Constructor
76 *
77 * @param[in] info Tensor info to use
78 * @param[in] accessor Tensor accessor
79 */
80 template <typename AccessorType>
Anthony Barbier2a07e182017-08-04 18:20:27 +010081 Tensor(TensorInfo &&info, AccessorType &&accessor)
Georgios Pinitasff421f22017-10-04 16:53:58 +010082 : _target(TargetHint::DONT_CARE), _info(info), _accessor(arm_compute::support::cpp14::make_unique<AccessorType>(std::forward<AccessorType>(accessor))), _tensor(nullptr)
Anthony Barbier2a07e182017-08-04 18:20:27 +010083 {
84 }
85 /** Default Destructor */
86 ~Tensor() = default;
87 /** Move Constructor
88 *
89 * @param[in] src Tensor to move
90 */
91 Tensor(Tensor &&src) noexcept;
92
93 /** Sets the given TensorInfo to the tensor
94 *
95 * @param[in] info TensorInfo to set
96 */
97 void set_info(TensorInfo &&info);
Anthony Barbier2a07e182017-08-04 18:20:27 +010098 /** Returns tensor's TensorInfo
99 *
100 * @return TensorInfo of the tensor
101 */
102 const TensorInfo &info() const;
Anthony Barbier2a07e182017-08-04 18:20:27 +0100103 /** Allocates and fills the tensor if needed */
104 void allocate_and_fill_if_needed();
Georgios Pinitase2c82fe2017-10-02 18:51:47 +0100105
106 // Inherited methods overriden:
107 bool call_accessor() override;
108 bool has_accessor() const override;
109 arm_compute::ITensor *set_target(TargetHint target) override;
Michalis Spyroued194b12017-10-31 15:04:34 +0000110 arm_compute::ITensor *tensor() override;
111 const arm_compute::ITensor *tensor() const override;
112 TargetHint target() const override;
113 void allocate() override;
Anthony Barbier2a07e182017-08-04 18:20:27 +0100114
115private:
Georgios Pinitase2c82fe2017-10-02 18:51:47 +0100116 TargetHint _target; /**< Target that this tensor is pinned on */
117 TensorInfo _info; /**< Tensor metadata */
118 std::unique_ptr<ITensorAccessor> _accessor; /**< Tensor Accessor */
119 std::unique_ptr<arm_compute::ITensor> _tensor; /**< Tensor */
Anthony Barbier2a07e182017-08-04 18:20:27 +0100120};
121} // namespace graph
122} // namespace arm_compute
123#endif /* __ARM_COMPUTE_GRAPH_TENSOR_H__ */