1 /*
2 * Copyright (c) 2017-2020 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
30 namespace arm_compute
31 {
32 namespace test
33 {
34 /** Accessor implementation for @ref GCTensor objects. */
35 class GCAccessor : public IAccessor
36 {
37 public:
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 /** Prevent instances of this class from being copy constructed */
48 GCAccessor(const GCAccessor &) = delete;
49 /** Prevent instances of this class from being copied */
50 GCAccessor &operator=(const GCAccessor &) = delete;
51 /** Allow instances of this class to be move constructed */
52 GCAccessor(GCAccessor &&) = default;
53 /** Prevent instances of this class to be moved */
54 GCAccessor &operator=(GCAccessor &&) = delete;
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;
63 DataLayout data_layout() const override;
64 DataType data_type() const override;
65 int num_channels() const override;
66 int num_elements() const override;
67 PaddingSize padding() const override;
68 QuantizationInfo quantization_info() const override;
69 const void *operator()(const Coordinates &coord) const override;
70 void *operator()(const Coordinates &coord) override;
71
72 private:
73 GCTensor &_tensor;
74 };
75
GCAccessor(GCTensor & tensor)76 inline GCAccessor::GCAccessor(GCTensor &tensor)
77 : _tensor{ tensor }
78 {
79 _tensor.map();
80 }
81
~GCAccessor()82 inline GCAccessor::~GCAccessor()
83 {
84 _tensor.unmap();
85 }
86
shape()87 inline TensorShape GCAccessor::shape() const
88 {
89 return _tensor.info()->tensor_shape();
90 }
91
element_size()92 inline size_t GCAccessor::element_size() const
93 {
94 return _tensor.info()->element_size();
95 }
96
size()97 inline size_t GCAccessor::size() const
98 {
99 return _tensor.info()->total_size();
100 }
101
format()102 inline Format GCAccessor::format() const
103 {
104 return _tensor.info()->format();
105 }
106
data_layout()107 inline DataLayout GCAccessor::data_layout() const
108 {
109 return _tensor.info()->data_layout();
110 }
111
data_type()112 inline DataType GCAccessor::data_type() const
113 {
114 return _tensor.info()->data_type();
115 }
116
num_channels()117 inline int GCAccessor::num_channels() const
118 {
119 return _tensor.info()->num_channels();
120 }
121
num_elements()122 inline int GCAccessor::num_elements() const
123 {
124 return _tensor.info()->tensor_shape().total_size();
125 }
126
padding()127 inline PaddingSize GCAccessor::padding() const
128 {
129 return _tensor.info()->padding();
130 }
131
quantization_info()132 inline QuantizationInfo GCAccessor::quantization_info() const
133 {
134 return _tensor.info()->quantization_info();
135 }
136
operator()137 inline const void *GCAccessor::operator()(const Coordinates &coord) const
138 {
139 return _tensor.ptr_to_element(coord);
140 }
141
operator()142 inline void *GCAccessor::operator()(const Coordinates &coord)
143 {
144 return _tensor.ptr_to_element(coord);
145 }
146 } // namespace test
147 } // namespace arm_compute
148 #endif /* ARM_COMPUTE_TEST_GCACCESSOR_H */
149