blob: 7428fb5cb7f3146acd4d38dd68dc66ec1a193414 [file] [log] [blame]
John Richardsondd715f22017-09-18 16:10:48 +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_PIXEL_WISE_MULTIPLICATION_FIXTURE
25#define ARM_COMPUTE_TEST_PIXEL_WISE_MULTIPLICATION_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"
Georgios Pinitas5a7e7762017-12-01 16:27:29 +000034#include "tests/validation/reference/PixelWiseMultiplication.h"
John Richardsondd715f22017-09-18 16:10:48 +010035
36namespace arm_compute
37{
38namespace test
39{
40namespace validation
41{
42template <typename TensorType, typename AccessorType, typename FunctionType, typename T1, typename T2>
43class PixelWiseMultiplicationValidationFixture : public framework::Fixture
44{
45public:
46 template <typename...>
47 void setup(TensorShape shape,
48 DataType dt_in1,
49 DataType dt_in2,
50 float scale,
51 ConvertPolicy convert_policy,
52 RoundingPolicy rounding_policy)
53 {
54 _target = compute_target(shape, dt_in1, dt_in2, scale, convert_policy, rounding_policy);
55 _reference = compute_reference(shape, dt_in1, dt_in2, scale, convert_policy, rounding_policy);
56 }
57
58protected:
59 template <typename U>
60 void fill(U &&tensor, unsigned int seed_offset)
61 {
62 library->fill_tensor_uniform(tensor, seed_offset);
63 }
64
65 TensorType compute_target(const TensorShape &shape, DataType dt_in1, DataType dt_in2, float scale, ConvertPolicy convert_policy, RoundingPolicy rounding_policy)
66 {
67 // Create tensors
68 TensorType src1 = create_tensor<TensorType>(shape, dt_in1);
69 TensorType src2 = create_tensor<TensorType>(shape, dt_in2);
70 TensorType dst = create_tensor<TensorType>(shape, dt_in2);
71
72 // Create and configure function
73 FunctionType multiply;
74 multiply.configure(&src1, &src2, &dst, scale, convert_policy, rounding_policy);
75
76 ARM_COMPUTE_EXPECT(src1.info()->is_resizable(), framework::LogLevel::ERRORS);
77 ARM_COMPUTE_EXPECT(src2.info()->is_resizable(), framework::LogLevel::ERRORS);
78 ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS);
79
80 // Allocate tensors
81 src1.allocator()->allocate();
82 src2.allocator()->allocate();
83 dst.allocator()->allocate();
84
85 ARM_COMPUTE_EXPECT(!src1.info()->is_resizable(), framework::LogLevel::ERRORS);
86 ARM_COMPUTE_EXPECT(!src2.info()->is_resizable(), framework::LogLevel::ERRORS);
87 ARM_COMPUTE_EXPECT(!dst.info()->is_resizable(), framework::LogLevel::ERRORS);
88
89 // Fill tensors
90 fill(AccessorType(src1), 0);
91 fill(AccessorType(src2), 1);
92
93 // Compute function
94 multiply.run();
95
96 return dst;
97 }
98
99 SimpleTensor<T2> compute_reference(const TensorShape &shape, DataType dt_in1, DataType dt_in2, float scale, ConvertPolicy convert_policy, RoundingPolicy rounding_policy)
100 {
101 // Create reference
102 SimpleTensor<T1> src1{ shape, dt_in1 };
103 SimpleTensor<T2> src2{ shape, dt_in2 };
104
105 // Fill reference
106 fill(src1, 0);
107 fill(src2, 1);
108
109 return reference::pixel_wise_multiplication<T1, T2>(src1, src2, scale, convert_policy, rounding_policy);
110 }
111
112 TensorType _target{};
113 SimpleTensor<T2> _reference{};
114};
115} // namespace validation
116} // namespace test
117} // namespace arm_compute
118#endif /* ARM_COMPUTE_TEST_PIXEL_WISE_MULTIPLICATION_FIXTURE */