Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1 | /* |
John Kesapides | fb68ca1 | 2019-01-21 14:13:27 +0000 | [diff] [blame] | 2 | * Copyright (c) 2017-2019 ARM Limited. |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 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 | */ |
Moritz Pflanzer | d58cec0 | 2017-07-18 15:44:21 +0100 | [diff] [blame] | 24 | #ifndef __ARM_COMPUTE_TEST_ACCESSOR_H__ |
| 25 | #define __ARM_COMPUTE_TEST_ACCESSOR_H__ |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 26 | |
| 27 | #include "arm_compute/runtime/Tensor.h" |
Moritz Pflanzer | d58cec0 | 2017-07-18 15:44:21 +0100 | [diff] [blame] | 28 | #include "tests/IAccessor.h" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 29 | |
| 30 | namespace arm_compute |
| 31 | { |
| 32 | namespace test |
| 33 | { |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 34 | /** Accessor implementation for @ref Tensor objects. */ |
Moritz Pflanzer | d58cec0 | 2017-07-18 15:44:21 +0100 | [diff] [blame] | 35 | class Accessor : public IAccessor |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 36 | { |
| 37 | public: |
| 38 | /** Create an accessor for the given @p tensor. |
| 39 | * |
| 40 | * @param[in, out] tensor To be accessed tensor. |
| 41 | */ |
John Kesapides | fb68ca1 | 2019-01-21 14:13:27 +0000 | [diff] [blame] | 42 | Accessor(ITensor &tensor); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 43 | |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 44 | /** Prevent instances of this class from being copy constructed */ |
Moritz Pflanzer | d58cec0 | 2017-07-18 15:44:21 +0100 | [diff] [blame] | 45 | Accessor(const Accessor &) = delete; |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 46 | /** Prevent instances of this class from being copied */ |
Moritz Pflanzer | d58cec0 | 2017-07-18 15:44:21 +0100 | [diff] [blame] | 47 | Accessor &operator=(const Accessor &) = delete; |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 48 | /** Allow instances of this class to be move constructed */ |
| 49 | Accessor(Accessor &&) = default; |
| 50 | /** Allow instances of this class to be moved */ |
Moritz Pflanzer | d58cec0 | 2017-07-18 15:44:21 +0100 | [diff] [blame] | 51 | Accessor &operator=(Accessor &&) = default; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 52 | |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 53 | /** Get the tensor data. |
| 54 | * |
| 55 | * @return a constant pointer to the tensor data. |
| 56 | */ |
| 57 | const void *data() const; |
| 58 | /** Get the tensor data. |
| 59 | * |
| 60 | * @return a pointer to the tensor data. |
| 61 | */ |
| 62 | void *data(); |
| 63 | |
Chunosov | d621bca | 2017-11-03 17:33:15 +0700 | [diff] [blame] | 64 | TensorShape shape() const override; |
| 65 | size_t element_size() const override; |
| 66 | size_t size() const override; |
| 67 | Format format() const override; |
Michele Di Giorgio | 4a65b98 | 2018-03-02 11:21:38 +0000 | [diff] [blame] | 68 | DataLayout data_layout() const override; |
Chunosov | d621bca | 2017-11-03 17:33:15 +0700 | [diff] [blame] | 69 | DataType data_type() const override; |
| 70 | int num_channels() const override; |
| 71 | int num_elements() const override; |
| 72 | PaddingSize padding() const override; |
Chunosov | d621bca | 2017-11-03 17:33:15 +0700 | [diff] [blame] | 73 | QuantizationInfo quantization_info() const override; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 74 | const void *operator()(const Coordinates &coord) const override; |
| 75 | void *operator()(const Coordinates &coord) override; |
| 76 | |
| 77 | private: |
John Kesapides | fb68ca1 | 2019-01-21 14:13:27 +0000 | [diff] [blame] | 78 | ITensor &_tensor; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 79 | }; |
| 80 | |
John Kesapides | fb68ca1 | 2019-01-21 14:13:27 +0000 | [diff] [blame] | 81 | inline Accessor::Accessor(ITensor &tensor) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 82 | : _tensor{ tensor } |
| 83 | { |
| 84 | } |
| 85 | |
Moritz Pflanzer | d58cec0 | 2017-07-18 15:44:21 +0100 | [diff] [blame] | 86 | inline TensorShape Accessor::shape() const |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 87 | { |
| 88 | return _tensor.info()->tensor_shape(); |
| 89 | } |
| 90 | |
Moritz Pflanzer | d58cec0 | 2017-07-18 15:44:21 +0100 | [diff] [blame] | 91 | inline size_t Accessor::element_size() const |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 92 | { |
| 93 | return _tensor.info()->element_size(); |
| 94 | } |
| 95 | |
Moritz Pflanzer | d58cec0 | 2017-07-18 15:44:21 +0100 | [diff] [blame] | 96 | inline size_t Accessor::size() const |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 97 | { |
| 98 | return _tensor.info()->total_size(); |
| 99 | } |
| 100 | |
Moritz Pflanzer | d58cec0 | 2017-07-18 15:44:21 +0100 | [diff] [blame] | 101 | inline Format Accessor::format() const |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 102 | { |
| 103 | return _tensor.info()->format(); |
| 104 | } |
| 105 | |
Michele Di Giorgio | 4a65b98 | 2018-03-02 11:21:38 +0000 | [diff] [blame] | 106 | inline DataLayout Accessor::data_layout() const |
| 107 | { |
| 108 | return _tensor.info()->data_layout(); |
| 109 | } |
| 110 | |
Moritz Pflanzer | d58cec0 | 2017-07-18 15:44:21 +0100 | [diff] [blame] | 111 | inline DataType Accessor::data_type() const |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 112 | { |
| 113 | return _tensor.info()->data_type(); |
| 114 | } |
| 115 | |
Moritz Pflanzer | d58cec0 | 2017-07-18 15:44:21 +0100 | [diff] [blame] | 116 | inline int Accessor::num_channels() const |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 117 | { |
| 118 | return _tensor.info()->num_channels(); |
| 119 | } |
| 120 | |
Moritz Pflanzer | d58cec0 | 2017-07-18 15:44:21 +0100 | [diff] [blame] | 121 | inline int Accessor::num_elements() const |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 122 | { |
| 123 | return _tensor.info()->tensor_shape().total_size(); |
| 124 | } |
| 125 | |
Giorgio Arena | a261181 | 2017-07-21 10:08:48 +0100 | [diff] [blame] | 126 | inline PaddingSize Accessor::padding() const |
| 127 | { |
| 128 | return _tensor.info()->padding(); |
| 129 | } |
| 130 | |
Chunosov | d621bca | 2017-11-03 17:33:15 +0700 | [diff] [blame] | 131 | inline QuantizationInfo Accessor::quantization_info() const |
| 132 | { |
| 133 | return _tensor.info()->quantization_info(); |
| 134 | } |
| 135 | |
SiCong Li | 86b5333 | 2017-08-23 11:02:43 +0100 | [diff] [blame] | 136 | inline const void *Accessor::data() const |
| 137 | { |
| 138 | return _tensor.buffer(); |
| 139 | } |
| 140 | |
| 141 | inline void *Accessor::data() |
| 142 | { |
| 143 | return _tensor.buffer(); |
| 144 | } |
| 145 | |
Moritz Pflanzer | d58cec0 | 2017-07-18 15:44:21 +0100 | [diff] [blame] | 146 | inline const void *Accessor::operator()(const Coordinates &coord) const |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 147 | { |
| 148 | return _tensor.ptr_to_element(coord); |
| 149 | } |
| 150 | |
Moritz Pflanzer | d58cec0 | 2017-07-18 15:44:21 +0100 | [diff] [blame] | 151 | inline void *Accessor::operator()(const Coordinates &coord) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 152 | { |
| 153 | return _tensor.ptr_to_element(coord); |
| 154 | } |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 155 | } // namespace test |
| 156 | } // namespace arm_compute |
Moritz Pflanzer | d58cec0 | 2017-07-18 15:44:21 +0100 | [diff] [blame] | 157 | #endif /* __ARM_COMPUTE_TEST_ACCESSOR_H__ */ |