blob: 60dc963ba7f3c078180b7d5603731cd7723f759c [file] [log] [blame]
Georgios Pinitas58bce682020-11-13 11:38:58 +00001/*
Matthew Bentham945b8da2023-07-12 11:54:59 +00002 * Copyright (c) 2020-2021, 2023 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:
Georgios Pinitas58bce682020-11-13 11:38:58 +000082 void setup(TensorShape shape0, TensorShape shape1)
83 {
84 Parent::_target = compute_target(shape0, shape1);
85 Parent::_reference = compute_reference(shape0, shape1);
86 }
87
88private:
89 TensorType compute_target(const TensorShape &shape0, const TensorShape &shape1)
90 {
91 TensorType src0 = create_tensor<TensorType>(shape0, _data_type);
92 TensorType src1 = create_tensor<TensorType>(shape1, _data_type);
93 TensorType dst = create_tensor<TensorType>(TensorShape::broadcast_shape(shape0, shape1), _data_type);
94
95 FunctionType logical_binary_op;
96
97 logical_binary_op.configure(&src0, &src1, &dst);
98
99 Parent::allocate_tensor({ &src0, &src1, &dst });
100
101 Parent::fill(AccessorType(src0), 0);
102 Parent::fill(AccessorType(src1), 1);
103
104 logical_binary_op.run();
105
106 return dst;
107 }
108
109 SimpleTensor<T> compute_reference(const TensorShape &shape0, const TensorShape &shape1)
110 {
111 // Create reference
112 SimpleTensor<T> src0{ shape0, _data_type };
113 SimpleTensor<T> src1{ shape1, _data_type };
114
115 // Fill reference
116 Parent::fill(src0, 0);
117 Parent::fill(src1, 1);
118
Sang-Hoon Park75eea332020-11-13 13:44:13 +0000119 return RefFunction(src0, src1);
Georgios Pinitas58bce682020-11-13 11:38:58 +0000120 }
121
Sang-Hoon Park75eea332020-11-13 13:44:13 +0000122 static constexpr auto _data_type = DataType::U8;
Georgios Pinitas58bce682020-11-13 11:38:58 +0000123};
124
125template <typename TensorType, typename AccessorType, typename FunctionType, typename T>
Sang-Hoon Park75eea332020-11-13 13:44:13 +0000126using LogicalOrValidationFixture = LogicalBinaryOperationValidationFixture<TensorType, AccessorType, FunctionType, T, &reference::logical_or<T>>;
127
128template <typename TensorType, typename AccessorType, typename FunctionType, typename T>
129using LogicalAndValidationFixture = LogicalBinaryOperationValidationFixture<TensorType, AccessorType, FunctionType, T, &reference::logical_and<T>>;
130
131template <typename TensorType, typename AccessorType, typename FunctionType, typename T>
Georgios Pinitas58bce682020-11-13 11:38:58 +0000132class LogicalNotValidationFixture : public LogicalOperationValidationFixtureBase<TensorType, AccessorType, FunctionType, T>
133{
134 using Parent = LogicalOperationValidationFixtureBase<TensorType, AccessorType, FunctionType, T>;
135
136public:
Georgios Pinitas58bce682020-11-13 11:38:58 +0000137 void setup(TensorShape shape, DataType data_type)
138 {
139 Parent::_target = compute_target(shape, data_type);
140 Parent::_reference = compute_reference(shape, data_type);
141 }
142
143private:
144 TensorType compute_target(const TensorShape &shape, DataType data_type)
145 {
146 TensorType src = create_tensor<TensorType>(shape, data_type);
147 TensorType dst = create_tensor<TensorType>(shape, data_type);
148
149 FunctionType logical_not;
150
151 logical_not.configure(&src, &dst);
152
153 Parent::allocate_tensor({ &src, &dst });
154
155 Parent::fill(AccessorType(src), 0);
156
157 logical_not.run();
158
159 return dst;
160 }
161
162 SimpleTensor<T> compute_reference(const TensorShape &shape, DataType data_type)
163 {
164 // Create reference
165 SimpleTensor<T> src{ shape, data_type };
166
167 // Fill reference
168 Parent::fill(src, 0);
169
170 return reference::logical_not<T>(src);
171 }
172};
173} // namespace validation
174} // namespace test
175} // namespace arm_compute
Sang-Hoon Park75eea332020-11-13 13:44:13 +0000176#endif /* ARM_COMPUTE_TEST_LOGICAL_FIXTURE */