blob: 65df0a5ddcbdfce163d2bac62034c82d1e8f89bd [file] [log] [blame]
Anthony Barbier7068f992017-10-26 15:23:08 +01001/*
Manuel Bottinic4ff82b2020-11-19 12:12:06 +00002 * Copyright (c) 2017-2020 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 */
Michalis Spyrouf4643372019-11-29 16:17:13 +000024#ifndef ARM_COMPUTE_TEST_GCACCESSOR_H
25#define ARM_COMPUTE_TEST_GCACCESSOR_H
Anthony Barbier7068f992017-10-26 15:23:08 +010026
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;
Manuel Bottinic4ff82b2020-11-19 12:12:06 +000053 /** Prevent instances of this class to be moved */
54 GCAccessor &operator=(GCAccessor &&) = delete;
Anthony Barbier7068f992017-10-26 15:23:08 +010055
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;
Anthony Barbier7068f992017-10-26 15:23:08 +010068 QuantizationInfo quantization_info() const override;
69 const void *operator()(const Coordinates &coord) const override;
70 void *operator()(const Coordinates &coord) override;
71
72private:
73 GCTensor &_tensor;
74};
75
76inline GCAccessor::GCAccessor(GCTensor &tensor)
77 : _tensor{ tensor }
78{
79 _tensor.map();
80}
81
82inline GCAccessor::~GCAccessor()
83{
84 _tensor.unmap();
85}
86
87inline TensorShape GCAccessor::shape() const
88{
89 return _tensor.info()->tensor_shape();
90}
91
92inline size_t GCAccessor::element_size() const
93{
94 return _tensor.info()->element_size();
95}
96
97inline size_t GCAccessor::size() const
98{
99 return _tensor.info()->total_size();
100}
101
102inline Format GCAccessor::format() const
103{
104 return _tensor.info()->format();
105}
106
Michele Di Giorgio4a65b982018-03-02 11:21:38 +0000107inline DataLayout GCAccessor::data_layout() const
108{
109 return _tensor.info()->data_layout();
110}
111
Anthony Barbier7068f992017-10-26 15:23:08 +0100112inline DataType GCAccessor::data_type() const
113{
114 return _tensor.info()->data_type();
115}
116
117inline int GCAccessor::num_channels() const
118{
119 return _tensor.info()->num_channels();
120}
121
122inline int GCAccessor::num_elements() const
123{
124 return _tensor.info()->tensor_shape().total_size();
125}
126
127inline PaddingSize GCAccessor::padding() const
128{
129 return _tensor.info()->padding();
130}
131
Anthony Barbier7068f992017-10-26 15:23:08 +0100132inline QuantizationInfo GCAccessor::quantization_info() const
133{
134 return _tensor.info()->quantization_info();
135}
136
137inline const void *GCAccessor::operator()(const Coordinates &coord) const
138{
139 return _tensor.ptr_to_element(coord);
140}
141
142inline void *GCAccessor::operator()(const Coordinates &coord)
143{
144 return _tensor.ptr_to_element(coord);
145}
146} // namespace test
147} // namespace arm_compute
Michalis Spyrouf4643372019-11-29 16:17:13 +0000148#endif /* ARM_COMPUTE_TEST_GCACCESSOR_H */