OpenASIP  2.0
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"
36 #include "ExecutableInstruction.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  */
54 UtilizationStats::UtilizationStats() : highestRegister_(-1) {
55 }
56 
57 /**
58  * Destructor.
59  */
61 }
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  */
73 void
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  */
192 UtilizationStats::busWrites(const std::string& busName) const {
193  if (MapTools::containsKey(buses_, busName))
194  return MapTools::valueForKey<ClockCycleCount>(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  */
206 UtilizationStats::socketWrites(const std::string& socketName) const {
207  if (MapTools::containsKey(sockets_, socketName))
208  return MapTools::valueForKey<ClockCycleCount>(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  */
220 UtilizationStats::triggerCount(const std::string& fuName) const {
221  if (MapTools::containsKey(fus_, fuName))
222  return MapTools::valueForKey<ClockCycleCount>(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))
237  return MapTools::valueForKey<ClockCycleCount>(
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 {
254  return MapTools::valueForKey<ClockCycleCount>(
255  MapTools::valueForKey<ComponentUtilizationIndex>(
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> >(
277  MapTools::valueForKey<RegisterUtilizationIndex>(
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> >(
299  MapTools::valueForKey<RegisterUtilizationIndex>(
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> >(
321  MapTools::valueForKey<RegisterUtilizationIndex>(
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 {
341  return MapTools::valueForKey<ClockCycleCount>(
342  MapTools::valueForKey<ComponentUtilizationIndex>(
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  */
356  return guardFUAccesses_;
357 }
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  */
366 int
368  return highestRegister_;
369 }
TTAProgram::Terminal::isFUPort
virtual bool isFUPort() const
Definition: Terminal.cc:118
TTAProgram::Move::destinationSocket
TTAMachine::Socket & destinationSocket() const
Definition: Move.cc:388
ExecutableInstruction
Definition: ExecutableInstruction.hh:49
TTAMachine::Component::name
virtual TCEString name() const
Definition: MachinePart.cc:125
UtilizationStats::triggerCount
ClockCycleCount triggerCount(const std::string &fuName) const
Definition: UtilizationStats.cc:220
TTAProgram::Instruction::move
Move & move(int i) const
Definition: Instruction.cc:193
TTAMachine::PortGuard::port
FUPort * port() const
TTAProgram::Terminal::index
virtual int index() const
Definition: Terminal.cc:274
UtilizationStats::guardRegisterReads
ClockCycleCount guardRegisterReads(const std::string &rfName, int registerIndex) const
Definition: UtilizationStats.cc:292
TTAMachine::RegisterGuard::registerIndex
int registerIndex() const
TTAMachine::BaseFUPort::parentUnit
FunctionUnit * parentUnit() const
Definition: BaseFUPort.cc:96
TTAProgram::Terminal::registerFile
virtual const TTAMachine::RegisterFile & registerFile() const
Definition: Terminal.cc:225
TTAProgram::Instruction
Definition: Instruction.hh:57
TTAProgram::Move::isUnconditional
bool isUnconditional() const
Definition: Move.cc:154
MapTools.hh
UtilizationStats::socketWrites
ClockCycleCount socketWrites(const std::string &socketName) const
Definition: UtilizationStats.cc:206
TTAMachine::BaseFUPort
Definition: BaseFUPort.hh:44
TTAProgram::Move::destination
Terminal & destination() const
Definition: Move.cc:323
UtilizationStats::calculateForInstruction
virtual void calculateForInstruction(const TTAProgram::Instruction &instructionData, const ExecutableInstruction &executionCounts)
Definition: UtilizationStats.cc:74
TTAProgram::Move::bus
const TTAMachine::Bus & bus() const
Definition: Move.cc:373
UtilizationStats::fus_
ComponentUtilizationIndex fus_
Function unit utilizations, i.e., total operation triggerings.
Definition: UtilizationStats.hh:105
UtilizationStats::FUGuardAccesses
FUOperationUtilizationIndex FUGuardAccesses() const
Definition: UtilizationStats.cc:355
Terminal.hh
Operation::name
virtual TCEString name() const
Definition: Operation.cc:93
Socket.hh
UtilizationStats::guardRfAccesses_
RFRegisterUtilizationIndex guardRfAccesses_
Guard register accesses for each register in a RF.
Definition: UtilizationStats.hh:114
BaseFUPort.hh
hash_set.hh
TTAProgram::Terminal::operation
virtual Operation & operation() const
Definition: Terminal.cc:319
TCEString.hh
StringTools::stringToUpper
static std::string stringToUpper(const std::string &source)
Definition: StringTools.cc:143
StringTools.hh
TTAProgram::Move::sourceSocket
TTAMachine::Socket & sourceSocket() const
Definition: Move.cc:393
TTAProgram::Terminal::isImmediateRegister
virtual bool isImmediateRegister() const
Definition: Terminal.cc:97
TTAMachine::FUPort
Definition: FUPort.hh:46
UtilizationStats::FUOperationUtilizationIndex
std::map< std::string, ComponentUtilizationIndex > FUOperationUtilizationIndex
Index for connecting function unit and operations implemented in them to utilization counts.
Definition: UtilizationStats.hh:62
Instruction.hh
TTAMachine::RegisterGuard
Definition: Guard.hh:137
UtilizationStats::fuOperations_
FUOperationUtilizationIndex fuOperations_
Index for operation utilizations for each function unit.
Definition: UtilizationStats.hh:109
Application.hh
TTAProgram::Move::guard
MoveGuard & guard() const
Definition: Move.cc:345
UtilizationStats::busWrites
ClockCycleCount busWrites(const std::string &busName) const
Definition: UtilizationStats.cc:192
UtilizationStats::operationExecutions
ClockCycleCount operationExecutions(const std::string &operationName) const
Definition: UtilizationStats.cc:234
TTAProgram::Terminal::isGPR
virtual bool isGPR() const
Definition: Terminal.cc:107
Guard.hh
Operation.hh
TTAProgram::Terminal::immediateUnit
virtual const TTAMachine::ImmediateUnit & immediateUnit() const
Definition: Terminal.cc:240
TTAProgram::Move
Definition: Move.hh:55
Bus.hh
TTAMachine::BaseFUPort::isTriggering
virtual bool isTriggering() const =0
TTAProgram::Terminal::functionUnit
virtual const TTAMachine::FunctionUnit & functionUnit() const
Definition: Terminal.cc:251
UtilizationStats::~UtilizationStats
virtual ~UtilizationStats()
Definition: UtilizationStats.cc:60
UtilizationStats::UtilizationStats
UtilizationStats()
Definition: UtilizationStats.cc:54
UtilizationStats.hh
MapTools::containsKey
static bool containsKey(const MapType &aMap, const KeyType &aKey)
MapTools::valueForKey
static ValueType valueForKey(const MapType &aMap, const KeyType &aKey)
UtilizationStats::registerWrites
ClockCycleCount registerWrites(const std::string &rfName, int registerIndex) const
Definition: UtilizationStats.cc:314
TTAMachine::Port::name
virtual std::string name() const
Definition: Port.cc:141
UtilizationStats::sockets_
ComponentUtilizationIndex sockets_
Socket write counts.
Definition: UtilizationStats.hh:101
UtilizationStats::buses_
ComponentUtilizationIndex buses_
Bus write counts.
Definition: UtilizationStats.hh:103
FUPort.hh
UtilizationStats::operations_
ComponentUtilizationIndex operations_
Operation utilizations (started operations).
Definition: UtilizationStats.hh:107
ExecutableInstruction.hh
TTAProgram::Move::source
Terminal & source() const
Definition: Move.cc:302
ClockCycleCount
CycleCount ClockCycleCount
Alias for ClockCycleCount.
Definition: SimulatorConstants.hh:57
TTAProgram::Terminal::port
virtual const TTAMachine::Port & port() const
Definition: Terminal.cc:378
KeyNotFound
Definition: Exception.hh:285
TTAMachine::PortGuard
Definition: Guard.hh:99
UtilizationStats::registerReads
ClockCycleCount registerReads(const std::string &rfName, int registerIndex) const
Definition: UtilizationStats.cc:270
UtilizationStats::highestRegister_
int highestRegister_
The highest register index used. This is an uglish way to fetch register access info for sequential s...
Definition: UtilizationStats.hh:120
TTAProgram::MoveGuard::guard
const TTAMachine::Guard & guard() const
Definition: MoveGuard.cc:86
Move.hh
TTAProgram::Terminal::isImmediate
virtual bool isImmediate() const
Definition: Terminal.cc:63
TTAMachine::RegisterGuard::registerFile
const RegisterFile * registerFile() const
UtilizationStats::rfAccesses_
RFRegisterUtilizationIndex rfAccesses_
Register read and write data for each register in each register file.
Definition: UtilizationStats.hh:111
UtilizationStats::highestUsedRegisterIndex
int highestUsedRegisterIndex() const
Definition: UtilizationStats.cc:367
TTAProgram::Instruction::moveCount
int moveCount() const
Definition: Instruction.cc:176
FunctionUnit.hh
ExecutableInstruction::moveExecutionCount
ClockCycleCount moveExecutionCount(std::size_t moveIndex) const
Definition: ExecutableInstruction.cc:110
MoveGuard.hh
UtilizationStats::guardFUAccesses_
FUOperationUtilizationIndex guardFUAccesses_
Guard FU port accesses.
Definition: UtilizationStats.hh:116