blob: 21db3ee23dbd4c042844eaf2eba56ed132c9c299 [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
2 * Copyright (c) 2017 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_CL_CLACCESSOR_H__
25#define __ARM_COMPUTE_TEST_CL_CLACCESSOR_H__
26
27#include "IAccessor.h"
28
29#include "arm_compute/runtime/CL/CLTensor.h"
30
31namespace arm_compute
32{
33namespace test
34{
35namespace cl
36{
37/** Accessor implementation for @ref CLTensor objects. */
38class CLAccessor : public IAccessor
39{
40public:
41 /** Create an accessor for the given @p tensor.
42 *
43 * @param[in, out] tensor To be accessed tensor.
44 *
45 * @note The CL memory is mapped by the constructor.
46 *
47 */
48 CLAccessor(CLTensor &tensor);
49
50 CLAccessor(const CLAccessor &) = delete;
51 CLAccessor &operator=(const CLAccessor &) = delete;
52 CLAccessor(CLAccessor &&) = default;
53 CLAccessor &operator=(CLAccessor &&) = default;
54
55 /** Destructor that unmaps the CL memory. */
56 ~CLAccessor();
57
58 TensorShape shape() const override;
59 size_t element_size() const override;
60 size_t size() const override;
61 Format format() const override;
62 DataType data_type() const override;
63 int num_channels() const override;
64 int num_elements() const override;
65 int fixed_point_position() const override;
66 const void *operator()(const Coordinates &coord) const override;
67 void *operator()(const Coordinates &coord) override;
68
69private:
70 CLTensor &_tensor;
71};
72
73inline CLAccessor::CLAccessor(CLTensor &tensor)
74 : _tensor{ tensor }
75{
76 _tensor.map();
77}
78
79inline CLAccessor::~CLAccessor()
80{
81 _tensor.unmap();
82}
83
84inline TensorShape CLAccessor::shape() const
85{
86 return _tensor.info()->tensor_shape();
87}
88
89inline size_t CLAccessor::element_size() const
90{
91 return _tensor.info()->element_size();
92}
93
94inline size_t CLAccessor::size() const
95{
96 return _tensor.info()->total_size();
97}
98
99inline Format CLAccessor::format() const
100{
101 return _tensor.info()->format();
102}
103
104inline DataType CLAccessor::data_type() const
105{
106 return _tensor.info()->data_type();
107}
108
109inline int CLAccessor::num_channels() const
110{
111 return _tensor.info()->num_channels();
112}
113
114inline int CLAccessor::num_elements() const
115{
116 return _tensor.info()->tensor_shape().total_size();
117}
118
119inline int CLAccessor::fixed_point_position() const
120{
121 return _tensor.info()->fixed_point_position();
122}
123
124inline const void *CLAccessor::operator()(const Coordinates &coord) const
125{
126 return _tensor.ptr_to_element(coord);
127}
128
129inline void *CLAccessor::operator()(const Coordinates &coord)
130{
131 return _tensor.ptr_to_element(coord);
132}
133} // cl
134} // namespace test
135} // namespace arm_compute
136#endif