Michalis Spyrou | 6a8d3b6 | 2018-08-31 10:07:09 +0100 | [diff] [blame] | 1 | /* |
SiCong Li | 5a7d157 | 2023-03-21 12:00:15 +0000 | [diff] [blame] | 2 | * Copyright (c) 2018-2019, 2023 Arm Limited. |
Michalis Spyrou | 6a8d3b6 | 2018-08-31 10:07:09 +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_BATCH_TO_SPACE_LAYER_DATASET |
| 25 | #define ARM_COMPUTE_TEST_BATCH_TO_SPACE_LAYER_DATASET |
| 26 | |
| 27 | #include "utils/TypePrinter.h" |
| 28 | |
| 29 | #include "arm_compute/core/TensorShape.h" |
| 30 | #include "arm_compute/core/Types.h" |
| 31 | |
| 32 | namespace arm_compute |
| 33 | { |
| 34 | namespace test |
| 35 | { |
| 36 | namespace datasets |
| 37 | { |
| 38 | class BatchToSpaceLayerDataset |
| 39 | { |
| 40 | public: |
SiCong Li | 5a7d157 | 2023-03-21 12:00:15 +0000 | [diff] [blame] | 41 | using type = std::tuple<TensorShape, std::vector<int32_t>, CropInfo, TensorShape>; |
Michalis Spyrou | 6a8d3b6 | 2018-08-31 10:07:09 +0100 | [diff] [blame] | 42 | |
| 43 | struct iterator |
| 44 | { |
SiCong Li | 5a7d157 | 2023-03-21 12:00:15 +0000 | [diff] [blame] | 45 | iterator(std::vector<TensorShape>::const_iterator src_it, |
| 46 | std::vector<std::vector<int32_t>>::const_iterator block_shape_it, |
| 47 | std::vector<CropInfo>::const_iterator crop_info_it, |
| 48 | std::vector<TensorShape>::const_iterator dst_it) |
Michalis Spyrou | 6a8d3b6 | 2018-08-31 10:07:09 +0100 | [diff] [blame] | 49 | : _src_it{ std::move(src_it) }, |
| 50 | _block_shape_it{ std::move(block_shape_it) }, |
SiCong Li | 5a7d157 | 2023-03-21 12:00:15 +0000 | [diff] [blame] | 51 | _crop_info_it{ std::move(crop_info_it) }, |
Michalis Spyrou | 6a8d3b6 | 2018-08-31 10:07:09 +0100 | [diff] [blame] | 52 | _dst_it{ std::move(dst_it) } |
| 53 | { |
| 54 | } |
| 55 | |
| 56 | std::string description() const |
| 57 | { |
| 58 | std::stringstream description; |
| 59 | description << "In=" << *_src_it << ":"; |
| 60 | description << "BlockShape=" << *_block_shape_it << ":"; |
SiCong Li | 5a7d157 | 2023-03-21 12:00:15 +0000 | [diff] [blame] | 61 | description << "CropInfo=" << *_crop_info_it << ":"; |
Michalis Spyrou | 6a8d3b6 | 2018-08-31 10:07:09 +0100 | [diff] [blame] | 62 | description << "Out=" << *_dst_it; |
| 63 | return description.str(); |
| 64 | } |
| 65 | |
| 66 | BatchToSpaceLayerDataset::type operator*() const |
| 67 | { |
SiCong Li | 5a7d157 | 2023-03-21 12:00:15 +0000 | [diff] [blame] | 68 | return std::make_tuple(*_src_it, *_block_shape_it, *_crop_info_it, *_dst_it); |
Michalis Spyrou | 6a8d3b6 | 2018-08-31 10:07:09 +0100 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | iterator &operator++() |
| 72 | { |
| 73 | ++_src_it; |
| 74 | ++_block_shape_it; |
SiCong Li | 5a7d157 | 2023-03-21 12:00:15 +0000 | [diff] [blame] | 75 | ++_crop_info_it; |
Michalis Spyrou | 6a8d3b6 | 2018-08-31 10:07:09 +0100 | [diff] [blame] | 76 | ++_dst_it; |
| 77 | |
| 78 | return *this; |
| 79 | } |
| 80 | |
| 81 | private: |
SiCong Li | 5a7d157 | 2023-03-21 12:00:15 +0000 | [diff] [blame] | 82 | std::vector<TensorShape>::const_iterator _src_it; |
| 83 | std::vector<std::vector<int32_t>>::const_iterator _block_shape_it; |
| 84 | std::vector<CropInfo>::const_iterator _crop_info_it; |
| 85 | std::vector<TensorShape>::const_iterator _dst_it; |
Michalis Spyrou | 6a8d3b6 | 2018-08-31 10:07:09 +0100 | [diff] [blame] | 86 | }; |
| 87 | |
| 88 | iterator begin() const |
| 89 | { |
SiCong Li | 5a7d157 | 2023-03-21 12:00:15 +0000 | [diff] [blame] | 90 | return iterator(_src_shapes.begin(), _block_shapes.begin(), _crop_infos.begin(), _dst_shapes.begin()); |
Michalis Spyrou | 6a8d3b6 | 2018-08-31 10:07:09 +0100 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | int size() const |
| 94 | { |
SiCong Li | 5a7d157 | 2023-03-21 12:00:15 +0000 | [diff] [blame] | 95 | return std::min(std::min(std::min(_src_shapes.size(), _block_shapes.size()), _crop_infos.size()), _dst_shapes.size()); |
Michalis Spyrou | 6a8d3b6 | 2018-08-31 10:07:09 +0100 | [diff] [blame] | 96 | } |
| 97 | |
SiCong Li | 5a7d157 | 2023-03-21 12:00:15 +0000 | [diff] [blame] | 98 | void add_config(const TensorShape &src, const std::vector<int32_t> &block_shape, const CropInfo &crop_info, const TensorShape &dst) |
Michalis Spyrou | 6a8d3b6 | 2018-08-31 10:07:09 +0100 | [diff] [blame] | 99 | { |
| 100 | _src_shapes.emplace_back(std::move(src)); |
SiCong Li | 5a7d157 | 2023-03-21 12:00:15 +0000 | [diff] [blame] | 101 | _block_shapes.emplace_back(std::move(block_shape)); |
| 102 | _crop_infos.emplace_back(std::move(crop_info)); |
Michalis Spyrou | 6a8d3b6 | 2018-08-31 10:07:09 +0100 | [diff] [blame] | 103 | _dst_shapes.emplace_back(std::move(dst)); |
| 104 | } |
| 105 | |
| 106 | protected: |
| 107 | BatchToSpaceLayerDataset() = default; |
| 108 | BatchToSpaceLayerDataset(BatchToSpaceLayerDataset &&) = default; |
| 109 | |
| 110 | private: |
SiCong Li | 5a7d157 | 2023-03-21 12:00:15 +0000 | [diff] [blame] | 111 | std::vector<TensorShape> _src_shapes{}; |
| 112 | std::vector<std::vector<int32_t>> _block_shapes{}; |
| 113 | std::vector<CropInfo> _crop_infos{}; |
| 114 | std::vector<TensorShape> _dst_shapes{}; |
Michalis Spyrou | 6a8d3b6 | 2018-08-31 10:07:09 +0100 | [diff] [blame] | 115 | }; |
| 116 | |
SiCong Li | 5a7d157 | 2023-03-21 12:00:15 +0000 | [diff] [blame] | 117 | /** Follow NCHW data layout across all datasets. I.e. |
| 118 | * TensorShape(Width(X), Height(Y), Channel(Z), Batch(W)) |
| 119 | */ |
| 120 | |
Michalis Spyrou | 6a8d3b6 | 2018-08-31 10:07:09 +0100 | [diff] [blame] | 121 | class SmallBatchToSpaceLayerDataset final : public BatchToSpaceLayerDataset |
| 122 | { |
| 123 | public: |
| 124 | SmallBatchToSpaceLayerDataset() |
| 125 | { |
SiCong Li | 5a7d157 | 2023-03-21 12:00:15 +0000 | [diff] [blame] | 126 | // Block size = 1 (effectively no batch to space) |
| 127 | add_config(TensorShape(1U, 1U, 1U, 4U), { 1U, 1U }, CropInfo(), TensorShape(1U, 1U, 1U, 4U)); |
| 128 | add_config(TensorShape(8U, 2U, 4U, 3U), { 1U, 1U }, CropInfo(), TensorShape(8U, 2U, 4U, 3U)); |
| 129 | // Same block size in both x and y |
| 130 | add_config(TensorShape(3U, 2U, 1U, 4U), { 2U, 2U }, CropInfo(), TensorShape(6U, 4U, 1U, 1U)); |
| 131 | add_config(TensorShape(1U, 3U, 2U, 9U), { 3U, 3U }, CropInfo(), TensorShape(3U, 9U, 2U, 1U)); |
| 132 | // Different block size in x and y |
| 133 | add_config(TensorShape(5U, 7U, 7U, 4U), { 2U, 1U }, CropInfo(), TensorShape(10U, 7U, 7U, 2U)); |
| 134 | add_config(TensorShape(3U, 3U, 1U, 8U), { 1U, 2U }, CropInfo(), TensorShape(3U, 6U, 1U, 4U)); |
| 135 | add_config(TensorShape(5U, 2U, 2U, 6U), { 3U, 2U }, CropInfo(), TensorShape(15U, 4U, 2U, 1U)); |
Michalis Spyrou | 6a8d3b6 | 2018-08-31 10:07:09 +0100 | [diff] [blame] | 136 | } |
| 137 | }; |
| 138 | |
SiCong Li | 5a7d157 | 2023-03-21 12:00:15 +0000 | [diff] [blame] | 139 | /** Relative small shapes that are still large enough to leave room for testing cropping of the output shape |
| 140 | */ |
| 141 | class SmallBatchToSpaceLayerWithCroppingDataset final : public BatchToSpaceLayerDataset |
| 142 | { |
| 143 | public: |
| 144 | SmallBatchToSpaceLayerWithCroppingDataset() |
| 145 | { |
| 146 | // Crop in both dims |
| 147 | add_config(TensorShape(5U, 3U, 2U, 8U), { 2U, 2U }, CropInfo(1U, 1U, 2U, 1U), TensorShape(8U, 3U, 2U, 2U)); |
| 148 | // Left crop in x dim |
| 149 | add_config(TensorShape(1U, 1U, 1U, 20U), { 4U, 5U }, CropInfo(2U, 1U, 0U, 2U), TensorShape(1U, 3U, 1U, 1U)); |
| 150 | // Left crop in y dim |
| 151 | add_config(TensorShape(3U, 1U, 1U, 8U), { 2U, 4U }, CropInfo(0U, 0U, 2U, 1U), TensorShape(6U, 1U, 1U, 1U)); |
| 152 | } |
| 153 | }; |
Michalis Spyrou | 6a8d3b6 | 2018-08-31 10:07:09 +0100 | [diff] [blame] | 154 | class LargeBatchToSpaceLayerDataset final : public BatchToSpaceLayerDataset |
| 155 | { |
| 156 | public: |
| 157 | LargeBatchToSpaceLayerDataset() |
| 158 | { |
SiCong Li | 5a7d157 | 2023-03-21 12:00:15 +0000 | [diff] [blame] | 159 | // Same block size in both x and y |
| 160 | add_config(TensorShape(64U, 32U, 2U, 4U), { 2U, 2U }, CropInfo(), TensorShape(128U, 64U, 2U, 1U)); |
| 161 | add_config(TensorShape(128U, 16U, 2U, 18U), { 3U, 3U }, CropInfo(), TensorShape(384U, 48U, 2U, 2U)); |
| 162 | // Different block size in x and y |
| 163 | add_config(TensorShape(16U, 8U, 2U, 8U), { 4U, 1U }, CropInfo(), TensorShape(64U, 8U, 2U, 2U)); |
| 164 | add_config(TensorShape(8U, 16U, 2U, 8U), { 2U, 4U }, CropInfo(), TensorShape(16U, 64U, 2U, 1U)); |
Michalis Spyrou | 6a8d3b6 | 2018-08-31 10:07:09 +0100 | [diff] [blame] | 165 | } |
| 166 | }; |
| 167 | } // namespace datasets |
| 168 | } // namespace test |
| 169 | } // namespace arm_compute |
| 170 | #endif /* ARM_COMPUTE_TEST_BATCH_TO_SPACE_LAYER_DATASET */ |