blob: d80032a032782c8c438209ef2de42ed14d246b48 [file] [log] [blame]
Moritz Pflanzera4f711b2017-07-05 11:02:23 +01001/*
Georgios Pinitas45514032020-12-30 00:03:09 +00002 * Copyright (c) 2017-2021 Arm Limited.
Moritz Pflanzera4f711b2017-07-05 11:02:23 +01003 *
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_INSTRUMENTS
25#define ARM_COMPUTE_TEST_INSTRUMENTS
26
Pablo Tello4e66d702022-03-07 18:20:12 +000027#if !defined(_WIN64) && !defined(BARE_METAL) && !defined(__APPLE__) && !defined(__OpenBSD__)
Moritz Pflanzer45634b42017-08-30 12:48:18 +010028#include "MaliCounter.h"
Anthony Barbier35aa6a32018-04-23 16:12:12 +010029#include "OpenCLMemoryUsage.h"
Anthony Barbier6e433492017-11-09 15:52:00 +000030#include "OpenCLTimer.h"
Moritz Pflanzera4f711b2017-07-05 11:02:23 +010031#include "PMUCounter.h"
Pablo Tello4e66d702022-03-07 18:20:12 +000032#endif /* !defined(_WIN64) && !defined(BARE_METAL) && !defined(__APPLE__) && !defined(__OpenBSD__) */
Anthony Barbiere8a49832018-01-18 10:04:05 +000033#include "SchedulerTimer.h"
Moritz Pflanzera4f711b2017-07-05 11:02:23 +010034#include "WallClockTimer.h"
35
Georgios Pinitas12833d02019-07-25 13:31:10 +010036#include <memory>
Moritz Pflanzera4f711b2017-07-05 11:02:23 +010037#include <sstream>
38#include <string>
39
40namespace arm_compute
41{
42namespace test
43{
44namespace framework
45{
46enum class InstrumentType : unsigned int
47{
48 ALL = ~0U,
49 NONE = 0,
Moritz Pflanzer09e4f982017-08-30 12:47:06 +010050 WALL_CLOCK_TIMER = 0x0100,
51 PMU = 0x0200,
52 PMU_CYCLE_COUNTER = 0x0201,
53 PMU_INSTRUCTION_COUNTER = 0x0202,
Moritz Pflanzer45634b42017-08-30 12:48:18 +010054 MALI = 0x0300,
Anthony Barbier6e433492017-11-09 15:52:00 +000055 OPENCL_TIMER = 0x0400,
Anthony Barbiere8a49832018-01-18 10:04:05 +000056 SCHEDULER_TIMER = 0x0500,
Anthony Barbier35aa6a32018-04-23 16:12:12 +010057 OPENCL_MEMORY_USAGE = 0x0600,
Anthony Barbier72f4ae52018-11-07 17:33:54 +000058 WALL_CLOCK_TIMESTAMPS = 0x0700,
59 OPENCL_TIMESTAMPS = 0x0800,
60 SCHEDULER_TIMESTAMPS = 0x0900,
Moritz Pflanzera4f711b2017-07-05 11:02:23 +010061};
62
Georgios Pinitas12833d02019-07-25 13:31:10 +010063struct InstrumentsInfo
64{
65 std::vector<ISchedulerUser *> _scheduler_users{};
66};
67extern std::unique_ptr<InstrumentsInfo> instruments_info;
68
Giorgio Arenace58a9f2017-10-31 17:59:17 +000069using InstrumentsDescription = std::pair<InstrumentType, ScaleFactor>;
Moritz Pflanzera4f711b2017-07-05 11:02:23 +010070
Giorgio Arenace58a9f2017-10-31 17:59:17 +000071InstrumentsDescription instrument_type_from_name(const std::string &name);
72
73inline ::std::stringstream &operator>>(::std::stringstream &stream, InstrumentsDescription &instrument)
Moritz Pflanzera4f711b2017-07-05 11:02:23 +010074{
75 std::string value;
76 stream >> value;
77 instrument = instrument_type_from_name(value);
78 return stream;
79}
80
Giorgio Arenace58a9f2017-10-31 17:59:17 +000081inline ::std::stringstream &operator<<(::std::stringstream &stream, InstrumentsDescription instrument)
Moritz Pflanzera4f711b2017-07-05 11:02:23 +010082{
Giorgio Arenace58a9f2017-10-31 17:59:17 +000083 switch(instrument.first)
Moritz Pflanzera4f711b2017-07-05 11:02:23 +010084 {
Anthony Barbier72f4ae52018-11-07 17:33:54 +000085 case InstrumentType::WALL_CLOCK_TIMESTAMPS:
86 switch(instrument.second)
87 {
88 case ScaleFactor::NONE:
89 stream << "WALL_CLOCK_TIMESTAMPS";
90 break;
91 case ScaleFactor::TIME_MS:
92 stream << "WALL_CLOCK_TIMESTAMPS_MS";
93 break;
94 case ScaleFactor::TIME_S:
95 stream << "WALL_CLOCK_TIMESTAMPS_S";
96 break;
97 default:
98 throw std::invalid_argument("Unsupported instrument scale");
99 }
100 break;
Moritz Pflanzera4f711b2017-07-05 11:02:23 +0100101 case InstrumentType::WALL_CLOCK_TIMER:
Giorgio Arenace58a9f2017-10-31 17:59:17 +0000102 switch(instrument.second)
103 {
104 case ScaleFactor::NONE:
105 stream << "WALL_CLOCK_TIMER";
106 break;
107 case ScaleFactor::TIME_MS:
108 stream << "WALL_CLOCK_TIMER_MS";
109 break;
110 case ScaleFactor::TIME_S:
111 stream << "WALL_CLOCK_TIMER_S";
112 break;
113 default:
114 throw std::invalid_argument("Unsupported instrument scale");
115 }
Moritz Pflanzera4f711b2017-07-05 11:02:23 +0100116 break;
Anthony Barbier72f4ae52018-11-07 17:33:54 +0000117 case InstrumentType::SCHEDULER_TIMESTAMPS:
118 switch(instrument.second)
119 {
120 case ScaleFactor::NONE:
121 stream << "SCHEDULER_TIMESTAMPS";
122 break;
123 case ScaleFactor::TIME_MS:
124 stream << "SCHEDULER_TIMESTAMPS_MS";
125 break;
126 case ScaleFactor::TIME_S:
127 stream << "SCHEDULER_TIMESTAMPS_S";
128 break;
129 default:
130 throw std::invalid_argument("Unsupported instrument scale");
131 }
132 break;
Anthony Barbiere8a49832018-01-18 10:04:05 +0000133 case InstrumentType::SCHEDULER_TIMER:
134 switch(instrument.second)
135 {
136 case ScaleFactor::NONE:
137 stream << "SCHEDULER_TIMER";
138 break;
139 case ScaleFactor::TIME_MS:
140 stream << "SCHEDULER_TIMER_MS";
141 break;
142 case ScaleFactor::TIME_S:
143 stream << "SCHEDULER_TIMER_S";
144 break;
145 default:
146 throw std::invalid_argument("Unsupported instrument scale");
147 }
148 break;
Moritz Pflanzer09e4f982017-08-30 12:47:06 +0100149 case InstrumentType::PMU:
Giorgio Arenace58a9f2017-10-31 17:59:17 +0000150 switch(instrument.second)
151 {
152 case ScaleFactor::NONE:
153 stream << "PMU";
154 break;
155 case ScaleFactor::SCALE_1K:
156 stream << "PMU_K";
157 break;
158 case ScaleFactor::SCALE_1M:
159 stream << "PMU_M";
160 break;
161 default:
162 throw std::invalid_argument("Unsupported instrument scale");
163 }
Moritz Pflanzer09e4f982017-08-30 12:47:06 +0100164 break;
Moritz Pflanzera4f711b2017-07-05 11:02:23 +0100165 case InstrumentType::PMU_CYCLE_COUNTER:
166 stream << "PMU_CYCLE_COUNTER";
167 break;
168 case InstrumentType::PMU_INSTRUCTION_COUNTER:
169 stream << "PMU_INSTRUCTION_COUNTER";
170 break;
Moritz Pflanzer45634b42017-08-30 12:48:18 +0100171 case InstrumentType::MALI:
Giorgio Arenace58a9f2017-10-31 17:59:17 +0000172 switch(instrument.second)
173 {
174 case ScaleFactor::NONE:
175 stream << "MALI";
176 break;
177 case ScaleFactor::SCALE_1K:
178 stream << "MALI_K";
179 break;
180 case ScaleFactor::SCALE_1M:
181 stream << "MALI_M";
182 break;
183 default:
184 throw std::invalid_argument("Unsupported instrument scale");
185 }
Moritz Pflanzer45634b42017-08-30 12:48:18 +0100186 break;
Anthony Barbier72f4ae52018-11-07 17:33:54 +0000187 case InstrumentType::OPENCL_TIMESTAMPS:
188 switch(instrument.second)
189 {
190 case ScaleFactor::NONE:
191 stream << "OPENCL_TIMESTAMPS";
192 break;
193 case ScaleFactor::TIME_US:
194 stream << "OPENCL_TIMESTAMPS_US";
195 break;
196 case ScaleFactor::TIME_MS:
197 stream << "OPENCL_TIMESTAMPS_MS";
198 break;
199 case ScaleFactor::TIME_S:
200 stream << "OPENCL_TIMESTAMPS_S";
201 break;
202 default:
203 throw std::invalid_argument("Unsupported instrument scale");
204 }
205 break;
Anthony Barbier6e433492017-11-09 15:52:00 +0000206 case InstrumentType::OPENCL_TIMER:
Giorgio Arenace58a9f2017-10-31 17:59:17 +0000207 switch(instrument.second)
208 {
209 case ScaleFactor::NONE:
210 stream << "OPENCL_TIMER";
211 break;
212 case ScaleFactor::TIME_US:
213 stream << "OPENCL_TIMER_US";
214 break;
215 case ScaleFactor::TIME_MS:
216 stream << "OPENCL_TIMER_MS";
217 break;
218 case ScaleFactor::TIME_S:
219 stream << "OPENCL_TIMER_S";
220 break;
221 default:
222 throw std::invalid_argument("Unsupported instrument scale");
223 }
Anthony Barbier6e433492017-11-09 15:52:00 +0000224 break;
Anthony Barbier35aa6a32018-04-23 16:12:12 +0100225 case InstrumentType::OPENCL_MEMORY_USAGE:
226 switch(instrument.second)
227 {
228 case ScaleFactor::NONE:
229 stream << "OPENCL_MEMORY_USAGE";
230 break;
231 case ScaleFactor::SCALE_1K:
232 stream << "OPENCL_MEMORY_USAGE_K";
233 break;
234 case ScaleFactor::SCALE_1M:
235 stream << "OPENCL_MEMORY_USAGE_M";
236 break;
237 default:
238 throw std::invalid_argument("Unsupported instrument scale");
239 }
240 break;
Moritz Pflanzera4f711b2017-07-05 11:02:23 +0100241 case InstrumentType::ALL:
242 stream << "ALL";
243 break;
244 case InstrumentType::NONE:
245 stream << "NONE";
246 break;
247 default:
248 throw std::invalid_argument("Unsupported instrument type");
249 }
250
251 return stream;
252}
253} // namespace framework
254} // namespace test
255} // namespace arm_compute
256#endif /* ARM_COMPUTE_TEST_INSTRUMENTS */