blob: 49bd12f327caa1383259441da533dd88ad1bd9f2 [file] [log] [blame]
Isabella Gottardib797fa22017-06-23 15:02:11 +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_CLLUTACCESSOR_H__
25#define __ARM_COMPUTE_TEST_CL_CLLUTACCESSOR_H__
26
27#include "ILutAccessor.h"
28
29#include "arm_compute/runtime/CL/CLLut.h"
30
31namespace arm_compute
32{
33namespace test
34{
35namespace cl
36{
37/** Accessor implementation for @ref CLLut objects. */
38template <typename T>
39class CLLutAccessor : public ILutAccessor<T>
40{
41public:
42 /** Create an accessor for the given @p CLLut.
43 */
44 CLLutAccessor(CLLut &lut)
45 : _lut{ lut }
46 {
47 _lut.map(true);
48 }
49 ~CLLutAccessor()
50 {
51 _lut.unmap();
52 }
53
54 CLLutAccessor(const CLLutAccessor &) = delete;
55 CLLutAccessor &operator=(const CLLutAccessor &) = delete;
56 CLLutAccessor(CLLutAccessor &&) = default;
57 CLLutAccessor &operator=(CLLutAccessor &&) = default;
58
59 int num_elements() const override
60 {
61 return _lut.num_elements();
62 }
63
64 const T &operator[](T input_value) const override
65 {
66 auto lut = reinterpret_cast<T *>(_lut.buffer());
67 int32_t real_index = _lut.index_offset() + static_cast<int32_t>(input_value);
68
69 if(0 <= real_index && real_index < num_elements())
70 {
71 return lut[real_index];
72 }
73 ARM_COMPUTE_ERROR("Error index not in range.");
74 }
75
76 T &operator[](T input_value) override
77 {
78 auto lut = reinterpret_cast<T *>(_lut.buffer());
79 int32_t real_index = _lut.index_offset() + static_cast<int32_t>(input_value);
80
81 if(0 <= real_index && real_index < num_elements())
82 {
83 return lut[real_index];
84 }
85 ARM_COMPUTE_ERROR("Error index not in range.");
86 }
87
88private:
89 CLLut &_lut;
90};
91
92} // namespace cl
93} // namespace test
94} // namespace arm_compute
95#endif /* __ARM_COMPUTE_TEST_CL_CLLUTACCESSOR_H__ */