Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +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 | */ |
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 | */ |
Moritz Pflanzer | d58cec0 | 2017-07-18 15:44:21 +0100 | [diff] [blame] | 42 | Accessor(Tensor &tensor); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 43 | |
Moritz Pflanzer | d58cec0 | 2017-07-18 15:44:21 +0100 | [diff] [blame] | 44 | Accessor(const Accessor &) = delete; |
| 45 | Accessor &operator=(const Accessor &) = delete; |
| 46 | Accessor(Accessor &&) = default; |
| 47 | Accessor &operator=(Accessor &&) = default; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 48 | |
| 49 | TensorShape shape() const override; |
| 50 | size_t element_size() const override; |
| 51 | size_t size() const override; |
| 52 | Format format() const override; |
| 53 | DataType data_type() const override; |
| 54 | int num_channels() const override; |
| 55 | int num_elements() const override; |
Giorgio Arena | a261181 | 2017-07-21 10:08:48 +0100 | [diff] [blame] | 56 | PaddingSize padding() const override; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 57 | int fixed_point_position() const override; |
| 58 | const void *operator()(const Coordinates &coord) const override; |
| 59 | void *operator()(const Coordinates &coord) override; |
SiCong Li | 86b5333 | 2017-08-23 11:02:43 +0100 | [diff] [blame] | 60 | const void *data() const; |
| 61 | void *data(); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 62 | |
| 63 | private: |
| 64 | Tensor &_tensor; |
| 65 | }; |
| 66 | |
Moritz Pflanzer | d58cec0 | 2017-07-18 15:44:21 +0100 | [diff] [blame] | 67 | inline Accessor::Accessor(Tensor &tensor) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 68 | : _tensor{ tensor } |
| 69 | { |
| 70 | } |
| 71 | |
Moritz Pflanzer | d58cec0 | 2017-07-18 15:44:21 +0100 | [diff] [blame] | 72 | inline TensorShape Accessor::shape() const |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 73 | { |
| 74 | return _tensor.info()->tensor_shape(); |
| 75 | } |
| 76 | |
Moritz Pflanzer | d58cec0 | 2017-07-18 15:44:21 +0100 | [diff] [blame] | 77 | inline size_t Accessor::element_size() const |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 78 | { |
| 79 | return _tensor.info()->element_size(); |
| 80 | } |
| 81 | |
Moritz Pflanzer | d58cec0 | 2017-07-18 15:44:21 +0100 | [diff] [blame] | 82 | inline size_t Accessor::size() const |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 83 | { |
| 84 | return _tensor.info()->total_size(); |
| 85 | } |
| 86 | |
Moritz Pflanzer | d58cec0 | 2017-07-18 15:44:21 +0100 | [diff] [blame] | 87 | inline Format Accessor::format() const |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 88 | { |
| 89 | return _tensor.info()->format(); |
| 90 | } |
| 91 | |
Moritz Pflanzer | d58cec0 | 2017-07-18 15:44:21 +0100 | [diff] [blame] | 92 | inline DataType Accessor::data_type() const |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 93 | { |
| 94 | return _tensor.info()->data_type(); |
| 95 | } |
| 96 | |
Moritz Pflanzer | d58cec0 | 2017-07-18 15:44:21 +0100 | [diff] [blame] | 97 | inline int Accessor::num_channels() const |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 98 | { |
| 99 | return _tensor.info()->num_channels(); |
| 100 | } |
| 101 | |
Moritz Pflanzer | d58cec0 | 2017-07-18 15:44:21 +0100 | [diff] [blame] | 102 | inline int Accessor::num_elements() const |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 103 | { |
| 104 | return _tensor.info()->tensor_shape().total_size(); |
| 105 | } |
| 106 | |
Giorgio Arena | a261181 | 2017-07-21 10:08:48 +0100 | [diff] [blame] | 107 | inline PaddingSize Accessor::padding() const |
| 108 | { |
| 109 | return _tensor.info()->padding(); |
| 110 | } |
| 111 | |
Moritz Pflanzer | d58cec0 | 2017-07-18 15:44:21 +0100 | [diff] [blame] | 112 | inline int Accessor::fixed_point_position() const |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 113 | { |
| 114 | return _tensor.info()->fixed_point_position(); |
| 115 | } |
| 116 | |
SiCong Li | 86b5333 | 2017-08-23 11:02:43 +0100 | [diff] [blame] | 117 | inline const void *Accessor::data() const |
| 118 | { |
| 119 | return _tensor.buffer(); |
| 120 | } |
| 121 | |
| 122 | inline void *Accessor::data() |
| 123 | { |
| 124 | return _tensor.buffer(); |
| 125 | } |
| 126 | |
Moritz Pflanzer | d58cec0 | 2017-07-18 15:44:21 +0100 | [diff] [blame] | 127 | inline const void *Accessor::operator()(const Coordinates &coord) const |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 128 | { |
| 129 | return _tensor.ptr_to_element(coord); |
| 130 | } |
| 131 | |
Moritz Pflanzer | d58cec0 | 2017-07-18 15:44:21 +0100 | [diff] [blame] | 132 | inline void *Accessor::operator()(const Coordinates &coord) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 133 | { |
| 134 | return _tensor.ptr_to_element(coord); |
| 135 | } |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 136 | } // namespace test |
| 137 | } // namespace arm_compute |
Moritz Pflanzer | d58cec0 | 2017-07-18 15:44:21 +0100 | [diff] [blame] | 138 | #endif /* __ARM_COMPUTE_TEST_ACCESSOR_H__ */ |