Moritz Pflanzer | a4f711b | 2017-07-05 11:02:23 +0100 | [diff] [blame] | 1 | /* |
Michele Di Giorgio | d9eaf61 | 2020-07-08 11:12:57 +0100 | [diff] [blame] | 2 | * Copyright (c) 2017-2019 Arm Limited. |
Moritz Pflanzer | a4f711b | 2017-07-05 11:02:23 +0100 | [diff] [blame] | 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 | |
Georgios Pinitas | 421405b | 2018-10-26 19:05:32 +0100 | [diff] [blame] | 27 | #if !defined(BARE_METAL) |
Moritz Pflanzer | 45634b4 | 2017-08-30 12:48:18 +0100 | [diff] [blame] | 28 | #include "MaliCounter.h" |
Anthony Barbier | 35aa6a3 | 2018-04-23 16:12:12 +0100 | [diff] [blame] | 29 | #include "OpenCLMemoryUsage.h" |
Anthony Barbier | 6e43349 | 2017-11-09 15:52:00 +0000 | [diff] [blame] | 30 | #include "OpenCLTimer.h" |
Moritz Pflanzer | a4f711b | 2017-07-05 11:02:23 +0100 | [diff] [blame] | 31 | #include "PMUCounter.h" |
Georgios Pinitas | 421405b | 2018-10-26 19:05:32 +0100 | [diff] [blame] | 32 | #endif /* !defined(BARE_METAL) */ |
Anthony Barbier | e8a4983 | 2018-01-18 10:04:05 +0000 | [diff] [blame] | 33 | #include "SchedulerTimer.h" |
Moritz Pflanzer | a4f711b | 2017-07-05 11:02:23 +0100 | [diff] [blame] | 34 | #include "WallClockTimer.h" |
| 35 | |
Georgios Pinitas | 12833d0 | 2019-07-25 13:31:10 +0100 | [diff] [blame] | 36 | #include <memory> |
Moritz Pflanzer | a4f711b | 2017-07-05 11:02:23 +0100 | [diff] [blame] | 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, |
Moritz Pflanzer | 09e4f98 | 2017-08-30 12:47:06 +0100 | [diff] [blame] | 50 | WALL_CLOCK_TIMER = 0x0100, |
| 51 | PMU = 0x0200, |
| 52 | PMU_CYCLE_COUNTER = 0x0201, |
| 53 | PMU_INSTRUCTION_COUNTER = 0x0202, |
Moritz Pflanzer | 45634b4 | 2017-08-30 12:48:18 +0100 | [diff] [blame] | 54 | MALI = 0x0300, |
Anthony Barbier | 6e43349 | 2017-11-09 15:52:00 +0000 | [diff] [blame] | 55 | OPENCL_TIMER = 0x0400, |
Anthony Barbier | e8a4983 | 2018-01-18 10:04:05 +0000 | [diff] [blame] | 56 | SCHEDULER_TIMER = 0x0500, |
Anthony Barbier | 35aa6a3 | 2018-04-23 16:12:12 +0100 | [diff] [blame] | 57 | OPENCL_MEMORY_USAGE = 0x0600, |
Anthony Barbier | 72f4ae5 | 2018-11-07 17:33:54 +0000 | [diff] [blame] | 58 | WALL_CLOCK_TIMESTAMPS = 0x0700, |
| 59 | OPENCL_TIMESTAMPS = 0x0800, |
| 60 | SCHEDULER_TIMESTAMPS = 0x0900, |
Moritz Pflanzer | a4f711b | 2017-07-05 11:02:23 +0100 | [diff] [blame] | 61 | }; |
| 62 | |
Georgios Pinitas | 12833d0 | 2019-07-25 13:31:10 +0100 | [diff] [blame] | 63 | struct InstrumentsInfo |
| 64 | { |
| 65 | std::vector<ISchedulerUser *> _scheduler_users{}; |
| 66 | }; |
| 67 | extern std::unique_ptr<InstrumentsInfo> instruments_info; |
| 68 | |
Giorgio Arena | ce58a9f | 2017-10-31 17:59:17 +0000 | [diff] [blame] | 69 | using InstrumentsDescription = std::pair<InstrumentType, ScaleFactor>; |
Moritz Pflanzer | a4f711b | 2017-07-05 11:02:23 +0100 | [diff] [blame] | 70 | |
Giorgio Arena | ce58a9f | 2017-10-31 17:59:17 +0000 | [diff] [blame] | 71 | InstrumentsDescription instrument_type_from_name(const std::string &name); |
| 72 | |
| 73 | inline ::std::stringstream &operator>>(::std::stringstream &stream, InstrumentsDescription &instrument) |
Moritz Pflanzer | a4f711b | 2017-07-05 11:02:23 +0100 | [diff] [blame] | 74 | { |
| 75 | std::string value; |
| 76 | stream >> value; |
| 77 | instrument = instrument_type_from_name(value); |
| 78 | return stream; |
| 79 | } |
| 80 | |
Giorgio Arena | ce58a9f | 2017-10-31 17:59:17 +0000 | [diff] [blame] | 81 | inline ::std::stringstream &operator<<(::std::stringstream &stream, InstrumentsDescription instrument) |
Moritz Pflanzer | a4f711b | 2017-07-05 11:02:23 +0100 | [diff] [blame] | 82 | { |
Giorgio Arena | ce58a9f | 2017-10-31 17:59:17 +0000 | [diff] [blame] | 83 | switch(instrument.first) |
Moritz Pflanzer | a4f711b | 2017-07-05 11:02:23 +0100 | [diff] [blame] | 84 | { |
Anthony Barbier | 72f4ae5 | 2018-11-07 17:33:54 +0000 | [diff] [blame] | 85 | 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 Pflanzer | a4f711b | 2017-07-05 11:02:23 +0100 | [diff] [blame] | 101 | case InstrumentType::WALL_CLOCK_TIMER: |
Giorgio Arena | ce58a9f | 2017-10-31 17:59:17 +0000 | [diff] [blame] | 102 | 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 Pflanzer | a4f711b | 2017-07-05 11:02:23 +0100 | [diff] [blame] | 116 | break; |
Anthony Barbier | 72f4ae5 | 2018-11-07 17:33:54 +0000 | [diff] [blame] | 117 | 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 Barbier | e8a4983 | 2018-01-18 10:04:05 +0000 | [diff] [blame] | 133 | 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 Pflanzer | 09e4f98 | 2017-08-30 12:47:06 +0100 | [diff] [blame] | 149 | case InstrumentType::PMU: |
Giorgio Arena | ce58a9f | 2017-10-31 17:59:17 +0000 | [diff] [blame] | 150 | 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 Pflanzer | 09e4f98 | 2017-08-30 12:47:06 +0100 | [diff] [blame] | 164 | break; |
Moritz Pflanzer | a4f711b | 2017-07-05 11:02:23 +0100 | [diff] [blame] | 165 | 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 Pflanzer | 45634b4 | 2017-08-30 12:48:18 +0100 | [diff] [blame] | 171 | case InstrumentType::MALI: |
Giorgio Arena | ce58a9f | 2017-10-31 17:59:17 +0000 | [diff] [blame] | 172 | 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 Pflanzer | 45634b4 | 2017-08-30 12:48:18 +0100 | [diff] [blame] | 186 | break; |
Anthony Barbier | 72f4ae5 | 2018-11-07 17:33:54 +0000 | [diff] [blame] | 187 | 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 Barbier | 6e43349 | 2017-11-09 15:52:00 +0000 | [diff] [blame] | 206 | case InstrumentType::OPENCL_TIMER: |
Giorgio Arena | ce58a9f | 2017-10-31 17:59:17 +0000 | [diff] [blame] | 207 | 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 Barbier | 6e43349 | 2017-11-09 15:52:00 +0000 | [diff] [blame] | 224 | break; |
Anthony Barbier | 35aa6a3 | 2018-04-23 16:12:12 +0100 | [diff] [blame] | 225 | 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 Pflanzer | a4f711b | 2017-07-05 11:02:23 +0100 | [diff] [blame] | 241 | 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 */ |