blob: 705fc59b292a49cc1a3f48b9ab2035a6357079cd [file] [log] [blame]
Moritz Pflanzera4f711b2017-07-05 11:02:23 +01001/*
Anthony Barbiere8a49832018-01-18 10:04:05 +00002 * Copyright (c) 2017-2018 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
Moritz Pflanzer45634b42017-08-30 12:48:18 +010027#include "MaliCounter.h"
Anthony Barbier35aa6a32018-04-23 16:12:12 +010028#include "OpenCLMemoryUsage.h"
Anthony Barbier6e433492017-11-09 15:52:00 +000029#include "OpenCLTimer.h"
Moritz Pflanzera4f711b2017-07-05 11:02:23 +010030#include "PMUCounter.h"
Anthony Barbiere8a49832018-01-18 10:04:05 +000031#include "SchedulerTimer.h"
Moritz Pflanzera4f711b2017-07-05 11:02:23 +010032#include "WallClockTimer.h"
33
34#include <sstream>
35#include <string>
36
37namespace arm_compute
38{
39namespace test
40{
41namespace framework
42{
43enum class InstrumentType : unsigned int
44{
45 ALL = ~0U,
46 NONE = 0,
Moritz Pflanzer09e4f982017-08-30 12:47:06 +010047 WALL_CLOCK_TIMER = 0x0100,
48 PMU = 0x0200,
49 PMU_CYCLE_COUNTER = 0x0201,
50 PMU_INSTRUCTION_COUNTER = 0x0202,
Moritz Pflanzer45634b42017-08-30 12:48:18 +010051 MALI = 0x0300,
Anthony Barbier6e433492017-11-09 15:52:00 +000052 OPENCL_TIMER = 0x0400,
Anthony Barbiere8a49832018-01-18 10:04:05 +000053 SCHEDULER_TIMER = 0x0500,
Anthony Barbier35aa6a32018-04-23 16:12:12 +010054 OPENCL_MEMORY_USAGE = 0x0600,
Moritz Pflanzera4f711b2017-07-05 11:02:23 +010055};
56
Giorgio Arenace58a9f2017-10-31 17:59:17 +000057using InstrumentsDescription = std::pair<InstrumentType, ScaleFactor>;
Moritz Pflanzera4f711b2017-07-05 11:02:23 +010058
Giorgio Arenace58a9f2017-10-31 17:59:17 +000059InstrumentsDescription instrument_type_from_name(const std::string &name);
60
61inline ::std::stringstream &operator>>(::std::stringstream &stream, InstrumentsDescription &instrument)
Moritz Pflanzera4f711b2017-07-05 11:02:23 +010062{
63 std::string value;
64 stream >> value;
65 instrument = instrument_type_from_name(value);
66 return stream;
67}
68
Giorgio Arenace58a9f2017-10-31 17:59:17 +000069inline ::std::stringstream &operator<<(::std::stringstream &stream, InstrumentsDescription instrument)
Moritz Pflanzera4f711b2017-07-05 11:02:23 +010070{
Giorgio Arenace58a9f2017-10-31 17:59:17 +000071 switch(instrument.first)
Moritz Pflanzera4f711b2017-07-05 11:02:23 +010072 {
73 case InstrumentType::WALL_CLOCK_TIMER:
Giorgio Arenace58a9f2017-10-31 17:59:17 +000074 switch(instrument.second)
75 {
76 case ScaleFactor::NONE:
77 stream << "WALL_CLOCK_TIMER";
78 break;
79 case ScaleFactor::TIME_MS:
80 stream << "WALL_CLOCK_TIMER_MS";
81 break;
82 case ScaleFactor::TIME_S:
83 stream << "WALL_CLOCK_TIMER_S";
84 break;
85 default:
86 throw std::invalid_argument("Unsupported instrument scale");
87 }
Moritz Pflanzera4f711b2017-07-05 11:02:23 +010088 break;
Anthony Barbiere8a49832018-01-18 10:04:05 +000089 case InstrumentType::SCHEDULER_TIMER:
90 switch(instrument.second)
91 {
92 case ScaleFactor::NONE:
93 stream << "SCHEDULER_TIMER";
94 break;
95 case ScaleFactor::TIME_MS:
96 stream << "SCHEDULER_TIMER_MS";
97 break;
98 case ScaleFactor::TIME_S:
99 stream << "SCHEDULER_TIMER_S";
100 break;
101 default:
102 throw std::invalid_argument("Unsupported instrument scale");
103 }
104 break;
Moritz Pflanzer09e4f982017-08-30 12:47:06 +0100105 case InstrumentType::PMU:
Giorgio Arenace58a9f2017-10-31 17:59:17 +0000106 switch(instrument.second)
107 {
108 case ScaleFactor::NONE:
109 stream << "PMU";
110 break;
111 case ScaleFactor::SCALE_1K:
112 stream << "PMU_K";
113 break;
114 case ScaleFactor::SCALE_1M:
115 stream << "PMU_M";
116 break;
117 default:
118 throw std::invalid_argument("Unsupported instrument scale");
119 }
Moritz Pflanzer09e4f982017-08-30 12:47:06 +0100120 break;
Moritz Pflanzera4f711b2017-07-05 11:02:23 +0100121 case InstrumentType::PMU_CYCLE_COUNTER:
122 stream << "PMU_CYCLE_COUNTER";
123 break;
124 case InstrumentType::PMU_INSTRUCTION_COUNTER:
125 stream << "PMU_INSTRUCTION_COUNTER";
126 break;
Moritz Pflanzer45634b42017-08-30 12:48:18 +0100127 case InstrumentType::MALI:
Giorgio Arenace58a9f2017-10-31 17:59:17 +0000128 switch(instrument.second)
129 {
130 case ScaleFactor::NONE:
131 stream << "MALI";
132 break;
133 case ScaleFactor::SCALE_1K:
134 stream << "MALI_K";
135 break;
136 case ScaleFactor::SCALE_1M:
137 stream << "MALI_M";
138 break;
139 default:
140 throw std::invalid_argument("Unsupported instrument scale");
141 }
Moritz Pflanzer45634b42017-08-30 12:48:18 +0100142 break;
Anthony Barbier6e433492017-11-09 15:52:00 +0000143 case InstrumentType::OPENCL_TIMER:
Giorgio Arenace58a9f2017-10-31 17:59:17 +0000144 switch(instrument.second)
145 {
146 case ScaleFactor::NONE:
147 stream << "OPENCL_TIMER";
148 break;
149 case ScaleFactor::TIME_US:
150 stream << "OPENCL_TIMER_US";
151 break;
152 case ScaleFactor::TIME_MS:
153 stream << "OPENCL_TIMER_MS";
154 break;
155 case ScaleFactor::TIME_S:
156 stream << "OPENCL_TIMER_S";
157 break;
158 default:
159 throw std::invalid_argument("Unsupported instrument scale");
160 }
Anthony Barbier6e433492017-11-09 15:52:00 +0000161 break;
Anthony Barbier35aa6a32018-04-23 16:12:12 +0100162 case InstrumentType::OPENCL_MEMORY_USAGE:
163 switch(instrument.second)
164 {
165 case ScaleFactor::NONE:
166 stream << "OPENCL_MEMORY_USAGE";
167 break;
168 case ScaleFactor::SCALE_1K:
169 stream << "OPENCL_MEMORY_USAGE_K";
170 break;
171 case ScaleFactor::SCALE_1M:
172 stream << "OPENCL_MEMORY_USAGE_M";
173 break;
174 default:
175 throw std::invalid_argument("Unsupported instrument scale");
176 }
177 break;
Moritz Pflanzera4f711b2017-07-05 11:02:23 +0100178 case InstrumentType::ALL:
179 stream << "ALL";
180 break;
181 case InstrumentType::NONE:
182 stream << "NONE";
183 break;
184 default:
185 throw std::invalid_argument("Unsupported instrument type");
186 }
187
188 return stream;
189}
190} // namespace framework
191} // namespace test
192} // namespace arm_compute
193#endif /* ARM_COMPUTE_TEST_INSTRUMENTS */