blob: c7dd1f6510c8acc2cb133bbb117a06c9eb392b5c [file] [log] [blame]
Georgios Pinitas58bce682020-11-13 11:38:58 +00001/*
Michele Di Giorgio4fc10b32021-04-30 18:30:41 +01002 * Copyright (c) 2020-2021 Arm Limited.
Georgios Pinitas58bce682020-11-13 11:38:58 +00003 *
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_LOGICAL_FIXTURE
25#define ARM_COMPUTE_TEST_LOGICAL_FIXTURE
26
27#include "arm_compute/core/TensorShape.h"
28#include "arm_compute/core/Types.h"
29#include "tests/AssetsLibrary.h"
30#include "tests/Globals.h"
31#include "tests/IAccessor.h"
32#include "tests/framework/Asserts.h"
33#include "tests/framework/Fixture.h"
34#include "tests/validation/reference/Logical.h"
35
36namespace arm_compute
37{
38namespace test
39{
40namespace validation
41{
42template <typename TensorType, typename AccessorType, typename FunctionType, typename T>
43class LogicalOperationValidationFixtureBase : public framework::Fixture
44{
45protected:
46 template <typename U>
47 void fill(U &&tensor, int i)
48 {
Sang-Hoon Park2dbc5862020-11-18 13:52:11 +000049 constexpr auto zero = static_cast<uint8_t>(0);
50 constexpr auto one = static_cast<uint8_t>(0x1);
51 constexpr auto mixed = static_cast<uint8_t>(0xAA);
52 constexpr auto mixed_bitwise_not = static_cast<uint8_t>((~0xAA));
Georgios Pinitas58bce682020-11-13 11:38:58 +000053
54 library->fill_static_values(tensor, i == 0 ?
55 std::vector<uint8_t> { zero, one, zero, one, mixed, zero, mixed } :
56 std::vector<uint8_t> { zero, zero, one, one, zero, mixed, mixed_bitwise_not });
57 }
58
59 void allocate_tensor(std::initializer_list<TensorType *> tensors)
60 {
61 for(auto t : tensors)
62 {
Michele Di Giorgio4fc10b32021-04-30 18:30:41 +010063 ARM_COMPUTE_ASSERT(t->info()->is_resizable());
Georgios Pinitas58bce682020-11-13 11:38:58 +000064 t->allocator()->allocate();
Michele Di Giorgio4fc10b32021-04-30 18:30:41 +010065 ARM_COMPUTE_ASSERT(!t->info()->is_resizable());
Georgios Pinitas58bce682020-11-13 11:38:58 +000066 }
67 }
68
69 TensorType _target{};
70 SimpleTensor<T> _reference{};
71};
72
Sang-Hoon Park75eea332020-11-13 13:44:13 +000073template <typename T>
74using LogicalBinaryRefFunctionPtrType = SimpleTensor<T>(const SimpleTensor<T> &, const SimpleTensor<T> &);
75
76template <typename TensorType, typename AccessorType, typename FunctionType, typename T, LogicalBinaryRefFunctionPtrType<T> RefFunction>
Georgios Pinitas58bce682020-11-13 11:38:58 +000077class LogicalBinaryOperationValidationFixture : public LogicalOperationValidationFixtureBase<TensorType, AccessorType, FunctionType, T>
78{
79 using Parent = LogicalOperationValidationFixtureBase<TensorType, AccessorType, FunctionType, T>;
80
81public:
82 template <typename...>
83 void setup(TensorShape shape0, TensorShape shape1)
84 {
85 Parent::_target = compute_target(shape0, shape1);
86 Parent::_reference = compute_reference(shape0, shape1);
87 }
88
89private:
90 TensorType compute_target(const TensorShape &shape0, const TensorShape &shape1)
91 {
92 TensorType src0 = create_tensor<TensorType>(shape0, _data_type);
93 TensorType src1 = create_tensor<TensorType>(shape1, _data_type);
94 TensorType dst = create_tensor<TensorType>(TensorShape::broadcast_shape(shape0, shape1), _data_type);
95
96 FunctionType logical_binary_op;
97
98 logical_binary_op.configure(&src0, &src1, &dst);
99
100 Parent::allocate_tensor({ &src0, &src1, &dst });
101
102 Parent::fill(AccessorType(src0), 0);
103 Parent::fill(AccessorType(src1), 1);
104
105 logical_binary_op.run();
106
107 return dst;
108 }
109
110 SimpleTensor<T> compute_reference(const TensorShape &shape0, const TensorShape &shape1)
111 {
112 // Create reference
113 SimpleTensor<T> src0{ shape0, _data_type };
114 SimpleTensor<T> src1{ shape1, _data_type };
115
116 // Fill reference
117 Parent::fill(src0, 0);
118 Parent::fill(src1, 1);
119
Sang-Hoon Park75eea332020-11-13 13:44:13 +0000120 return RefFunction(src0, src1);
Georgios Pinitas58bce682020-11-13 11:38:58 +0000121 }
122
Sang-Hoon Park75eea332020-11-13 13:44:13 +0000123 static constexpr auto _data_type = DataType::U8;
Georgios Pinitas58bce682020-11-13 11:38:58 +0000124};
125
126template <typename TensorType, typename AccessorType, typename FunctionType, typename T>
Sang-Hoon Park75eea332020-11-13 13:44:13 +0000127using LogicalOrValidationFixture = LogicalBinaryOperationValidationFixture<TensorType, AccessorType, FunctionType, T, &reference::logical_or<T>>;
128
129template <typename TensorType, typename AccessorType, typename FunctionType, typename T>
130using LogicalAndValidationFixture = LogicalBinaryOperationValidationFixture<TensorType, AccessorType, FunctionType, T, &reference::logical_and<T>>;
131
132template <typename TensorType, typename AccessorType, typename FunctionType, typename T>
Georgios Pinitas58bce682020-11-13 11:38:58 +0000133class LogicalNotValidationFixture : public LogicalOperationValidationFixtureBase<TensorType, AccessorType, FunctionType, T>
134{
135 using Parent = LogicalOperationValidationFixtureBase<TensorType, AccessorType, FunctionType, T>;
136
137public:
138 template <typename...>
139 void setup(TensorShape shape, DataType data_type)
140 {
141 Parent::_target = compute_target(shape, data_type);
142 Parent::_reference = compute_reference(shape, data_type);
143 }
144
145private:
146 TensorType compute_target(const TensorShape &shape, DataType data_type)
147 {
148 TensorType src = create_tensor<TensorType>(shape, data_type);
149 TensorType dst = create_tensor<TensorType>(shape, data_type);
150
151 FunctionType logical_not;
152
153 logical_not.configure(&src, &dst);
154
155 Parent::allocate_tensor({ &src, &dst });
156
157 Parent::fill(AccessorType(src), 0);
158
159 logical_not.run();
160
161 return dst;
162 }
163
164 SimpleTensor<T> compute_reference(const TensorShape &shape, DataType data_type)
165 {
166 // Create reference
167 SimpleTensor<T> src{ shape, data_type };
168
169 // Fill reference
170 Parent::fill(src, 0);
171
172 return reference::logical_not<T>(src);
173 }
174};
175} // namespace validation
176} // namespace test
177} // namespace arm_compute
Sang-Hoon Park75eea332020-11-13 13:44:13 +0000178#endif /* ARM_COMPUTE_TEST_LOGICAL_FIXTURE */