Moritz Pflanzer | a4f711b | 2017-07-05 11:02:23 +0100 | [diff] [blame] | 1 | /* |
Anthony Barbier | e8a4983 | 2018-01-18 10:04:05 +0000 | [diff] [blame] | 2 | * Copyright (c) 2017-2018 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 | |
| 36 | #include <sstream> |
| 37 | #include <string> |
| 38 | |
| 39 | namespace arm_compute |
| 40 | { |
| 41 | namespace test |
| 42 | { |
| 43 | namespace framework |
| 44 | { |
| 45 | enum class InstrumentType : unsigned int |
| 46 | { |
| 47 | ALL = ~0U, |
| 48 | NONE = 0, |
Moritz Pflanzer | 09e4f98 | 2017-08-30 12:47:06 +0100 | [diff] [blame] | 49 | WALL_CLOCK_TIMER = 0x0100, |
| 50 | PMU = 0x0200, |
| 51 | PMU_CYCLE_COUNTER = 0x0201, |
| 52 | PMU_INSTRUCTION_COUNTER = 0x0202, |
Moritz Pflanzer | 45634b4 | 2017-08-30 12:48:18 +0100 | [diff] [blame] | 53 | MALI = 0x0300, |
Anthony Barbier | 6e43349 | 2017-11-09 15:52:00 +0000 | [diff] [blame] | 54 | OPENCL_TIMER = 0x0400, |
Anthony Barbier | e8a4983 | 2018-01-18 10:04:05 +0000 | [diff] [blame] | 55 | SCHEDULER_TIMER = 0x0500, |
Anthony Barbier | 35aa6a3 | 2018-04-23 16:12:12 +0100 | [diff] [blame] | 56 | OPENCL_MEMORY_USAGE = 0x0600, |
Anthony Barbier | 72f4ae5 | 2018-11-07 17:33:54 +0000 | [diff] [blame] | 57 | WALL_CLOCK_TIMESTAMPS = 0x0700, |
| 58 | OPENCL_TIMESTAMPS = 0x0800, |
| 59 | SCHEDULER_TIMESTAMPS = 0x0900, |
Moritz Pflanzer | a4f711b | 2017-07-05 11:02:23 +0100 | [diff] [blame] | 60 | }; |
| 61 | |
Giorgio Arena | ce58a9f | 2017-10-31 17:59:17 +0000 | [diff] [blame] | 62 | using InstrumentsDescription = std::pair<InstrumentType, ScaleFactor>; |
Moritz Pflanzer | a4f711b | 2017-07-05 11:02:23 +0100 | [diff] [blame] | 63 | |
Giorgio Arena | ce58a9f | 2017-10-31 17:59:17 +0000 | [diff] [blame] | 64 | InstrumentsDescription instrument_type_from_name(const std::string &name); |
| 65 | |
| 66 | inline ::std::stringstream &operator>>(::std::stringstream &stream, InstrumentsDescription &instrument) |
Moritz Pflanzer | a4f711b | 2017-07-05 11:02:23 +0100 | [diff] [blame] | 67 | { |
| 68 | std::string value; |
| 69 | stream >> value; |
| 70 | instrument = instrument_type_from_name(value); |
| 71 | return stream; |
| 72 | } |
| 73 | |
Giorgio Arena | ce58a9f | 2017-10-31 17:59:17 +0000 | [diff] [blame] | 74 | inline ::std::stringstream &operator<<(::std::stringstream &stream, InstrumentsDescription instrument) |
Moritz Pflanzer | a4f711b | 2017-07-05 11:02:23 +0100 | [diff] [blame] | 75 | { |
Giorgio Arena | ce58a9f | 2017-10-31 17:59:17 +0000 | [diff] [blame] | 76 | switch(instrument.first) |
Moritz Pflanzer | a4f711b | 2017-07-05 11:02:23 +0100 | [diff] [blame] | 77 | { |
Anthony Barbier | 72f4ae5 | 2018-11-07 17:33:54 +0000 | [diff] [blame] | 78 | case InstrumentType::WALL_CLOCK_TIMESTAMPS: |
| 79 | switch(instrument.second) |
| 80 | { |
| 81 | case ScaleFactor::NONE: |
| 82 | stream << "WALL_CLOCK_TIMESTAMPS"; |
| 83 | break; |
| 84 | case ScaleFactor::TIME_MS: |
| 85 | stream << "WALL_CLOCK_TIMESTAMPS_MS"; |
| 86 | break; |
| 87 | case ScaleFactor::TIME_S: |
| 88 | stream << "WALL_CLOCK_TIMESTAMPS_S"; |
| 89 | break; |
| 90 | default: |
| 91 | throw std::invalid_argument("Unsupported instrument scale"); |
| 92 | } |
| 93 | break; |
Moritz Pflanzer | a4f711b | 2017-07-05 11:02:23 +0100 | [diff] [blame] | 94 | case InstrumentType::WALL_CLOCK_TIMER: |
Giorgio Arena | ce58a9f | 2017-10-31 17:59:17 +0000 | [diff] [blame] | 95 | switch(instrument.second) |
| 96 | { |
| 97 | case ScaleFactor::NONE: |
| 98 | stream << "WALL_CLOCK_TIMER"; |
| 99 | break; |
| 100 | case ScaleFactor::TIME_MS: |
| 101 | stream << "WALL_CLOCK_TIMER_MS"; |
| 102 | break; |
| 103 | case ScaleFactor::TIME_S: |
| 104 | stream << "WALL_CLOCK_TIMER_S"; |
| 105 | break; |
| 106 | default: |
| 107 | throw std::invalid_argument("Unsupported instrument scale"); |
| 108 | } |
Moritz Pflanzer | a4f711b | 2017-07-05 11:02:23 +0100 | [diff] [blame] | 109 | break; |
Anthony Barbier | 72f4ae5 | 2018-11-07 17:33:54 +0000 | [diff] [blame] | 110 | case InstrumentType::SCHEDULER_TIMESTAMPS: |
| 111 | switch(instrument.second) |
| 112 | { |
| 113 | case ScaleFactor::NONE: |
| 114 | stream << "SCHEDULER_TIMESTAMPS"; |
| 115 | break; |
| 116 | case ScaleFactor::TIME_MS: |
| 117 | stream << "SCHEDULER_TIMESTAMPS_MS"; |
| 118 | break; |
| 119 | case ScaleFactor::TIME_S: |
| 120 | stream << "SCHEDULER_TIMESTAMPS_S"; |
| 121 | break; |
| 122 | default: |
| 123 | throw std::invalid_argument("Unsupported instrument scale"); |
| 124 | } |
| 125 | break; |
Anthony Barbier | e8a4983 | 2018-01-18 10:04:05 +0000 | [diff] [blame] | 126 | case InstrumentType::SCHEDULER_TIMER: |
| 127 | switch(instrument.second) |
| 128 | { |
| 129 | case ScaleFactor::NONE: |
| 130 | stream << "SCHEDULER_TIMER"; |
| 131 | break; |
| 132 | case ScaleFactor::TIME_MS: |
| 133 | stream << "SCHEDULER_TIMER_MS"; |
| 134 | break; |
| 135 | case ScaleFactor::TIME_S: |
| 136 | stream << "SCHEDULER_TIMER_S"; |
| 137 | break; |
| 138 | default: |
| 139 | throw std::invalid_argument("Unsupported instrument scale"); |
| 140 | } |
| 141 | break; |
Moritz Pflanzer | 09e4f98 | 2017-08-30 12:47:06 +0100 | [diff] [blame] | 142 | case InstrumentType::PMU: |
Giorgio Arena | ce58a9f | 2017-10-31 17:59:17 +0000 | [diff] [blame] | 143 | switch(instrument.second) |
| 144 | { |
| 145 | case ScaleFactor::NONE: |
| 146 | stream << "PMU"; |
| 147 | break; |
| 148 | case ScaleFactor::SCALE_1K: |
| 149 | stream << "PMU_K"; |
| 150 | break; |
| 151 | case ScaleFactor::SCALE_1M: |
| 152 | stream << "PMU_M"; |
| 153 | break; |
| 154 | default: |
| 155 | throw std::invalid_argument("Unsupported instrument scale"); |
| 156 | } |
Moritz Pflanzer | 09e4f98 | 2017-08-30 12:47:06 +0100 | [diff] [blame] | 157 | break; |
Moritz Pflanzer | a4f711b | 2017-07-05 11:02:23 +0100 | [diff] [blame] | 158 | case InstrumentType::PMU_CYCLE_COUNTER: |
| 159 | stream << "PMU_CYCLE_COUNTER"; |
| 160 | break; |
| 161 | case InstrumentType::PMU_INSTRUCTION_COUNTER: |
| 162 | stream << "PMU_INSTRUCTION_COUNTER"; |
| 163 | break; |
Moritz Pflanzer | 45634b4 | 2017-08-30 12:48:18 +0100 | [diff] [blame] | 164 | case InstrumentType::MALI: |
Giorgio Arena | ce58a9f | 2017-10-31 17:59:17 +0000 | [diff] [blame] | 165 | switch(instrument.second) |
| 166 | { |
| 167 | case ScaleFactor::NONE: |
| 168 | stream << "MALI"; |
| 169 | break; |
| 170 | case ScaleFactor::SCALE_1K: |
| 171 | stream << "MALI_K"; |
| 172 | break; |
| 173 | case ScaleFactor::SCALE_1M: |
| 174 | stream << "MALI_M"; |
| 175 | break; |
| 176 | default: |
| 177 | throw std::invalid_argument("Unsupported instrument scale"); |
| 178 | } |
Moritz Pflanzer | 45634b4 | 2017-08-30 12:48:18 +0100 | [diff] [blame] | 179 | break; |
Anthony Barbier | 72f4ae5 | 2018-11-07 17:33:54 +0000 | [diff] [blame] | 180 | case InstrumentType::OPENCL_TIMESTAMPS: |
| 181 | switch(instrument.second) |
| 182 | { |
| 183 | case ScaleFactor::NONE: |
| 184 | stream << "OPENCL_TIMESTAMPS"; |
| 185 | break; |
| 186 | case ScaleFactor::TIME_US: |
| 187 | stream << "OPENCL_TIMESTAMPS_US"; |
| 188 | break; |
| 189 | case ScaleFactor::TIME_MS: |
| 190 | stream << "OPENCL_TIMESTAMPS_MS"; |
| 191 | break; |
| 192 | case ScaleFactor::TIME_S: |
| 193 | stream << "OPENCL_TIMESTAMPS_S"; |
| 194 | break; |
| 195 | default: |
| 196 | throw std::invalid_argument("Unsupported instrument scale"); |
| 197 | } |
| 198 | break; |
Anthony Barbier | 6e43349 | 2017-11-09 15:52:00 +0000 | [diff] [blame] | 199 | case InstrumentType::OPENCL_TIMER: |
Giorgio Arena | ce58a9f | 2017-10-31 17:59:17 +0000 | [diff] [blame] | 200 | switch(instrument.second) |
| 201 | { |
| 202 | case ScaleFactor::NONE: |
| 203 | stream << "OPENCL_TIMER"; |
| 204 | break; |
| 205 | case ScaleFactor::TIME_US: |
| 206 | stream << "OPENCL_TIMER_US"; |
| 207 | break; |
| 208 | case ScaleFactor::TIME_MS: |
| 209 | stream << "OPENCL_TIMER_MS"; |
| 210 | break; |
| 211 | case ScaleFactor::TIME_S: |
| 212 | stream << "OPENCL_TIMER_S"; |
| 213 | break; |
| 214 | default: |
| 215 | throw std::invalid_argument("Unsupported instrument scale"); |
| 216 | } |
Anthony Barbier | 6e43349 | 2017-11-09 15:52:00 +0000 | [diff] [blame] | 217 | break; |
Anthony Barbier | 35aa6a3 | 2018-04-23 16:12:12 +0100 | [diff] [blame] | 218 | case InstrumentType::OPENCL_MEMORY_USAGE: |
| 219 | switch(instrument.second) |
| 220 | { |
| 221 | case ScaleFactor::NONE: |
| 222 | stream << "OPENCL_MEMORY_USAGE"; |
| 223 | break; |
| 224 | case ScaleFactor::SCALE_1K: |
| 225 | stream << "OPENCL_MEMORY_USAGE_K"; |
| 226 | break; |
| 227 | case ScaleFactor::SCALE_1M: |
| 228 | stream << "OPENCL_MEMORY_USAGE_M"; |
| 229 | break; |
| 230 | default: |
| 231 | throw std::invalid_argument("Unsupported instrument scale"); |
| 232 | } |
| 233 | break; |
Moritz Pflanzer | a4f711b | 2017-07-05 11:02:23 +0100 | [diff] [blame] | 234 | case InstrumentType::ALL: |
| 235 | stream << "ALL"; |
| 236 | break; |
| 237 | case InstrumentType::NONE: |
| 238 | stream << "NONE"; |
| 239 | break; |
| 240 | default: |
| 241 | throw std::invalid_argument("Unsupported instrument type"); |
| 242 | } |
| 243 | |
| 244 | return stream; |
| 245 | } |
| 246 | } // namespace framework |
| 247 | } // namespace test |
| 248 | } // namespace arm_compute |
| 249 | #endif /* ARM_COMPUTE_TEST_INSTRUMENTS */ |