blob: 60a94c20d40872e0bab817b35bea601ebb9d81e0 [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
Michele Di Giorgio4a65b982018-03-02 11:21:38 +00002 * Copyright (c) 2017-2018 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 */
Moritz Pflanzerd58cec02017-07-18 15:44:21 +010024#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 */
Moritz Pflanzerd58cec02017-07-18 15:44:21 +010042 Accessor(Tensor &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;
50 /** Allow instances of this class to be moved */
Moritz Pflanzerd58cec02017-07-18 15:44:21 +010051 Accessor &operator=(Accessor &&) = default;
Anthony Barbier6ff3b192017-09-04 18:44:23 +010052
Alex Gildayc357c472018-03-21 13:54:09 +000053 /** 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
Chunosovd621bca2017-11-03 17:33:15 +070064 TensorShape shape() const override;
65 size_t element_size() const override;
66 size_t size() const override;
67 Format format() const override;
Michele Di Giorgio4a65b982018-03-02 11:21:38 +000068 DataLayout data_layout() const override;
Chunosovd621bca2017-11-03 17:33:15 +070069 DataType data_type() const override;
70 int num_channels() const override;
71 int num_elements() const override;
72 PaddingSize padding() const override;
73 int fixed_point_position() const override;
74 QuantizationInfo quantization_info() const override;
Anthony Barbier6ff3b192017-09-04 18:44:23 +010075 const void *operator()(const Coordinates &coord) const override;
76 void *operator()(const Coordinates &coord) override;
77
78private:
79 Tensor &_tensor;
80};
81
Moritz Pflanzerd58cec02017-07-18 15:44:21 +010082inline Accessor::Accessor(Tensor &tensor)
Anthony Barbier6ff3b192017-09-04 18:44:23 +010083 : _tensor{ tensor }
84{
85}
86
Moritz Pflanzerd58cec02017-07-18 15:44:21 +010087inline TensorShape Accessor::shape() const
Anthony Barbier6ff3b192017-09-04 18:44:23 +010088{
89 return _tensor.info()->tensor_shape();
90}
91
Moritz Pflanzerd58cec02017-07-18 15:44:21 +010092inline size_t Accessor::element_size() const
Anthony Barbier6ff3b192017-09-04 18:44:23 +010093{
94 return _tensor.info()->element_size();
95}
96
Moritz Pflanzerd58cec02017-07-18 15:44:21 +010097inline size_t Accessor::size() const
Anthony Barbier6ff3b192017-09-04 18:44:23 +010098{
99 return _tensor.info()->total_size();
100}
101
Moritz Pflanzerd58cec02017-07-18 15:44:21 +0100102inline Format Accessor::format() const
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100103{
104 return _tensor.info()->format();
105}
106
Michele Di Giorgio4a65b982018-03-02 11:21:38 +0000107inline DataLayout Accessor::data_layout() const
108{
109 return _tensor.info()->data_layout();
110}
111
Moritz Pflanzerd58cec02017-07-18 15:44:21 +0100112inline DataType Accessor::data_type() const
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100113{
114 return _tensor.info()->data_type();
115}
116
Moritz Pflanzerd58cec02017-07-18 15:44:21 +0100117inline int Accessor::num_channels() const
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100118{
119 return _tensor.info()->num_channels();
120}
121
Moritz Pflanzerd58cec02017-07-18 15:44:21 +0100122inline int Accessor::num_elements() const
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100123{
124 return _tensor.info()->tensor_shape().total_size();
125}
126
Giorgio Arenaa2611812017-07-21 10:08:48 +0100127inline PaddingSize Accessor::padding() const
128{
129 return _tensor.info()->padding();
130}
131
Moritz Pflanzerd58cec02017-07-18 15:44:21 +0100132inline int Accessor::fixed_point_position() const
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100133{
134 return _tensor.info()->fixed_point_position();
135}
136
Chunosovd621bca2017-11-03 17:33:15 +0700137inline QuantizationInfo Accessor::quantization_info() const
138{
139 return _tensor.info()->quantization_info();
140}
141
SiCong Li86b53332017-08-23 11:02:43 +0100142inline const void *Accessor::data() const
143{
144 return _tensor.buffer();
145}
146
147inline void *Accessor::data()
148{
149 return _tensor.buffer();
150}
151
Moritz Pflanzerd58cec02017-07-18 15:44:21 +0100152inline const void *Accessor::operator()(const Coordinates &coord) const
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100153{
154 return _tensor.ptr_to_element(coord);
155}
156
Moritz Pflanzerd58cec02017-07-18 15:44:21 +0100157inline void *Accessor::operator()(const Coordinates &coord)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100158{
159 return _tensor.ptr_to_element(coord);
160}
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100161} // namespace test
162} // namespace arm_compute
Moritz Pflanzerd58cec02017-07-18 15:44:21 +0100163#endif /* __ARM_COMPUTE_TEST_ACCESSOR_H__ */