blob: 1bdf615fb1aca2808ba188daf256b0313a2a3d4f [file] [log] [blame]
ramelg0137515692022-02-26 22:06:20 +00001/*
Matthew Bentham945b8da2023-07-12 11:54:59 +00002 * Copyright (c) 2022-2023 Arm Limited.
ramelg0137515692022-02-26 22:06:20 +00003 *
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:
Adnan AlSinan9104cd52022-04-06 16:19:31 +010048 void setup(TensorShape shape, Pooling3dLayerInfo pool_info, DataType data_type, QuantizationInfo input_qinfo = QuantizationInfo(), QuantizationInfo output_qinfo = QuantizationInfo())
ramelg0137515692022-02-26 22:06:20 +000049 {
Adnan AlSinan9104cd52022-04-06 16:19:31 +010050 _target = compute_target(shape, pool_info, data_type, input_qinfo, output_qinfo);
51 _reference = compute_reference(shape, pool_info, data_type, input_qinfo, output_qinfo);
ramelg0137515692022-02-26 22:06:20 +000052 }
53
54protected:
55 template <typename U>
56 void fill(U &&tensor)
57 {
58 if(tensor.data_type() == DataType::F32)
59 {
60 std::uniform_real_distribution<float> distribution(-1.0f, 1.0f);
61 library->fill(tensor, distribution, 0);
62 }
63 else if(tensor.data_type() == DataType::F16)
64 {
65 arm_compute::utils::uniform_real_distribution_16bit<half> distribution{ -1.0f, 1.0f };
66 library->fill(tensor, distribution, 0);
67 }
68 else // data type is quantized_asymmetric
69 {
Adnan AlSinan9104cd52022-04-06 16:19:31 +010070 library->fill_tensor_uniform(tensor, 0);
ramelg0137515692022-02-26 22:06:20 +000071 }
72 }
73
74 TensorType compute_target(TensorShape shape, Pooling3dLayerInfo info,
Adnan AlSinan9104cd52022-04-06 16:19:31 +010075 DataType data_type, QuantizationInfo input_qinfo, QuantizationInfo output_qinfo)
ramelg0137515692022-02-26 22:06:20 +000076 {
77 // Create tensors
Adnan AlSinan9104cd52022-04-06 16:19:31 +010078 TensorType src = create_tensor<TensorType>(shape, data_type, 1, input_qinfo, DataLayout::NDHWC);
ramelg0137515692022-02-26 22:06:20 +000079 const TensorShape dst_shape = misc::shape_calculator::compute_pool3d_shape((src.info()->tensor_shape()), info);
Adnan AlSinan9104cd52022-04-06 16:19:31 +010080 TensorType dst = create_tensor<TensorType>(dst_shape, data_type, 1, output_qinfo, DataLayout::NDHWC);
ramelg0137515692022-02-26 22:06:20 +000081
82 // Create and configure function
83 FunctionType pool_layer;
84 pool_layer.validate(src.info(), dst.info(), info);
85 pool_layer.configure(&src, &dst, info);
86
87 ARM_COMPUTE_ASSERT(src.info()->is_resizable());
88 ARM_COMPUTE_ASSERT(dst.info()->is_resizable());
89
90 // Allocate tensors
91 src.allocator()->allocate();
92 dst.allocator()->allocate();
93
94 ARM_COMPUTE_ASSERT(!src.info()->is_resizable());
95 ARM_COMPUTE_ASSERT(!dst.info()->is_resizable());
96
97 // Fill tensors
98 fill(AccessorType(src));
99
100 // Compute function
101 pool_layer.run();
102 return dst;
103 }
104
Adnan AlSinan9104cd52022-04-06 16:19:31 +0100105 SimpleTensor<T> compute_reference(TensorShape shape, Pooling3dLayerInfo info, DataType data_type, QuantizationInfo input_qinfo, QuantizationInfo output_qinfo)
ramelg0137515692022-02-26 22:06:20 +0000106 {
107 // Create reference
Adnan AlSinan9104cd52022-04-06 16:19:31 +0100108 SimpleTensor<T> src(shape, data_type, 1, input_qinfo, DataLayout::NDHWC);
ramelg0137515692022-02-26 22:06:20 +0000109 // Fill reference
110 fill(src);
Adnan AlSinan9104cd52022-04-06 16:19:31 +0100111 return reference::pooling_3d_layer<T>(src, info, output_qinfo);
ramelg0137515692022-02-26 22:06:20 +0000112 }
113
Adnan AlSinan9104cd52022-04-06 16:19:31 +0100114 TensorType _target{};
115 SimpleTensor<T> _reference{};
ramelg0137515692022-02-26 22:06:20 +0000116};
117
118template <typename TensorType, typename AccessorType, typename FunctionType, typename T>
119class Pooling3dLayerValidationFixture : public Pooling3dLayerValidationGenericFixture<TensorType, AccessorType, FunctionType, T>
120{
121public:
ramelg0137515692022-02-26 22:06:20 +0000122 void setup(TensorShape shape, PoolingType pool_type, Size3D pool_size, Size3D stride, Padding3D padding, bool exclude_padding, DataType data_type)
123 {
124 Pooling3dLayerValidationGenericFixture<TensorType, AccessorType, FunctionType, T>::setup(shape, Pooling3dLayerInfo(pool_type, pool_size, stride, padding, exclude_padding),
125 data_type);
126 }
127};
128
129template <typename TensorType, typename AccessorType, typename FunctionType, typename T>
Adnan AlSinan9104cd52022-04-06 16:19:31 +0100130class Pooling3dLayerValidationQuantizedFixture : public Pooling3dLayerValidationGenericFixture<TensorType, AccessorType, FunctionType, T>
131{
132public:
Adnan AlSinan9104cd52022-04-06 16:19:31 +0100133 void setup(TensorShape shape, PoolingType pool_type, Size3D pool_size, Size3D stride, Padding3D padding, bool exclude_padding, DataType data_type,
134 QuantizationInfo input_qinfo = QuantizationInfo(), QuantizationInfo output_qinfo = QuantizationInfo())
135 {
136 Pooling3dLayerValidationGenericFixture<TensorType, AccessorType, FunctionType, T>::setup(shape, Pooling3dLayerInfo(pool_type, pool_size, stride, padding, exclude_padding),
137 data_type, input_qinfo, output_qinfo);
138 }
139};
140
141template <typename TensorType, typename AccessorType, typename FunctionType, typename T>
ramelg0137515692022-02-26 22:06:20 +0000142class Pooling3dLayerGlobalValidationFixture : public Pooling3dLayerValidationGenericFixture<TensorType, AccessorType, FunctionType, T>
143{
144public:
ramelg0137515692022-02-26 22:06:20 +0000145 void setup(TensorShape shape, PoolingType pool_type, DataType data_type)
146 {
147 Pooling3dLayerValidationGenericFixture<TensorType, AccessorType, FunctionType, T>::setup(shape, Pooling3dLayerInfo(pool_type), data_type);
148 }
149};
150
151template <typename TensorType, typename AccessorType, typename FunctionType, typename T>
152class SpecialPooling3dLayerValidationFixture : public Pooling3dLayerValidationGenericFixture<TensorType, AccessorType, FunctionType, T>
153{
154public:
ramelg0137515692022-02-26 22:06:20 +0000155 void setup(TensorShape src_shape, Pooling3dLayerInfo pool_info, DataType data_type)
156 {
157 Pooling3dLayerValidationGenericFixture<TensorType, AccessorType, FunctionType, T>::setup(src_shape, pool_info, data_type);
158 }
159};
160
ramelg0137515692022-02-26 22:06:20 +0000161} // namespace validation
162} // namespace test
163} // namespace arm_compute
164#endif /* ARM_COMPUTE_TEST_POOLING_3D_LAYER_FIXTURE */