xref: /aosp_15_r20/external/ComputeLibrary/tests/datasets/PoolingLayerDataset.h (revision c217d954acce2dbc11938adb493fc0abd69584f3)
1 /*
2  * Copyright (c) 2017-2021 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_POOLING_LAYER_DATASET
25 #define ARM_COMPUTE_TEST_POOLING_LAYER_DATASET
26 
27 #include "arm_compute/core/TensorShape.h"
28 #include "arm_compute/core/Types.h"
29 #include "utils/TypePrinter.h"
30 
31 namespace arm_compute
32 {
33 namespace test
34 {
35 namespace datasets
36 {
37 class PoolingLayerDataset
38 {
39 public:
40     using type = std::tuple<TensorShape, PoolingLayerInfo>;
41 
42     struct iterator
43     {
iteratoriterator44         iterator(std::vector<TensorShape>::const_iterator      src_it,
45                  std::vector<PoolingLayerInfo>::const_iterator infos_it)
46             : _src_it{ std::move(src_it) },
47               _infos_it{ std::move(infos_it) }
48         {
49         }
50 
descriptioniterator51         std::string description() const
52         {
53             std::stringstream description;
54             description << "In=" << *_src_it << ":";
55             description << "Info=" << *_infos_it << ":";
56             return description.str();
57         }
58 
59         PoolingLayerDataset::type operator*() const
60         {
61             return std::make_tuple(*_src_it, *_infos_it);
62         }
63 
64         iterator &operator++()
65         {
66             ++_src_it;
67             ++_infos_it;
68 
69             return *this;
70         }
71 
72     private:
73         std::vector<TensorShape>::const_iterator      _src_it;
74         std::vector<PoolingLayerInfo>::const_iterator _infos_it;
75     };
76 
begin()77     iterator begin() const
78     {
79         return iterator(_src_shapes.begin(), _infos.begin());
80     }
81 
size()82     int size() const
83     {
84         return std::min(_src_shapes.size(), _infos.size());
85     }
86 
add_config(TensorShape src,PoolingLayerInfo info)87     void add_config(TensorShape src, PoolingLayerInfo info)
88     {
89         _src_shapes.emplace_back(std::move(src));
90         _infos.emplace_back(std::move(info));
91     }
92 
93 protected:
94     PoolingLayerDataset()                       = default;
95     PoolingLayerDataset(PoolingLayerDataset &&) = default;
96 
97 private:
98     std::vector<TensorShape>      _src_shapes{};
99     std::vector<PoolingLayerInfo> _infos{};
100 };
101 
102 // Special pooling dataset
103 class PoolingLayerDatasetSpecial final : public PoolingLayerDataset
104 {
105 public:
PoolingLayerDatasetSpecial()106     PoolingLayerDatasetSpecial()
107     {
108         // Special cases
109         add_config(TensorShape(2U, 3U, 4U, 1U), PoolingLayerInfo(PoolingType::AVG, Size2D(2, 2), DataLayout::NCHW, PadStrideInfo(3, 3, 0, 0), true));
110         add_config(TensorShape(60U, 52U, 3U, 2U), PoolingLayerInfo(PoolingType::AVG, Size2D(100, 100), DataLayout::NCHW, PadStrideInfo(5, 5, 50, 50), true));
111         // Asymmetric padding
112         add_config(TensorShape(112U, 112U, 32U), PoolingLayerInfo(PoolingType::MAX, 3, DataLayout::NCHW, PadStrideInfo(2, 2, 0, 1, 0, 1, DimensionRoundingType::FLOOR)));
113         add_config(TensorShape(14U, 14U, 832U), PoolingLayerInfo(PoolingType::MAX, 2, DataLayout::NCHW, PadStrideInfo(1, 1, 0, 0, DimensionRoundingType::CEIL)));
114     }
115 };
116 } // namespace datasets
117 } // namespace test
118 } // namespace arm_compute
119 #endif /* ARM_COMPUTE_TEST_POOLING_LAYER_DATASET */
120