OpenASIP 2.2
Loading...
Searching...
No Matches
UtilizationStats.cc
Go to the documentation of this file.
1/*
2 Copyright (c) 2002-2009 Tampere University.
3
4 This file is part of TTA-Based Codesign Environment (TCE).
5
6 Permission is hereby granted, free of charge, to any person obtaining a
7 copy of this software and associated documentation files (the "Software"),
8 to deal in the Software without restriction, including without limitation
9 the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 and/or sell copies of the Software, and to permit persons to whom the
11 Software is furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all 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
19 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 DEALINGS IN THE SOFTWARE.
23 */
24/**
25 * @file UtilizationStats.hh
26 *
27 * Implementation of UtilizationStats class.
28 *
29 * @author Pekka Jääskeläinen 2005 (pjaaskel-no.spam-cs.tut.fi)
30 * @note rating: red
31 */
32#include "UtilizationStats.hh"
33#include "MapTools.hh"
34#include "Instruction.hh"
35#include "Move.hh"
37#include "Terminal.hh"
38#include "FunctionUnit.hh"
39#include "Bus.hh"
40#include "Socket.hh"
41#include "Operation.hh"
42#include "StringTools.hh"
43#include "BaseFUPort.hh"
44#include "FUPort.hh"
45#include "Guard.hh"
46#include "MoveGuard.hh"
47#include "hash_set.hh"
48#include "Application.hh"
49#include "TCEString.hh"
50
51/**
52 * Constructor.
53 */
54UtilizationStats::UtilizationStats() : highestRegister_(-1) {
55}
56
57/**
58 * Destructor.
59 */
62
63/**
64 * Accumulates the utilization counts for each machine part used by the
65 * instruction.
66 *
67 * @note This function assumes that moves in Instruction and
68 * ExecutableInstruction are in same order.
69 *
70 * @param instructionData The instruction.
71 * @param executionCounts Execution counts of the instruction.
72 */
73void
75 const TTAProgram::Instruction& instructionData,
76 const ExecutableInstruction& executionCounts) {
77
78 // used to make sure output socket utilizations are computed only
79 // maximum once per instruction, even though the socket is read by
80 // multiple buses
81 hash_set<const char*> alreadyRegisteredOutputSockets;
82
83 for (int i = 0; i < instructionData.moveCount(); ++i) {
84 const TTAProgram::Move& move = instructionData.move(i);
85 const ClockCycleCount execCount =
86 executionCounts.moveExecutionCount(i);
87
88 // it depends on GCU implementation whether immediate jumps are
89 // redirected through bus and sockets or not, let's assume they
90 // are, as they are in current CU implementations, according to Teemu
91 buses_[move.bus().name()] += execCount;
92
93 // socket utilizations
94 if (!move.source().isImmediate() &&
95 move.sourceSocket().name() != move.destinationSocket().name() &&
96 alreadyRegisteredOutputSockets.find(
97 move.sourceSocket().name().c_str()) ==
98 alreadyRegisteredOutputSockets.end()) {
99
100 sockets_[move.sourceSocket().name()] += execCount;
101 alreadyRegisteredOutputSockets.insert(
102 move.sourceSocket().name().c_str());
103 }
104 sockets_[move.destinationSocket().name()] += execCount;
105
106 // operation utilizations
107 if (move.destination().isFUPort() &&
108 dynamic_cast<const TTAMachine::BaseFUPort&>(
109 move.destination().port()).isTriggering()) {
110 const std::string operationUpper =
112 move.destination().operation().name());
113 const std::string fuName =
114 move.destination().functionUnit().name();
115 fus_[fuName] += execCount;
116 operations_[operationUpper] += execCount;
117 fuOperations_[fuName][operationUpper] += execCount;
118 }
119
120 // register reads
121 if (move.source().isGPR()) {
122 const std::string rfName = move.source().registerFile().name();
123 const int regIndex = move.source().index();
124 if (regIndex > highestRegister_) {
125 highestRegister_ = regIndex;
126 }
127 rfAccesses_[rfName][regIndex].first =
128 registerReads(rfName, regIndex) + execCount;
129 }
130
131 // guarded moves
132 if (!move.isUnconditional()) {
133 // RF reads
134 if (dynamic_cast<const TTAMachine::RegisterGuard*>(
135 &move.guard().guard())) {
136 const TTAMachine::RegisterGuard& moveGuard =
137 dynamic_cast<const TTAMachine::RegisterGuard&>(
138 move.guard().guard());
139
140 const std::string rfName = moveGuard.registerFile()->name();
141 const int regIndex = moveGuard.registerIndex();
142 if (regIndex > highestRegister_)
143 highestRegister_ = regIndex;
144
145 guardRfAccesses_[rfName][regIndex].first =
146 guardRegisterReads(rfName, regIndex) + execCount;
147 } else { // FU Port reads
148 if (dynamic_cast<const TTAMachine::PortGuard*>(
149 &move.guard().guard())) {
150 const TTAMachine::PortGuard& moveGuard =
151 dynamic_cast<const TTAMachine::PortGuard&>(
152 move.guard().guard());
153
154 const TTAMachine::FUPort& port = *moveGuard.port();
155 const std::string fuName = port.parentUnit()->name();
156 guardFUAccesses_[fuName][port.name()] += execCount;
157 }
158 }
159 }
160
161 // immediate register reads
162 if (move.source().isImmediateRegister()) {
163 const std::string iuName = move.source().immediateUnit().name();
164 const int regIndex = move.source().index();
165 rfAccesses_[iuName][regIndex].first =
166 registerReads(iuName, regIndex) + execCount;
167 if (regIndex > highestRegister_)
168 highestRegister_ = regIndex;
169 }
170
171 // register writes
172 if (move.destination().isGPR()) {
173 const std::string rfName =
174 move.destination().registerFile().name();
175 const int regIndex = move.destination().index();
176 if (regIndex > highestRegister_) {
177 highestRegister_ = regIndex;
178 }
179 rfAccesses_[rfName][regIndex].second =
180 registerWrites(rfName, regIndex) + execCount;
181 }
182 }
183}
184
185/**
186 * Returns the count of writes to the given bus.
187 *
188 * @param busName The name of the bus.
189 * @return The count of writes.
190 */
192UtilizationStats::busWrites(const std::string& busName) const {
193 if (MapTools::containsKey(buses_, busName))
195 else
196 return 0;
197}
198
199/**
200 * Returns the count of writes to the given socket.
201 *
202 * @param socketName The name of the socket.
203 * @return The count of writes.
204 */
206UtilizationStats::socketWrites(const std::string& socketName) const {
207 if (MapTools::containsKey(sockets_, socketName))
209 else
210 return 0;
211}
212
213/**
214 * Returns the count of operation triggers in given FU.
215 *
216 * @param fuName The name of the FU.
217 * @return The count of triggers.
218 */
220UtilizationStats::triggerCount(const std::string& fuName) const {
221 if (MapTools::containsKey(fus_, fuName))
223 else
224 return 0;
225}
226
227/**
228 * Returns the total count of operation executions.
229 *
230 * @param operationName The name of the operation.
231 * @return The count of executions.
232 */
235 const std::string& operationName) const {
236 if (MapTools::containsKey(operations_, operationName))
238 operations_, operationName);
239 else
240 return 0;
241}
242
243/**
244 * Returns the total count of given operation executions in given FU.
245 *
246 * @param fuName The name of the function unit.
247 * @param operationName The name of the operation.
248 * @return The count of executions.
249 */
252 const std::string& fuName, const std::string& operationName) const {
253 try {
256 fuOperations_, fuName), operationName);
257 } catch (const KeyNotFound&) {
258 return 0;
259 }
260}
261
262/**
263 * Returns the count of times the given register was read during simulation.
264 *
265 * @param rfName The name of the register file.
266 * @param registerIndex The index of the register.
267 * @return The count of reads.
268 */
271 const std::string& rfName,
272 int registerIndex) const {
273 try {
274 return
276 std::pair<ClockCycleCount, ClockCycleCount> >(
278 rfAccesses_, rfName), registerIndex).first;
279 } catch (const KeyNotFound&) {
280 return 0;
281 }
282}
283
284/**
285 * Returns the count of times the guarded register was read during simulation.
286 *
287 * @param rfName The name of the register file.
288 * @param registerIndex The index of the register.
289 * @return The count of guarded reads.
290 */
293 const std::string& rfName,
294 int registerIndex) const {
295 try {
296 return
298 std::pair<ClockCycleCount, ClockCycleCount> >(
300 guardRfAccesses_, rfName), registerIndex).first;
301 } catch (const KeyNotFound&) {
302 return 0;
303 }
304}
305
306/**
307 * Returns the count of times the given register was written during simulation.
308 *
309 * @param rfName The name of the register file.
310 * @param registerIndex The index of the register.
311 * @return The count of writes.
312 */
315 const std::string& rfName,
316 int registerIndex) const {
317 try {
318 return
320 std::pair<ClockCycleCount, ClockCycleCount> >(
322 rfAccesses_, rfName), registerIndex).second;
323 } catch (const KeyNotFound&) {
324 return 0;
325 }
326}
327
328/**
329 * Returns number of reads for a single FU port guard
330 *
331 * @param fuName Name of the FU
332 * @param fuPort Name of the FU port
333 * @return Number of reads for a single FU port guard
334 */
337 const std::string& fuName,
338 const std::string& fuPort) const {
339
340 try {
343 guardFUAccesses_, fuName), fuPort);
344 } catch (const KeyNotFound&) {
345 return 0;
346 }
347}
348
349/**
350 * Returns a map containing the FU port guard accesses
351 *
352 * @return A map containing the FU port guard accesses
353 */
358
359/**
360 * Returns the highest used register index.
361 *
362 * This is useful when fetching register access data for sequential simulation.
363 *
364 * @return The index of the highest index register.
365 */
366int
CycleCount ClockCycleCount
Alias for ClockCycleCount.
ClockCycleCount moveExecutionCount(std::size_t moveIndex) const
static ValueType valueForKey(const MapType &aMap, const KeyType &aKey)
static KeyType keyForValue(const MapType &aMap, const ValueType &aValue)
static bool containsKey(const MapType &aMap, const KeyType &aKey)
virtual TCEString name() const
Definition Operation.cc:93
static std::string stringToUpper(const std::string &source)
FunctionUnit * parentUnit() const
Definition BaseFUPort.cc:96
virtual bool isTriggering() const =0
virtual TCEString name() const
FUPort * port() const
virtual std::string name() const
Definition Port.cc:141
const RegisterFile * registerFile() const
Move & move(int i) const
const TTAMachine::Guard & guard() const
Definition MoveGuard.cc:86
TTAMachine::Socket & destinationSocket() const
Definition Move.cc:388
MoveGuard & guard() const
Definition Move.cc:345
TTAMachine::Socket & sourceSocket() const
Definition Move.cc:393
bool isUnconditional() const
Definition Move.cc:154
Terminal & source() const
Definition Move.cc:302
Terminal & destination() const
Definition Move.cc:323
const TTAMachine::Bus & bus() const
Definition Move.cc:373
virtual const TTAMachine::FunctionUnit & functionUnit() const
Definition Terminal.cc:251
virtual int index() const
Definition Terminal.cc:274
virtual Operation & operation() const
Definition Terminal.cc:319
virtual bool isGPR() const
Definition Terminal.cc:107
virtual bool isImmediateRegister() const
Definition Terminal.cc:97
virtual const TTAMachine::Port & port() const
Definition Terminal.cc:378
virtual bool isImmediate() const
Definition Terminal.cc:63
virtual const TTAMachine::ImmediateUnit & immediateUnit() const
Definition Terminal.cc:240
virtual const TTAMachine::RegisterFile & registerFile() const
Definition Terminal.cc:225
virtual bool isFUPort() const
Definition Terminal.cc:118
ComponentUtilizationIndex operations_
Operation utilizations (started operations).
std::map< std::string, ComponentUtilizationIndex > FUOperationUtilizationIndex
Index for connecting function unit and operations implemented in them to utilization counts.
int highestRegister_
The highest register index used. This is an uglish way to fetch register access info for sequential s...
int highestUsedRegisterIndex() const
FUOperationUtilizationIndex FUGuardAccesses() const
virtual ~UtilizationStats()
ClockCycleCount busWrites(const std::string &busName) const
ClockCycleCount operationExecutions(const std::string &operationName) const
FUOperationUtilizationIndex fuOperations_
Index for operation utilizations for each function unit.
ClockCycleCount triggerCount(const std::string &fuName) const
ComponentUtilizationIndex fus_
Function unit utilizations, i.e., total operation triggerings.
ClockCycleCount guardRegisterReads(const std::string &rfName, int registerIndex) const
ClockCycleCount registerReads(const std::string &rfName, int registerIndex) const
virtual void calculateForInstruction(const TTAProgram::Instruction &instructionData, const ExecutableInstruction &executionCounts)
RFRegisterUtilizationIndex guardRfAccesses_
Guard register accesses for each register in a RF.
ComponentUtilizationIndex sockets_
Socket write counts.
ClockCycleCount registerWrites(const std::string &rfName, int registerIndex) const
ComponentUtilizationIndex buses_
Bus write counts.
ClockCycleCount socketWrites(const std::string &socketName) const
RFRegisterUtilizationIndex rfAccesses_
Register read and write data for each register in each register file.
FUOperationUtilizationIndex guardFUAccesses_
Guard FU port accesses.