John Richardson | dd715f2 | 2017-09-18 16:10:48 +0100 | [diff] [blame] | 1 | /* |
Manuel Bottini | 79fa9a2 | 2019-02-22 17:54:22 +0000 | [diff] [blame] | 2 | * Copyright (c) 2017-2019 ARM Limited. |
John Richardson | dd715f2 | 2017-09-18 16:10:48 +0100 | [diff] [blame] | 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 Pinitas | 5a7e776 | 2017-12-01 16:27:29 +0000 | [diff] [blame] | 34 | #include "tests/validation/reference/PixelWiseMultiplication.h" |
John Richardson | dd715f2 | 2017-09-18 16:10:48 +0100 | [diff] [blame] | 35 | |
| 36 | namespace arm_compute |
| 37 | { |
| 38 | namespace test |
| 39 | { |
| 40 | namespace validation |
| 41 | { |
| 42 | template <typename TensorType, typename AccessorType, typename FunctionType, typename T1, typename T2> |
Georgios Pinitas | bf28a3c | 2018-09-18 14:34:48 +0100 | [diff] [blame] | 43 | class PixelWiseMultiplicationGenericValidationFixture : public framework::Fixture |
John Richardson | dd715f2 | 2017-09-18 16:10:48 +0100 | [diff] [blame] | 44 | { |
| 45 | public: |
| 46 | template <typename...> |
Michele Di Giorgio | 6259e5f | 2018-01-17 17:29:33 +0000 | [diff] [blame] | 47 | void setup(const TensorShape &shape0, |
| 48 | const TensorShape &shape1, |
| 49 | DataType dt_in1, |
| 50 | DataType dt_in2, |
| 51 | float scale, |
| 52 | ConvertPolicy convert_policy, |
Georgios Pinitas | bf28a3c | 2018-09-18 14:34:48 +0100 | [diff] [blame] | 53 | RoundingPolicy rounding_policy, |
| 54 | QuantizationInfo qinfo0, |
| 55 | QuantizationInfo qinfo1, |
| 56 | QuantizationInfo qinfo_out) |
John Richardson | dd715f2 | 2017-09-18 16:10:48 +0100 | [diff] [blame] | 57 | { |
Georgios Pinitas | bf28a3c | 2018-09-18 14:34:48 +0100 | [diff] [blame] | 58 | _target = compute_target(shape0, shape1, dt_in1, dt_in2, scale, convert_policy, rounding_policy, qinfo0, qinfo1, qinfo_out); |
| 59 | _reference = compute_reference(shape0, shape1, dt_in1, dt_in2, scale, convert_policy, rounding_policy, qinfo0, qinfo1, qinfo_out); |
John Richardson | dd715f2 | 2017-09-18 16:10:48 +0100 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | protected: |
| 63 | template <typename U> |
| 64 | void fill(U &&tensor, unsigned int seed_offset) |
| 65 | { |
| 66 | library->fill_tensor_uniform(tensor, seed_offset); |
| 67 | } |
| 68 | |
Michele Di Giorgio | 6259e5f | 2018-01-17 17:29:33 +0000 | [diff] [blame] | 69 | TensorType compute_target(const TensorShape &shape0, const TensorShape &shape1, DataType dt_in1, DataType dt_in2, |
Georgios Pinitas | bf28a3c | 2018-09-18 14:34:48 +0100 | [diff] [blame] | 70 | float scale, ConvertPolicy convert_policy, RoundingPolicy rounding_policy, |
| 71 | QuantizationInfo qinfo0, QuantizationInfo qinfo1, QuantizationInfo qinfo_out) |
John Richardson | dd715f2 | 2017-09-18 16:10:48 +0100 | [diff] [blame] | 72 | { |
| 73 | // Create tensors |
Georgios Pinitas | bf28a3c | 2018-09-18 14:34:48 +0100 | [diff] [blame] | 74 | TensorType src1 = create_tensor<TensorType>(shape0, dt_in1, 1, qinfo0); |
| 75 | TensorType src2 = create_tensor<TensorType>(shape1, dt_in2, 1, qinfo1); |
| 76 | TensorType dst = create_tensor<TensorType>(TensorShape::broadcast_shape(shape0, shape1), dt_in2, 1, qinfo_out); |
John Richardson | dd715f2 | 2017-09-18 16:10:48 +0100 | [diff] [blame] | 77 | |
| 78 | // Create and configure function |
| 79 | FunctionType multiply; |
| 80 | multiply.configure(&src1, &src2, &dst, scale, convert_policy, rounding_policy); |
| 81 | |
| 82 | ARM_COMPUTE_EXPECT(src1.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 83 | ARM_COMPUTE_EXPECT(src2.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 84 | ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 85 | |
| 86 | // Allocate tensors |
| 87 | src1.allocator()->allocate(); |
| 88 | src2.allocator()->allocate(); |
| 89 | dst.allocator()->allocate(); |
| 90 | |
| 91 | ARM_COMPUTE_EXPECT(!src1.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 92 | ARM_COMPUTE_EXPECT(!src2.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 93 | ARM_COMPUTE_EXPECT(!dst.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 94 | |
| 95 | // Fill tensors |
| 96 | fill(AccessorType(src1), 0); |
| 97 | fill(AccessorType(src2), 1); |
| 98 | |
| 99 | // Compute function |
| 100 | multiply.run(); |
| 101 | |
| 102 | return dst; |
| 103 | } |
| 104 | |
Michele Di Giorgio | 6259e5f | 2018-01-17 17:29:33 +0000 | [diff] [blame] | 105 | SimpleTensor<T2> compute_reference(const TensorShape &shape0, const TensorShape &shape1, DataType dt_in1, DataType dt_in2, |
Georgios Pinitas | bf28a3c | 2018-09-18 14:34:48 +0100 | [diff] [blame] | 106 | float scale, ConvertPolicy convert_policy, RoundingPolicy rounding_policy, |
| 107 | QuantizationInfo qinfo0, QuantizationInfo qinfo1, QuantizationInfo qinfo_out) |
John Richardson | dd715f2 | 2017-09-18 16:10:48 +0100 | [diff] [blame] | 108 | { |
| 109 | // Create reference |
Georgios Pinitas | bf28a3c | 2018-09-18 14:34:48 +0100 | [diff] [blame] | 110 | SimpleTensor<T1> src1{ shape0, dt_in1, 1, qinfo0 }; |
| 111 | SimpleTensor<T2> src2{ shape1, dt_in2, 1, qinfo1 }; |
John Richardson | dd715f2 | 2017-09-18 16:10:48 +0100 | [diff] [blame] | 112 | |
| 113 | // Fill reference |
| 114 | fill(src1, 0); |
| 115 | fill(src2, 1); |
| 116 | |
Georgios Pinitas | bf28a3c | 2018-09-18 14:34:48 +0100 | [diff] [blame] | 117 | return reference::pixel_wise_multiplication<T1, T2>(src1, src2, scale, convert_policy, rounding_policy, qinfo_out); |
John Richardson | dd715f2 | 2017-09-18 16:10:48 +0100 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | TensorType _target{}; |
| 121 | SimpleTensor<T2> _reference{}; |
| 122 | }; |
Michele Di Giorgio | 6259e5f | 2018-01-17 17:29:33 +0000 | [diff] [blame] | 123 | |
| 124 | template <typename TensorType, typename AccessorType, typename FunctionType, typename T1, typename T2> |
Manuel Bottini | 79fa9a2 | 2019-02-22 17:54:22 +0000 | [diff] [blame] | 125 | class PixelWiseMultiplicationQuatizedValidationFixture : public PixelWiseMultiplicationGenericValidationFixture<TensorType, AccessorType, FunctionType, T1, T2> |
| 126 | { |
| 127 | public: |
| 128 | template <typename...> |
| 129 | void setup(const TensorShape &shape, DataType dt_in1, DataType dt_in2, float scale, ConvertPolicy convert_policy, RoundingPolicy rounding_policy, |
| 130 | QuantizationInfo in1_qua_info, QuantizationInfo in2_qua_info, QuantizationInfo out_qua_info) |
| 131 | { |
| 132 | PixelWiseMultiplicationGenericValidationFixture<TensorType, AccessorType, FunctionType, T1, T2>::setup(shape, shape, dt_in1, dt_in2, scale, convert_policy, rounding_policy, |
| 133 | in1_qua_info, in2_qua_info, out_qua_info); |
| 134 | } |
| 135 | }; |
| 136 | |
| 137 | template <typename TensorType, typename AccessorType, typename FunctionType, typename T1, typename T2> |
Georgios Pinitas | bf28a3c | 2018-09-18 14:34:48 +0100 | [diff] [blame] | 138 | class PixelWiseMultiplicationValidationFixture : public PixelWiseMultiplicationGenericValidationFixture<TensorType, AccessorType, FunctionType, T1, T2> |
Michele Di Giorgio | 6259e5f | 2018-01-17 17:29:33 +0000 | [diff] [blame] | 139 | { |
| 140 | public: |
| 141 | template <typename...> |
| 142 | void setup(const TensorShape &shape, DataType dt_in1, DataType dt_in2, float scale, ConvertPolicy convert_policy, RoundingPolicy rounding_policy) |
| 143 | { |
Georgios Pinitas | bf28a3c | 2018-09-18 14:34:48 +0100 | [diff] [blame] | 144 | PixelWiseMultiplicationGenericValidationFixture<TensorType, AccessorType, FunctionType, T1, T2>::setup(shape, shape, dt_in1, dt_in2, scale, convert_policy, rounding_policy, |
| 145 | QuantizationInfo(), QuantizationInfo(), QuantizationInfo()); |
Michele Di Giorgio | 6259e5f | 2018-01-17 17:29:33 +0000 | [diff] [blame] | 146 | } |
| 147 | }; |
| 148 | |
Georgios Pinitas | bf28a3c | 2018-09-18 14:34:48 +0100 | [diff] [blame] | 149 | template <typename TensorType, typename AccessorType, typename FunctionType, typename T1, typename T2> |
| 150 | class PixelWiseMultiplicationBroadcastValidationFixture : public PixelWiseMultiplicationGenericValidationFixture<TensorType, AccessorType, FunctionType, T1, T2> |
| 151 | { |
| 152 | public: |
| 153 | template <typename...> |
| 154 | void setup(const TensorShape &shape0, const TensorShape &shape1, DataType dt_in1, DataType dt_in2, float scale, ConvertPolicy convert_policy, RoundingPolicy rounding_policy) |
| 155 | { |
| 156 | PixelWiseMultiplicationGenericValidationFixture<TensorType, AccessorType, FunctionType, T1, T2>::setup(shape0, shape1, dt_in1, dt_in2, scale, convert_policy, rounding_policy, |
| 157 | QuantizationInfo(), QuantizationInfo(), QuantizationInfo()); |
| 158 | } |
| 159 | }; |
| 160 | |
| 161 | template <typename TensorType, typename AccessorType, typename FunctionType, typename T1, typename T2> |
| 162 | class PixelWiseMultiplicationValidationQuantizedFixture : public PixelWiseMultiplicationGenericValidationFixture<TensorType, AccessorType, FunctionType, T1, T2> |
| 163 | { |
| 164 | public: |
| 165 | template <typename...> |
| 166 | void setup(const TensorShape &shape, DataType dt, float scale, ConvertPolicy convert_policy, RoundingPolicy rounding_policy, |
| 167 | QuantizationInfo qinfo0, QuantizationInfo qinfo1, QuantizationInfo qinfo_out) |
| 168 | { |
| 169 | PixelWiseMultiplicationGenericValidationFixture<TensorType, AccessorType, FunctionType, T1, T2>::setup(shape, shape, dt, dt, scale, convert_policy, rounding_policy, |
| 170 | qinfo0, qinfo1, qinfo_out); |
| 171 | } |
| 172 | }; |
John Richardson | dd715f2 | 2017-09-18 16:10:48 +0100 | [diff] [blame] | 173 | } // namespace validation |
| 174 | } // namespace test |
| 175 | } // namespace arm_compute |
| 176 | #endif /* ARM_COMPUTE_TEST_PIXEL_WISE_MULTIPLICATION_FIXTURE */ |