OpenASIP  2.0
MachineAnalysis.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 MachineAnalysis.cc
26  *
27  * Implementation of MachineAnalysis class.
28  *
29  * @author Heikki Kultala 2008 (heikki.kultala-no.spam-tut.fi)
30  * @note rating: red
31  */
32 
33 #include "MachineAnalysis.hh"
34 #include "Machine.hh"
35 
37 
38 #include <cmath>
39 
40 //#define DEBUG_MACHINE_ANALYSIS
41 
42 /**
43  * Constructor.
44  * @param machine to analyse.
45  */
47 
48  // do heurictics for FU's
49 
52 
53  // todo: better heuristics here, based on available operations etc.
54  fuILP_ = fuNav.count() * 0.55;
55 
56  // Connectivity heuristics
57 
58  int fuPortConnecteds = 0;
59  int fuPortUnconnecteds = 0;
60 
61  for (int i = 0; i < fuNav.count(); i++) {
62  TTAMachine::FunctionUnit& fu1 = *fuNav.item(i);
63  for (int j = 0; j < fu1.portCount(); j++ ) {
64  TTAMachine::Port& port1 = *fu1.port(j);
65  if (port1.inputSocket() != NULL) {
66  for (int k = 0; k < fuNav.count(); k++) {
67  TTAMachine::FunctionUnit& fu2 = *fuNav.item(k);
68  for (int l = 0; l < fu2.portCount(); l++ ) {
69  TTAMachine::Port& port2 = *fu2.port(l);
70  if (port2.outputSocket() != NULL) {
72  port2,port1)) {
73  fuPortConnecteds++;
74  } else {
75  fuPortUnconnecteds++;
76  }
77  }
78  }
79  }
80  }
81  }
82  }
83 
84  bypassability_ = fuPortConnecteds/
85  float(fuPortConnecteds+fuPortUnconnecteds);
86 
89  int rfCount = regNav.count();
90 
93 
94  int rfFuConnecteds = 0;
95  int rfFuUnconnecteds = 0;
96 
97  for (int i = 0; i < fuNav.count(); i++) {
98  TTAMachine::FunctionUnit& fu1 = *fuNav.item(i);
99  for (int j = 0; j < fu1.portCount(); j++ ) {
100  TTAMachine::Port& port = *fu1.port(j);
101  if (port.inputSocket() != NULL) {
102  for (int i = 0; i < rfCount; i++) {
103  TTAMachine::RegisterFile& rf = *regNav.item(i);
105  rfFuConnecteds++;
106  } else {
107  rfFuUnconnecteds++;
108  }
109  }
110  }
111 
112  if (port.outputSocket() != NULL) {
113  for (int i = 0; i < rfCount; i++) {
114  TTAMachine::RegisterFile& rf = *regNav.item(i);
116  rfFuConnecteds++;
117  } else {
118  rfFuUnconnecteds++;
119  }
120  }
121  }
122  }
123  }
124 
125  // do heuristics for RF's
126 
127  int rfWritePorts = 0;
128  int rfReadPorts = 0;
129  for (int i = 0; i < rfCount; i++) {
130  TTAMachine::RegisterFile& rf = *regNav.item(i);
131  for (int j = 0; j < rf.portCount(); j++) {
132  const TTAMachine::Port& port = *rf.port(j);
133  if (port.outputSocket() != NULL) {
134  rfReadPorts++;
135  }
136  if (port.inputSocket() != NULL) {
137  rfWritePorts++;
138  }
139  }
140  }
141 
142  // rfILP comes from all RF's with
143  float avgRfWrites = float(rfWritePorts)/pow(rfCount,0.5);
144  float avgRfReads = float(rfReadPorts)/pow(rfCount,0.5);
145  float bypassedRfReadILP = avgRfReads/(1.17-(0.56*bypassability_));
146  float bypassedRfWriteILP = avgRfWrites/(0.83-(0.415*bypassability_));
147  float rfReadILP = avgRfReads/1.17;
148  float rfWriteILP = avgRfWrites/0.83;
149 
150  // todo: fuzzier heuristic
151  rfILP_ = std::min(rfReadILP, rfWriteILP);
152  bypassedRfILP_ = std::min(bypassedRfReadILP, bypassedRfWriteILP);
153 
154  connectivity_ = rfFuConnecteds/
155  float(rfFuConnecteds+rfFuUnconnecteds);
156  float transfers = connectivity_* busNav.count();
157 
158  busILP_ = transfers / (2.5-(0.415*bypassability_));
159 
160  // take the final value by inverse of pythagoral of inverses
161  averageILP_ = pow((pow(busILP_,-2)+
162  pow(bypassedRfILP_,-2)+
163  pow(fuILP_,-2)), -0.5);
164 
165  // then calculate guardability.
166 
167  float guardedBuses = 0;
168  for (int i = 0; i < busNav.count(); i++) {
169  TTAMachine::Bus& bus = *busNav.item(i);
170  if (bus.guardCount() > 0) {
171  guardedBuses++;
172  }
173  }
174  guardability_ = busNav.count() / guardedBuses;
175 
176 #ifdef DEBUG_MACHINE_ANALYSIS
177  std::cout << "Machine analysis done.." << std::endl;
178  std::cout << "\tbypassability: " << bypassability_ << std::endl;
179  std::cout << "\tconnectivity: " << connectivity_ << std::endl;
180  std::cout << "\tguardability: " << guardability_ << std::endl;
181  std::cout << "\tRF ilp: " << rfILP_ << std::endl;
182  std::cout << "\t\tread ilp: " << rfReadILP << std::endl;
183  std::cout << "\t\twrite ilp: " << rfWriteILP << std::endl;
184  std::cout << "\tbypassd rf ilp: " << bypassedRfILP_ << std::endl;
185  std::cout << "\tbus ilp: " << busILP_ << std::endl;
186  std::cout << "\tfu ilp: " << fuILP_ << std::endl;
187  std::cout << "total ilp: " << averageILP_ << std::endl;
188 #endif
189 
190 }
TTAMachine::Port::inputSocket
virtual Socket * inputSocket() const
Definition: Port.cc:261
MachineConnectivityCheck.hh
machine
TTAMachine::Machine * machine
the architecture definition of the estimated processor
Definition: EstimatorCmdLineUI.cc:59
MachineAnalysis::fuILP_
float fuILP_
Definition: MachineAnalysis.hh:56
TTAMachine::Bus
Definition: Bus.hh:53
TTAMachine::FunctionUnit::port
virtual BaseFUPort * port(const std::string &name) const
Definition: FunctionUnit.cc:145
TTAMachine::Machine::Navigator::count
int count() const
MachineAnalysis::MachineAnalysis
MachineAnalysis(const TTAMachine::Machine &machine)
Definition: MachineAnalysis.cc:46
TTAMachine::FunctionUnit
Definition: FunctionUnit.hh:55
MachineAnalysis.hh
MachineAnalysis::bypassedRfILP_
float bypassedRfILP_
Definition: MachineAnalysis.hh:58
TTAMachine::Port
Definition: Port.hh:54
MachineAnalysis::rfILP_
float rfILP_
Definition: MachineAnalysis.hh:57
MachineConnectivityCheck::isConnected
static bool isConnected(const TTAMachine::Port &sourcePort, const TTAMachine::Port &destinationPort, const TTAMachine::Guard *guard=NULL)
Definition: MachineConnectivityCheck.cc:128
TTAMachine::Machine::functionUnitNavigator
virtual FunctionUnitNavigator functionUnitNavigator() const
Definition: Machine.cc:380
MachineAnalysis::averageILP_
float averageILP_
Definition: MachineAnalysis.hh:62
MachineAnalysis::connectivity_
float connectivity_
Definition: MachineAnalysis.hh:54
Machine.hh
TTAMachine::Bus::guardCount
int guardCount() const
Definition: Bus.cc:441
TTAMachine::Unit::portCount
virtual int portCount() const
Definition: Unit.cc:135
MachineAnalysis::guardability_
float guardability_
Definition: MachineAnalysis.hh:60
TTAMachine::BaseRegisterFile::port
virtual RFPort * port(const std::string &name) const
Definition: BaseRegisterFile.cc:129
TTAMachine::Machine::registerFileNavigator
virtual RegisterFileNavigator registerFileNavigator() const
Definition: Machine.cc:450
TTAMachine::Machine::busNavigator
virtual BusNavigator busNavigator() const
Definition: Machine.cc:356
TTAMachine::Port::outputSocket
virtual Socket * outputSocket() const
Definition: Port.cc:281
MachineAnalysis::busILP_
float busILP_
Definition: MachineAnalysis.hh:55
TTAMachine::Machine::Navigator::item
ComponentType * item(int index) const
TTAMachine::RegisterFile
Definition: RegisterFile.hh:47
MachineAnalysis::bypassability_
float bypassability_
Definition: MachineAnalysis.hh:59
TTAMachine::Machine::Navigator
Definition: Machine.hh:186
TTAMachine::Machine
Definition: Machine.hh:73