Michele Di Giorgio | 980002b | 2018-08-08 09:25:51 +0100 | [diff] [blame] | 1 | /* |
Matthew Bentham | 945b8da | 2023-07-12 11:54:59 +0000 | [diff] [blame] | 2 | * Copyright (c) 2018-2021, 2023 Arm Limited. |
Michele Di Giorgio | 980002b | 2018-08-08 09:25:51 +0100 | [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_COL2IM_FIXTURE |
| 25 | #define ARM_COMPUTE_TEST_COL2IM_FIXTURE |
| 26 | |
| 27 | #include "arm_compute/core/Helpers.h" |
| 28 | #include "arm_compute/core/TensorShape.h" |
| 29 | #include "arm_compute/core/Types.h" |
| 30 | #include "arm_compute/core/utils/misc/ShapeCalculator.h" |
| 31 | #include "arm_compute/runtime/Tensor.h" |
| 32 | #include "tests/AssetsLibrary.h" |
| 33 | #include "tests/Globals.h" |
| 34 | #include "tests/IAccessor.h" |
| 35 | #include "tests/framework/Asserts.h" |
| 36 | #include "tests/framework/Fixture.h" |
| 37 | #include "tests/validation/reference/Col2Im.h" |
| 38 | |
| 39 | namespace arm_compute |
| 40 | { |
| 41 | namespace test |
| 42 | { |
| 43 | namespace validation |
| 44 | { |
| 45 | using namespace arm_compute::misc::shape_calculator; |
| 46 | |
Giorgio Arena | 226e4b9 | 2018-08-23 12:00:02 +0100 | [diff] [blame] | 47 | template <typename TensorType, typename AccessorType, typename FunctionType, typename T, bool batch_size_on_z> |
Manuel Bottini | 7b23732 | 2021-07-14 17:07:23 +0100 | [diff] [blame] | 48 | class Col2ImOpValidationFixture : public framework::Fixture |
Michele Di Giorgio | 980002b | 2018-08-08 09:25:51 +0100 | [diff] [blame] | 49 | { |
| 50 | public: |
Michele Di Giorgio | 980002b | 2018-08-08 09:25:51 +0100 | [diff] [blame] | 51 | void setup(TensorShape input_shape, const unsigned int convolved_width, unsigned int convolved_height, unsigned int num_groups, DataType data_type) |
| 52 | { |
Giorgio Arena | 226e4b9 | 2018-08-23 12:00:02 +0100 | [diff] [blame] | 53 | const Size2D convolved_dims(convolved_width, convolved_height); |
Michele Di Giorgio | 980002b | 2018-08-08 09:25:51 +0100 | [diff] [blame] | 54 | |
Giorgio Arena | 226e4b9 | 2018-08-23 12:00:02 +0100 | [diff] [blame] | 55 | const TensorShape output_shape = compute_col2im_shape(TensorInfo(input_shape, 1, data_type), convolved_dims, batch_size_on_z, num_groups); |
Michele Di Giorgio | 980002b | 2018-08-08 09:25:51 +0100 | [diff] [blame] | 56 | |
| 57 | _target = compute_target(input_shape, output_shape, convolved_dims, num_groups, data_type); |
| 58 | _reference = compute_reference(input_shape, output_shape, num_groups, data_type); |
| 59 | } |
| 60 | |
| 61 | protected: |
| 62 | template <typename U> |
| 63 | void fill(U &&tensor, const int seed) |
| 64 | { |
| 65 | library->fill_tensor_uniform(tensor, seed); |
| 66 | } |
| 67 | |
Giorgio Arena | 226e4b9 | 2018-08-23 12:00:02 +0100 | [diff] [blame] | 68 | TensorType compute_target(const TensorShape &input_shape, const TensorShape &output_shape, const Size2D &convolved_dims, unsigned int num_groups, DataType data_type) |
Michele Di Giorgio | 980002b | 2018-08-08 09:25:51 +0100 | [diff] [blame] | 69 | { |
| 70 | // Create tensors |
| 71 | TensorType src = create_tensor<TensorType>(input_shape, data_type); |
| 72 | TensorType dst = create_tensor<TensorType>(output_shape, data_type); |
| 73 | |
| 74 | // Create and configure function |
| 75 | FunctionType col2im_func; |
Manuel Bottini | 7b23732 | 2021-07-14 17:07:23 +0100 | [diff] [blame] | 76 | col2im_func.configure(src.info(), dst.info(), convolved_dims, num_groups); |
Michele Di Giorgio | 980002b | 2018-08-08 09:25:51 +0100 | [diff] [blame] | 77 | |
Michele Di Giorgio | 4fc10b3 | 2021-04-30 18:30:41 +0100 | [diff] [blame] | 78 | ARM_COMPUTE_ASSERT(src.info()->is_resizable()); |
| 79 | ARM_COMPUTE_ASSERT(dst.info()->is_resizable()); |
Michele Di Giorgio | 980002b | 2018-08-08 09:25:51 +0100 | [diff] [blame] | 80 | |
| 81 | // Allocate tensors |
| 82 | src.allocator()->allocate(); |
| 83 | dst.allocator()->allocate(); |
| 84 | |
Michele Di Giorgio | 4fc10b3 | 2021-04-30 18:30:41 +0100 | [diff] [blame] | 85 | ARM_COMPUTE_ASSERT(!src.info()->is_resizable()); |
| 86 | ARM_COMPUTE_ASSERT(!dst.info()->is_resizable()); |
Michele Di Giorgio | 980002b | 2018-08-08 09:25:51 +0100 | [diff] [blame] | 87 | |
| 88 | // Fill tensors |
| 89 | fill(AccessorType(src), 0); |
| 90 | |
Manuel Bottini | 7b23732 | 2021-07-14 17:07:23 +0100 | [diff] [blame] | 91 | arm_compute::ITensorPack pack = |
| 92 | { |
| 93 | { arm_compute::TensorType::ACL_SRC, &src }, |
| 94 | { arm_compute::TensorType::ACL_DST, &dst } |
| 95 | }; |
Michele Di Giorgio | 980002b | 2018-08-08 09:25:51 +0100 | [diff] [blame] | 96 | // Compute function |
Manuel Bottini | 7b23732 | 2021-07-14 17:07:23 +0100 | [diff] [blame] | 97 | col2im_func.run(pack); |
Michele Di Giorgio | 980002b | 2018-08-08 09:25:51 +0100 | [diff] [blame] | 98 | |
| 99 | return dst; |
| 100 | } |
| 101 | |
| 102 | SimpleTensor<T> compute_reference(const TensorShape &input_shape, const TensorShape &output_shape, unsigned int num_groups, DataType data_type) |
| 103 | { |
| 104 | // Create reference |
| 105 | SimpleTensor<T> src{ input_shape, data_type }; |
| 106 | |
| 107 | // Fill reference |
| 108 | fill(src, 0); |
| 109 | |
| 110 | return reference::col2im<T>(src, output_shape, num_groups); |
| 111 | } |
| 112 | TensorType _target{}; |
| 113 | SimpleTensor<T> _reference{}; |
| 114 | }; |
| 115 | } // namespace validation |
| 116 | } // namespace test |
| 117 | } // namespace arm_compute |
| 118 | #endif /* ARM_COMPUTE_TEST_COL2IM_FIXTURE */ |