• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2017-2018 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_REMAP_FIXTURE
25 #define ARM_COMPUTE_TEST_REMAP_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/reference/Remap.h"
35 
36 #include <random>
37 
38 namespace arm_compute
39 {
40 namespace test
41 {
42 namespace validation
43 {
44 template <typename TensorType, typename AccessorType, typename FunctionType, typename T>
45 class RemapValidationFixture : public framework::Fixture
46 {
47 public:
48     template <typename...>
setup(TensorShape shape,InterpolationPolicy policy,DataType data_type,BorderMode border_mode)49     void setup(TensorShape shape, InterpolationPolicy policy, DataType data_type, BorderMode border_mode)
50     {
51         std::mt19937                           gen(library->seed());
52         std::uniform_int_distribution<uint8_t> distribution(0, 255);
53         const T                                constant_border_value = static_cast<T>(distribution(gen));
54 
55         _target    = compute_target(shape, policy, data_type, border_mode, constant_border_value);
56         _reference = compute_reference(shape, policy, data_type, border_mode, constant_border_value);
57     }
58 
59 protected:
60     template <typename U>
fill(U && tensor,int i,float min,float max)61     void fill(U &&tensor, int i, float min, float max)
62     {
63         std::uniform_int_distribution<> distribution((int)min, (int)max);
64         library->fill(tensor, distribution, i);
65     }
66 
compute_target(const TensorShape & shape,InterpolationPolicy policy,DataType data_type,BorderMode border_mode,T constant_border_value)67     TensorType compute_target(const TensorShape &shape, InterpolationPolicy policy, DataType data_type, BorderMode border_mode, T constant_border_value)
68     {
69         // Create tensors
70         TensorType src   = create_tensor<TensorType>(shape, data_type);
71         TensorType map_x = create_tensor<TensorType>(shape, DataType::F32);
72         TensorType map_y = create_tensor<TensorType>(shape, DataType::F32);
73         TensorType dst   = create_tensor<TensorType>(shape, data_type);
74 
75         // Create and configure function
76         FunctionType remap;
77         remap.configure(&src, &map_x, &map_y, &dst, policy, border_mode, constant_border_value);
78 
79         ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS);
80         ARM_COMPUTE_EXPECT(map_x.info()->is_resizable(), framework::LogLevel::ERRORS);
81         ARM_COMPUTE_EXPECT(map_y.info()->is_resizable(), framework::LogLevel::ERRORS);
82         ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS);
83 
84         // Allocate tensors
85         src.allocator()->allocate();
86         map_x.allocator()->allocate();
87         map_y.allocator()->allocate();
88         dst.allocator()->allocate();
89 
90         ARM_COMPUTE_EXPECT(!src.info()->is_resizable(), framework::LogLevel::ERRORS);
91         ARM_COMPUTE_EXPECT(!map_x.info()->is_resizable(), framework::LogLevel::ERRORS);
92         ARM_COMPUTE_EXPECT(!map_y.info()->is_resizable(), framework::LogLevel::ERRORS);
93         ARM_COMPUTE_EXPECT(!dst.info()->is_resizable(), framework::LogLevel::ERRORS);
94 
95         // Fill tensors
96         fill(AccessorType(src), 0, 0, 255);
97         fill(AccessorType(map_x), 1, -5, shape.x() + 5);
98         fill(AccessorType(map_y), 2, -5, shape.y() + 5);
99 
100         // Compute function
101         remap.run();
102 
103         return dst;
104     }
105 
compute_reference(const TensorShape & shape,InterpolationPolicy policy,DataType data_type,BorderMode border_mode,T constant_border_value)106     SimpleTensor<T> compute_reference(const TensorShape &shape, InterpolationPolicy policy, DataType data_type, BorderMode border_mode, T constant_border_value)
107     {
108         ARM_COMPUTE_ERROR_ON(data_type != DataType::U8);
109 
110         // Create reference
111         SimpleTensor<T>     src{ shape, data_type };
112         SimpleTensor<float> map_x{ shape, DataType::F32 };
113         SimpleTensor<float> map_y{ shape, DataType::F32 };
114 
115         // Create the valid mask Tensor
116         _valid_mask = SimpleTensor<T> { shape, data_type };
117 
118         // Fill reference
119         fill(src, 0, 0, 255);
120         fill(map_x, 1, -5, shape.x() + 5);
121         fill(map_y, 2, -5, shape.y() + 5);
122 
123         // Compute reference
124         return reference::remap<T>(src, map_x, map_y, _valid_mask, policy, border_mode, constant_border_value);
125     }
126 
127     TensorType      _target{};
128     SimpleTensor<T> _reference{};
129     SimpleTensor<T> _valid_mask{};
130 };
131 } // namespace validation
132 } // namespace test
133 } // namespace arm_compute
134 #endif /* ARM_COMPUTE_TEST_REMAP_FIXTURE */
135