blob: 563f1dcced18ab1e70acc12c0136931d58e89a84 [file] [log] [blame]
ramelg0137515692022-02-26 22:06:20 +00001/*
2 * Copyright (c) 2022 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_POOLING_3D_LAYER_FIXTURE
25#define ARM_COMPUTE_TEST_POOLING_3D_LAYER_FIXTURE
26
27#include "arm_compute/core/TensorShape.h"
28#include "arm_compute/core/Types.h"
29#include "arm_compute/core/utils/misc/ShapeCalculator.h"
30#include "arm_compute/runtime/Tensor.h"
31#include "tests/AssetsLibrary.h"
32#include "tests/Globals.h"
33#include "tests/IAccessor.h"
34#include "tests/framework/Asserts.h"
35#include "tests/framework/Fixture.h"
36#include "tests/validation/reference/Pooling3dLayer.h"
37#include <random>
38namespace arm_compute
39{
40namespace test
41{
42namespace validation
43{
44template <typename TensorType, typename AccessorType, typename FunctionType, typename T>
45class Pooling3dLayerValidationGenericFixture : public framework::Fixture
46{
47public:
48 template <typename...>
Adnan AlSinan9104cd52022-04-06 16:19:31 +010049 void setup(TensorShape shape, Pooling3dLayerInfo pool_info, DataType data_type, QuantizationInfo input_qinfo = QuantizationInfo(), QuantizationInfo output_qinfo = QuantizationInfo())
ramelg0137515692022-02-26 22:06:20 +000050 {
Adnan AlSinan9104cd52022-04-06 16:19:31 +010051 _target = compute_target(shape, pool_info, data_type, input_qinfo, output_qinfo);
52 _reference = compute_reference(shape, pool_info, data_type, input_qinfo, output_qinfo);
ramelg0137515692022-02-26 22:06:20 +000053 }
54
55protected:
56 template <typename U>
57 void fill(U &&tensor)
58 {
59 if(tensor.data_type() == DataType::F32)
60 {
61 std::uniform_real_distribution<float> distribution(-1.0f, 1.0f);
62 library->fill(tensor, distribution, 0);
63 }
64 else if(tensor.data_type() == DataType::F16)
65 {
66 arm_compute::utils::uniform_real_distribution_16bit<half> distribution{ -1.0f, 1.0f };
67 library->fill(tensor, distribution, 0);
68 }
69 else // data type is quantized_asymmetric
70 {
Adnan AlSinan9104cd52022-04-06 16:19:31 +010071 library->fill_tensor_uniform(tensor, 0);
ramelg0137515692022-02-26 22:06:20 +000072 }
73 }
74
75 TensorType compute_target(TensorShape shape, Pooling3dLayerInfo info,
Adnan AlSinan9104cd52022-04-06 16:19:31 +010076 DataType data_type, QuantizationInfo input_qinfo, QuantizationInfo output_qinfo)
ramelg0137515692022-02-26 22:06:20 +000077 {
78 // Create tensors
Adnan AlSinan9104cd52022-04-06 16:19:31 +010079 TensorType src = create_tensor<TensorType>(shape, data_type, 1, input_qinfo, DataLayout::NDHWC);
ramelg0137515692022-02-26 22:06:20 +000080 const TensorShape dst_shape = misc::shape_calculator::compute_pool3d_shape((src.info()->tensor_shape()), info);
Adnan AlSinan9104cd52022-04-06 16:19:31 +010081 TensorType dst = create_tensor<TensorType>(dst_shape, data_type, 1, output_qinfo, DataLayout::NDHWC);
ramelg0137515692022-02-26 22:06:20 +000082
83 // Create and configure function
84 FunctionType pool_layer;
85 pool_layer.validate(src.info(), dst.info(), info);
86 pool_layer.configure(&src, &dst, info);
87
88 ARM_COMPUTE_ASSERT(src.info()->is_resizable());
89 ARM_COMPUTE_ASSERT(dst.info()->is_resizable());
90
91 // Allocate tensors
92 src.allocator()->allocate();
93 dst.allocator()->allocate();
94
95 ARM_COMPUTE_ASSERT(!src.info()->is_resizable());
96 ARM_COMPUTE_ASSERT(!dst.info()->is_resizable());
97
98 // Fill tensors
99 fill(AccessorType(src));
100
101 // Compute function
102 pool_layer.run();
103 return dst;
104 }
105
Adnan AlSinan9104cd52022-04-06 16:19:31 +0100106 SimpleTensor<T> compute_reference(TensorShape shape, Pooling3dLayerInfo info, DataType data_type, QuantizationInfo input_qinfo, QuantizationInfo output_qinfo)
ramelg0137515692022-02-26 22:06:20 +0000107 {
108 // Create reference
Adnan AlSinan9104cd52022-04-06 16:19:31 +0100109 SimpleTensor<T> src(shape, data_type, 1, input_qinfo, DataLayout::NDHWC);
ramelg0137515692022-02-26 22:06:20 +0000110 // Fill reference
111 fill(src);
Adnan AlSinan9104cd52022-04-06 16:19:31 +0100112 return reference::pooling_3d_layer<T>(src, info, output_qinfo);
ramelg0137515692022-02-26 22:06:20 +0000113 }
114
Adnan AlSinan9104cd52022-04-06 16:19:31 +0100115 TensorType _target{};
116 SimpleTensor<T> _reference{};
ramelg0137515692022-02-26 22:06:20 +0000117};
118
119template <typename TensorType, typename AccessorType, typename FunctionType, typename T>
120class Pooling3dLayerValidationFixture : public Pooling3dLayerValidationGenericFixture<TensorType, AccessorType, FunctionType, T>
121{
122public:
123 template <typename...>
124 void setup(TensorShape shape, PoolingType pool_type, Size3D pool_size, Size3D stride, Padding3D padding, bool exclude_padding, DataType data_type)
125 {
126 Pooling3dLayerValidationGenericFixture<TensorType, AccessorType, FunctionType, T>::setup(shape, Pooling3dLayerInfo(pool_type, pool_size, stride, padding, exclude_padding),
127 data_type);
128 }
129};
130
131template <typename TensorType, typename AccessorType, typename FunctionType, typename T>
Adnan AlSinan9104cd52022-04-06 16:19:31 +0100132class Pooling3dLayerValidationQuantizedFixture : public Pooling3dLayerValidationGenericFixture<TensorType, AccessorType, FunctionType, T>
133{
134public:
135 template <typename...>
136 void setup(TensorShape shape, PoolingType pool_type, Size3D pool_size, Size3D stride, Padding3D padding, bool exclude_padding, DataType data_type,
137 QuantizationInfo input_qinfo = QuantizationInfo(), QuantizationInfo output_qinfo = QuantizationInfo())
138 {
139 Pooling3dLayerValidationGenericFixture<TensorType, AccessorType, FunctionType, T>::setup(shape, Pooling3dLayerInfo(pool_type, pool_size, stride, padding, exclude_padding),
140 data_type, input_qinfo, output_qinfo);
141 }
142};
143
144template <typename TensorType, typename AccessorType, typename FunctionType, typename T>
ramelg0137515692022-02-26 22:06:20 +0000145class Pooling3dLayerGlobalValidationFixture : public Pooling3dLayerValidationGenericFixture<TensorType, AccessorType, FunctionType, T>
146{
147public:
148 template <typename...>
149 void setup(TensorShape shape, PoolingType pool_type, DataType data_type)
150 {
151 Pooling3dLayerValidationGenericFixture<TensorType, AccessorType, FunctionType, T>::setup(shape, Pooling3dLayerInfo(pool_type), data_type);
152 }
153};
154
155template <typename TensorType, typename AccessorType, typename FunctionType, typename T>
156class SpecialPooling3dLayerValidationFixture : public Pooling3dLayerValidationGenericFixture<TensorType, AccessorType, FunctionType, T>
157{
158public:
159 template <typename...>
160 void setup(TensorShape src_shape, Pooling3dLayerInfo pool_info, DataType data_type)
161 {
162 Pooling3dLayerValidationGenericFixture<TensorType, AccessorType, FunctionType, T>::setup(src_shape, pool_info, data_type);
163 }
164};
165
ramelg0137515692022-02-26 22:06:20 +0000166} // namespace validation
167} // namespace test
168} // namespace arm_compute
169#endif /* ARM_COMPUTE_TEST_POOLING_3D_LAYER_FIXTURE */