blob: b1f7f28cd317d01c73e3364cdc4e6f346660f025 [file] [log] [blame]
Abe Mbise7905f912017-09-07 18:21:28 +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_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"
34#include "tests/validation/CPP/Gaussian5x5.h"
35
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
55 _target = compute_target(shape, data_type, border_mode, constant_border_value);
56 _reference = compute_reference(shape, data_type, border_mode, constant_border_value);
57 }
58
59protected:
60 template <typename U>
61 void fill(U &&tensor)
62 {
63 library->fill_tensor_uniform(tensor, 0);
64 }
65
66 TensorType compute_target(const TensorShape &shape, DataType data_type, BorderMode border_mode, uint8_t constant_border_value)
67 {
68 // Create tensors
69 TensorType src = create_tensor<TensorType>(shape, data_type);
70 TensorType dst = create_tensor<TensorType>(shape, data_type);
71
72 // Create and configure function
73 FunctionType gaussian5x5;
74 gaussian5x5.configure(&src, &dst, border_mode, constant_border_value);
75
76 ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS);
77 ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS);
78
79 // Allocate tensors
80 src.allocator()->allocate();
81 dst.allocator()->allocate();
82
83 ARM_COMPUTE_EXPECT(!src.info()->is_resizable(), framework::LogLevel::ERRORS);
84 ARM_COMPUTE_EXPECT(!dst.info()->is_resizable(), framework::LogLevel::ERRORS);
85
86 // Fill tensors
87 fill(AccessorType(src));
88
89 // Compute function
90 gaussian5x5.run();
91
92 return dst;
93 }
94
95 SimpleTensor<T> compute_reference(const TensorShape &shape, DataType data_type, BorderMode border_mode, uint8_t constant_border_value)
96 {
97 ARM_COMPUTE_ERROR_ON(data_type != DataType::U8);
98
99 // Create reference
100 SimpleTensor<T> src{ shape, data_type };
101
102 // Fill reference
103 fill(src);
104
105 // Compute reference
106 return reference::gaussian5x5<T>(src, border_mode, constant_border_value);
107 }
108
109 BorderMode _border_mode{};
110 TensorType _target{};
111 SimpleTensor<T> _reference{};
112};
113} // namespace validation
114} // namespace test
115} // namespace arm_compute
116#endif /* ARM_COMPUTE_TEST_GAUSSIAN5X5_FIXTURE */