Anthony Barbier | 2a07e18 | 2017-08-04 18:20:27 +0100 | [diff] [blame] | 1 | /* |
| 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 Pinitas | e2c82fe | 2017-10-02 18:51:47 +0100 | [diff] [blame] | 28 | #include "arm_compute/graph/ITensorObject.h" |
Anthony Barbier | 2a07e18 | 2017-08-04 18:20:27 +0100 | [diff] [blame] | 29 | #include "arm_compute/graph/Types.h" |
| 30 | #include "support/ToolchainSupport.h" |
| 31 | |
| 32 | #include <memory> |
| 33 | |
| 34 | namespace arm_compute |
| 35 | { |
| 36 | namespace graph |
| 37 | { |
| 38 | /** Tensor class */ |
Georgios Pinitas | e2c82fe | 2017-10-02 18:51:47 +0100 | [diff] [blame] | 39 | class Tensor final : public ITensorObject |
Anthony Barbier | 2a07e18 | 2017-08-04 18:20:27 +0100 | [diff] [blame] | 40 | { |
| 41 | public: |
| 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 Pinitas | ff421f2 | 2017-10-04 16:53:58 +0100 | [diff] [blame] | 53 | : _target(TargetHint::DONT_CARE), _info(), _accessor(std::move(accessor)), _tensor(nullptr) |
Anthony Barbier | 2a07e18 | 2017-08-04 18:20:27 +0100 | [diff] [blame] | 54 | { |
| 55 | } |
| 56 | /** Constructor |
| 57 | * |
| 58 | * @param[in] accessor Tensor accessor |
| 59 | */ |
| 60 | template <typename AccessorType> |
| 61 | Tensor(AccessorType &&accessor) |
Georgios Pinitas | ff421f2 | 2017-10-04 16:53:58 +0100 | [diff] [blame] | 62 | : _target(TargetHint::DONT_CARE), _info(), _accessor(arm_compute::support::cpp14::make_unique<AccessorType>(std::forward<AccessorType>(accessor))), _tensor(nullptr) |
Anthony Barbier | 2a07e18 | 2017-08-04 18:20:27 +0100 | [diff] [blame] | 63 | { |
| 64 | } |
| 65 | /** Constructor |
| 66 | * |
| 67 | * @param[in] info Tensor info to use |
| 68 | * @param[in] accessor Tensor accessor |
| 69 | */ |
| 70 | template <typename AccessorType> |
Gian Marco | 44ec2e7 | 2017-10-19 14:13:38 +0100 | [diff] [blame] | 71 | 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 Barbier | 2a07e18 | 2017-08-04 18:20:27 +0100 | [diff] [blame] | 81 | Tensor(TensorInfo &&info, AccessorType &&accessor) |
Georgios Pinitas | ff421f2 | 2017-10-04 16:53:58 +0100 | [diff] [blame] | 82 | : _target(TargetHint::DONT_CARE), _info(info), _accessor(arm_compute::support::cpp14::make_unique<AccessorType>(std::forward<AccessorType>(accessor))), _tensor(nullptr) |
Anthony Barbier | 2a07e18 | 2017-08-04 18:20:27 +0100 | [diff] [blame] | 83 | { |
| 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 Barbier | 2a07e18 | 2017-08-04 18:20:27 +0100 | [diff] [blame] | 98 | /** Returns tensor's TensorInfo |
| 99 | * |
| 100 | * @return TensorInfo of the tensor |
| 101 | */ |
| 102 | const TensorInfo &info() const; |
Anthony Barbier | 2a07e18 | 2017-08-04 18:20:27 +0100 | [diff] [blame] | 103 | /** Allocates and fills the tensor if needed */ |
| 104 | void allocate_and_fill_if_needed(); |
Georgios Pinitas | e2c82fe | 2017-10-02 18:51:47 +0100 | [diff] [blame] | 105 | |
| 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 Spyrou | ed194b1 | 2017-10-31 15:04:34 +0000 | [diff] [blame] | 110 | arm_compute::ITensor *tensor() override; |
| 111 | const arm_compute::ITensor *tensor() const override; |
| 112 | TargetHint target() const override; |
| 113 | void allocate() override; |
Anthony Barbier | 2a07e18 | 2017-08-04 18:20:27 +0100 | [diff] [blame] | 114 | |
| 115 | private: |
Georgios Pinitas | e2c82fe | 2017-10-02 18:51:47 +0100 | [diff] [blame] | 116 | 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 Barbier | 2a07e18 | 2017-08-04 18:20:27 +0100 | [diff] [blame] | 120 | }; |
| 121 | } // namespace graph |
| 122 | } // namespace arm_compute |
| 123 | #endif /* __ARM_COMPUTE_GRAPH_TENSOR_H__ */ |