ramelg01 | 3751569 | 2022-02-26 22:06:20 +0000 | [diff] [blame] | 1 | /* |
Matthew Bentham | 945b8da | 2023-07-12 11:54:59 +0000 | [diff] [blame^] | 2 | * Copyright (c) 2022-2023 Arm Limited. |
ramelg01 | 3751569 | 2022-02-26 22:06:20 +0000 | [diff] [blame] | 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> |
| 38 | namespace arm_compute |
| 39 | { |
| 40 | namespace test |
| 41 | { |
| 42 | namespace validation |
| 43 | { |
| 44 | template <typename TensorType, typename AccessorType, typename FunctionType, typename T> |
| 45 | class Pooling3dLayerValidationGenericFixture : public framework::Fixture |
| 46 | { |
| 47 | public: |
Adnan AlSinan | 9104cd5 | 2022-04-06 16:19:31 +0100 | [diff] [blame] | 48 | void setup(TensorShape shape, Pooling3dLayerInfo pool_info, DataType data_type, QuantizationInfo input_qinfo = QuantizationInfo(), QuantizationInfo output_qinfo = QuantizationInfo()) |
ramelg01 | 3751569 | 2022-02-26 22:06:20 +0000 | [diff] [blame] | 49 | { |
Adnan AlSinan | 9104cd5 | 2022-04-06 16:19:31 +0100 | [diff] [blame] | 50 | _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); |
ramelg01 | 3751569 | 2022-02-26 22:06:20 +0000 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | protected: |
| 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 AlSinan | 9104cd5 | 2022-04-06 16:19:31 +0100 | [diff] [blame] | 70 | library->fill_tensor_uniform(tensor, 0); |
ramelg01 | 3751569 | 2022-02-26 22:06:20 +0000 | [diff] [blame] | 71 | } |
| 72 | } |
| 73 | |
| 74 | TensorType compute_target(TensorShape shape, Pooling3dLayerInfo info, |
Adnan AlSinan | 9104cd5 | 2022-04-06 16:19:31 +0100 | [diff] [blame] | 75 | DataType data_type, QuantizationInfo input_qinfo, QuantizationInfo output_qinfo) |
ramelg01 | 3751569 | 2022-02-26 22:06:20 +0000 | [diff] [blame] | 76 | { |
| 77 | // Create tensors |
Adnan AlSinan | 9104cd5 | 2022-04-06 16:19:31 +0100 | [diff] [blame] | 78 | TensorType src = create_tensor<TensorType>(shape, data_type, 1, input_qinfo, DataLayout::NDHWC); |
ramelg01 | 3751569 | 2022-02-26 22:06:20 +0000 | [diff] [blame] | 79 | const TensorShape dst_shape = misc::shape_calculator::compute_pool3d_shape((src.info()->tensor_shape()), info); |
Adnan AlSinan | 9104cd5 | 2022-04-06 16:19:31 +0100 | [diff] [blame] | 80 | TensorType dst = create_tensor<TensorType>(dst_shape, data_type, 1, output_qinfo, DataLayout::NDHWC); |
ramelg01 | 3751569 | 2022-02-26 22:06:20 +0000 | [diff] [blame] | 81 | |
| 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 AlSinan | 9104cd5 | 2022-04-06 16:19:31 +0100 | [diff] [blame] | 105 | SimpleTensor<T> compute_reference(TensorShape shape, Pooling3dLayerInfo info, DataType data_type, QuantizationInfo input_qinfo, QuantizationInfo output_qinfo) |
ramelg01 | 3751569 | 2022-02-26 22:06:20 +0000 | [diff] [blame] | 106 | { |
| 107 | // Create reference |
Adnan AlSinan | 9104cd5 | 2022-04-06 16:19:31 +0100 | [diff] [blame] | 108 | SimpleTensor<T> src(shape, data_type, 1, input_qinfo, DataLayout::NDHWC); |
ramelg01 | 3751569 | 2022-02-26 22:06:20 +0000 | [diff] [blame] | 109 | // Fill reference |
| 110 | fill(src); |
Adnan AlSinan | 9104cd5 | 2022-04-06 16:19:31 +0100 | [diff] [blame] | 111 | return reference::pooling_3d_layer<T>(src, info, output_qinfo); |
ramelg01 | 3751569 | 2022-02-26 22:06:20 +0000 | [diff] [blame] | 112 | } |
| 113 | |
Adnan AlSinan | 9104cd5 | 2022-04-06 16:19:31 +0100 | [diff] [blame] | 114 | TensorType _target{}; |
| 115 | SimpleTensor<T> _reference{}; |
ramelg01 | 3751569 | 2022-02-26 22:06:20 +0000 | [diff] [blame] | 116 | }; |
| 117 | |
| 118 | template <typename TensorType, typename AccessorType, typename FunctionType, typename T> |
| 119 | class Pooling3dLayerValidationFixture : public Pooling3dLayerValidationGenericFixture<TensorType, AccessorType, FunctionType, T> |
| 120 | { |
| 121 | public: |
ramelg01 | 3751569 | 2022-02-26 22:06:20 +0000 | [diff] [blame] | 122 | 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 | |
| 129 | template <typename TensorType, typename AccessorType, typename FunctionType, typename T> |
Adnan AlSinan | 9104cd5 | 2022-04-06 16:19:31 +0100 | [diff] [blame] | 130 | class Pooling3dLayerValidationQuantizedFixture : public Pooling3dLayerValidationGenericFixture<TensorType, AccessorType, FunctionType, T> |
| 131 | { |
| 132 | public: |
Adnan AlSinan | 9104cd5 | 2022-04-06 16:19:31 +0100 | [diff] [blame] | 133 | 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 | |
| 141 | template <typename TensorType, typename AccessorType, typename FunctionType, typename T> |
ramelg01 | 3751569 | 2022-02-26 22:06:20 +0000 | [diff] [blame] | 142 | class Pooling3dLayerGlobalValidationFixture : public Pooling3dLayerValidationGenericFixture<TensorType, AccessorType, FunctionType, T> |
| 143 | { |
| 144 | public: |
ramelg01 | 3751569 | 2022-02-26 22:06:20 +0000 | [diff] [blame] | 145 | 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 | |
| 151 | template <typename TensorType, typename AccessorType, typename FunctionType, typename T> |
| 152 | class SpecialPooling3dLayerValidationFixture : public Pooling3dLayerValidationGenericFixture<TensorType, AccessorType, FunctionType, T> |
| 153 | { |
| 154 | public: |
ramelg01 | 3751569 | 2022-02-26 22:06:20 +0000 | [diff] [blame] | 155 | 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 | |
ramelg01 | 3751569 | 2022-02-26 22:06:20 +0000 | [diff] [blame] | 161 | } // namespace validation |
| 162 | } // namespace test |
| 163 | } // namespace arm_compute |
| 164 | #endif /* ARM_COMPUTE_TEST_POOLING_3D_LAYER_FIXTURE */ |