blob: 7ab068c2119063f1cc905db1efd22724e3b7db4a [file] [log] [blame]
George Wort2d7e6832019-02-22 16:37:41 +00001/*
Michele Di Giorgiod9eaf612020-07-08 11:12:57 +01002 * Copyright (c) 2019-2020 Arm Limited.
George Wort2d7e6832019-02-22 16:37:41 +00003 *
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_GEMMLOWPOUTPUT_DATASET
25#define ARM_COMPUTE_TEST_GEMMLOWPOUTPUT_DATASET
26
27#include "utils/TypePrinter.h"
28
29#include "arm_compute/core/TensorShape.h"
30#include "arm_compute/core/Utils.h"
31
32using namespace arm_compute;
33
34namespace arm_compute
35{
36namespace test
37{
38namespace datasets
39{
40class GEMMLowpFusedOffsetOutputDataset
41{
42public:
43 using type = std::tuple<TensorShape, TensorShape, TensorShape, int32_t, int32_t, GEMMLowpOutputStageInfo>;
44
45 struct iterator
46 {
47 iterator(std::vector<TensorShape>::const_iterator a_it,
48 std::vector<TensorShape>::const_iterator b_it,
49 std::vector<TensorShape>::const_iterator c_it,
50 std::vector<int32_t>::const_iterator a_offset_it,
51 std::vector<int32_t>::const_iterator b_offset_it,
52 std::vector<GEMMLowpOutputStageInfo>::const_iterator output_stage_it)
53 : _a_it{ std::move(a_it) },
54 _b_it{ std::move(b_it) },
55 _c_it{ std::move(c_it) },
56 _a_offset_it{ std::move(a_offset_it) },
57 _b_offset_it{ std::move(b_offset_it) },
58 _output_stage_it{ std::move(output_stage_it) }
59 {
60 }
61
62 std::string description() const
63 {
64 std::stringstream description;
65 description << "A=" << *_a_it << ":";
66 description << "B=" << *_b_it << ":";
67 description << "C=" << *_c_it << ":";
68 description << "a_offset=" << *_a_offset_it << ":";
69 description << "b_offset=" << *_b_offset_it << ":";
70 description << "output_type=" << string_from_gemmlowp_output_stage((*_output_stage_it).type) << ":";
71 description << "output_offset=" << (*_output_stage_it).gemmlowp_offset << ":";
Vidhya Sudhan Loganathan951b8a42019-11-04 14:42:08 +000072 description << "output_multiplier={";
73 for(auto it = (*_output_stage_it).gemmlowp_multipliers.begin(); it != (*_output_stage_it).gemmlowp_multipliers.end(); ++it)
74 {
75 description << (*it) << ", ";
76 }
77 description << "}:";
78 description << "output_shift={";
79
80 for(auto it = (*_output_stage_it).gemmlowp_shifts.begin(); it != (*_output_stage_it).gemmlowp_shifts.end(); ++it)
81 {
82 description << (*it) << ", ";
83 }
84 description << "}:";
George Wort2d7e6832019-02-22 16:37:41 +000085 description << "output_min=" << (*_output_stage_it).gemmlowp_min_bound << ":";
86 description << "output_max=" << (*_output_stage_it).gemmlowp_max_bound << ":";
Vidhya Sudhan Loganathan951b8a42019-11-04 14:42:08 +000087 description << "is_quantized_per_channel=" << (*_output_stage_it).is_quantized_per_channel << ":";
George Wort2d7e6832019-02-22 16:37:41 +000088
89 return description.str();
90 }
91
92 GEMMLowpFusedOffsetOutputDataset::type operator*() const
93 {
94 return std::make_tuple(*_a_it, *_b_it, *_c_it, *_a_offset_it, *_b_offset_it, *_output_stage_it);
95 }
96
97 iterator &operator++()
98 {
99 ++_a_it;
100 ++_b_it;
101 ++_c_it;
102 ++_a_offset_it;
103 ++_b_offset_it;
104 ++_output_stage_it;
105
106 return *this;
107 }
108
109 private:
110 std::vector<TensorShape>::const_iterator _a_it;
111 std::vector<TensorShape>::const_iterator _b_it;
112 std::vector<TensorShape>::const_iterator _c_it;
113 std::vector<int32_t>::const_iterator _a_offset_it;
114 std::vector<int32_t>::const_iterator _b_offset_it;
115 std::vector<GEMMLowpOutputStageInfo>::const_iterator _output_stage_it;
116 };
117
118 iterator begin() const
119 {
120 return iterator(_a_shapes.begin(), _b_shapes.begin(), _c_shapes.begin(), _a_offset.begin(), _b_offset.begin(), _output_stage.begin());
121 }
122
123 int size() const
124 {
125 return std::min(_a_shapes.size(), std::min(_b_shapes.size(), std::min(_c_shapes.size(), std::min(_a_offset.size(), std::min(_b_offset.size(), _output_stage.size())))));
126 }
127
128 void add_config(TensorShape a, TensorShape b, TensorShape c, int32_t a_offset, int32_t b_offset, GEMMLowpOutputStageInfo output_stage)
129 {
130 _a_shapes.emplace_back(std::move(a));
131 _b_shapes.emplace_back(std::move(b));
132 _c_shapes.emplace_back(std::move(c));
133 _a_offset.emplace_back(std::move(a_offset));
134 _b_offset.emplace_back(std::move(b_offset));
135 _output_stage.emplace_back(std::move(output_stage));
136 }
137
138 GEMMLowpOutputStageInfo OutputStageInfo(GEMMLowpOutputStageType type, int32_t offset, int32_t multiplier, int32_t shift, int32_t min, int32_t max)
139 {
140 GEMMLowpOutputStageInfo output_stage = GEMMLowpOutputStageInfo();
141 output_stage.type = type;
142 output_stage.gemmlowp_offset = offset;
143 output_stage.gemmlowp_multiplier = multiplier;
144 output_stage.gemmlowp_shift = shift;
145 output_stage.gemmlowp_min_bound = min;
146 output_stage.gemmlowp_max_bound = max;
Vidhya Sudhan Loganathan951b8a42019-11-04 14:42:08 +0000147 output_stage.gemmlowp_multipliers.push_back(multiplier);
148 output_stage.gemmlowp_shifts.push_back(shift);
George Wort2d7e6832019-02-22 16:37:41 +0000149 return output_stage;
150 }
151
152protected:
153 GEMMLowpFusedOffsetOutputDataset() = default;
154 GEMMLowpFusedOffsetOutputDataset(GEMMLowpFusedOffsetOutputDataset &&) = default;
155
156private:
157 std::vector<TensorShape> _a_shapes{};
158 std::vector<TensorShape> _b_shapes{};
159 std::vector<TensorShape> _c_shapes{};
160 std::vector<int32_t> _a_offset{};
161 std::vector<int32_t> _b_offset{};
162 std::vector<GEMMLowpOutputStageInfo> _output_stage{};
163};
164
Manuel Bottini959c26d2019-12-02 16:22:35 +0000165class SmallGEMMLowpFusedOffsetOutputUint8Dataset final : public GEMMLowpFusedOffsetOutputDataset
George Wort2d7e6832019-02-22 16:37:41 +0000166{
167public:
Manuel Bottini959c26d2019-12-02 16:22:35 +0000168 SmallGEMMLowpFusedOffsetOutputUint8Dataset()
George Wort2d7e6832019-02-22 16:37:41 +0000169 {
SiCong Li7e5b7bf2020-11-17 09:41:13 +0000170 add_config(TensorShape(21U, 13U), TensorShape(1U, 21U), TensorShape(1U, 13U), 0, 0, OutputStageInfo(GEMMLowpOutputStageType::QUANTIZE_DOWN, -100, 2, 13, 10, 210));
George Wort2d7e6832019-02-22 16:37:41 +0000171 add_config(TensorShape(52U, 13U), TensorShape(33U, 52U), TensorShape(33U, 13U), 0, 4, OutputStageInfo(GEMMLowpOutputStageType::QUANTIZE_DOWN, 100, 2, 13, 10, 210));
George Wort2d7e6832019-02-22 16:37:41 +0000172 add_config(TensorShape(31U, 27U), TensorShape(23U, 31U), TensorShape(23U, 27U), 18, 23, OutputStageInfo(GEMMLowpOutputStageType::QUANTIZE_DOWN, 200, 2, 13, 10, 210));
SiCong Li7e5b7bf2020-11-17 09:41:13 +0000173 add_config(TensorShape(32U, 72U), TensorShape(16U, 32U), TensorShape(16U, 72U), -9, 1, OutputStageInfo(GEMMLowpOutputStageType::QUANTIZE_DOWN, -100, 2, 13, 10, 210));
George Wort2d7e6832019-02-22 16:37:41 +0000174
175 add_config(TensorShape(21U, 1U), TensorShape(43U, 21U), TensorShape(43U, 1U), 0, 0, OutputStageInfo(GEMMLowpOutputStageType::QUANTIZE_DOWN_FIXEDPOINT, -2, 254601600, 10, 10, 210));
George Wort2d7e6832019-02-22 16:37:41 +0000176 add_config(TensorShape(31U, 3U), TensorShape(72U, 31U), TensorShape(72U, 3U), -2, 13, OutputStageInfo(GEMMLowpOutputStageType::QUANTIZE_DOWN_FIXEDPOINT, 0, 254601600, 10, 10, 210));
George Wort2d7e6832019-02-22 16:37:41 +0000177 add_config(TensorShape(31U, 27U), TensorShape(23U, 31U), TensorShape(23U, 27U), 5, 13, OutputStageInfo(GEMMLowpOutputStageType::QUANTIZE_DOWN_FIXEDPOINT, 2, 254601602, 10, 10, 210));
George Wort2d7e6832019-02-22 16:37:41 +0000178 add_config(TensorShape(32U, 72U), TensorShape(17U, 32U), TensorShape(17U, 72U), -9, 1, OutputStageInfo(GEMMLowpOutputStageType::QUANTIZE_DOWN_FIXEDPOINT, -1, 254601602, 10, 10, 210));
179 }
180};
181
Manuel Bottini959c26d2019-12-02 16:22:35 +0000182class SmallGEMMLowpFusedOffsetOutputInt8Dataset final : public GEMMLowpFusedOffsetOutputDataset
183{
184public:
185 SmallGEMMLowpFusedOffsetOutputInt8Dataset()
186 {
SiCong Li7e5b7bf2020-11-17 09:41:13 +0000187 add_config(TensorShape(21U, 1U), TensorShape(1U, 21U), TensorShape(1U, 1U), 0, 0, OutputStageInfo(GEMMLowpOutputStageType::QUANTIZE_DOWN, -50, 2, 13, -10, 110));
Manuel Bottini959c26d2019-12-02 16:22:35 +0000188 add_config(TensorShape(31U, 3U), TensorShape(72U, 31U), TensorShape(72U, 3U), -2, 13, OutputStageInfo(GEMMLowpOutputStageType::QUANTIZE_DOWN, 0, 2, 13, -10, 110));
189 add_config(TensorShape(52U, 26U), TensorShape(33U, 52U), TensorShape(33U, 26U), -2, 0, OutputStageInfo(GEMMLowpOutputStageType::QUANTIZE_DOWN, 0, 2, 13, -10, 110));
190 add_config(TensorShape(38U, 43U), TensorShape(21U, 38U), TensorShape(21U, 43U), -3, -2, OutputStageInfo(GEMMLowpOutputStageType::QUANTIZE_DOWN, -40, 2, 13, -10, 110));
191
192 add_config(TensorShape(21U, 13U), TensorShape(33U, 21U), TensorShape(33U, 13U), 0, 0, OutputStageInfo(GEMMLowpOutputStageType::QUANTIZE_DOWN_FIXEDPOINT, -1, 254601600, 10, -10, 110));
193 add_config(TensorShape(52U, 26U), TensorShape(33U, 52U), TensorShape(33U, 26U), -2, 0, OutputStageInfo(GEMMLowpOutputStageType::QUANTIZE_DOWN_FIXEDPOINT, 1, 254601600, 10, -10, 110));
194 add_config(TensorShape(38U, 43U), TensorShape(21U, 38U), TensorShape(21U, 43U), -3, -2, OutputStageInfo(GEMMLowpOutputStageType::QUANTIZE_DOWN_FIXEDPOINT, -2, 254601602, 10, -10, 110));
195 add_config(TensorShape(32U, 72U), TensorShape(17U, 32U), TensorShape(17U, 72U), -9, 1, OutputStageInfo(GEMMLowpOutputStageType::QUANTIZE_DOWN_FIXEDPOINT, -1, 254601602, 10, -10, 110));
196 }
197};
198
Vidhya Sudhan Loganathan951b8a42019-11-04 14:42:08 +0000199class SmallGEMMLowpFusedOffsetOutputPerChannelDataset final : public GEMMLowpFusedOffsetOutputDataset
200{
201public:
202 SmallGEMMLowpFusedOffsetOutputPerChannelDataset()
203 {
204 add_config(TensorShape(21U, 1U, 6U), TensorShape(43U, 21U, 6U), TensorShape(43U, 1U, 6U), 0, 0, OutputStageInfo(GEMMLowpOutputStageType::QUANTIZE_DOWN, -200, 2, 13, 10, 210));
205 add_config(TensorShape(21U, 13U, 3U), TensorShape(33U, 21U, 3U), TensorShape(33U, 13U, 3U), 0, 0, OutputStageInfo(GEMMLowpOutputStageType::QUANTIZE_DOWN, -100, 2, 13, 10, 210));
206 add_config(TensorShape(31U, 3U, 2U), TensorShape(72U, 31U, 2U), TensorShape(72U, 3U, 2U), -2, 13, OutputStageInfo(GEMMLowpOutputStageType::QUANTIZE_DOWN, 0, 2, 13, 10, 210));
207 add_config(TensorShape(52U, 13U, 7U), TensorShape(33U, 52U, 7U), TensorShape(33U, 13U, 7U), 0, 4, OutputStageInfo(GEMMLowpOutputStageType::QUANTIZE_DOWN, 100, 2, 13, 10, 210));
208 add_config(TensorShape(52U, 26U, 8U), TensorShape(33U, 52U, 8U), TensorShape(33U, 26U, 8U), -2, 0, OutputStageInfo(GEMMLowpOutputStageType::QUANTIZE_DOWN, 0, 2, 13, 10, 210));
209 }
210};
Manuel Bottini959c26d2019-12-02 16:22:35 +0000211
212class LargeGEMMLowpFusedOffsetOutputUint8Dataset final : public GEMMLowpFusedOffsetOutputDataset
George Wort2d7e6832019-02-22 16:37:41 +0000213{
214public:
Manuel Bottini959c26d2019-12-02 16:22:35 +0000215 LargeGEMMLowpFusedOffsetOutputUint8Dataset()
George Wort2d7e6832019-02-22 16:37:41 +0000216 {
George Wort2d7e6832019-02-22 16:37:41 +0000217 add_config(TensorShape(923U, 429U), TensorShape(871U, 923U), TensorShape(871U, 429U), 0, 0, OutputStageInfo(GEMMLowpOutputStageType::QUANTIZE_DOWN, -100, 2, 18, 10, 210));
George Wort2d7e6832019-02-22 16:37:41 +0000218 add_config(TensorShape(873U, 513U), TensorShape(784U, 873U), TensorShape(784U, 513U), 0, 4, OutputStageInfo(GEMMLowpOutputStageType::QUANTIZE_DOWN, 100, 2, 18, 10, 210));
George Wort2d7e6832019-02-22 16:37:41 +0000219 add_config(TensorShape(1021U, 973U), TensorShape(783U, 1021U), TensorShape(783U, 973U), 5, 13, OutputStageInfo(GEMMLowpOutputStageType::QUANTIZE_DOWN, 200, 2, 18, 10, 210));
George Wort2d7e6832019-02-22 16:37:41 +0000220 add_config(TensorShape(941U, 1011U), TensorShape(623U, 941U), TensorShape(623U, 1011U), -9, 1, OutputStageInfo(GEMMLowpOutputStageType::QUANTIZE_DOWN, -100, 2, 18, 10, 210));
221
George Wort2d7e6832019-02-22 16:37:41 +0000222 add_config(TensorShape(923U, 429U), TensorShape(871U, 923U), TensorShape(871U, 429U), 0, 0, OutputStageInfo(GEMMLowpOutputStageType::QUANTIZE_DOWN_FIXEDPOINT, -1, 254601600, 15, 10, 210));
George Wort2d7e6832019-02-22 16:37:41 +0000223 add_config(TensorShape(873U, 513U), TensorShape(784U, 873U), TensorShape(784U, 513U), 0, 4, OutputStageInfo(GEMMLowpOutputStageType::QUANTIZE_DOWN_FIXEDPOINT, 1, 254601600, 15, 10, 210));
George Wort2d7e6832019-02-22 16:37:41 +0000224 add_config(TensorShape(1021U, 973U), TensorShape(783U, 1021U), TensorShape(783U, 973U), 5, 13, OutputStageInfo(GEMMLowpOutputStageType::QUANTIZE_DOWN_FIXEDPOINT, -2, 254601602, 15, 10, 210));
225 add_config(TensorShape(681U, 1023U), TensorShape(213U, 681U), TensorShape(213U, 1023U), -3, -2, OutputStageInfo(GEMMLowpOutputStageType::QUANTIZE_DOWN_FIXEDPOINT, -1, 254601602, 15, 10, 210));
226 }
227};
Manuel Bottini959c26d2019-12-02 16:22:35 +0000228
229class LargeGEMMLowpFusedOffsetOutputInt8Dataset final : public GEMMLowpFusedOffsetOutputDataset
230{
231public:
232 LargeGEMMLowpFusedOffsetOutputInt8Dataset()
233 {
234 add_config(TensorShape(923U, 1U, 15U), TensorShape(871U, 923U, 15U), TensorShape(871U, 1U, 15U), 0, 0, OutputStageInfo(GEMMLowpOutputStageType::QUANTIZE_DOWN, -50, 2, 18, -10, 110));
235 add_config(TensorShape(873U, 7U), TensorShape(784U, 873U), TensorShape(784U, 7U), -1, 3, OutputStageInfo(GEMMLowpOutputStageType::QUANTIZE_DOWN, 0, 2, 18, -10, 110));
236 add_config(TensorShape(697U, 872U), TensorShape(563U, 697U), TensorShape(563U, 872U), -2, 0, OutputStageInfo(GEMMLowpOutputStageType::QUANTIZE_DOWN, 0, 2, 18, -10, 110));
237 add_config(TensorShape(681U, 1023U), TensorShape(213U, 681U), TensorShape(213U, 1023U), -3, -2, OutputStageInfo(GEMMLowpOutputStageType::QUANTIZE_DOWN, -50, 2, 18, -10, 110));
238
239 add_config(TensorShape(923U, 1U), TensorShape(871U, 923U), TensorShape(871U, 1U), 0, 0, OutputStageInfo(GEMMLowpOutputStageType::QUANTIZE_DOWN_FIXEDPOINT, -2, 254601600, 15, -10, 110));
240 add_config(TensorShape(873U, 7U), TensorShape(784U, 873U), TensorShape(784U, 7U), -1, 3, OutputStageInfo(GEMMLowpOutputStageType::QUANTIZE_DOWN_FIXEDPOINT, 0, 254601600, 15, -10, 110));
241 add_config(TensorShape(697U, 872U), TensorShape(563U, 697U), TensorShape(563U, 872U), -2, 0, OutputStageInfo(GEMMLowpOutputStageType::QUANTIZE_DOWN_FIXEDPOINT, 2, 254601602, 15, -10, 110));
242 add_config(TensorShape(1021U, 973U), TensorShape(783U, 1021U), TensorShape(783U, 973U), 5, 13, OutputStageInfo(GEMMLowpOutputStageType::QUANTIZE_DOWN_FIXEDPOINT, -2, 254601602, 15, -10, 110));
243 }
244};
George Wort2d7e6832019-02-22 16:37:41 +0000245} // namespace datasets
246} // namespace test
247} // namespace arm_compute
248#endif /* ARM_COMPUTE_TEST_GEMMLOWPOUTPUT_DATASET */