Compute Library
 20.05
GCAccessor.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017-2019 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 
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  /** Allow instances of this class to be moved */
54  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;
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 
77  : _tensor{ tensor }
78 {
79  _tensor.map();
80 }
81 
83 {
84  _tensor.unmap();
85 }
86 
88 {
89  return _tensor.info()->tensor_shape();
90 }
91 
92 inline size_t GCAccessor::element_size() const
93 {
94  return _tensor.info()->element_size();
95 }
96 
97 inline size_t GCAccessor::size() const
98 {
99  return _tensor.info()->total_size();
100 }
101 
103 {
104  return _tensor.info()->format();
105 }
106 
108 {
109  return _tensor.info()->data_layout();
110 }
111 
113 {
114  return _tensor.info()->data_type();
115 }
116 
117 inline int GCAccessor::num_channels() const
118 {
119  return _tensor.info()->num_channels();
120 }
121 
122 inline int GCAccessor::num_elements() const
123 {
124  return _tensor.info()->tensor_shape().total_size();
125 }
126 
128 {
129  return _tensor.info()->padding();
130 }
131 
133 {
134  return _tensor.info()->quantization_info();
135 }
136 
137 inline const void *GCAccessor::operator()(const Coordinates &coord) const
138 {
139  return _tensor.ptr_to_element(coord);
140 }
141 
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 */
uint8_t * ptr_to_element(const Coordinates &id) const
Return a pointer to the element at the passed coordinates.
Definition: ITensor.h:63
Shape of a tensor.
Definition: TensorShape.h:39
QuantizationInfo quantization_info() const override
Quantization info in case of asymmetric quantized type.
Definition: GCAccessor.h:132
const void * operator()(const Coordinates &coord) const override
Read only access to the specified element.
Definition: GCAccessor.h:137
GCAccessor(GCTensor &tensor)
Create an accessor for the given tensor.
Definition: GCAccessor.h:76
Accessor implementation for GCTensor objects.
Definition: GCAccessor.h:35
Container for 2D border size.
Definition: Types.h:272
size_t num_channels() const override
The number of channels for each tensor element.
Definition: TensorInfo.h:257
DataLayout data_layout() const override
Get the data layout of the tensor.
Definition: TensorInfo.h:315
int num_channels() const override
Number of channels of the tensor.
Definition: GCAccessor.h:117
Format format() const override
Image format of the tensor.
Definition: GCAccessor.h:102
QuantizationInfo quantization_info() const override
Get the quantization settings (scale and offset) of the tensor.
Definition: TensorInfo.h:311
PaddingSize padding() const override
Padding of tensor.
Definition: TensorInfo.h:277
Interface for OpenGL ES tensor.
Definition: GCTensor.h:38
Copyright (c) 2017-2020 ARM Limited.
Format format() const override
Colour format of the image.
Definition: TensorInfo.h:269
DataType data_type() const override
Data type used for each element of the tensor.
Definition: TensorInfo.h:265
Quantization information.
Format
Image colour formats.
Definition: Types.h:54
PaddingSize padding() const override
Available padding around the tensor.
Definition: GCAccessor.h:127
size_t total_size() const override
Returns the total size of the tensor in bytes.
Definition: TensorInfo.h:273
Coordinates of an item.
Definition: Coordinates.h:37
size_t total_size() const
Collapses all dimensions to a single linear total size.
Definition: TensorShape.h:171
~GCAccessor()
Destructor that unmaps the GLES memory.
Definition: GCAccessor.h:82
DataType data_type() const override
Data type of the tensor.
Definition: GCAccessor.h:112
void unmap()
Enqueue an unmap operation of the allocated and mapped buffer on the given queue.
Definition: GCTensor.cpp:69
int num_elements() const override
Number of elements of the tensor.
Definition: GCAccessor.h:122
size_t size() const override
Total size of the tensor in bytes.
Definition: GCAccessor.h:97
TensorInfo * info() const override
Interface to be implemented by the child class to return the tensor's metadata.
Definition: GCTensor.cpp:39
Common interface to provide information and access to tensor like structures.
Definition: IAccessor.h:37
void map(bool blocking=true)
Enqueue a map operation of the allocated buffer on the given queue.
Definition: GCTensor.cpp:64
DataLayout data_layout() const override
Data layout of the tensor.
Definition: GCAccessor.h:107
TensorShape shape() const override
Shape of the tensor.
Definition: GCAccessor.h:87
const TensorShape & tensor_shape() const override
Size for each dimension of the tensor.
Definition: TensorInfo.h:261
DataType
Available data types.
Definition: Types.h:77
size_t element_size() const override
Size of each element in the tensor in bytes.
Definition: GCAccessor.h:92
DataLayout
[DataLayout enum definition]
Definition: Types.h:120
size_t element_size() const override
Element size in bytes calculated as data_size() * num_channels()
Definition: TensorInfo.h:249
GCAccessor & operator=(const GCAccessor &)=delete
Prevent instances of this class from being copied.