xref: /aosp_15_r20/external/ComputeLibrary/tests/validation/fixtures/ElementwiseOperationsFixture.h (revision c217d954acce2dbc11938adb493fc0abd69584f3)
1 /*
2  * Copyright (c) 2018-2021 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_ELEMENTWISE_OPERATIONS_FIXTURE
25 #define ARM_COMPUTE_TEST_ELEMENTWISE_OPERATIONS_FIXTURE
26 
27 #include "arm_compute/core/TensorShape.h"
28 #include "arm_compute/core/Types.h"
29 #include "arm_compute/core/Validate.h"
30 #include "tests/AssetsLibrary.h"
31 #include "tests/Globals.h"
32 #include "tests/IAccessor.h"
33 #include "tests/framework/Asserts.h"
34 #include "tests/framework/Fixture.h"
35 #include "tests/validation/Helpers.h"
36 #include "tests/validation/reference/ActivationLayer.h"
37 #include "tests/validation/reference/ElementwiseOperations.h"
38 
39 namespace arm_compute
40 {
41 namespace test
42 {
43 namespace validation
44 {
45 template <typename TensorType, typename AccessorType, typename FunctionType, typename T>
46 class ArithmeticOperationsGenericFixture : public framework::Fixture
47 {
48 public:
49     template <typename...>
50     void setup(ArithmeticOperation op, const TensorShape &shape0, const TensorShape &shape1,
51                DataType data_type0, DataType data_type1, DataType output_data_type,
52                QuantizationInfo qinfo0, QuantizationInfo qinfo1, QuantizationInfo qinfo_out, bool is_inplace = false, bool use_dynamic_shape = false)
53     {
54         _op                = op;
55         _use_dynamic_shape = use_dynamic_shape;
56         _is_inplace        = is_inplace;
57 
58         _target    = compute_target(shape0, shape1, data_type0, data_type1, output_data_type, qinfo0, qinfo1, qinfo_out);
59         _reference = compute_reference(shape0, shape1, data_type0, data_type1, output_data_type, qinfo0, qinfo1, qinfo_out);
60     }
61 
62 protected:
63     template <typename U>
fill(U && tensor,int i)64     void fill(U &&tensor, int i)
65     {
66         if(is_data_type_float(tensor.data_type()))
67         {
68             switch(_op)
69             {
70                 case ArithmeticOperation::DIV:
71                     library->fill_tensor_uniform_ranged(tensor, i, { std::pair<float, float>(-0.001f, 0.001f) });
72                     break;
73                 case ArithmeticOperation::POWER:
74                     library->fill_tensor_uniform(tensor, i, 0.0f, 5.0f);
75                     break;
76                 default:
77                     library->fill_tensor_uniform(tensor, i);
78             }
79         }
80         else
81         {
82             library->fill_tensor_uniform(tensor, i);
83         }
84     }
85 
compute_target(const TensorShape & shape0,const TensorShape & shape1,DataType data_type0,DataType data_type1,DataType output_data_type,QuantizationInfo qinfo0,QuantizationInfo qinfo1,QuantizationInfo qinfo_out)86     TensorType compute_target(const TensorShape &shape0, const TensorShape &shape1, DataType data_type0, DataType data_type1, DataType output_data_type,
87                               QuantizationInfo qinfo0, QuantizationInfo qinfo1, QuantizationInfo qinfo_out)
88     {
89         // Create tensors
90         const TensorShape out_shape = TensorShape::broadcast_shape(shape0, shape1);
91         TensorType        ref_src1  = create_tensor<TensorType>(shape0, data_type0, 1, qinfo0);
92         TensorType        ref_src2  = create_tensor<TensorType>(shape1, data_type1, 1, qinfo1);
93         TensorType        dst       = create_tensor<TensorType>(out_shape, output_data_type, 1, qinfo_out);
94 
95         // Check whether do in-place computation and whether inputs are broadcast compatible
96         TensorType *actual_dst = &dst;
97         if(_is_inplace)
98         {
99             bool src1_is_inplace = !arm_compute::detail::have_different_dimensions(out_shape, shape0, 0) && (qinfo0 == qinfo_out) && (data_type0 == output_data_type);
100             bool src2_is_inplace = !arm_compute::detail::have_different_dimensions(out_shape, shape1, 0) && (qinfo1 == qinfo_out) && (data_type1 == output_data_type);
101             bool do_in_place     = out_shape.total_size() != 0 && (src1_is_inplace || src2_is_inplace);
102             ARM_COMPUTE_ASSERT(do_in_place);
103 
104             if(src1_is_inplace)
105             {
106                 actual_dst = &ref_src1;
107             }
108             else
109             {
110                 actual_dst = &ref_src2;
111             }
112         }
113 
114         // if _use_dynamic_shape is true, this fixture will test scenario for dynamic shapes.
115         // - At configure time, all input tensors are marked as dynamic using set_tensor_dynamic()
116         // - After configure, tensors are marked as static for run using set_tensor_static()
117         // - The tensors with static shape are given to run()
118         if(_use_dynamic_shape)
119         {
120             set_tensor_dynamic(ref_src1);
121             set_tensor_dynamic(ref_src2);
122         }
123 
124         // Create and configure function
125         FunctionType elem_op;
126         elem_op.configure(&ref_src1, &ref_src2, actual_dst);
127 
128         if(_use_dynamic_shape)
129         {
130             set_tensor_static(ref_src1);
131             set_tensor_static(ref_src2);
132         }
133 
134         ARM_COMPUTE_ASSERT(ref_src1.info()->is_resizable());
135         ARM_COMPUTE_ASSERT(ref_src2.info()->is_resizable());
136 
137         // Allocate tensors
138         ref_src1.allocator()->allocate();
139         ref_src2.allocator()->allocate();
140 
141         // If don't do in-place computation, still need to allocate original dst
142         if(!_is_inplace)
143         {
144             ARM_COMPUTE_ASSERT(dst.info()->is_resizable());
145             dst.allocator()->allocate();
146             ARM_COMPUTE_ASSERT(!dst.info()->is_resizable());
147         }
148 
149         ARM_COMPUTE_ASSERT(!ref_src1.info()->is_resizable());
150         ARM_COMPUTE_ASSERT(!ref_src2.info()->is_resizable());
151 
152         // Fill tensors
153         fill(AccessorType(ref_src1), 0);
154         fill(AccessorType(ref_src2), 1);
155 
156         // Compute function
157         elem_op.run();
158 
159         return std::move(*actual_dst);
160     }
161 
compute_reference(const TensorShape & shape0,const TensorShape & shape1,DataType data_type0,DataType data_type1,DataType output_data_type,QuantizationInfo qinfo0,QuantizationInfo qinfo1,QuantizationInfo qinfo_out)162     SimpleTensor<T> compute_reference(const TensorShape &shape0, const TensorShape &shape1,
163                                       DataType data_type0, DataType data_type1, DataType output_data_type,
164                                       QuantizationInfo qinfo0, QuantizationInfo qinfo1, QuantizationInfo qinfo_out)
165     {
166         // Create reference
167         SimpleTensor<T> ref_src1{ shape0, data_type0, 1, qinfo0 };
168         SimpleTensor<T> ref_src2{ shape1, data_type1, 1, qinfo1 };
169         SimpleTensor<T> ref_dst{ TensorShape::broadcast_shape(shape0, shape1), output_data_type, 1, qinfo_out };
170 
171         // Fill reference
172         fill(ref_src1, 0);
173         fill(ref_src2, 1);
174 
175         return reference::arithmetic_operation<T>(_op, ref_src1, ref_src2, ref_dst);
176     }
177 
178     TensorType          _target{};
179     SimpleTensor<T>     _reference{};
180     ArithmeticOperation _op{ ArithmeticOperation::ADD };
181     bool                _use_dynamic_shape{ false };
182     bool                _is_inplace{ false };
183 };
184 
185 // Arithmetic operation fused with activation function
186 template <typename TensorType, typename AccessorType, typename FunctionType, typename T>
187 class ArithmeticOperationsFuseActivationFixture : public ArithmeticOperationsGenericFixture<TensorType, AccessorType, FunctionType, T>
188 {
189 public:
190     template <typename...>
191     void setup(ArithmeticOperation op, const TensorShape &shape0, const TensorShape &shape1,
192                DataType data_type0, DataType data_type1, DataType output_data_type,
193                QuantizationInfo qinfo0, QuantizationInfo qinfo1, QuantizationInfo qinfo_out, ActivationLayerInfo act_info, bool is_inplace = true)
194     {
195         ArithmeticOperationsGenericFixture<TensorType, AccessorType, FunctionType, T>::setup(op, shape0, shape1,
196                                                                                              data_type0, data_type1, output_data_type,
197                                                                                              qinfo0, qinfo1, qinfo_out, is_inplace);
198         _act_info   = act_info;
199         _is_inplace = is_inplace;
200     }
201 
202 protected:
compute_target(const TensorShape & shape0,const TensorShape & shape1,DataType data_type0,DataType data_type1,DataType output_data_type,QuantizationInfo qinfo0,QuantizationInfo qinfo1,QuantizationInfo qinfo_out)203     TensorType compute_target(const TensorShape &shape0, const TensorShape &shape1, DataType data_type0, DataType data_type1, DataType output_data_type,
204                               QuantizationInfo qinfo0, QuantizationInfo qinfo1, QuantizationInfo qinfo_out)
205     {
206         // Create tensors
207         const TensorShape out_shape = TensorShape::broadcast_shape(shape0, shape1);
208         TensorType        ref_src1  = create_tensor<TensorType>(shape0, data_type0, 1, qinfo0);
209         TensorType        ref_src2  = create_tensor<TensorType>(shape1, data_type1, 1, qinfo1);
210         TensorType        dst       = create_tensor<TensorType>(out_shape, output_data_type, 1, qinfo_out);
211 
212         // Check whether do in-place computation and whether inputs are broadcast compatible
213         TensorType *actual_dst = &dst;
214         if(_is_inplace)
215         {
216             bool src1_is_inplace = !arm_compute::detail::have_different_dimensions(out_shape, shape0, 0) && (qinfo0 == qinfo_out) && (data_type0 == output_data_type);
217             bool src2_is_inplace = !arm_compute::detail::have_different_dimensions(out_shape, shape1, 0) && (qinfo1 == qinfo_out) && (data_type1 == output_data_type);
218             bool do_in_place     = out_shape.total_size() != 0 && (src1_is_inplace || src2_is_inplace);
219             ARM_COMPUTE_ASSERT(do_in_place);
220 
221             if(src1_is_inplace)
222             {
223                 actual_dst = &ref_src1;
224             }
225             else
226             {
227                 actual_dst = &ref_src2;
228             }
229         }
230 
231         // Create and configure function
232         FunctionType elem_op;
233         elem_op.configure(&ref_src1, &ref_src2, actual_dst, _act_info);
234 
235         ARM_COMPUTE_ASSERT(ref_src1.info()->is_resizable());
236         ARM_COMPUTE_ASSERT(ref_src2.info()->is_resizable());
237 
238         // Allocate tensors
239         ref_src1.allocator()->allocate();
240         ref_src2.allocator()->allocate();
241 
242         // If don't do in-place computation, still need to allocate original dst
243         if(!_is_inplace)
244         {
245             ARM_COMPUTE_ASSERT(dst.info()->is_resizable());
246             dst.allocator()->allocate();
247             ARM_COMPUTE_ASSERT(!dst.info()->is_resizable());
248         }
249 
250         ARM_COMPUTE_ASSERT(!ref_src1.info()->is_resizable());
251         ARM_COMPUTE_ASSERT(!ref_src2.info()->is_resizable());
252 
253         // Fill tensors
254         fill(AccessorType(ref_src1), 0);
255         fill(AccessorType(ref_src2), 1);
256 
257         // Compute function
258         elem_op.run();
259 
260         return std::move(*actual_dst);
261     }
262 
compute_reference(const TensorShape & shape0,const TensorShape & shape1,DataType data_type0,DataType data_type1,DataType output_data_type,QuantizationInfo qinfo0,QuantizationInfo qinfo1,QuantizationInfo qinfo_out)263     SimpleTensor<T> compute_reference(const TensorShape &shape0, const TensorShape &shape1,
264                                       DataType data_type0, DataType data_type1, DataType output_data_type,
265                                       QuantizationInfo qinfo0, QuantizationInfo qinfo1, QuantizationInfo qinfo_out)
266     {
267         auto result = ArithmeticOperationsGenericFixture<TensorType, AccessorType, FunctionType, T>::compute_reference(shape0, shape1, data_type0,
268                                                                                                                        data_type1, output_data_type, qinfo0, qinfo1, qinfo_out);
269         return _act_info.enabled() ? reference::activation_layer(result, _act_info, qinfo_out) : result;
270     }
271 
272     ActivationLayerInfo _act_info{};
273     bool                _is_inplace{ false };
274 };
275 
276 template <typename TensorType, typename AccessorType, typename FunctionType, typename T>
277 class ArithmeticDivisionBroadcastValidationFixture : public ArithmeticOperationsGenericFixture<TensorType, AccessorType, FunctionType, T>
278 {
279 public:
280     template <typename...>
setup(const TensorShape & shape0,const TensorShape & shape1,DataType data_type0,DataType data_type1,DataType output_data_type,bool is_inplace)281     void setup(const TensorShape &shape0, const TensorShape &shape1, DataType data_type0, DataType data_type1, DataType output_data_type, bool is_inplace)
282     {
283         ArithmeticOperationsGenericFixture<TensorType, AccessorType, FunctionType, T>::setup(ArithmeticOperation::DIV, shape0, shape1,
284                                                                                              data_type0, data_type1, output_data_type,
285                                                                                              QuantizationInfo(), QuantizationInfo(), QuantizationInfo(), is_inplace);
286     }
287 };
288 
289 template <typename TensorType, typename AccessorType, typename FunctionType, typename T>
290 class ArithmeticDivisionValidationFixture : public ArithmeticOperationsGenericFixture<TensorType, AccessorType, FunctionType, T>
291 {
292 public:
293     template <typename...>
setup(const TensorShape & shape,DataType data_type0,DataType data_type1,DataType output_data_type,bool is_inplace)294     void setup(const TensorShape &shape, DataType data_type0, DataType data_type1, DataType output_data_type, bool is_inplace)
295     {
296         ArithmeticOperationsGenericFixture<TensorType, AccessorType, FunctionType, T>::setup(ArithmeticOperation::DIV, shape, shape,
297                                                                                              data_type0, data_type1, output_data_type,
298                                                                                              QuantizationInfo(), QuantizationInfo(), QuantizationInfo(), is_inplace);
299     }
300 };
301 
302 template <typename TensorType, typename AccessorType, typename FunctionType, typename T>
303 class ArithmeticDivisionBroadcastDynamicShapeValidationFixture : public ArithmeticOperationsGenericFixture<TensorType, AccessorType, FunctionType, T>
304 {
305 public:
306     template <typename...>
setup(const TensorShape & shape0,const TensorShape & shape1,DataType data_type0,DataType data_type1,DataType output_data_type,bool is_inplace)307     void setup(const TensorShape &shape0, const TensorShape &shape1, DataType data_type0, DataType data_type1, DataType output_data_type, bool is_inplace)
308     {
309         ArithmeticOperationsGenericFixture<TensorType, AccessorType, FunctionType, T>::setup(ArithmeticOperation::DIV, shape0, shape1,
310                                                                                              data_type0, data_type1, output_data_type,
311                                                                                              QuantizationInfo(), QuantizationInfo(), QuantizationInfo(), is_inplace, true);
312     }
313 };
314 
315 template <typename TensorType, typename AccessorType, typename FunctionType, typename T>
316 class ArithmeticDivisionDynamicShapeValidationFixture : public ArithmeticOperationsGenericFixture<TensorType, AccessorType, FunctionType, T>
317 {
318 public:
319     template <typename...>
setup(const TensorShape & shape,DataType data_type0,DataType data_type1,DataType output_data_type,bool is_inplace)320     void setup(const TensorShape &shape, DataType data_type0, DataType data_type1, DataType output_data_type, bool is_inplace)
321     {
322         ArithmeticOperationsGenericFixture<TensorType, AccessorType, FunctionType, T>::setup(ArithmeticOperation::DIV, shape, shape,
323                                                                                              data_type0, data_type1, output_data_type,
324                                                                                              QuantizationInfo(), QuantizationInfo(), QuantizationInfo(), is_inplace);
325     }
326 };
327 
328 template <typename TensorType, typename AccessorType, typename FunctionType, typename T>
329 class ArithmeticDivisionBroadcastValidationFloatFixture : public ArithmeticOperationsFuseActivationFixture<TensorType, AccessorType, FunctionType, T>
330 {
331 public:
332     template <typename...>
setup(const TensorShape & shape0,const TensorShape & shape1,DataType data_type0,DataType data_type1,DataType output_data_type,ActivationLayerInfo act_info,bool is_inplace)333     void setup(const TensorShape &shape0, const TensorShape &shape1, DataType data_type0, DataType data_type1, DataType output_data_type, ActivationLayerInfo act_info, bool is_inplace)
334     {
335         ArithmeticOperationsFuseActivationFixture<TensorType, AccessorType, FunctionType, T>::setup(ArithmeticOperation::DIV, shape0, shape1,
336                                                                                                     data_type0, data_type1, output_data_type,
337                                                                                                     QuantizationInfo(), QuantizationInfo(), QuantizationInfo(), act_info, is_inplace);
338     }
339 };
340 
341 template <typename TensorType, typename AccessorType, typename FunctionType, typename T>
342 class ArithmeticDivisionValidationFloatFixture : public ArithmeticOperationsFuseActivationFixture<TensorType, AccessorType, FunctionType, T>
343 {
344 public:
345     template <typename...>
setup(const TensorShape & shape,DataType data_type0,DataType data_type1,DataType output_data_type,ActivationLayerInfo act_info,bool is_inplace)346     void setup(const TensorShape &shape, DataType data_type0, DataType data_type1, DataType output_data_type, ActivationLayerInfo act_info, bool is_inplace)
347     {
348         ArithmeticOperationsFuseActivationFixture<TensorType, AccessorType, FunctionType, T>::setup(ArithmeticOperation::DIV, shape, shape,
349                                                                                                     data_type0, data_type1, output_data_type,
350                                                                                                     QuantizationInfo(), QuantizationInfo(), QuantizationInfo(), act_info, is_inplace);
351     }
352 };
353 
354 template <typename TensorType, typename AccessorType, typename FunctionType, typename T>
355 class ArithmeticDivisionValidationIntegerFixture : public ArithmeticOperationsFuseActivationFixture<TensorType, AccessorType, FunctionType, T>
356 {
357 public:
358     template <typename...>
setup(const TensorShape & shape,DataType data_type0,DataType data_type1,DataType output_data_type,ActivationLayerInfo act_info,bool is_inplace)359     void setup(const TensorShape &shape, DataType data_type0, DataType data_type1, DataType output_data_type, ActivationLayerInfo act_info, bool is_inplace)
360     {
361         ArithmeticOperationsFuseActivationFixture<TensorType, AccessorType, FunctionType, T>::setup(ArithmeticOperation::DIV, shape, shape,
362                                                                                                     data_type0, data_type1, output_data_type,
363                                                                                                     QuantizationInfo(), QuantizationInfo(), QuantizationInfo(), act_info, is_inplace);
364     }
365 };
366 
367 template <typename TensorType, typename AccessorType, typename FunctionType, typename T>
368 class ArithmeticDivisionValidationQuantizedFixture : public ArithmeticOperationsGenericFixture<TensorType, AccessorType, FunctionType, T>
369 {
370 public:
371     template <typename...>
setup(const TensorShape & shape,DataType data_type0,DataType data_type1,DataType output_data_type,QuantizationInfo qinfo0,QuantizationInfo qinfo1,QuantizationInfo qinfo_out,bool is_inplace)372     void setup(const TensorShape &shape, DataType data_type0, DataType data_type1, DataType output_data_type,
373                QuantizationInfo qinfo0, QuantizationInfo qinfo1, QuantizationInfo qinfo_out, bool is_inplace)
374 
375     {
376         ArithmeticOperationsGenericFixture<TensorType, AccessorType, FunctionType, T>::setup(ArithmeticOperation::DIV, shape, shape,
377                                                                                              data_type0, data_type1, output_data_type,
378                                                                                              qinfo0, qinfo1, qinfo_out, is_inplace);
379     }
380 };
381 
382 template <typename TensorType, typename AccessorType, typename FunctionType, typename T>
383 class ElementwiseMaxBroadcastValidationFixture : public ArithmeticOperationsGenericFixture<TensorType, AccessorType, FunctionType, T>
384 {
385 public:
386     template <typename...>
setup(const TensorShape & shape0,const TensorShape & shape1,DataType data_type0,DataType data_type1,DataType output_data_type,bool is_inplace)387     void setup(const TensorShape &shape0, const TensorShape &shape1, DataType data_type0, DataType data_type1, DataType output_data_type, bool is_inplace)
388     {
389         ArithmeticOperationsGenericFixture<TensorType, AccessorType, FunctionType, T>::setup(ArithmeticOperation::MAX, shape0, shape1,
390                                                                                              data_type0, data_type1, output_data_type,
391                                                                                              QuantizationInfo(), QuantizationInfo(), QuantizationInfo(), is_inplace);
392     }
393 };
394 
395 template <typename TensorType, typename AccessorType, typename FunctionType, typename T>
396 class ElementwiseMaxValidationFixture : public ArithmeticOperationsGenericFixture<TensorType, AccessorType, FunctionType, T>
397 {
398 public:
399     template <typename...>
setup(const TensorShape & shape,DataType data_type0,DataType data_type1,DataType output_data_type,bool is_inplace)400     void setup(const TensorShape &shape, DataType data_type0, DataType data_type1, DataType output_data_type, bool is_inplace)
401     {
402         ArithmeticOperationsGenericFixture<TensorType, AccessorType, FunctionType, T>::setup(ArithmeticOperation::MAX, shape, shape,
403                                                                                              data_type0, data_type1, output_data_type,
404                                                                                              QuantizationInfo(), QuantizationInfo(), QuantizationInfo(), is_inplace);
405     }
406 };
407 
408 template <typename TensorType, typename AccessorType, typename FunctionType, typename T>
409 class ElementwiseMaxBroadcastValidationFloatFixture : public ArithmeticOperationsFuseActivationFixture<TensorType, AccessorType, FunctionType, T>
410 {
411 public:
412     template <typename...>
setup(const TensorShape & shape0,const TensorShape & shape1,DataType data_type0,DataType data_type1,DataType output_data_type,ActivationLayerInfo act_info,bool is_inplace)413     void setup(const TensorShape &shape0, const TensorShape &shape1, DataType data_type0, DataType data_type1, DataType output_data_type, ActivationLayerInfo act_info, bool is_inplace)
414     {
415         ArithmeticOperationsFuseActivationFixture<TensorType, AccessorType, FunctionType, T>::setup(ArithmeticOperation::MAX, shape0, shape1,
416                                                                                                     data_type0, data_type1, output_data_type,
417                                                                                                     QuantizationInfo(), QuantizationInfo(), QuantizationInfo(), act_info, is_inplace);
418     }
419 };
420 
421 template <typename TensorType, typename AccessorType, typename FunctionType, typename T>
422 class ElementwiseMaxValidationFloatFixture : public ArithmeticOperationsFuseActivationFixture<TensorType, AccessorType, FunctionType, T>
423 {
424 public:
425     template <typename...>
setup(const TensorShape & shape,DataType data_type0,DataType data_type1,DataType output_data_type,ActivationLayerInfo act_info,bool is_inplace)426     void setup(const TensorShape &shape, DataType data_type0, DataType data_type1, DataType output_data_type, ActivationLayerInfo act_info, bool is_inplace)
427     {
428         ArithmeticOperationsFuseActivationFixture<TensorType, AccessorType, FunctionType, T>::setup(ArithmeticOperation::MAX, shape, shape,
429                                                                                                     data_type0, data_type1, output_data_type,
430                                                                                                     QuantizationInfo(), QuantizationInfo(), QuantizationInfo(), act_info, is_inplace);
431     }
432 };
433 
434 template <typename TensorType, typename AccessorType, typename FunctionType, typename T>
435 class ElementwiseMaxValidationQuantizedFixture : public ArithmeticOperationsGenericFixture<TensorType, AccessorType, FunctionType, T>
436 {
437 public:
438     template <typename...>
setup(const TensorShape & shape,DataType data_type0,DataType data_type1,DataType output_data_type,QuantizationInfo qinfo0,QuantizationInfo qinfo1,QuantizationInfo qinfo_out,bool is_inplace)439     void setup(const TensorShape &shape, DataType data_type0, DataType data_type1, DataType output_data_type,
440                QuantizationInfo qinfo0, QuantizationInfo qinfo1, QuantizationInfo qinfo_out, bool is_inplace)
441 
442     {
443         ArithmeticOperationsGenericFixture<TensorType, AccessorType, FunctionType, T>::setup(ArithmeticOperation::MAX, shape, shape,
444                                                                                              data_type0, data_type1, output_data_type,
445                                                                                              qinfo0, qinfo1, qinfo_out, is_inplace);
446     }
447 };
448 
449 template <typename TensorType, typename AccessorType, typename FunctionType, typename T>
450 class ElementwiseMaxQuantizedBroadcastValidationFixture : public ArithmeticOperationsGenericFixture<TensorType, AccessorType, FunctionType, T>
451 {
452 public:
453     template <typename...>
setup(const TensorShape & shape0,const TensorShape & shape1,DataType data_type0,DataType data_type1,DataType output_data_type,QuantizationInfo qinfo0,QuantizationInfo qinfo1,QuantizationInfo qinfo_out,bool is_inplace)454     void setup(const TensorShape &shape0, const TensorShape &shape1, DataType data_type0, DataType data_type1, DataType output_data_type,
455                QuantizationInfo qinfo0, QuantizationInfo qinfo1, QuantizationInfo qinfo_out, bool is_inplace)
456 
457     {
458         ArithmeticOperationsGenericFixture<TensorType, AccessorType, FunctionType, T>::setup(ArithmeticOperation::MAX, shape0, shape1,
459                                                                                              data_type0, data_type1, output_data_type,
460                                                                                              qinfo0, qinfo1, qinfo_out, is_inplace);
461     }
462 };
463 
464 template <typename TensorType, typename AccessorType, typename FunctionType, typename T>
465 class ElementwiseMinBroadcastValidationFixture : public ArithmeticOperationsGenericFixture<TensorType, AccessorType, FunctionType, T>
466 {
467 public:
468     template <typename...>
setup(const TensorShape & shape0,const TensorShape & shape1,DataType data_type0,DataType data_type1,DataType output_data_type,bool is_inplace)469     void setup(const TensorShape &shape0, const TensorShape &shape1, DataType data_type0, DataType data_type1, DataType output_data_type, bool is_inplace)
470     {
471         ArithmeticOperationsGenericFixture<TensorType, AccessorType, FunctionType, T>::setup(ArithmeticOperation::MIN, shape0, shape1,
472                                                                                              data_type0, data_type1, output_data_type,
473                                                                                              QuantizationInfo(), QuantizationInfo(), QuantizationInfo(), is_inplace);
474     }
475 };
476 
477 template <typename TensorType, typename AccessorType, typename FunctionType, typename T>
478 class ElementwiseMinValidationFixture : public ArithmeticOperationsGenericFixture<TensorType, AccessorType, FunctionType, T>
479 {
480 public:
481     template <typename...>
setup(const TensorShape & shape,DataType data_type0,DataType data_type1,DataType output_data_type,bool is_inplace)482     void setup(const TensorShape &shape, DataType data_type0, DataType data_type1, DataType output_data_type, bool is_inplace)
483     {
484         ArithmeticOperationsGenericFixture<TensorType, AccessorType, FunctionType, T>::setup(ArithmeticOperation::MIN, shape, shape,
485                                                                                              data_type0, data_type1, output_data_type,
486                                                                                              QuantizationInfo(), QuantizationInfo(), QuantizationInfo(), is_inplace);
487     }
488 };
489 
490 template <typename TensorType, typename AccessorType, typename FunctionType, typename T>
491 class ElementwiseMinBroadcastValidationFloatFixture : public ArithmeticOperationsFuseActivationFixture<TensorType, AccessorType, FunctionType, T>
492 {
493 public:
494     template <typename...>
setup(const TensorShape & shape0,const TensorShape & shape1,DataType data_type0,DataType data_type1,DataType output_data_type,ActivationLayerInfo act_info,bool is_inplace)495     void setup(const TensorShape &shape0, const TensorShape &shape1, DataType data_type0, DataType data_type1, DataType output_data_type, ActivationLayerInfo act_info, bool is_inplace)
496     {
497         ArithmeticOperationsFuseActivationFixture<TensorType, AccessorType, FunctionType, T>::setup(ArithmeticOperation::MIN, shape0, shape1,
498                                                                                                     data_type0, data_type1, output_data_type,
499                                                                                                     QuantizationInfo(), QuantizationInfo(), QuantizationInfo(), act_info, is_inplace);
500     }
501 };
502 
503 template <typename TensorType, typename AccessorType, typename FunctionType, typename T>
504 class ElementwiseMinValidationFloatFixture : public ArithmeticOperationsFuseActivationFixture<TensorType, AccessorType, FunctionType, T>
505 {
506 public:
507     template <typename...>
setup(const TensorShape & shape,DataType data_type0,DataType data_type1,DataType output_data_type,ActivationLayerInfo act_info,bool is_inplace)508     void setup(const TensorShape &shape, DataType data_type0, DataType data_type1, DataType output_data_type, ActivationLayerInfo act_info, bool is_inplace)
509     {
510         ArithmeticOperationsFuseActivationFixture<TensorType, AccessorType, FunctionType, T>::setup(ArithmeticOperation::MIN, shape, shape,
511                                                                                                     data_type0, data_type1, output_data_type,
512                                                                                                     QuantizationInfo(), QuantizationInfo(), QuantizationInfo(), act_info, is_inplace);
513     }
514 };
515 
516 template <typename TensorType, typename AccessorType, typename FunctionType, typename T>
517 class ElementwiseMinValidationQuantizedFixture : public ArithmeticOperationsGenericFixture<TensorType, AccessorType, FunctionType, T>
518 {
519 public:
520     template <typename...>
setup(const TensorShape & shape,DataType data_type0,DataType data_type1,DataType output_data_type,QuantizationInfo qinfo0,QuantizationInfo qinfo1,QuantizationInfo qinfo_out,bool is_inplace)521     void setup(const TensorShape &shape, DataType data_type0, DataType data_type1, DataType output_data_type,
522                QuantizationInfo qinfo0, QuantizationInfo qinfo1, QuantizationInfo qinfo_out, bool is_inplace)
523 
524     {
525         ArithmeticOperationsGenericFixture<TensorType, AccessorType, FunctionType, T>::setup(ArithmeticOperation::MIN, shape, shape,
526                                                                                              data_type0, data_type1, output_data_type,
527                                                                                              qinfo0, qinfo1, qinfo_out, is_inplace);
528     }
529 };
530 
531 template <typename TensorType, typename AccessorType, typename FunctionType, typename T>
532 class ElementwiseMinQuantizedBroadcastValidationFixture : public ArithmeticOperationsGenericFixture<TensorType, AccessorType, FunctionType, T>
533 {
534 public:
535     template <typename...>
setup(const TensorShape & shape0,const TensorShape & shape1,DataType data_type0,DataType data_type1,DataType output_data_type,QuantizationInfo qinfo0,QuantizationInfo qinfo1,QuantizationInfo qinfo_out,bool is_inplace)536     void setup(const TensorShape &shape0, const TensorShape &shape1, DataType data_type0, DataType data_type1, DataType output_data_type,
537                QuantizationInfo qinfo0, QuantizationInfo qinfo1, QuantizationInfo qinfo_out, bool is_inplace)
538 
539     {
540         ArithmeticOperationsGenericFixture<TensorType, AccessorType, FunctionType, T>::setup(ArithmeticOperation::MIN, shape0, shape1,
541                                                                                              data_type0, data_type1, output_data_type,
542                                                                                              qinfo0, qinfo1, qinfo_out, is_inplace);
543     }
544 };
545 
546 template <typename TensorType, typename AccessorType, typename FunctionType, typename T>
547 class ElementwiseSquaredDiffBroadcastValidationFixture : public ArithmeticOperationsGenericFixture<TensorType, AccessorType, FunctionType, T>
548 {
549 public:
550     template <typename...>
setup(const TensorShape & shape0,const TensorShape & shape1,DataType data_type0,DataType data_type1,DataType output_data_type,bool is_inplace)551     void setup(const TensorShape &shape0, const TensorShape &shape1, DataType data_type0, DataType data_type1, DataType output_data_type, bool is_inplace)
552     {
553         ArithmeticOperationsGenericFixture<TensorType, AccessorType, FunctionType, T>::setup(ArithmeticOperation::SQUARED_DIFF, shape0, shape1,
554                                                                                              data_type0, data_type1, output_data_type,
555                                                                                              QuantizationInfo(), QuantizationInfo(), QuantizationInfo(), is_inplace);
556     }
557 };
558 
559 template <typename TensorType, typename AccessorType, typename FunctionType, typename T>
560 class ElementwiseSquaredDiffValidationFixture : public ArithmeticOperationsGenericFixture<TensorType, AccessorType, FunctionType, T>
561 {
562 public:
563     template <typename...>
setup(const TensorShape & shape,DataType data_type0,DataType data_type1,DataType output_data_type,bool is_inplace)564     void setup(const TensorShape &shape, DataType data_type0, DataType data_type1, DataType output_data_type, bool is_inplace)
565     {
566         ArithmeticOperationsGenericFixture<TensorType, AccessorType, FunctionType, T>::setup(ArithmeticOperation::SQUARED_DIFF, shape, shape,
567                                                                                              data_type0, data_type1, output_data_type,
568                                                                                              QuantizationInfo(), QuantizationInfo(), QuantizationInfo(), is_inplace);
569     }
570 };
571 
572 template <typename TensorType, typename AccessorType, typename FunctionType, typename T>
573 class ElementwiseSquaredDiffBroadcastValidationFloatFixture : public ArithmeticOperationsFuseActivationFixture<TensorType, AccessorType, FunctionType, T>
574 {
575 public:
576     template <typename...>
setup(const TensorShape & shape0,const TensorShape & shape1,DataType data_type0,DataType data_type1,DataType output_data_type,ActivationLayerInfo act_info,bool is_inplace)577     void setup(const TensorShape &shape0, const TensorShape &shape1, DataType data_type0, DataType data_type1, DataType output_data_type, ActivationLayerInfo act_info, bool is_inplace)
578     {
579         ArithmeticOperationsFuseActivationFixture<TensorType, AccessorType, FunctionType, T>::setup(ArithmeticOperation::SQUARED_DIFF, shape0, shape1,
580                                                                                                     data_type0, data_type1, output_data_type,
581                                                                                                     QuantizationInfo(), QuantizationInfo(), QuantizationInfo(), act_info, is_inplace);
582     }
583 };
584 
585 template <typename TensorType, typename AccessorType, typename FunctionType, typename T>
586 class ElementwiseSquaredDiffValidationFloatFixture : public ArithmeticOperationsFuseActivationFixture<TensorType, AccessorType, FunctionType, T>
587 {
588 public:
589     template <typename...>
setup(const TensorShape & shape,DataType data_type0,DataType data_type1,DataType output_data_type,ActivationLayerInfo act_info,bool is_inplace)590     void setup(const TensorShape &shape, DataType data_type0, DataType data_type1, DataType output_data_type, ActivationLayerInfo act_info, bool is_inplace)
591     {
592         ArithmeticOperationsFuseActivationFixture<TensorType, AccessorType, FunctionType, T>::setup(ArithmeticOperation::SQUARED_DIFF, shape, shape,
593                                                                                                     data_type0, data_type1, output_data_type,
594                                                                                                     QuantizationInfo(), QuantizationInfo(), QuantizationInfo(), act_info, is_inplace);
595     }
596 };
597 
598 template <typename TensorType, typename AccessorType, typename FunctionType, typename T>
599 class ElementwiseSquaredDiffValidationQuantizedFixture : public ArithmeticOperationsGenericFixture<TensorType, AccessorType, FunctionType, T>
600 {
601 public:
602     template <typename...>
setup(const TensorShape & shape,DataType data_type0,DataType data_type1,DataType output_data_type,QuantizationInfo qinfo0,QuantizationInfo qinfo1,QuantizationInfo qinfo_out,bool is_inplace)603     void setup(const TensorShape &shape, DataType data_type0, DataType data_type1, DataType output_data_type,
604                QuantizationInfo qinfo0, QuantizationInfo qinfo1, QuantizationInfo qinfo_out, bool is_inplace)
605 
606     {
607         ArithmeticOperationsGenericFixture<TensorType, AccessorType, FunctionType, T>::setup(ArithmeticOperation::SQUARED_DIFF, shape, shape,
608                                                                                              data_type0, data_type1, output_data_type,
609                                                                                              qinfo0, qinfo1, qinfo_out, is_inplace);
610     }
611 };
612 
613 template <typename TensorType, typename AccessorType, typename FunctionType, typename T>
614 class ElementwiseSquaredDiffQuantizedBroadcastValidationFixture : public ArithmeticOperationsGenericFixture<TensorType, AccessorType, FunctionType, T>
615 {
616 public:
617     template <typename...>
setup(const TensorShape & shape0,const TensorShape & shape1,DataType data_type0,DataType data_type1,DataType output_data_type,QuantizationInfo qinfo0,QuantizationInfo qinfo1,QuantizationInfo qinfo_out,bool is_inplace)618     void setup(const TensorShape &shape0, const TensorShape &shape1, DataType data_type0, DataType data_type1, DataType output_data_type,
619                QuantizationInfo qinfo0, QuantizationInfo qinfo1, QuantizationInfo qinfo_out, bool is_inplace)
620 
621     {
622         ArithmeticOperationsGenericFixture<TensorType, AccessorType, FunctionType, T>::setup(ArithmeticOperation::SQUARED_DIFF, shape0, shape1,
623                                                                                              data_type0, data_type1, output_data_type,
624                                                                                              qinfo0, qinfo1, qinfo_out, is_inplace);
625     }
626 };
627 
628 template <typename TensorType, typename AccessorType, typename FunctionType, typename T>
629 class PReluLayerBroadcastValidationFixture : public ArithmeticOperationsGenericFixture<TensorType, AccessorType, FunctionType, T>
630 {
631 public:
632     template <typename...>
setup(const TensorShape & shape0,const TensorShape & shape1,DataType data_type0,DataType data_type1,DataType output_data_type)633     void setup(const TensorShape &shape0, const TensorShape &shape1, DataType data_type0, DataType data_type1, DataType output_data_type)
634     {
635         ArithmeticOperationsGenericFixture<TensorType, AccessorType, FunctionType, T>::setup(ArithmeticOperation::PRELU, shape0, shape1,
636                                                                                              data_type0, data_type1, output_data_type,
637                                                                                              QuantizationInfo(), QuantizationInfo(), QuantizationInfo());
638     }
639 };
640 
641 template <typename TensorType, typename AccessorType, typename FunctionType, typename T>
642 class PReluLayerValidationFixture : public ArithmeticOperationsGenericFixture<TensorType, AccessorType, FunctionType, T>
643 {
644 public:
645     template <typename...>
setup(const TensorShape & shape,DataType data_type0,DataType data_type1,DataType output_data_type)646     void setup(const TensorShape &shape, DataType data_type0, DataType data_type1, DataType output_data_type)
647     {
648         ArithmeticOperationsGenericFixture<TensorType, AccessorType, FunctionType, T>::setup(ArithmeticOperation::PRELU, shape, shape,
649                                                                                              data_type0, data_type1, output_data_type,
650                                                                                              QuantizationInfo(), QuantizationInfo(), QuantizationInfo());
651     }
652 };
653 
654 template <typename TensorType, typename AccessorType, typename FunctionType, typename T>
655 class PReluLayerValidationQuantizedFixture : public ArithmeticOperationsGenericFixture<TensorType, AccessorType, FunctionType, T>
656 {
657 public:
658     template <typename...>
setup(const TensorShape & shape,DataType data_type0,DataType data_type1,DataType output_data_type,QuantizationInfo qinfo0,QuantizationInfo qinfo1,QuantizationInfo qinfo_out)659     void setup(const TensorShape &shape, DataType data_type0, DataType data_type1, DataType output_data_type,
660                QuantizationInfo qinfo0, QuantizationInfo qinfo1, QuantizationInfo qinfo_out)
661 
662     {
663         ArithmeticOperationsGenericFixture<TensorType, AccessorType, FunctionType, T>::setup(ArithmeticOperation::PRELU, shape, shape,
664                                                                                              data_type0, data_type1, output_data_type,
665                                                                                              qinfo0, qinfo1, qinfo_out);
666     }
667 };
668 
669 template <typename TensorType, typename AccessorType, typename FunctionType, typename T>
670 class PReluLayerQuantizedBroadcastValidationFixture : public ArithmeticOperationsGenericFixture<TensorType, AccessorType, FunctionType, T>
671 {
672 public:
673     template <typename...>
setup(const TensorShape & shape0,const TensorShape & shape1,DataType data_type0,DataType data_type1,DataType output_data_type,QuantizationInfo qinfo0,QuantizationInfo qinfo1,QuantizationInfo qinfo_out)674     void setup(const TensorShape &shape0, const TensorShape &shape1, DataType data_type0, DataType data_type1, DataType output_data_type,
675                QuantizationInfo qinfo0, QuantizationInfo qinfo1, QuantizationInfo qinfo_out)
676 
677     {
678         ArithmeticOperationsGenericFixture<TensorType, AccessorType, FunctionType, T>::setup(ArithmeticOperation::PRELU, shape0, shape1,
679                                                                                              data_type0, data_type1, output_data_type,
680                                                                                              qinfo0, qinfo1, qinfo_out);
681     }
682 };
683 
684 template <typename TensorType, typename AccessorType, typename FunctionType, typename T>
685 class ElementwisePowerBroadcastValidationFixture : public ArithmeticOperationsGenericFixture<TensorType, AccessorType, FunctionType, T>
686 {
687 public:
688     template <typename...>
setup(const TensorShape & shape0,const TensorShape & shape1,DataType data_type0,DataType data_type1,DataType output_data_type,bool is_inplace)689     void setup(const TensorShape &shape0, const TensorShape &shape1, DataType data_type0, DataType data_type1, DataType output_data_type, bool is_inplace)
690     {
691         ArithmeticOperationsGenericFixture<TensorType, AccessorType, FunctionType, T>::setup(ArithmeticOperation::POWER, shape0, shape1,
692                                                                                              data_type0, data_type1, output_data_type,
693                                                                                              QuantizationInfo(), QuantizationInfo(), QuantizationInfo(), is_inplace);
694     }
695 };
696 
697 template <typename TensorType, typename AccessorType, typename FunctionType, typename T>
698 class ElementwisePowerValidationFixture : public ArithmeticOperationsGenericFixture<TensorType, AccessorType, FunctionType, T>
699 {
700 public:
701     template <typename...>
setup(const TensorShape & shape,DataType data_type0,DataType data_type1,DataType output_data_type,bool is_inplace)702     void setup(const TensorShape &shape, DataType data_type0, DataType data_type1, DataType output_data_type, bool is_inplace)
703     {
704         ArithmeticOperationsGenericFixture<TensorType, AccessorType, FunctionType, T>::setup(ArithmeticOperation::POWER, shape, shape,
705                                                                                              data_type0, data_type1, output_data_type,
706                                                                                              QuantizationInfo(), QuantizationInfo(), QuantizationInfo(), is_inplace);
707     }
708 };
709 
710 template <typename TensorType, typename AccessorType, typename FunctionType, typename T>
711 class ElementwisePowerBroadcastValidationFloatFixture : public ArithmeticOperationsFuseActivationFixture<TensorType, AccessorType, FunctionType, T>
712 {
713 public:
714     template <typename...>
setup(const TensorShape & shape0,const TensorShape & shape1,DataType data_type0,DataType data_type1,DataType output_data_type,ActivationLayerInfo act_info,bool is_inplace)715     void setup(const TensorShape &shape0, const TensorShape &shape1, DataType data_type0, DataType data_type1, DataType output_data_type, ActivationLayerInfo act_info, bool is_inplace)
716     {
717         ArithmeticOperationsFuseActivationFixture<TensorType, AccessorType, FunctionType, T>::setup(ArithmeticOperation::POWER, shape0, shape1,
718                                                                                                     data_type0, data_type1, output_data_type,
719                                                                                                     QuantizationInfo(), QuantizationInfo(), QuantizationInfo(), act_info, is_inplace);
720     }
721 };
722 
723 template <typename TensorType, typename AccessorType, typename FunctionType, typename T>
724 class ElementwisePowerValidationFloatFixture : public ArithmeticOperationsFuseActivationFixture<TensorType, AccessorType, FunctionType, T>
725 {
726 public:
727     template <typename...>
setup(const TensorShape & shape,DataType data_type0,DataType data_type1,DataType output_data_type,ActivationLayerInfo act_info,bool is_inplace)728     void setup(const TensorShape &shape, DataType data_type0, DataType data_type1, DataType output_data_type, ActivationLayerInfo act_info, bool is_inplace)
729     {
730         ArithmeticOperationsFuseActivationFixture<TensorType, AccessorType, FunctionType, T>::setup(ArithmeticOperation::POWER, shape, shape,
731                                                                                                     data_type0, data_type1, output_data_type,
732                                                                                                     QuantizationInfo(), QuantizationInfo(), QuantizationInfo(), act_info, is_inplace);
733     }
734 };
735 
736 } // namespace validation
737 } // namespace test
738 } // namespace arm_compute
739 #endif /* ARM_COMPUTE_TEST_ARITHMETIC_OPERATIONS_FIXTURE */
740