blob: 9e7b73f34f7950570f595d9c37b238d521a9e04a [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_CLACCESSOR_H__
25#define __ARM_COMPUTE_TEST_CLACCESSOR_H__
Anthony Barbier6ff3b192017-09-04 18:44:23 +010026
27#include "arm_compute/runtime/CL/CLTensor.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 CLTensor objects. */
35class CLAccessor : public IAccessor
36{
37public:
38 /** Create an accessor for the given @p tensor.
39 *
40 * @param[in, out] tensor To be accessed tensor.
41 *
42 * @note The CL memory is mapped by the constructor.
43 *
44 */
45 CLAccessor(CLTensor &tensor);
46
47 CLAccessor(const CLAccessor &) = delete;
48 CLAccessor &operator=(const CLAccessor &) = delete;
49 CLAccessor(CLAccessor &&) = default;
50 CLAccessor &operator=(CLAccessor &&) = default;
51
52 /** Destructor that unmaps the CL memory. */
53 ~CLAccessor();
54
Chunosovd621bca2017-11-03 17:33:15 +070055 TensorShape shape() const override;
56 size_t element_size() const override;
57 size_t size() const override;
58 Format format() const override;
59 DataType data_type() const override;
60 int num_channels() const override;
61 int num_elements() const override;
62 PaddingSize padding() const override;
63 int fixed_point_position() const override;
64 QuantizationInfo quantization_info() const override;
Anthony Barbier6ff3b192017-09-04 18:44:23 +010065 const void *operator()(const Coordinates &coord) const override;
66 void *operator()(const Coordinates &coord) override;
SiCong Li86b53332017-08-23 11:02:43 +010067 const void *data() const;
68 void *data();
Anthony Barbier6ff3b192017-09-04 18:44:23 +010069
70private:
71 CLTensor &_tensor;
72};
73
74inline CLAccessor::CLAccessor(CLTensor &tensor)
75 : _tensor{ tensor }
76{
77 _tensor.map();
78}
79
80inline CLAccessor::~CLAccessor()
81{
82 _tensor.unmap();
83}
84
85inline TensorShape CLAccessor::shape() const
86{
87 return _tensor.info()->tensor_shape();
88}
89
90inline size_t CLAccessor::element_size() const
91{
92 return _tensor.info()->element_size();
93}
94
95inline size_t CLAccessor::size() const
96{
97 return _tensor.info()->total_size();
98}
99
100inline Format CLAccessor::format() const
101{
102 return _tensor.info()->format();
103}
104
105inline DataType CLAccessor::data_type() const
106{
107 return _tensor.info()->data_type();
108}
109
110inline int CLAccessor::num_channels() const
111{
112 return _tensor.info()->num_channels();
113}
114
115inline int CLAccessor::num_elements() const
116{
117 return _tensor.info()->tensor_shape().total_size();
118}
119
Giorgio Arenaa2611812017-07-21 10:08:48 +0100120inline PaddingSize CLAccessor::padding() const
121{
122 return _tensor.info()->padding();
123}
124
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100125inline int CLAccessor::fixed_point_position() const
126{
127 return _tensor.info()->fixed_point_position();
128}
129
Chunosovd621bca2017-11-03 17:33:15 +0700130inline QuantizationInfo CLAccessor::quantization_info() const
131{
132 return _tensor.info()->quantization_info();
133}
134
SiCong Li86b53332017-08-23 11:02:43 +0100135inline const void *CLAccessor::data() const
136{
137 return _tensor.buffer();
138}
139
140inline void *CLAccessor::data()
141{
142 return _tensor.buffer();
143}
144
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100145inline const void *CLAccessor::operator()(const Coordinates &coord) const
146{
147 return _tensor.ptr_to_element(coord);
148}
149
150inline void *CLAccessor::operator()(const Coordinates &coord)
151{
152 return _tensor.ptr_to_element(coord);
153}
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100154} // namespace test
155} // namespace arm_compute
Moritz Pflanzerd58cec02017-07-18 15:44:21 +0100156#endif /* __ARM_COMPUTE_TEST_CLACCESSOR_H__ */