blob: 43da0ae49cb2f1741f18bea8ddecafd70e731da7 [file] [log] [blame]
Georgios Pinitas7900a9e2018-11-23 11:44:58 +00001/*
Michele Di Giorgiod9eaf612020-07-08 11:12:57 +01002 * Copyright (c) 2018-2020 Arm Limited.
Georgios Pinitas7900a9e2018-11-23 11:44: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_COMPARISON_FIXTURE
25#define ARM_COMPUTE_TEST_COMPARISON_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/Helpers.h"
35#include "tests/validation/reference/Comparisons.h"
36
37namespace arm_compute
38{
39namespace test
40{
41namespace validation
42{
43template <typename TensorType, typename AccessorType, typename FunctionType, typename T>
44class ComparisonValidationGenericFixture : public framework::Fixture
45{
46public:
47 template <typename...>
48 void setup(ComparisonOperation op, const TensorShape &shape0, const TensorShape &shape1, DataType data_type, QuantizationInfo qinfo0, QuantizationInfo qinfo1)
49 {
50 _target = compute_target(op, shape0, shape1, data_type, qinfo0, qinfo1);
51 _reference = compute_reference(op, shape0, shape1, data_type, qinfo0, qinfo1);
52 }
53
54protected:
55 template <typename U>
56 void fill(U &&tensor, int i)
57 {
58 library->fill_tensor_uniform(tensor, i);
59 }
60
61 TensorType compute_target(ComparisonOperation op,
62 const TensorShape &shape0, const TensorShape &shape1, DataType data_type,
63 QuantizationInfo qinfo0, QuantizationInfo qinfo1)
64 {
65 // Create tensors
66 TensorType ref_src1 = create_tensor<TensorType>(shape0, data_type, 1, qinfo0);
67 TensorType ref_src2 = create_tensor<TensorType>(shape1, data_type, 1, qinfo1);
68 TensorType dst = create_tensor<TensorType>(TensorShape::broadcast_shape(shape0, shape1), DataType::U8);
69
70 // Create and configure function
71 FunctionType comp_op;
72 comp_op.configure(&ref_src1, &ref_src2, &dst, op);
73
74 ARM_COMPUTE_EXPECT(ref_src1.info()->is_resizable(), framework::LogLevel::ERRORS);
75 ARM_COMPUTE_EXPECT(ref_src2.info()->is_resizable(), framework::LogLevel::ERRORS);
76 ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS);
77
78 // Allocate tensors
79 ref_src1.allocator()->allocate();
80 ref_src2.allocator()->allocate();
81 dst.allocator()->allocate();
82
83 ARM_COMPUTE_EXPECT(!ref_src1.info()->is_resizable(), framework::LogLevel::ERRORS);
84 ARM_COMPUTE_EXPECT(!ref_src2.info()->is_resizable(), framework::LogLevel::ERRORS);
85 ARM_COMPUTE_EXPECT(!dst.info()->is_resizable(), framework::LogLevel::ERRORS);
86
87 // Fill tensors
88 fill(AccessorType(ref_src1), 0);
89 fill(AccessorType(ref_src2), 1);
90
91 // Compute function
92 comp_op.run();
93
94 return dst;
95 }
96
97 SimpleTensor<uint8_t> compute_reference(ComparisonOperation op,
98 const TensorShape &shape0, const TensorShape &shape1, DataType data_type,
99 QuantizationInfo qinfo0, QuantizationInfo qinfo1)
100 {
101 // Create reference
102 SimpleTensor<T> ref_src1{ shape0, data_type, 1, qinfo0 };
103 SimpleTensor<T> ref_src2{ shape1, data_type, 1, qinfo1 };
104
105 // Fill reference
106 fill(ref_src1, 0);
107 fill(ref_src2, 1);
108
109 return reference::compare<T>(op, ref_src1, ref_src2);
110 }
111
112 TensorType _target{};
113 SimpleTensor<uint8_t> _reference{};
114};
115
116template <typename TensorType, typename AccessorType, typename FunctionType, typename T>
117class ComparisonBroadcastValidationFixture : public ComparisonValidationGenericFixture<TensorType, AccessorType, FunctionType, T>
118{
119public:
120 template <typename...>
121 void setup(ComparisonOperation op, const TensorShape &shape0, const TensorShape &shape1, DataType data_type)
122 {
123 ComparisonValidationGenericFixture<TensorType, AccessorType, FunctionType, T>::setup(op, shape0, shape1, data_type, QuantizationInfo(), QuantizationInfo());
124 }
125};
126
127template <typename TensorType, typename AccessorType, typename FunctionType, typename T>
128class ComparisonValidationFixture : public ComparisonValidationGenericFixture<TensorType, AccessorType, FunctionType, T>
129{
130public:
131 template <typename...>
132 void setup(ComparisonOperation op, const TensorShape &shape, DataType data_type)
133 {
134 ComparisonValidationGenericFixture<TensorType, AccessorType, FunctionType, T>::setup(op, shape, shape, data_type, QuantizationInfo(), QuantizationInfo());
135 }
136};
137
138template <typename TensorType, typename AccessorType, typename FunctionType, typename T>
139class ComparisonValidationQuantizedFixture : public ComparisonValidationGenericFixture<TensorType, AccessorType, FunctionType, T>
140{
141public:
142 template <typename...>
143 void setup(ComparisonOperation op, const TensorShape &shape, DataType data_type, QuantizationInfo qinfo0, QuantizationInfo qinfo1)
144
145 {
146 ComparisonValidationGenericFixture<TensorType, AccessorType, FunctionType, T>::setup(op, shape, shape, data_type, qinfo0, qinfo1);
147 }
148};
Michele Di Giorgio81870c02020-04-30 12:02:20 +0100149
150template <typename TensorType, typename AccessorType, typename FunctionType, typename T>
151class ComparisonQuantizedBroadcastValidationFixture : public ComparisonValidationGenericFixture<TensorType, AccessorType, FunctionType, T>
152{
153public:
154 template <typename...>
155 void setup(ComparisonOperation op, const TensorShape &shape0, const TensorShape &shape1, DataType data_type, QuantizationInfo qinfo0, QuantizationInfo qinfo1)
156 {
157 ComparisonValidationGenericFixture<TensorType, AccessorType, FunctionType, T>::setup(op, shape0, shape1, data_type, qinfo0, qinfo1);
158 }
159};
Georgios Pinitas7900a9e2018-11-23 11:44:58 +0000160} // namespace validation
161} // namespace test
162} // namespace arm_compute
163#endif /* ARM_COMPUTE_TEST_COMPARISON_FIXTURE */