blob: 6dc09e38f110802f45eb06b3b0be2ff41dc4e71b [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
Michele Di Giorgiod9eaf612020-07-08 11:12:57 +01002 * Copyright (c) 2017-2020 Arm Limited.
Anthony Barbier6ff3b192017-09-04 18:44:23 +01003 *
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 */
Michalis Spyrouf4643372019-11-29 16:17:13 +000024#ifndef ARM_COMPUTE_TEST_ACCESSOR_H
25#define ARM_COMPUTE_TEST_ACCESSOR_H
Anthony Barbier6ff3b192017-09-04 18:44:23 +010026
27#include "arm_compute/runtime/Tensor.h"
Moritz Pflanzerd58cec02017-07-18 15:44:21 +010028#include "tests/IAccessor.h"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010029
30namespace arm_compute
31{
32namespace test
33{
Anthony Barbier6ff3b192017-09-04 18:44:23 +010034/** Accessor implementation for @ref Tensor objects. */
Moritz Pflanzerd58cec02017-07-18 15:44:21 +010035class Accessor : public IAccessor
Anthony Barbier6ff3b192017-09-04 18:44:23 +010036{
37public:
38 /** Create an accessor for the given @p tensor.
39 *
40 * @param[in, out] tensor To be accessed tensor.
41 */
John Kesapidesfb68ca12019-01-21 14:13:27 +000042 Accessor(ITensor &tensor);
Anthony Barbier6ff3b192017-09-04 18:44:23 +010043
Alex Gildayc357c472018-03-21 13:54:09 +000044 /** Prevent instances of this class from being copy constructed */
Moritz Pflanzerd58cec02017-07-18 15:44:21 +010045 Accessor(const Accessor &) = delete;
Alex Gildayc357c472018-03-21 13:54:09 +000046 /** Prevent instances of this class from being copied */
Moritz Pflanzerd58cec02017-07-18 15:44:21 +010047 Accessor &operator=(const Accessor &) = delete;
Alex Gildayc357c472018-03-21 13:54:09 +000048 /** Allow instances of this class to be move constructed */
49 Accessor(Accessor &&) = default;
Anthony Barbier6ff3b192017-09-04 18:44:23 +010050
Alex Gildayc357c472018-03-21 13:54:09 +000051 /** Get the tensor data.
52 *
53 * @return a constant pointer to the tensor data.
54 */
55 const void *data() const;
56 /** Get the tensor data.
57 *
58 * @return a pointer to the tensor data.
59 */
60 void *data();
61
Chunosovd621bca2017-11-03 17:33:15 +070062 TensorShape shape() const override;
63 size_t element_size() const override;
64 size_t size() const override;
65 Format format() const override;
Michele Di Giorgio4a65b982018-03-02 11:21:38 +000066 DataLayout data_layout() const override;
Chunosovd621bca2017-11-03 17:33:15 +070067 DataType data_type() const override;
68 int num_channels() const override;
69 int num_elements() const override;
70 PaddingSize padding() const override;
Chunosovd621bca2017-11-03 17:33:15 +070071 QuantizationInfo quantization_info() const override;
Anthony Barbier6ff3b192017-09-04 18:44:23 +010072 const void *operator()(const Coordinates &coord) const override;
73 void *operator()(const Coordinates &coord) override;
74
75private:
John Kesapidesfb68ca12019-01-21 14:13:27 +000076 ITensor &_tensor;
Anthony Barbier6ff3b192017-09-04 18:44:23 +010077};
78
John Kesapidesfb68ca12019-01-21 14:13:27 +000079inline Accessor::Accessor(ITensor &tensor)
Anthony Barbier6ff3b192017-09-04 18:44:23 +010080 : _tensor{ tensor }
81{
82}
83
Moritz Pflanzerd58cec02017-07-18 15:44:21 +010084inline TensorShape Accessor::shape() const
Anthony Barbier6ff3b192017-09-04 18:44:23 +010085{
86 return _tensor.info()->tensor_shape();
87}
88
Moritz Pflanzerd58cec02017-07-18 15:44:21 +010089inline size_t Accessor::element_size() const
Anthony Barbier6ff3b192017-09-04 18:44:23 +010090{
91 return _tensor.info()->element_size();
92}
93
Moritz Pflanzerd58cec02017-07-18 15:44:21 +010094inline size_t Accessor::size() const
Anthony Barbier6ff3b192017-09-04 18:44:23 +010095{
96 return _tensor.info()->total_size();
97}
98
Moritz Pflanzerd58cec02017-07-18 15:44:21 +010099inline Format Accessor::format() const
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100100{
101 return _tensor.info()->format();
102}
103
Michele Di Giorgio4a65b982018-03-02 11:21:38 +0000104inline DataLayout Accessor::data_layout() const
105{
106 return _tensor.info()->data_layout();
107}
108
Moritz Pflanzerd58cec02017-07-18 15:44:21 +0100109inline DataType Accessor::data_type() const
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100110{
111 return _tensor.info()->data_type();
112}
113
Moritz Pflanzerd58cec02017-07-18 15:44:21 +0100114inline int Accessor::num_channels() const
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100115{
116 return _tensor.info()->num_channels();
117}
118
Moritz Pflanzerd58cec02017-07-18 15:44:21 +0100119inline int Accessor::num_elements() const
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100120{
121 return _tensor.info()->tensor_shape().total_size();
122}
123
Giorgio Arenaa2611812017-07-21 10:08:48 +0100124inline PaddingSize Accessor::padding() const
125{
126 return _tensor.info()->padding();
127}
128
Chunosovd621bca2017-11-03 17:33:15 +0700129inline QuantizationInfo Accessor::quantization_info() const
130{
131 return _tensor.info()->quantization_info();
132}
133
SiCong Li86b53332017-08-23 11:02:43 +0100134inline const void *Accessor::data() const
135{
136 return _tensor.buffer();
137}
138
139inline void *Accessor::data()
140{
141 return _tensor.buffer();
142}
143
Moritz Pflanzerd58cec02017-07-18 15:44:21 +0100144inline const void *Accessor::operator()(const Coordinates &coord) const
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100145{
146 return _tensor.ptr_to_element(coord);
147}
148
Moritz Pflanzerd58cec02017-07-18 15:44:21 +0100149inline void *Accessor::operator()(const Coordinates &coord)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100150{
151 return _tensor.ptr_to_element(coord);
152}
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100153} // namespace test
154} // namespace arm_compute
Michalis Spyrouf4643372019-11-29 16:17:13 +0000155#endif /* ARM_COMPUTE_TEST_ACCESSOR_H */