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