blob: 8e1a8422b2f833e5377865e85f9cfc3e6a291b23 [file] [log] [blame]
David Svantesson3b162e52023-03-28 14:13:32 +00001/*
2 * Copyright (c) 2023 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 ACL_TESTS_DATASETS_REORDERLAYERDATASET
25#define ACL_TESTS_DATASETS_REORDERLAYERDATASET
26
27#include "arm_compute/core/TensorShape.h"
28#include "arm_compute/core/Types.h"
29#include "utils/TypePrinter.h"
30
31namespace arm_compute
32{
33namespace test
34{
35namespace datasets
36{
37/** [ReorderLayer datasets] **/
38class ReorderLayerDataset
39{
40public:
41 using type = std::tuple<TensorShape, TensorShape, WeightFormat, WeightFormat>;
42
43 struct iterator
44 {
45 iterator(std::vector<TensorShape>::const_iterator in_it,
46 std::vector<TensorShape>::const_iterator out_it,
47 std::vector<WeightFormat>::const_iterator _wf_in_it,
48 std::vector<WeightFormat>::const_iterator _wf_out_it)
49 : _in_it{ std::move(in_it) },
50 _out_it{ std::move(out_it) },
51 _wf_in_it{ std::move(_wf_in_it) },
52 _wf_out_it{ std::move(_wf_out_it) }
53 {
54 }
55
56 std::string description() const
57 {
58 std::stringstream description;
59 description << "In=" << *_in_it << ":";
60 description << "Out=" << *_out_it << ":";
61 description << "Wf_In=" << *_wf_in_it << ":";
62 description << "Wf_Out=" << *_wf_out_it;
63 return description.str();
64 }
65
66 ReorderLayerDataset::type operator*() const
67 {
68 return std::make_tuple(*_in_it, *_out_it, *_wf_in_it, *_wf_out_it);
69 }
70
71 iterator &operator++()
72 {
73 ++_in_it;
74 ++_out_it;
75 ++_wf_in_it;
76 ++_wf_out_it;
77
78 return *this;
79 }
80
81 private:
82 std::vector<TensorShape>::const_iterator _in_it;
83 std::vector<TensorShape>::const_iterator _out_it;
84 std::vector<WeightFormat>::const_iterator _wf_in_it;
85 std::vector<WeightFormat>::const_iterator _wf_out_it;
86 };
87
88 iterator begin() const
89 {
90 return iterator(_in_shapes.begin(), _out_shapes.begin(), _in_wfs.begin(), _out_wfs.begin());
91 }
92
93 int size() const
94 {
95 return std::min(_in_shapes.size(), std::min(_out_shapes.size(), std::min(_in_wfs.size(), _out_wfs.size())));
96 }
97
98 void add_config(TensorShape in, TensorShape out, WeightFormat in_wf, WeightFormat out_wf)
99 {
100 _in_shapes.emplace_back(std::move(in));
101 _out_shapes.emplace_back(std::move(out));
102 _in_wfs.emplace_back(std::move(in_wf));
103 _out_wfs.emplace_back(std::move(out_wf));
104 }
105
106 // protected:
107 ReorderLayerDataset() = default;
108 ReorderLayerDataset(ReorderLayerDataset &&) = default;
109
110 private:
111 std::vector<TensorShape> _in_shapes{};
112 std::vector<TensorShape> _out_shapes{};
113 std::vector<WeightFormat> _in_wfs{};
114 std::vector<WeightFormat> _out_wfs{};
115};
116
117/** [ReorderLayer datasets] **/
118
119class ReorderLayerDatasetBlock4 final : public ReorderLayerDataset
120{
121 public:
122 ReorderLayerDatasetBlock4()
123 {
124 add_config(TensorShape(10U, 9U), TensorShape(10U, 12U), WeightFormat::OHWI, WeightFormat::OHWIo4);
125 add_config(TensorShape(16U, 16U), TensorShape(16U, 16U), WeightFormat::OHWI, WeightFormat::OHWIo4);
126 add_config(TensorShape(10U, 511U), TensorShape(10U, 512U), WeightFormat::OHWI, WeightFormat::OHWIo4);
127 add_config(TensorShape(234U, 301U), TensorShape(234U, 304U), WeightFormat::OHWI, WeightFormat::OHWIo4);
128 add_config(TensorShape(1024U, 1024U), TensorShape(1024U, 1024U), WeightFormat::OHWI, WeightFormat::OHWIo4);
129 add_config(TensorShape(10U, 9U, 1U, 1U), TensorShape(10U, 12U, 1U, 1U), WeightFormat::OHWI, WeightFormat::OHWIo4);
130 add_config(TensorShape(16U, 16U, 1U, 1U), TensorShape(16U, 16U, 1U, 1U), WeightFormat::OHWI, WeightFormat::OHWIo4);
131 add_config(TensorShape(10U, 511U, 1U, 1U), TensorShape(10U, 512U, 1U, 1U), WeightFormat::OHWI, WeightFormat::OHWIo4);
132 add_config(TensorShape(234U, 301U, 1U, 1U), TensorShape(234U, 304U, 1U, 1U), WeightFormat::OHWI, WeightFormat::OHWIo4);
133 add_config(TensorShape(1024U, 1024U, 1U, 1U), TensorShape(1024U, 1024U, 1U, 1U), WeightFormat::OHWI, WeightFormat::OHWIo4);
134 }
135};
136
137class ReorderLayerDatasetBlock8 final : public ReorderLayerDataset
138{
139 public:
140 ReorderLayerDatasetBlock8()
141 {
142 add_config(TensorShape(10U, 9U), TensorShape(10U, 16U), WeightFormat::OHWI, WeightFormat::OHWIo8);
143 add_config(TensorShape(16U, 16U), TensorShape(16U, 16U), WeightFormat::OHWI, WeightFormat::OHWIo8);
144 add_config(TensorShape(10U, 511U), TensorShape(10U, 512U), WeightFormat::OHWI, WeightFormat::OHWIo8);
145 add_config(TensorShape(234U, 301U), TensorShape(234U, 304U), WeightFormat::OHWI, WeightFormat::OHWIo8);
146 add_config(TensorShape(1024U, 1024U), TensorShape(1024U, 1024U), WeightFormat::OHWI, WeightFormat::OHWIo8);
147 add_config(TensorShape(10U, 9U, 1U, 1U), TensorShape(10U, 16U, 1U, 1U), WeightFormat::OHWI, WeightFormat::OHWIo8);
148 add_config(TensorShape(16U, 16U, 1U, 1U), TensorShape(16U, 16U, 1U, 1U), WeightFormat::OHWI, WeightFormat::OHWIo8);
149 add_config(TensorShape(10U, 511U, 1U, 1U), TensorShape(10U, 512U, 1U, 1U), WeightFormat::OHWI, WeightFormat::OHWIo8);
150 add_config(TensorShape(234U, 301U, 1U, 1U), TensorShape(234U, 304U, 1U, 1U), WeightFormat::OHWI, WeightFormat::OHWIo8);
151 add_config(TensorShape(1024U, 1024U, 1U, 1U), TensorShape(1024U, 1024U, 1U, 1U), WeightFormat::OHWI, WeightFormat::OHWIo8);
152 }
153};
154
155} // namespace datasets
156} // namespace test
157} // namespace arm_compute
158#endif /* ACL_TESTS_DATASETS_REORDERLAYERDATASET */