blob: df0fbaa72e4a6affa870774dd904a1dcc15282bc [file] [log] [blame]
Anthony Barbier7068f992017-10-26 15:23:08 +01001/*
Michele Di Giorgio4a65b982018-03-02 11:21:38 +00002 * Copyright (c) 2017-2018 ARM Limited.
Anthony Barbier7068f992017-10-26 15:23:08 +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 */
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
Alex Gildayc357c472018-03-21 13:54:09 +000047 /** Prevent instances of this class from being copy constructed */
Anthony Barbier7068f992017-10-26 15:23:08 +010048 GCAccessor(const GCAccessor &) = delete;
Alex Gildayc357c472018-03-21 13:54:09 +000049 /** Prevent instances of this class from being copied */
Anthony Barbier7068f992017-10-26 15:23:08 +010050 GCAccessor &operator=(const GCAccessor &) = delete;
Alex Gildayc357c472018-03-21 13:54:09 +000051 /** Allow instances of this class to be move constructed */
52 GCAccessor(GCAccessor &&) = default;
53 /** Allow instances of this class to be moved */
Anthony Barbier7068f992017-10-26 15:23:08 +010054 GCAccessor &operator=(GCAccessor &&) = default;
55
56 /** Destructor that unmaps the GLES memory. */
57 ~GCAccessor();
58
59 TensorShape shape() const override;
60 size_t element_size() const override;
61 size_t size() const override;
62 Format format() const override;
Michele Di Giorgio4a65b982018-03-02 11:21:38 +000063 DataLayout data_layout() const override;
Anthony Barbier7068f992017-10-26 15:23:08 +010064 DataType data_type() const override;
65 int num_channels() const override;
66 int num_elements() const override;
67 PaddingSize padding() const override;
68 int fixed_point_position() const override;
69 QuantizationInfo quantization_info() const override;
70 const void *operator()(const Coordinates &coord) const override;
71 void *operator()(const Coordinates &coord) override;
72
73private:
74 GCTensor &_tensor;
75};
76
77inline GCAccessor::GCAccessor(GCTensor &tensor)
78 : _tensor{ tensor }
79{
80 _tensor.map();
81}
82
83inline GCAccessor::~GCAccessor()
84{
85 _tensor.unmap();
86}
87
88inline TensorShape GCAccessor::shape() const
89{
90 return _tensor.info()->tensor_shape();
91}
92
93inline size_t GCAccessor::element_size() const
94{
95 return _tensor.info()->element_size();
96}
97
98inline size_t GCAccessor::size() const
99{
100 return _tensor.info()->total_size();
101}
102
103inline Format GCAccessor::format() const
104{
105 return _tensor.info()->format();
106}
107
Michele Di Giorgio4a65b982018-03-02 11:21:38 +0000108inline DataLayout GCAccessor::data_layout() const
109{
110 return _tensor.info()->data_layout();
111}
112
Anthony Barbier7068f992017-10-26 15:23:08 +0100113inline DataType GCAccessor::data_type() const
114{
115 return _tensor.info()->data_type();
116}
117
118inline int GCAccessor::num_channels() const
119{
120 return _tensor.info()->num_channels();
121}
122
123inline int GCAccessor::num_elements() const
124{
125 return _tensor.info()->tensor_shape().total_size();
126}
127
128inline PaddingSize GCAccessor::padding() const
129{
130 return _tensor.info()->padding();
131}
132
133inline int GCAccessor::fixed_point_position() const
134{
135 return _tensor.info()->fixed_point_position();
136}
137
138inline QuantizationInfo GCAccessor::quantization_info() const
139{
140 return _tensor.info()->quantization_info();
141}
142
143inline const void *GCAccessor::operator()(const Coordinates &coord) const
144{
145 return _tensor.ptr_to_element(coord);
146}
147
148inline void *GCAccessor::operator()(const Coordinates &coord)
149{
150 return _tensor.ptr_to_element(coord);
151}
152} // namespace test
153} // namespace arm_compute
154#endif /* __ARM_COMPUTE_TEST_GCACCESSOR_H__ */