blob: b9f19f3e77e3b50d1950a40e2bc09352c56039e2 [file] [log] [blame]
John Richardsondd715f22017-09-18 16:10:48 +01001/*
Michele Di Giorgio6259e5f2018-01-17 17:29:33 +00002 * Copyright (c) 2017-2018 ARM Limited.
John Richardsondd715f22017-09-18 16:10:48 +01003 *
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>
Michele Di Giorgio6259e5f2018-01-17 17:29:33 +000043class PixelWiseMultiplicationBroadcastValidationFixture : public framework::Fixture
John Richardsondd715f22017-09-18 16:10:48 +010044{
45public:
46 template <typename...>
Michele Di Giorgio6259e5f2018-01-17 17:29:33 +000047 void setup(const TensorShape &shape0,
48 const TensorShape &shape1,
49 DataType dt_in1,
50 DataType dt_in2,
51 float scale,
52 ConvertPolicy convert_policy,
53 RoundingPolicy rounding_policy)
John Richardsondd715f22017-09-18 16:10:48 +010054 {
Michele Di Giorgio6259e5f2018-01-17 17:29:33 +000055 _target = compute_target(shape0, shape1, dt_in1, dt_in2, scale, convert_policy, rounding_policy);
56 _reference = compute_reference(shape0, shape1, dt_in1, dt_in2, scale, convert_policy, rounding_policy);
John Richardsondd715f22017-09-18 16:10:48 +010057 }
58
59protected:
60 template <typename U>
61 void fill(U &&tensor, unsigned int seed_offset)
62 {
63 library->fill_tensor_uniform(tensor, seed_offset);
64 }
65
Michele Di Giorgio6259e5f2018-01-17 17:29:33 +000066 TensorType compute_target(const TensorShape &shape0, const TensorShape &shape1, DataType dt_in1, DataType dt_in2,
67 float scale, ConvertPolicy convert_policy, RoundingPolicy rounding_policy)
John Richardsondd715f22017-09-18 16:10:48 +010068 {
69 // Create tensors
Michele Di Giorgio6259e5f2018-01-17 17:29:33 +000070 TensorType src1 = create_tensor<TensorType>(shape0, dt_in1);
71 TensorType src2 = create_tensor<TensorType>(shape1, dt_in2);
72 TensorType dst = create_tensor<TensorType>(TensorShape::broadcast_shape(shape0, shape1), dt_in2);
John Richardsondd715f22017-09-18 16:10:48 +010073
74 // Create and configure function
75 FunctionType multiply;
76 multiply.configure(&src1, &src2, &dst, scale, convert_policy, rounding_policy);
77
78 ARM_COMPUTE_EXPECT(src1.info()->is_resizable(), framework::LogLevel::ERRORS);
79 ARM_COMPUTE_EXPECT(src2.info()->is_resizable(), framework::LogLevel::ERRORS);
80 ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS);
81
82 // Allocate tensors
83 src1.allocator()->allocate();
84 src2.allocator()->allocate();
85 dst.allocator()->allocate();
86
87 ARM_COMPUTE_EXPECT(!src1.info()->is_resizable(), framework::LogLevel::ERRORS);
88 ARM_COMPUTE_EXPECT(!src2.info()->is_resizable(), framework::LogLevel::ERRORS);
89 ARM_COMPUTE_EXPECT(!dst.info()->is_resizable(), framework::LogLevel::ERRORS);
90
91 // Fill tensors
92 fill(AccessorType(src1), 0);
93 fill(AccessorType(src2), 1);
94
95 // Compute function
96 multiply.run();
97
98 return dst;
99 }
100
Michele Di Giorgio6259e5f2018-01-17 17:29:33 +0000101 SimpleTensor<T2> compute_reference(const TensorShape &shape0, const TensorShape &shape1, DataType dt_in1, DataType dt_in2,
102 float scale, ConvertPolicy convert_policy, RoundingPolicy rounding_policy)
John Richardsondd715f22017-09-18 16:10:48 +0100103 {
104 // Create reference
Michele Di Giorgio6259e5f2018-01-17 17:29:33 +0000105 SimpleTensor<T1> src1{ shape0, dt_in1 };
106 SimpleTensor<T2> src2{ shape1, dt_in2 };
John Richardsondd715f22017-09-18 16:10:48 +0100107
108 // Fill reference
109 fill(src1, 0);
110 fill(src2, 1);
111
112 return reference::pixel_wise_multiplication<T1, T2>(src1, src2, scale, convert_policy, rounding_policy);
113 }
114
115 TensorType _target{};
116 SimpleTensor<T2> _reference{};
117};
Michele Di Giorgio6259e5f2018-01-17 17:29:33 +0000118
119template <typename TensorType, typename AccessorType, typename FunctionType, typename T1, typename T2>
120class PixelWiseMultiplicationValidationFixture : public PixelWiseMultiplicationBroadcastValidationFixture<TensorType, AccessorType, FunctionType, T1, T2>
121{
122public:
123 template <typename...>
124 void setup(const TensorShape &shape, DataType dt_in1, DataType dt_in2, float scale, ConvertPolicy convert_policy, RoundingPolicy rounding_policy)
125 {
126 PixelWiseMultiplicationBroadcastValidationFixture<TensorType, AccessorType, FunctionType, T1, T2>::setup(shape, shape, dt_in1, dt_in2, scale, convert_policy, rounding_policy);
127 }
128};
129
John Richardsondd715f22017-09-18 16:10:48 +0100130} // namespace validation
131} // namespace test
132} // namespace arm_compute
133#endif /* ARM_COMPUTE_TEST_PIXEL_WISE_MULTIPLICATION_FIXTURE */