blob: 9d8c8fcbcef77a4ee6a261d177a1c862cdb06f72 [file] [log] [blame]
zhenglin0fb6cf52017-12-12 15:56:09 +08001/*
zhenglin2219dea2018-01-30 18:15:52 +08002 * Copyright (c) 2017-2018 ARM Limited.
zhenglin0fb6cf52017-12-12 15:56:09 +08003 *
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>
Michele Di Giorgiod63dfa22018-09-12 10:18:54 +010044class NormalizePlanarYUVLayerValidationGenericFixture : public framework::Fixture
zhenglin0fb6cf52017-12-12 15:56:09 +080045{
46public:
47 template <typename...>
Michele Di Giorgiod63dfa22018-09-12 10:18:54 +010048 void setup(TensorShape shape0, TensorShape shape1, DataType dt, DataLayout data_layout, QuantizationInfo quantization_info)
zhenglin0fb6cf52017-12-12 15:56:09 +080049 {
50 _data_type = dt;
Michele Di Giorgiod63dfa22018-09-12 10:18:54 +010051 _target = compute_target(shape0, shape1, dt, data_layout, quantization_info);
52 _reference = compute_reference(shape0, shape1, dt, quantization_info);
zhenglin0fb6cf52017-12-12 15:56:09 +080053 }
54
55protected:
56 template <typename U>
Michele Di Giorgiob57be0d2018-08-31 16:26:25 +010057 void fill(U &&src_tensor, U &&mean_tensor, U &&std_tensor)
zhenglin0fb6cf52017-12-12 15:56:09 +080058 {
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);
Michele Di Giorgiob57be0d2018-08-31 16:26:25 +010065 std::uniform_real_distribution<> distribution_std(0.1, max_bound);
zhenglin0fb6cf52017-12-12 15:56:09 +080066 library->fill(src_tensor, distribution, 0);
67 library->fill(mean_tensor, distribution, 1);
Michele Di Giorgiob57be0d2018-08-31 16:26:25 +010068 library->fill(std_tensor, distribution_std, 2);
zhenglin0fb6cf52017-12-12 15:56:09 +080069 }
Michele Di Giorgiod63dfa22018-09-12 10:18:54 +010070 else if(is_data_type_quantized_asymmetric(src_tensor.data_type()))
71 {
72 library->fill_tensor_uniform(src_tensor, 0);
73 library->fill_tensor_uniform(mean_tensor, 1);
74 library->fill_tensor_uniform(std_tensor, 2);
75 }
zhenglin0fb6cf52017-12-12 15:56:09 +080076 }
77
Michele Di Giorgiod63dfa22018-09-12 10:18:54 +010078 TensorType compute_target(TensorShape shape0, const TensorShape &shape1, DataType dt, DataLayout data_layout, QuantizationInfo quantization_info)
zhenglin0fb6cf52017-12-12 15:56:09 +080079 {
Michele Di Giorgiob57be0d2018-08-31 16:26:25 +010080 if(data_layout == DataLayout::NHWC)
81 {
82 permute(shape0, PermutationVector(2U, 0U, 1U));
83 }
84
zhenglin0fb6cf52017-12-12 15:56:09 +080085 // Create tensors
Michele Di Giorgiod63dfa22018-09-12 10:18:54 +010086 TensorType src = create_tensor<TensorType>(shape0, dt, 1, quantization_info, data_layout);
87 TensorType mean = create_tensor<TensorType>(shape1, dt, 1, quantization_info);
88 TensorType std = create_tensor<TensorType>(shape1, dt, 1, quantization_info);
89 TensorType dst;
zhenglin0fb6cf52017-12-12 15:56:09 +080090
91 // Create and configure function
92 FunctionType norm;
Michele Di Giorgiob57be0d2018-08-31 16:26:25 +010093 norm.configure(&src, &dst, &mean, &std);
zhenglin0fb6cf52017-12-12 15:56:09 +080094
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);
Michele Di Giorgiob57be0d2018-08-31 16:26:25 +010098 ARM_COMPUTE_EXPECT(std.info()->is_resizable(), framework::LogLevel::ERRORS);
zhenglin0fb6cf52017-12-12 15:56:09 +080099
100 // Allocate tensors
101 src.allocator()->allocate();
102 dst.allocator()->allocate();
103 mean.allocator()->allocate();
Michele Di Giorgiob57be0d2018-08-31 16:26:25 +0100104 std.allocator()->allocate();
zhenglin0fb6cf52017-12-12 15:56:09 +0800105
106 ARM_COMPUTE_EXPECT(!src.info()->is_resizable(), framework::LogLevel::ERRORS);
107 ARM_COMPUTE_EXPECT(!dst.info()->is_resizable(), framework::LogLevel::ERRORS);
108 ARM_COMPUTE_EXPECT(!mean.info()->is_resizable(), framework::LogLevel::ERRORS);
Michele Di Giorgiob57be0d2018-08-31 16:26:25 +0100109 ARM_COMPUTE_EXPECT(!std.info()->is_resizable(), framework::LogLevel::ERRORS);
zhenglin0fb6cf52017-12-12 15:56:09 +0800110
111 // Fill tensors
Michele Di Giorgiob57be0d2018-08-31 16:26:25 +0100112 fill(AccessorType(src), AccessorType(mean), AccessorType(std));
zhenglin0fb6cf52017-12-12 15:56:09 +0800113
114 // Compute function
115 norm.run();
116
117 return dst;
118 }
119
Michele Di Giorgiod63dfa22018-09-12 10:18:54 +0100120 SimpleTensor<T> compute_reference(const TensorShape &shape0, const TensorShape &shape1, DataType dt, QuantizationInfo quantization_info)
zhenglin0fb6cf52017-12-12 15:56:09 +0800121 {
122 // Create reference
Michele Di Giorgiod63dfa22018-09-12 10:18:54 +0100123 SimpleTensor<T> ref_src{ shape0, dt, 1, quantization_info };
124 SimpleTensor<T> ref_mean{ shape1, dt, 1, quantization_info };
125 SimpleTensor<T> ref_std{ shape1, dt, 1, quantization_info };
zhenglin0fb6cf52017-12-12 15:56:09 +0800126
127 // Fill reference
Michele Di Giorgiob57be0d2018-08-31 16:26:25 +0100128 fill(ref_src, ref_mean, ref_std);
zhenglin0fb6cf52017-12-12 15:56:09 +0800129
Michele Di Giorgiob57be0d2018-08-31 16:26:25 +0100130 return reference::normalize_planar_yuv_layer(ref_src, ref_mean, ref_std);
zhenglin0fb6cf52017-12-12 15:56:09 +0800131 }
132
133 TensorType _target{};
134 SimpleTensor<T> _reference{};
135 DataType _data_type{};
136};
Michele Di Giorgiod63dfa22018-09-12 10:18:54 +0100137
138template <typename TensorType, typename AccessorType, typename FunctionType, typename T>
139class NormalizePlanarYUVLayerValidationFixture : public NormalizePlanarYUVLayerValidationGenericFixture<TensorType, AccessorType, FunctionType, T>
140{
141public:
142 template <typename...>
143 void setup(TensorShape shape0, TensorShape shape1, DataType dt, DataLayout data_layout)
144 {
145 NormalizePlanarYUVLayerValidationGenericFixture<TensorType, AccessorType, FunctionType, T>::setup(shape0, shape1, dt, data_layout, QuantizationInfo());
146 }
147};
148
149template <typename TensorType, typename AccessorType, typename FunctionType, typename T>
150class NormalizePlanarYUVLayerValidationQuantizedFixture : public NormalizePlanarYUVLayerValidationGenericFixture<TensorType, AccessorType, FunctionType, T>
151{
152public:
153 template <typename...>
154 void setup(TensorShape shape0, TensorShape shape1, DataType dt, DataLayout data_layout, QuantizationInfo quantization_info)
155 {
156 NormalizePlanarYUVLayerValidationGenericFixture<TensorType, AccessorType, FunctionType, T>::setup(shape0, shape1, dt, data_layout, quantization_info);
157 }
158};
zhenglin0fb6cf52017-12-12 15:56:09 +0800159} // namespace validation
160} // namespace test
161} // namespace arm_compute
162#endif /* ARM_COMPUTE_TEST_NORMALIZE_PLANAR_YUV_LAYER_FIXTURE */