xref: /aosp_15_r20/external/ComputeLibrary/tests/datasets/ChannelShuffleLayerDataset.h (revision c217d954acce2dbc11938adb493fc0abd69584f3)
1 /*
2  * Copyright (c) 2018, 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_CHANNEL_SHUFFLE_LAYER_DATASET
25 #define ARM_COMPUTE_TEST_CHANNEL_SHUFFLE_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 ChannelShuffleLayerDataset
39 {
40 public:
41     using type = std::tuple<TensorShape, int>;
42 
43     struct iterator
44     {
iteratoriterator45         iterator(std::vector<TensorShape>::const_iterator tensor_it,
46                  std::vector<int>::const_iterator         num_groups_it)
47             : _tensor_it{ std::move(tensor_it) },
48               _num_groups_it{ std::move(num_groups_it) }
49         {
50         }
51 
descriptioniterator52         std::string description() const
53         {
54             std::stringstream description;
55             description << "In=" << *_tensor_it << ":";
56             description << "NumGroups=" << *_num_groups_it;
57             return description.str();
58         }
59 
60         ChannelShuffleLayerDataset::type operator*() const
61         {
62             return std::make_tuple(*_tensor_it, *_num_groups_it);
63         }
64 
65         iterator &operator++()
66         {
67             ++_tensor_it;
68             ++_num_groups_it;
69 
70             return *this;
71         }
72 
73     private:
74         std::vector<TensorShape>::const_iterator _tensor_it;
75         std::vector<int>::const_iterator         _num_groups_it;
76     };
77 
begin()78     iterator begin() const
79     {
80         return iterator(_tensor_shapes.begin(), _num_groups.begin());
81     }
82 
size()83     int size() const
84     {
85         return std::min(_tensor_shapes.size(), _num_groups.size());
86     }
87 
add_config(TensorShape tensor,int num_groups)88     void add_config(TensorShape tensor, int num_groups)
89     {
90         _tensor_shapes.emplace_back(std::move(tensor));
91         _num_groups.emplace_back(std::move(num_groups));
92     }
93 
94 protected:
95     ChannelShuffleLayerDataset()                              = default;
96     ChannelShuffleLayerDataset(ChannelShuffleLayerDataset &&) = default;
97 
98 private:
99     std::vector<TensorShape> _tensor_shapes{};
100     std::vector<int>         _num_groups{};
101 };
102 
103 class SmallRandomChannelShuffleLayerDataset final : public ChannelShuffleLayerDataset
104 {
105 public:
SmallRandomChannelShuffleLayerDataset()106     SmallRandomChannelShuffleLayerDataset()
107     {
108         add_config(TensorShape(1U, 1U, 605U, 16U), 5);
109         add_config(TensorShape(15U, 16U, 4U, 12U), 2);
110         add_config(TensorShape(21U, 11U, 12U, 7U), 4);
111         add_config(TensorShape(21U, 11U, 12U, 7U), 6);
112         add_config(TensorShape(7U, 3U, 6U, 11U), 3);
113     }
114 };
115 
116 class LargeRandomChannelShuffleLayerDataset final : public ChannelShuffleLayerDataset
117 {
118 public:
LargeRandomChannelShuffleLayerDataset()119     LargeRandomChannelShuffleLayerDataset()
120     {
121         add_config(TensorShape(210U, 43U, 20U, 3U), 5);
122         add_config(TensorShape(283U, 213U, 15U, 3U), 3);
123         add_config(TensorShape(500U, 115U, 16U, 2U), 4);
124     }
125 };
126 } // namespace datasets
127 } // namespace test
128 } // namespace arm_compute
129 #endif /* ARM_COMPUTE_TEST_CHANNEL_SHUFFLE_LAYER_DATASET */
130