blob: 651f0f567e613635907a6c32a1feb423c2c5c8dd [file] [log] [blame]
Moritz Pflanzera4f711b2017-07-05 11:02:23 +01001/*
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 Pflanzer45634b42017-08-30 12:48:18 +010027#include "MaliCounter.h"
Anthony Barbier6e433492017-11-09 15:52:00 +000028#include "OpenCLTimer.h"
Moritz Pflanzera4f711b2017-07-05 11:02:23 +010029#include "PMUCounter.h"
30#include "WallClockTimer.h"
31
32#include <sstream>
33#include <string>
34
35namespace arm_compute
36{
37namespace test
38{
39namespace framework
40{
41enum class InstrumentType : unsigned int
42{
43 ALL = ~0U,
44 NONE = 0,
Moritz Pflanzer09e4f982017-08-30 12:47:06 +010045 WALL_CLOCK_TIMER = 0x0100,
46 PMU = 0x0200,
47 PMU_CYCLE_COUNTER = 0x0201,
48 PMU_INSTRUCTION_COUNTER = 0x0202,
Moritz Pflanzer45634b42017-08-30 12:48:18 +010049 MALI = 0x0300,
Anthony Barbier6e433492017-11-09 15:52:00 +000050 OPENCL_TIMER = 0x0400,
Moritz Pflanzera4f711b2017-07-05 11:02:23 +010051};
52
Giorgio Arenace58a9f2017-10-31 17:59:17 +000053using InstrumentsDescription = std::pair<InstrumentType, ScaleFactor>;
Moritz Pflanzera4f711b2017-07-05 11:02:23 +010054
Giorgio Arenace58a9f2017-10-31 17:59:17 +000055InstrumentsDescription instrument_type_from_name(const std::string &name);
56
57inline ::std::stringstream &operator>>(::std::stringstream &stream, InstrumentsDescription &instrument)
Moritz Pflanzera4f711b2017-07-05 11:02:23 +010058{
59 std::string value;
60 stream >> value;
61 instrument = instrument_type_from_name(value);
62 return stream;
63}
64
Giorgio Arenace58a9f2017-10-31 17:59:17 +000065inline ::std::stringstream &operator<<(::std::stringstream &stream, InstrumentsDescription instrument)
Moritz Pflanzera4f711b2017-07-05 11:02:23 +010066{
Giorgio Arenace58a9f2017-10-31 17:59:17 +000067 switch(instrument.first)
Moritz Pflanzera4f711b2017-07-05 11:02:23 +010068 {
69 case InstrumentType::WALL_CLOCK_TIMER:
Giorgio Arenace58a9f2017-10-31 17:59:17 +000070 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 Pflanzera4f711b2017-07-05 11:02:23 +010084 break;
Moritz Pflanzer09e4f982017-08-30 12:47:06 +010085 case InstrumentType::PMU:
Giorgio Arenace58a9f2017-10-31 17:59:17 +000086 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 Pflanzer09e4f982017-08-30 12:47:06 +0100100 break;
Moritz Pflanzera4f711b2017-07-05 11:02:23 +0100101 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 Pflanzer45634b42017-08-30 12:48:18 +0100107 case InstrumentType::MALI:
Giorgio Arenace58a9f2017-10-31 17:59:17 +0000108 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 Pflanzer45634b42017-08-30 12:48:18 +0100122 break;
Anthony Barbier6e433492017-11-09 15:52:00 +0000123 case InstrumentType::OPENCL_TIMER:
Giorgio Arenace58a9f2017-10-31 17:59:17 +0000124 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 Barbier6e433492017-11-09 15:52:00 +0000141 break;
Moritz Pflanzera4f711b2017-07-05 11:02:23 +0100142 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 */