Gian Marco Iodice | d2fab73 | 2018-03-02 11:18:12 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (c) 2018 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_WINOGRAD_OUTPUT_TRANSFORM_DATASET |
| 25 | #define ARM_COMPUTE_TEST_WINOGRAD_OUTPUT_TRANSFORM_DATASET |
| 26 | |
| 27 | #include "utils/TypePrinter.h" |
| 28 | |
| 29 | #include "arm_compute/core/TensorShape.h" |
| 30 | |
| 31 | namespace arm_compute |
| 32 | { |
| 33 | namespace test |
| 34 | { |
| 35 | namespace datasets |
| 36 | { |
| 37 | class WinogradOutputTransformDataset |
| 38 | { |
| 39 | public: |
| 40 | using type = std::tuple<TensorShape, Size2D, Size2D, Size2D, DataLayout>; |
| 41 | |
| 42 | struct iterator |
| 43 | { |
| 44 | iterator(std::vector<TensorShape>::const_iterator a_it, |
| 45 | std::vector<Size2D>::const_iterator b_it, |
| 46 | std::vector<Size2D>::const_iterator c_it, |
| 47 | std::vector<Size2D>::const_iterator d_it, |
| 48 | std::vector<DataLayout>::const_iterator data_layout_it) |
| 49 | : _a_it{ std::move(a_it) }, |
| 50 | _b_it{ std::move(b_it) }, |
| 51 | _c_it{ std::move(c_it) }, |
| 52 | _d_it{ std::move(d_it) }, |
| 53 | _data_layout_it{ std::move(data_layout_it) } |
| 54 | { |
| 55 | } |
| 56 | |
| 57 | std::string description() const |
| 58 | { |
| 59 | std::stringstream description; |
| 60 | description << "Input=" << *_a_it << ":"; |
| 61 | description << "KernelDims=" << *_b_it << ":"; |
| 62 | description << "OutputDims=" << *_c_it << ":"; |
| 63 | description << "NumTiles=" << *_d_it << ":"; |
| 64 | description << "DataLayout=" << *_data_layout_it; |
| 65 | return description.str(); |
| 66 | } |
| 67 | |
| 68 | WinogradOutputTransformDataset::type operator*() const |
| 69 | { |
| 70 | return std::make_tuple(*_a_it, *_b_it, *_c_it, *_d_it, *_data_layout_it); |
| 71 | } |
| 72 | |
| 73 | iterator &operator++() |
| 74 | { |
| 75 | ++_a_it; |
| 76 | ++_b_it; |
| 77 | ++_c_it; |
| 78 | ++_d_it; |
| 79 | ++_data_layout_it; |
| 80 | |
| 81 | return *this; |
| 82 | } |
| 83 | |
| 84 | private: |
| 85 | std::vector<TensorShape>::const_iterator _a_it; |
| 86 | std::vector<Size2D>::const_iterator _b_it; |
| 87 | std::vector<Size2D>::const_iterator _c_it; |
| 88 | std::vector<Size2D>::const_iterator _d_it; |
| 89 | std::vector<DataLayout>::const_iterator _data_layout_it; |
| 90 | }; |
| 91 | |
| 92 | iterator begin() const |
| 93 | { |
| 94 | return iterator(_a_shapes.begin(), _b_dims.begin(), _c_dims.begin(), _d_dims.begin(), _data_layout.begin()); |
| 95 | } |
| 96 | |
| 97 | int size() const |
| 98 | { |
| 99 | return std::min(_a_shapes.size(), std::min(_b_dims.size(), std::min(_c_dims.size(), std::min(_d_dims.size(), _data_layout.size())))); |
| 100 | } |
| 101 | |
| 102 | void add_config(TensorShape a, Size2D b, Size2D c, Size2D d, DataLayout data_layout) |
| 103 | { |
| 104 | _a_shapes.emplace_back(std::move(a)); |
| 105 | _b_dims.emplace_back(std::move(b)); |
| 106 | _c_dims.emplace_back(std::move(c)); |
| 107 | _d_dims.emplace_back(std::move(d)); |
| 108 | _data_layout.emplace_back(std::move(data_layout)); |
| 109 | } |
| 110 | |
| 111 | protected: |
| 112 | WinogradOutputTransformDataset() = default; |
| 113 | WinogradOutputTransformDataset(WinogradOutputTransformDataset &&) = default; |
| 114 | |
| 115 | private: |
| 116 | std::vector<TensorShape> _a_shapes{}; |
| 117 | std::vector<Size2D> _b_dims{}; |
| 118 | std::vector<Size2D> _c_dims{}; |
| 119 | std::vector<Size2D> _d_dims{}; |
| 120 | std::vector<DataLayout> _data_layout{}; |
| 121 | }; |
| 122 | |
| 123 | class SmallWinogradOutputTransformDataset final : public WinogradOutputTransformDataset |
| 124 | { |
| 125 | public: |
| 126 | SmallWinogradOutputTransformDataset() |
| 127 | { |
| 128 | add_config(TensorShape(24U, 49U, 16U), Size2D(3, 3), Size2D(14U, 14U), Size2D(7U, 7U), DataLayout::NCHW); |
| 129 | add_config(TensorShape(13U, 6U, 16U), Size2D(3, 3), Size2D(5U, 4U), Size2D(3U, 2U), DataLayout::NCHW); |
| 130 | add_config(TensorShape(7U, 20U, 16U), Size2D(3, 3), Size2D(8U, 9U), Size2D(4U, 5U), DataLayout::NCHW); |
| 131 | add_config(TensorShape(24U, 49U, 16U, 3U), Size2D(3, 3), Size2D(14U, 14U), Size2D(7U, 7U), DataLayout::NCHW); |
| 132 | add_config(TensorShape(13U, 6U, 16U, 2U), Size2D(3, 3), Size2D(5U, 4U), Size2D(3U, 2U), DataLayout::NCHW); |
| 133 | add_config(TensorShape(7U, 20U, 16U, 5U), Size2D(3, 3), Size2D(8U, 9U), Size2D(4U, 5U), DataLayout::NCHW); |
| 134 | } |
| 135 | }; |
| 136 | |
| 137 | class LargeWinogradOutputTransformDataset final : public WinogradOutputTransformDataset |
| 138 | { |
| 139 | public: |
| 140 | LargeWinogradOutputTransformDataset() |
| 141 | { |
| 142 | add_config(TensorShape(128U, 3136U, 16U), Size2D(3, 3), Size2D(112U, 112U), Size2D(56U, 56U), DataLayout::NCHW); |
| 143 | add_config(TensorShape(256U, 784U, 16U), Size2D(3, 3), Size2D(55U, 55U), Size2D(28U, 28U), DataLayout::NCHW); |
| 144 | add_config(TensorShape(512U, 169U, 16U), Size2D(3, 3), Size2D(26U, 26U), Size2D(13U, 13U), DataLayout::NCHW); |
| 145 | add_config(TensorShape(128U, 3136U, 16U, 3U), Size2D(3, 3), Size2D(112U, 112U), Size2D(56U, 56U), DataLayout::NCHW); |
| 146 | add_config(TensorShape(256U, 784U, 16U, 2U), Size2D(3, 3), Size2D(55U, 55U), Size2D(28U, 28U), DataLayout::NCHW); |
| 147 | add_config(TensorShape(512U, 169U, 16U, 5U), Size2D(3, 3), Size2D(26U, 26U), Size2D(13U, 13U), DataLayout::NCHW); |
| 148 | } |
| 149 | }; |
| 150 | } // namespace datasets |
| 151 | } // namespace test |
| 152 | } // namespace arm_compute |
| 153 | #endif /* ARM_COMPUTE_TEST_WINOGRAD_OUTPUT_TRANSFORM_DATASET */ |