blob: d090d8583d7d73b9970277005666ed58b05fa032 [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_FIXED_POINT_PIXEL_WISE_MULTIPLICATION_FIXTURE
25#define ARM_COMPUTE_TEST_FIXED_POINT_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"
34#include "tests/validation/CPP/FixedPointPixelWiseMultiplication.h"
35
36namespace arm_compute
37{
38namespace test
39{
40namespace validation
41{
42template <typename TensorType, typename AccessorType, typename FunctionType, typename T>
43class FixedPointPixelWiseMultiplicationValidationFixture : 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 int fixed_point_position)
54 {
55 _target = compute_target(shape, dt_in1, dt_in2, scale, convert_policy, rounding_policy, fixed_point_position);
56 _reference = compute_reference(shape, dt_in1, dt_in2, scale, convert_policy, fixed_point_position);
57 }
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
66 TensorType compute_target(const TensorShape &shape, DataType dt_in1, DataType dt_in2, float scale, ConvertPolicy convert_policy, RoundingPolicy rounding_policy, int fixed_point_position)
67 {
68 // Create tensors
69 TensorType src1 = create_tensor<TensorType>(shape, dt_in1, 1, fixed_point_position);
70 TensorType src2 = create_tensor<TensorType>(shape, dt_in2, 1, fixed_point_position);
71 TensorType dst = create_tensor<TensorType>(shape, dt_in2, 1, fixed_point_position);
72
73 // Create and configure function
74 FunctionType multiply;
75 multiply.configure(&src1, &src2, &dst, scale, convert_policy, rounding_policy);
76
77 ARM_COMPUTE_EXPECT(src1.info()->is_resizable(), framework::LogLevel::ERRORS);
78 ARM_COMPUTE_EXPECT(src2.info()->is_resizable(), framework::LogLevel::ERRORS);
79 ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS);
80
81 // Allocate tensors
82 src1.allocator()->allocate();
83 src2.allocator()->allocate();
84 dst.allocator()->allocate();
85
86 ARM_COMPUTE_EXPECT(!src1.info()->is_resizable(), framework::LogLevel::ERRORS);
87 ARM_COMPUTE_EXPECT(!src2.info()->is_resizable(), framework::LogLevel::ERRORS);
88 ARM_COMPUTE_EXPECT(!dst.info()->is_resizable(), framework::LogLevel::ERRORS);
89
90 // Fill tensors
91 fill(AccessorType(src1), 0);
92 fill(AccessorType(src2), 1);
93
94 // Compute function
95 multiply.run();
96
97 return dst;
98 }
99
100 SimpleTensor<T> compute_reference(const TensorShape &shape, DataType dt_in1, DataType dt_in2, float scale, ConvertPolicy convert_policy, int fixed_point_position)
101 {
102 // Create reference
103 SimpleTensor<T> src1{ shape, dt_in1, 1, fixed_point_position };
104 SimpleTensor<T> src2{ shape, dt_in2, 1, fixed_point_position };
105
106 // Fill reference
107 fill(src1, 0);
108 fill(src2, 1);
109
110 return reference::fixed_point_pixel_wise_multiplication<T>(src1, src2, scale, convert_policy);
111 }
112
113 TensorType _target{};
114 SimpleTensor<T> _reference{};
115};
116} // namespace validation
117} // namespace test
118} // namespace arm_compute
119#endif /* ARM_COMPUTE_TEST_FIXED_POINT_PIXEL_WISE_MULTIPLICATION_FIXTURE */