blob: 68f91e16562065d4f0eafda253daade29c9539b2 [file] [log] [blame]
Abe Mbise7905f912017-09-07 18:21:28 +01001/*
Michele Di Giorgiod9eaf612020-07-08 11:12:57 +01002 * Copyright (c) 2017 Arm Limited.
Abe Mbise7905f912017-09-07 18:21:28 +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_GAUSSIAN5X5_FIXTURE
25#define ARM_COMPUTE_TEST_GAUSSIAN5X5_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/Gaussian5x5.h"
Abe Mbise7905f912017-09-07 18:21:28 +010035
36#include <random>
37
38namespace arm_compute
39{
40namespace test
41{
42namespace validation
43{
44template <typename TensorType, typename AccessorType, typename FunctionType, typename T>
45class Gaussian5x5ValidationFixture : public framework::Fixture
46{
47public:
48 template <typename...>
49 void setup(TensorShape shape, 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 uint8_t constant_border_value = distribution(gen);
54
Gian Marco1a39f6d2017-11-08 10:19:21 +000055 _border_mode = border_mode;
56 _target = compute_target(shape, data_type, border_mode, constant_border_value);
57 _reference = compute_reference(shape, data_type, border_mode, constant_border_value);
Abe Mbise7905f912017-09-07 18:21:28 +010058 }
59
60protected:
61 template <typename U>
62 void fill(U &&tensor)
63 {
64 library->fill_tensor_uniform(tensor, 0);
65 }
66
67 TensorType compute_target(const TensorShape &shape, DataType data_type, BorderMode border_mode, uint8_t constant_border_value)
68 {
69 // Create tensors
70 TensorType src = create_tensor<TensorType>(shape, data_type);
71 TensorType dst = create_tensor<TensorType>(shape, data_type);
72
73 // Create and configure function
74 FunctionType gaussian5x5;
75 gaussian5x5.configure(&src, &dst, border_mode, constant_border_value);
76
77 ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS);
78 ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS);
79
80 // Allocate tensors
81 src.allocator()->allocate();
82 dst.allocator()->allocate();
83
84 ARM_COMPUTE_EXPECT(!src.info()->is_resizable(), framework::LogLevel::ERRORS);
85 ARM_COMPUTE_EXPECT(!dst.info()->is_resizable(), framework::LogLevel::ERRORS);
86
87 // Fill tensors
88 fill(AccessorType(src));
89
90 // Compute function
91 gaussian5x5.run();
92
93 return dst;
94 }
95
96 SimpleTensor<T> compute_reference(const TensorShape &shape, DataType data_type, BorderMode border_mode, uint8_t constant_border_value)
97 {
98 ARM_COMPUTE_ERROR_ON(data_type != DataType::U8);
99
100 // Create reference
101 SimpleTensor<T> src{ shape, data_type };
102
103 // Fill reference
104 fill(src);
105
106 // Compute reference
107 return reference::gaussian5x5<T>(src, border_mode, constant_border_value);
108 }
109
110 BorderMode _border_mode{};
111 TensorType _target{};
112 SimpleTensor<T> _reference{};
113};
114} // namespace validation
115} // namespace test
116} // namespace arm_compute
117#endif /* ARM_COMPUTE_TEST_GAUSSIAN5X5_FIXTURE */