Moritz Pflanzer | a4f711b | 2017-07-05 11:02:23 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2017 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 | |
Moritz Pflanzer | 45634b4 | 2017-08-30 12:48:18 +0100 | [diff] [blame] | 27 | #include "MaliCounter.h" |
Anthony Barbier | 6e43349 | 2017-11-09 15:52:00 +0000 | [diff] [blame] | 28 | #include "OpenCLTimer.h" |
Moritz Pflanzer | a4f711b | 2017-07-05 11:02:23 +0100 | [diff] [blame] | 29 | #include "PMUCounter.h" |
| 30 | #include "WallClockTimer.h" |
| 31 | |
| 32 | #include <sstream> |
| 33 | #include <string> |
| 34 | |
| 35 | namespace arm_compute |
| 36 | { |
| 37 | namespace test |
| 38 | { |
| 39 | namespace framework |
| 40 | { |
| 41 | enum class InstrumentType : unsigned int |
| 42 | { |
| 43 | ALL = ~0U, |
| 44 | NONE = 0, |
Moritz Pflanzer | 09e4f98 | 2017-08-30 12:47:06 +0100 | [diff] [blame] | 45 | WALL_CLOCK_TIMER = 0x0100, |
| 46 | PMU = 0x0200, |
| 47 | PMU_CYCLE_COUNTER = 0x0201, |
| 48 | PMU_INSTRUCTION_COUNTER = 0x0202, |
Moritz Pflanzer | 45634b4 | 2017-08-30 12:48:18 +0100 | [diff] [blame] | 49 | MALI = 0x0300, |
Anthony Barbier | 6e43349 | 2017-11-09 15:52:00 +0000 | [diff] [blame] | 50 | OPENCL_TIMER = 0x0400, |
Moritz Pflanzer | a4f711b | 2017-07-05 11:02:23 +0100 | [diff] [blame] | 51 | }; |
| 52 | |
Giorgio Arena | ce58a9f | 2017-10-31 17:59:17 +0000 | [diff] [blame^] | 53 | using InstrumentsDescription = std::pair<InstrumentType, ScaleFactor>; |
Moritz Pflanzer | a4f711b | 2017-07-05 11:02:23 +0100 | [diff] [blame] | 54 | |
Giorgio Arena | ce58a9f | 2017-10-31 17:59:17 +0000 | [diff] [blame^] | 55 | InstrumentsDescription instrument_type_from_name(const std::string &name); |
| 56 | |
| 57 | inline ::std::stringstream &operator>>(::std::stringstream &stream, InstrumentsDescription &instrument) |
Moritz Pflanzer | a4f711b | 2017-07-05 11:02:23 +0100 | [diff] [blame] | 58 | { |
| 59 | std::string value; |
| 60 | stream >> value; |
| 61 | instrument = instrument_type_from_name(value); |
| 62 | return stream; |
| 63 | } |
| 64 | |
Giorgio Arena | ce58a9f | 2017-10-31 17:59:17 +0000 | [diff] [blame^] | 65 | inline ::std::stringstream &operator<<(::std::stringstream &stream, InstrumentsDescription instrument) |
Moritz Pflanzer | a4f711b | 2017-07-05 11:02:23 +0100 | [diff] [blame] | 66 | { |
Giorgio Arena | ce58a9f | 2017-10-31 17:59:17 +0000 | [diff] [blame^] | 67 | switch(instrument.first) |
Moritz Pflanzer | a4f711b | 2017-07-05 11:02:23 +0100 | [diff] [blame] | 68 | { |
| 69 | case InstrumentType::WALL_CLOCK_TIMER: |
Giorgio Arena | ce58a9f | 2017-10-31 17:59:17 +0000 | [diff] [blame^] | 70 | switch(instrument.second) |
| 71 | { |
| 72 | case ScaleFactor::NONE: |
| 73 | stream << "WALL_CLOCK_TIMER"; |
| 74 | break; |
| 75 | case ScaleFactor::TIME_MS: |
| 76 | stream << "WALL_CLOCK_TIMER_MS"; |
| 77 | break; |
| 78 | case ScaleFactor::TIME_S: |
| 79 | stream << "WALL_CLOCK_TIMER_S"; |
| 80 | break; |
| 81 | default: |
| 82 | throw std::invalid_argument("Unsupported instrument scale"); |
| 83 | } |
Moritz Pflanzer | a4f711b | 2017-07-05 11:02:23 +0100 | [diff] [blame] | 84 | break; |
Moritz Pflanzer | 09e4f98 | 2017-08-30 12:47:06 +0100 | [diff] [blame] | 85 | case InstrumentType::PMU: |
Giorgio Arena | ce58a9f | 2017-10-31 17:59:17 +0000 | [diff] [blame^] | 86 | switch(instrument.second) |
| 87 | { |
| 88 | case ScaleFactor::NONE: |
| 89 | stream << "PMU"; |
| 90 | break; |
| 91 | case ScaleFactor::SCALE_1K: |
| 92 | stream << "PMU_K"; |
| 93 | break; |
| 94 | case ScaleFactor::SCALE_1M: |
| 95 | stream << "PMU_M"; |
| 96 | break; |
| 97 | default: |
| 98 | throw std::invalid_argument("Unsupported instrument scale"); |
| 99 | } |
Moritz Pflanzer | 09e4f98 | 2017-08-30 12:47:06 +0100 | [diff] [blame] | 100 | break; |
Moritz Pflanzer | a4f711b | 2017-07-05 11:02:23 +0100 | [diff] [blame] | 101 | case InstrumentType::PMU_CYCLE_COUNTER: |
| 102 | stream << "PMU_CYCLE_COUNTER"; |
| 103 | break; |
| 104 | case InstrumentType::PMU_INSTRUCTION_COUNTER: |
| 105 | stream << "PMU_INSTRUCTION_COUNTER"; |
| 106 | break; |
Moritz Pflanzer | 45634b4 | 2017-08-30 12:48:18 +0100 | [diff] [blame] | 107 | case InstrumentType::MALI: |
Giorgio Arena | ce58a9f | 2017-10-31 17:59:17 +0000 | [diff] [blame^] | 108 | switch(instrument.second) |
| 109 | { |
| 110 | case ScaleFactor::NONE: |
| 111 | stream << "MALI"; |
| 112 | break; |
| 113 | case ScaleFactor::SCALE_1K: |
| 114 | stream << "MALI_K"; |
| 115 | break; |
| 116 | case ScaleFactor::SCALE_1M: |
| 117 | stream << "MALI_M"; |
| 118 | break; |
| 119 | default: |
| 120 | throw std::invalid_argument("Unsupported instrument scale"); |
| 121 | } |
Moritz Pflanzer | 45634b4 | 2017-08-30 12:48:18 +0100 | [diff] [blame] | 122 | break; |
Anthony Barbier | 6e43349 | 2017-11-09 15:52:00 +0000 | [diff] [blame] | 123 | case InstrumentType::OPENCL_TIMER: |
Giorgio Arena | ce58a9f | 2017-10-31 17:59:17 +0000 | [diff] [blame^] | 124 | switch(instrument.second) |
| 125 | { |
| 126 | case ScaleFactor::NONE: |
| 127 | stream << "OPENCL_TIMER"; |
| 128 | break; |
| 129 | case ScaleFactor::TIME_US: |
| 130 | stream << "OPENCL_TIMER_US"; |
| 131 | break; |
| 132 | case ScaleFactor::TIME_MS: |
| 133 | stream << "OPENCL_TIMER_MS"; |
| 134 | break; |
| 135 | case ScaleFactor::TIME_S: |
| 136 | stream << "OPENCL_TIMER_S"; |
| 137 | break; |
| 138 | default: |
| 139 | throw std::invalid_argument("Unsupported instrument scale"); |
| 140 | } |
Anthony Barbier | 6e43349 | 2017-11-09 15:52:00 +0000 | [diff] [blame] | 141 | break; |
Moritz Pflanzer | a4f711b | 2017-07-05 11:02:23 +0100 | [diff] [blame] | 142 | case InstrumentType::ALL: |
| 143 | stream << "ALL"; |
| 144 | break; |
| 145 | case InstrumentType::NONE: |
| 146 | stream << "NONE"; |
| 147 | break; |
| 148 | default: |
| 149 | throw std::invalid_argument("Unsupported instrument type"); |
| 150 | } |
| 151 | |
| 152 | return stream; |
| 153 | } |
| 154 | } // namespace framework |
| 155 | } // namespace test |
| 156 | } // namespace arm_compute |
| 157 | #endif /* ARM_COMPUTE_TEST_INSTRUMENTS */ |