blob: 0f7c491c3c72a5d68d2f9d1827ceb1dd0b309b8d [file] [log] [blame]
Anthony Barbier7068f992017-10-26 15:23:08 +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 */
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
30namespace arm_compute
31{
32namespace test
33{
34/** Accessor implementation for @ref GCTensor objects. */
35class GCAccessor : 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 GLES memory is mapped by the constructor.
43 *
44 */
45 GCAccessor(GCTensor &tensor);
46
47 GCAccessor(const GCAccessor &) = delete;
48 GCAccessor &operator=(const GCAccessor &) = delete;
49 GCAccessor(GCAccessor &&) = default;
50 GCAccessor &operator=(GCAccessor &&) = default;
51
52 /** Destructor that unmaps the GLES memory. */
53 ~GCAccessor();
54
55 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;
65 const void *operator()(const Coordinates &coord) const override;
66 void *operator()(const Coordinates &coord) override;
67
68private:
69 GCTensor &_tensor;
70};
71
72inline GCAccessor::GCAccessor(GCTensor &tensor)
73 : _tensor{ tensor }
74{
75 _tensor.map();
76}
77
78inline GCAccessor::~GCAccessor()
79{
80 _tensor.unmap();
81}
82
83inline TensorShape GCAccessor::shape() const
84{
85 return _tensor.info()->tensor_shape();
86}
87
88inline size_t GCAccessor::element_size() const
89{
90 return _tensor.info()->element_size();
91}
92
93inline size_t GCAccessor::size() const
94{
95 return _tensor.info()->total_size();
96}
97
98inline Format GCAccessor::format() const
99{
100 return _tensor.info()->format();
101}
102
103inline DataType GCAccessor::data_type() const
104{
105 return _tensor.info()->data_type();
106}
107
108inline int GCAccessor::num_channels() const
109{
110 return _tensor.info()->num_channels();
111}
112
113inline int GCAccessor::num_elements() const
114{
115 return _tensor.info()->tensor_shape().total_size();
116}
117
118inline PaddingSize GCAccessor::padding() const
119{
120 return _tensor.info()->padding();
121}
122
123inline int GCAccessor::fixed_point_position() const
124{
125 return _tensor.info()->fixed_point_position();
126}
127
128inline QuantizationInfo GCAccessor::quantization_info() const
129{
130 return _tensor.info()->quantization_info();
131}
132
133inline const void *GCAccessor::operator()(const Coordinates &coord) const
134{
135 return _tensor.ptr_to_element(coord);
136}
137
138inline void *GCAccessor::operator()(const Coordinates &coord)
139{
140 return _tensor.ptr_to_element(coord);
141}
142} // namespace test
143} // namespace arm_compute
144#endif /* __ARM_COMPUTE_TEST_GCACCESSOR_H__ */