Compute Library
 23.11
Instruments.h
Go to the documentation of this file.
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_INSTRUMENTS
25 #define ARM_COMPUTE_TEST_INSTRUMENTS
26 
27 #if !defined(_WIN64) && !defined(BARE_METAL) && !defined(__APPLE__) && !defined(__OpenBSD__)
28 #include "MaliCounter.h"
29 #include "OpenCLMemoryUsage.h"
30 #include "OpenCLTimer.h"
31 #include "PMUCounter.h"
32 #endif /* !defined(_WIN64) && !defined(BARE_METAL) && !defined(__APPLE__) && !defined(__OpenBSD__) */
33 #include "SchedulerTimer.h"
34 #include "WallClockTimer.h"
35 
36 #include <memory>
37 #include <sstream>
38 #include <string>
39 
40 namespace arm_compute
41 {
42 namespace test
43 {
44 namespace framework
45 {
46 enum class InstrumentType : unsigned int
47 {
48  ALL = ~0U,
49  NONE = 0,
50  WALL_CLOCK_TIMER = 0x0100,
51  PMU = 0x0200,
52  PMU_CYCLE_COUNTER = 0x0201,
53  PMU_INSTRUCTION_COUNTER = 0x0202,
54  MALI = 0x0300,
55  OPENCL_TIMER = 0x0400,
56  SCHEDULER_TIMER = 0x0500,
57  OPENCL_MEMORY_USAGE = 0x0600,
58  WALL_CLOCK_TIMESTAMPS = 0x0700,
59  OPENCL_TIMESTAMPS = 0x0800,
60  SCHEDULER_TIMESTAMPS = 0x0900,
61 };
62 
64 {
65  std::vector<ISchedulerUser *> _scheduler_users{};
66 };
67 extern std::unique_ptr<InstrumentsInfo> instruments_info;
68 
69 using InstrumentsDescription = std::pair<InstrumentType, ScaleFactor>;
70 
72 
73 inline ::std::stringstream &operator>>(::std::stringstream &stream, InstrumentsDescription &instrument)
74 {
75  std::string value;
76  stream >> value;
77  instrument = instrument_type_from_name(value);
78  return stream;
79 }
80 
81 inline ::std::stringstream &operator<<(::std::stringstream &stream, InstrumentsDescription instrument)
82 {
83  switch(instrument.first)
84  {
86  switch(instrument.second)
87  {
88  case ScaleFactor::NONE:
89  stream << "WALL_CLOCK_TIMESTAMPS";
90  break;
92  stream << "WALL_CLOCK_TIMESTAMPS_MS";
93  break;
95  stream << "WALL_CLOCK_TIMESTAMPS_S";
96  break;
97  default:
98  throw std::invalid_argument("Unsupported instrument scale");
99  }
100  break;
102  switch(instrument.second)
103  {
104  case ScaleFactor::NONE:
105  stream << "WALL_CLOCK_TIMER";
106  break;
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  }
116  break;
118  switch(instrument.second)
119  {
120  case ScaleFactor::NONE:
121  stream << "SCHEDULER_TIMESTAMPS";
122  break;
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;
134  switch(instrument.second)
135  {
136  case ScaleFactor::NONE:
137  stream << "SCHEDULER_TIMER";
138  break;
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;
149  case InstrumentType::PMU:
150  switch(instrument.second)
151  {
152  case ScaleFactor::NONE:
153  stream << "PMU";
154  break;
156  stream << "PMU_K";
157  break;
159  stream << "PMU_M";
160  break;
161  default:
162  throw std::invalid_argument("Unsupported instrument scale");
163  }
164  break;
166  stream << "PMU_CYCLE_COUNTER";
167  break;
169  stream << "PMU_INSTRUCTION_COUNTER";
170  break;
172  switch(instrument.second)
173  {
174  case ScaleFactor::NONE:
175  stream << "MALI";
176  break;
178  stream << "MALI_K";
179  break;
181  stream << "MALI_M";
182  break;
183  default:
184  throw std::invalid_argument("Unsupported instrument scale");
185  }
186  break;
188  switch(instrument.second)
189  {
190  case ScaleFactor::NONE:
191  stream << "OPENCL_TIMESTAMPS";
192  break;
194  stream << "OPENCL_TIMESTAMPS_US";
195  break;
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;
207  switch(instrument.second)
208  {
209  case ScaleFactor::NONE:
210  stream << "OPENCL_TIMER";
211  break;
213  stream << "OPENCL_TIMER_US";
214  break;
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  }
224  break;
226  switch(instrument.second)
227  {
228  case ScaleFactor::NONE:
229  stream << "OPENCL_MEMORY_USAGE";
230  break;
232  stream << "OPENCL_MEMORY_USAGE_K";
233  break;
235  stream << "OPENCL_MEMORY_USAGE_M";
236  break;
237  default:
238  throw std::invalid_argument("Unsupported instrument scale");
239  }
240  break;
241  case InstrumentType::ALL:
242  stream << "ALL";
243  break;
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 */
arm_compute::test::framework::InstrumentType::MALI
@ MALI
arm_compute::test::framework::InstrumentType::ALL
@ ALL
OpenCLTimer.h
arm_compute::test::framework::InstrumentType::SCHEDULER_TIMER
@ SCHEDULER_TIMER
arm_compute::test::framework::InstrumentType::SCHEDULER_TIMESTAMPS
@ SCHEDULER_TIMESTAMPS
arm_compute::test::framework::InstrumentType::OPENCL_TIMER
@ OPENCL_TIMER
arm_compute::test::framework::InstrumentType::OPENCL_MEMORY_USAGE
@ OPENCL_MEMORY_USAGE
arm_compute::test::framework::operator>>
inline ::std::istream & operator>>(::std::istream &stream, DatasetMode &mode)
Definition: DatasetModes.h:69
arm_compute::test::framework::ScaleFactor::TIME_US
@ TIME_US
WallClockTimer.h
arm_compute::test::framework::InstrumentsInfo::_scheduler_users
std::vector< ISchedulerUser * > _scheduler_users
Definition: Instruments.h:65
arm_compute::test::framework::InstrumentType::PMU_CYCLE_COUNTER
@ PMU_CYCLE_COUNTER
SchedulerTimer.h
arm_compute::utils::cast::U
U
Definition: SaturateCast.h:65
arm_compute::test::framework::InstrumentType::PMU_INSTRUCTION_COUNTER
@ PMU_INSTRUCTION_COUNTER
arm_compute::test::framework::InstrumentType::OPENCL_TIMESTAMPS
@ OPENCL_TIMESTAMPS
arm_compute::test::framework::instrument_type_from_name
InstrumentsDescription instrument_type_from_name(const std::string &name)
Definition: Instruments.cpp:37
arm_compute::test::framework::ScaleFactor::NONE
@ NONE
name
const char * name
Definition: NEBatchNormalizationLayerKernel.cpp:66
arm_compute::test::framework::ScaleFactor::TIME_S
@ TIME_S
arm_compute::test::framework::ScaleFactor::SCALE_1K
@ SCALE_1K
arm_compute::test::framework::ScaleFactor::TIME_MS
@ TIME_MS
arm_compute::test::framework::InstrumentsInfo
Definition: Instruments.h:63
arm_compute::test::framework::InstrumentType::WALL_CLOCK_TIMER
@ WALL_CLOCK_TIMER
MaliCounter.h
arm_compute::test::framework::InstrumentType::WALL_CLOCK_TIMESTAMPS
@ WALL_CLOCK_TIMESTAMPS
arm_compute
Copyright (c) 2017-2023 Arm Limited.
Definition: introduction.dox:24
arm_compute::test::framework::operator<<
inline ::std::ostream & operator<<(::std::ostream &stream, DatasetMode mode)
Definition: DatasetModes.h:77
arm_compute::test::framework::InstrumentType::NONE
@ NONE
PMUCounter.h
arm_compute::test::framework::InstrumentType::PMU
@ PMU
arm_compute::test::framework::PMU
Class provides access to CPU hardware counters.
Definition: PMU.h:43
OpenCLMemoryUsage.h
arm_compute::test::framework::ScaleFactor::SCALE_1M
@ SCALE_1M
arm_compute::test::framework::instruments_info
std::unique_ptr< InstrumentsInfo > instruments_info
Definition: Framework.cpp:50
arm_compute::test::framework::InstrumentsDescription
std::pair< InstrumentType, ScaleFactor > InstrumentsDescription
Definition: Instruments.h:69
arm_compute::test::framework::InstrumentType
InstrumentType
Definition: Instruments.h:46