blob: 2bad53b3feab37a7900a4f0c37907b3e4a63c2d2 [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
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 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
Moritz Pflanzerd58cec02017-07-18 15:44:21 +010044 Accessor(const Accessor &) = delete;
45 Accessor &operator=(const Accessor &) = delete;
46 Accessor(Accessor &&) = default;
47 Accessor &operator=(Accessor &&) = default;
Anthony Barbier6ff3b192017-09-04 18:44:23 +010048
Chunosovd621bca2017-11-03 17:33:15 +070049 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;
56 PaddingSize padding() const override;
57 int fixed_point_position() const override;
58 QuantizationInfo quantization_info() const override;
Anthony Barbier6ff3b192017-09-04 18:44:23 +010059 const void *operator()(const Coordinates &coord) const override;
60 void *operator()(const Coordinates &coord) override;
SiCong Li86b53332017-08-23 11:02:43 +010061 const void *data() const;
62 void *data();
Anthony Barbier6ff3b192017-09-04 18:44:23 +010063
64private:
65 Tensor &_tensor;
66};
67
Moritz Pflanzerd58cec02017-07-18 15:44:21 +010068inline Accessor::Accessor(Tensor &tensor)
Anthony Barbier6ff3b192017-09-04 18:44:23 +010069 : _tensor{ tensor }
70{
71}
72
Moritz Pflanzerd58cec02017-07-18 15:44:21 +010073inline TensorShape Accessor::shape() const
Anthony Barbier6ff3b192017-09-04 18:44:23 +010074{
75 return _tensor.info()->tensor_shape();
76}
77
Moritz Pflanzerd58cec02017-07-18 15:44:21 +010078inline size_t Accessor::element_size() const
Anthony Barbier6ff3b192017-09-04 18:44:23 +010079{
80 return _tensor.info()->element_size();
81}
82
Moritz Pflanzerd58cec02017-07-18 15:44:21 +010083inline size_t Accessor::size() const
Anthony Barbier6ff3b192017-09-04 18:44:23 +010084{
85 return _tensor.info()->total_size();
86}
87
Moritz Pflanzerd58cec02017-07-18 15:44:21 +010088inline Format Accessor::format() const
Anthony Barbier6ff3b192017-09-04 18:44:23 +010089{
90 return _tensor.info()->format();
91}
92
Moritz Pflanzerd58cec02017-07-18 15:44:21 +010093inline DataType Accessor::data_type() const
Anthony Barbier6ff3b192017-09-04 18:44:23 +010094{
95 return _tensor.info()->data_type();
96}
97
Moritz Pflanzerd58cec02017-07-18 15:44:21 +010098inline int Accessor::num_channels() const
Anthony Barbier6ff3b192017-09-04 18:44:23 +010099{
100 return _tensor.info()->num_channels();
101}
102
Moritz Pflanzerd58cec02017-07-18 15:44:21 +0100103inline int Accessor::num_elements() const
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100104{
105 return _tensor.info()->tensor_shape().total_size();
106}
107
Giorgio Arenaa2611812017-07-21 10:08:48 +0100108inline PaddingSize Accessor::padding() const
109{
110 return _tensor.info()->padding();
111}
112
Moritz Pflanzerd58cec02017-07-18 15:44:21 +0100113inline int Accessor::fixed_point_position() const
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100114{
115 return _tensor.info()->fixed_point_position();
116}
117
Chunosovd621bca2017-11-03 17:33:15 +0700118inline QuantizationInfo Accessor::quantization_info() const
119{
120 return _tensor.info()->quantization_info();
121}
122
SiCong Li86b53332017-08-23 11:02:43 +0100123inline const void *Accessor::data() const
124{
125 return _tensor.buffer();
126}
127
128inline void *Accessor::data()
129{
130 return _tensor.buffer();
131}
132
Moritz Pflanzerd58cec02017-07-18 15:44:21 +0100133inline const void *Accessor::operator()(const Coordinates &coord) const
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100134{
135 return _tensor.ptr_to_element(coord);
136}
137
Moritz Pflanzerd58cec02017-07-18 15:44:21 +0100138inline void *Accessor::operator()(const Coordinates &coord)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100139{
140 return _tensor.ptr_to_element(coord);
141}
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100142} // namespace test
143} // namespace arm_compute
Moritz Pflanzerd58cec02017-07-18 15:44:21 +0100144#endif /* __ARM_COMPUTE_TEST_ACCESSOR_H__ */