blob: ae5c53a053a88ba852ff6b8338529d35d0abac71 [file] [log] [blame]
zhenglin0fb6cf52017-12-12 15:56:09 +08001/*
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_NORMALIZE_PLANAR_YUV_LAYER_FIXTURE
25#define ARM_COMPUTE_TEST_NORMALIZE_PLANAR_YUV_LAYER_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/Helpers.h"
35#include "tests/validation/reference/NormalizePlanarYUVLayer.h"
36
37namespace arm_compute
38{
39namespace test
40{
41namespace validation
42{
43template <typename TensorType, typename AccessorType, typename FunctionType, typename T>
44class NormalizePlanarYUVLayerValidationFixedPointFixture : public framework::Fixture
45{
46public:
47 template <typename...>
48 void setup(TensorShape shape0, TensorShape shape1, DataType dt)
49 {
50 _data_type = dt;
51 _target = compute_target(shape0, shape1, dt);
52 _reference = compute_reference(shape0, shape1, dt);
53 }
54
55protected:
56 template <typename U>
57 void fill(U &&src_tensor, U &&mean_tensor, U &&sd_tensor)
58 {
59 if(is_data_type_float(_data_type))
60 {
61 float min_bound = 0.f;
62 float max_bound = 0.f;
63 std::tie(min_bound, max_bound) = get_normalize_planar_yuv_layer_test_bounds<T>();
64 std::uniform_real_distribution<> distribution(min_bound, max_bound);
65 std::uniform_real_distribution<> distribution_sd(0, max_bound);
66 library->fill(src_tensor, distribution, 0);
67 library->fill(mean_tensor, distribution, 1);
68 library->fill(sd_tensor, distribution_sd, 2);
69 }
70 }
71
72 TensorType compute_target(const TensorShape &shape0, const TensorShape &shape1, DataType dt)
73 {
74 // Create tensors
75 TensorType src = create_tensor<TensorType>(shape0, dt, 1);
76 TensorType dst = create_tensor<TensorType>(shape0, dt, 1);
77 TensorType mean = create_tensor<TensorType>(shape1, dt, 1);
78 TensorType sd = create_tensor<TensorType>(shape1, dt, 1);
79
80 // Create and configure function
81 FunctionType norm;
82 norm.configure(&src, &dst, &mean, &sd);
83
84 ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS);
85 ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS);
86 ARM_COMPUTE_EXPECT(mean.info()->is_resizable(), framework::LogLevel::ERRORS);
87 ARM_COMPUTE_EXPECT(sd.info()->is_resizable(), framework::LogLevel::ERRORS);
88
89 // Allocate tensors
90 src.allocator()->allocate();
91 dst.allocator()->allocate();
92 mean.allocator()->allocate();
93 sd.allocator()->allocate();
94
95 ARM_COMPUTE_EXPECT(!src.info()->is_resizable(), framework::LogLevel::ERRORS);
96 ARM_COMPUTE_EXPECT(!dst.info()->is_resizable(), framework::LogLevel::ERRORS);
97 ARM_COMPUTE_EXPECT(!mean.info()->is_resizable(), framework::LogLevel::ERRORS);
98 ARM_COMPUTE_EXPECT(!sd.info()->is_resizable(), framework::LogLevel::ERRORS);
99
100 // Fill tensors
101 fill(AccessorType(src), AccessorType(mean), AccessorType(sd));
102
103 // Compute function
104 norm.run();
105
106 return dst;
107 }
108
109 SimpleTensor<T> compute_reference(const TensorShape &shape0, const TensorShape &shape1, DataType dt)
110 {
111 // Create reference
112 SimpleTensor<T> ref_src{ shape0, dt, 1 };
113 SimpleTensor<T> ref_mean{ shape1, dt, 1 };
114 SimpleTensor<T> ref_sd{ shape1, dt, 1 };
115
116 // Fill reference
117 fill(ref_src, ref_mean, ref_sd);
118
119 return reference::normalize_planar_yuv_layer(ref_src, ref_mean, ref_sd);
120 }
121
122 TensorType _target{};
123 SimpleTensor<T> _reference{};
124 DataType _data_type{};
125};
126
127template <typename TensorType, typename AccessorType, typename FunctionType, typename T>
128class NormalizePlanarYUVLayerValidationFixture : public NormalizePlanarYUVLayerValidationFixedPointFixture<TensorType, AccessorType, FunctionType, T>
129{
130public:
131 template <typename...>
132 void setup(TensorShape shape0, TensorShape shape1, DataType dt)
133 {
134 NormalizePlanarYUVLayerValidationFixedPointFixture<TensorType, AccessorType, FunctionType, T>::setup(shape0, shape1, dt);
135 }
136};
137} // namespace validation
138} // namespace test
139} // namespace arm_compute
140#endif /* ARM_COMPUTE_TEST_NORMALIZE_PLANAR_YUV_LAYER_FIXTURE */