Compute Library
 23.08
Accessor.h
Go to the documentation of this file.
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_ACCESSOR_H
25 #define ARM_COMPUTE_TEST_ACCESSOR_H
26 
28 #include "tests/IAccessor.h"
29 
30 namespace arm_compute
31 {
32 namespace test
33 {
34 /** Accessor implementation for @ref Tensor objects. */
35 class Accessor : 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  */
43 
44  /** Prevent instances of this class from being copy constructed */
45  Accessor(const Accessor &) = delete;
46  /** Prevent instances of this class from being copied */
47  Accessor &operator=(const Accessor &) = delete;
48  /** Allow instances of this class to be move constructed */
49  Accessor(Accessor &&) = default;
50 
51  /** Get the tensor data.
52  *
53  * @return a constant pointer to the tensor data.
54  */
55  const void *data() const;
56  /** Get the tensor data.
57  *
58  * @return a pointer to the tensor data.
59  */
60  void *data();
61 
62  TensorShape shape() const override;
63  size_t element_size() const override;
64  size_t size() const override;
65  Format format() const override;
66  DataLayout data_layout() const override;
67  DataType data_type() const override;
68  int num_channels() const override;
69  int num_elements() const override;
70  PaddingSize padding() const override;
71  QuantizationInfo quantization_info() const override;
72  const void *operator()(const Coordinates &coord) const override;
73  void *operator()(const Coordinates &coord) override;
74 
75 private:
76  ITensor &_tensor;
77 };
78 
80  : _tensor{ tensor }
81 {
82 }
83 
85 {
86  return _tensor.info()->tensor_shape();
87 }
88 
89 inline size_t Accessor::element_size() const
90 {
91  return _tensor.info()->element_size();
92 }
93 
94 inline size_t Accessor::size() const
95 {
96  return _tensor.info()->total_size();
97 }
98 
99 inline Format Accessor::format() const
100 {
101  return _tensor.info()->format();
102 }
103 
105 {
106  return _tensor.info()->data_layout();
107 }
108 
110 {
111  return _tensor.info()->data_type();
112 }
113 
114 inline int Accessor::num_channels() const
115 {
116  return _tensor.info()->num_channels();
117 }
118 
119 inline int Accessor::num_elements() const
120 {
121  return _tensor.info()->tensor_shape().total_size();
122 }
123 
125 {
126  return _tensor.info()->padding();
127 }
128 
130 {
131  return _tensor.info()->quantization_info();
132 }
133 
134 inline const void *Accessor::data() const
135 {
136  return _tensor.buffer();
137 }
138 
139 inline void *Accessor::data()
140 {
141  return _tensor.buffer();
142 }
143 
144 inline const void *Accessor::operator()(const Coordinates &coord) const
145 {
146  return _tensor.ptr_to_element(coord);
147 }
148 
149 inline void *Accessor::operator()(const Coordinates &coord)
150 {
151  return _tensor.ptr_to_element(coord);
152 }
153 } // namespace test
154 } // namespace arm_compute
155 #endif /* ARM_COMPUTE_TEST_ACCESSOR_H */
arm_compute::ITensorInfo::data_layout
virtual DataLayout data_layout() const =0
Get the data layout of the tensor.
arm_compute::ITensorInfo::num_channels
virtual size_t num_channels() const =0
The number of channels for each tensor element.
arm_compute::ITensorInfo::tensor_shape
virtual const TensorShape & tensor_shape() const =0
Size for each dimension of the tensor.
arm_compute::QuantizationInfo
Quantization information.
Definition: QuantizationInfo.h:68
arm_compute::DataLayout
DataLayout
[DataLayout enum definition]
Definition: CoreTypes.h:109
arm_compute::BorderSize
Container for 2D border size.
Definition: Types.h:242
arm_compute::TensorShape
Shape of a tensor.
Definition: TensorShape.h:39
arm_compute::ITensorInfo::element_size
virtual size_t element_size() const =0
Element size in bytes calculated as data_size() * num_channels()
arm_compute::test::Accessor::operator=
Accessor & operator=(const Accessor &)=delete
Prevent instances of this class from being copied.
arm_compute::test::Accessor::data
const void * data() const
Get the tensor data.
Definition: Accessor.h:134
arm_compute::ITensor
Interface for CPU tensor.
Definition: ITensor.h:36
arm_compute::test::Accessor::padding
PaddingSize padding() const override
Available padding around the tensor.
Definition: Accessor.h:124
arm_compute::test::Accessor
Accessor implementation for Tensor objects.
Definition: Accessor.h:35
arm_compute::test::Accessor::Accessor
Accessor(ITensor &tensor)
Create an accessor for the given tensor.
Definition: Accessor.h:79
arm_compute::test::Accessor::data_layout
DataLayout data_layout() const override
Data layout of the tensor.
Definition: Accessor.h:104
arm_compute::test::Accessor::shape
TensorShape shape() const override
Shape of the tensor.
Definition: Accessor.h:84
arm_compute::ITensor::info
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor's metadata.
IAccessor.h
arm_compute::TensorShape::total_size
size_t total_size() const
Collapses all dimensions to a single linear total size.
Definition: TensorShape.h:176
arm_compute::test::Accessor::data_type
DataType data_type() const override
Data type of the tensor.
Definition: Accessor.h:109
arm_compute::test::Accessor::num_channels
int num_channels() const override
Number of channels of the tensor.
Definition: Accessor.h:114
arm_compute::test::Accessor::element_size
size_t element_size() const override
Size of each element in the tensor in bytes.
Definition: Accessor.h:89
arm_compute::ITensorInfo::data_type
virtual DataType data_type() const =0
Data type used for each element of the tensor.
arm_compute::test::Accessor::num_elements
int num_elements() const override
Number of elements of the tensor.
Definition: Accessor.h:119
arm_compute::test::Accessor::quantization_info
QuantizationInfo quantization_info() const override
Quantization info in case of asymmetric quantized type.
Definition: Accessor.h:129
arm_compute::test::Accessor::operator()
const void * operator()(const Coordinates &coord) const override
Read only access to the specified element.
Definition: Accessor.h:144
arm_compute::test::Accessor::format
Format format() const override
Image format of the tensor.
Definition: Accessor.h:99
arm_compute::Coordinates
Coordinates of an item.
Definition: Coordinates.h:37
tensor
CLTensor * tensor
Pointer to the auxiliary tensor.
Definition: ClWorkloadRuntime.cpp:66
Tensor.h
arm_compute::Format
Format
Image colour formats.
Definition: CoreTypes.h:57
arm_compute::ITensorInfo::quantization_info
virtual QuantizationInfo quantization_info() const =0
Get the quantization settings (scale and offset) of the tensor.
arm_compute::test::Accessor::size
size_t size() const override
Total size of the tensor in bytes.
Definition: Accessor.h:94
arm_compute
Copyright (c) 2017-2023 Arm Limited.
Definition: introduction.dox:24
arm_compute::ITensor::ptr_to_element
uint8_t * ptr_to_element(const Coordinates &id) const
Return a pointer to the element at the passed coordinates.
Definition: ITensor.h:63
arm_compute::test::IAccessor
Common interface to provide information and access to tensor like structures.
Definition: IAccessor.h:38
arm_compute::ITensorInfo::format
virtual Format format() const =0
Colour format of the image.
arm_compute::ITensorInfo::total_size
virtual size_t total_size() const =0
Returns the total size of the tensor in bytes.
arm_compute::DataType
DataType
Available data types.
Definition: CoreTypes.h:82
arm_compute::ITensor::buffer
virtual uint8_t * buffer() const =0
Interface to be implemented by the child class to return a pointer to CPU memory.
arm_compute::ITensorInfo::padding
virtual PaddingSize padding() const =0
Padding of tensor.