OpenASIP  2.0
DSDBManager.hh
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 DSDBManager.hh
26  *
27  * Declaration of DSDBManager class.
28  *
29  * @author Veli-Pekka Jääskeläinen 2006 (vjaaskel-no.spam-cs.tut.fi)
30  * @note rating: red
31  */
32 
33 #ifndef TTA_DSDB_MANAGER_HH
34 #define TTA_DSDB_MANAGER_HH
35 
36 #include <string>
37 #include <set>
38 #include <vector>
39 #include <boost/tuple/tuple.hpp>
40 #include <boost/tuple/tuple_comparison.hpp>
41 #include "DBTypes.hh"
42 #include "Exception.hh"
43 #include "SimulatorConstants.hh"
44 #include "CostEstimatorTypes.hh"
45 
46 
47 class SQLite;
49 
50 namespace TTAMachine {
51  class Machine;
52 }
53 
54 namespace IDF {
56 }
57 
58 #define ILLEGAL_ROW_ID (-1)
59 
60 /**
61  * Design space database manager.
62  *
63  * Design space database stores information about explored machine
64  * configurations for test applications.
65  *
66  * The following information can be stored:
67  * - Machine architectures.
68  * - Implementations for architectures which define a working machine
69  * configuration.
70  * - Longest path delay estimates for implementations.
71  * - Area estimates for implementations.
72  * - Test applications for exploration.
73  * - Runtimes as clock cycle counts for application-architecture pairs.
74  * - Energy estimates for application-implementation pairs.
75  */
76 class DSDBManager {
77 public:
83  RowID arch, bool hasImpl, RowID impl) :
84  architectureID(arch),
85  hasImplementation(hasImpl),
86  implementationID(impl) {}
87 
92  };
93 
94  struct ApplicationData {
95  std::string id;
96  std::string name;
97  };
98 
99  /// Struct for configuration costs with a specified application
102  std::string application;
106  double area;
107  };
108 
109  struct idComparator {
111  if (c1.configurationID != c2.configurationID)
112  return (c1.configurationID < c2.configurationID);
113  // if the id's match then applications must differ
114  return (c1.application < c2.application);
115  }
116  };
117 
120  if (c1.cycleCount == c2.cycleCount) {
121  if (c1.configurationID != c2.configurationID) {
122  return (c1.configurationID < c2.configurationID);
123  } else {
124  return (c1.application < c2.application);
125  }
126  }
127  return (c1.cycleCount < c2.cycleCount);
128  }
129  };
130 
133  if (c1.energyEstimate == c2.energyEstimate) {
134  if (c1.configurationID != c2.configurationID) {
135  return (c1.configurationID < c2.configurationID);
136  } else {
137  return (c1.application < c2.application);
138  }
139  }
140  return (c1.energyEstimate < c2.energyEstimate);
141  }
142  };
143 
144  struct appComparator {
146  if (c1.application == c2.application)
147  return (c1.configurationID < c2.configurationID);
148  return (c1.application < c2.application);
149  }
150  };
151 
152  typedef boost::tuple<RowID, int, ClockCycleCount>
154 
155  typedef std::set<ParetoPointConnectivityAndCycles>
157 
158  /// Identifiers for ordering results.
159  enum Order {
164  };
165 
166  DSDBManager(const std::string& file);
167 
168  virtual ~DSDBManager();
169 
170  static DSDBManager* createNew(const std::string& file);
171 
172  std::string dsdbFile() const;
173 
176  const IDF::MachineImplementation& impl, double longestPathDelay,
178 
179  RowID addConfiguration(const MachineConfiguration& conf);
180 
181  RowID addApplication(const std::string& path);
182 
183  void addEnergyEstimate(
184  RowID application, RowID implementation, double energyEstimate);
185 
186  void addCycleCount(
187  RowID application, RowID architecture, ClockCycleCount count);
188 
190 
192 
193  bool hasApplication(RowID id) const;
194  bool hasApplication(const std::string& applicationPath) const;
195  void removeApplication(RowID id);
196 
197  std::string applicationPath(RowID id) const;
198 
199  bool hasArchitecture(RowID id) const;
201 
202  RowID architectureId(const TTAMachine::Machine& mach) const;
203 
204  bool hasImplementation(RowID id) const;
206 
207  bool hasConfiguration(RowID id) const;
208  MachineConfiguration configuration(RowID id) const;
209  RowID configurationId(const MachineConfiguration& conf) const;
210 
211  void removeConfiguration(RowID id);
212 
213  bool hasEnergyEstimate(RowID application, RowID implementation) const;
214  double energyEstimate(RowID application, RowID implementation) const;
215 
216  bool hasCycleCount(RowID application, RowID architecture) const;
217  ClockCycleCount cycleCount(RowID application, RowID architecture) const;
218  std::vector<ClockCycleCount>
219  cycleCounts(const MachineConfiguration& conf) const;
220  bool
222  RowID application, RowID architecture) const;
223  void setUnschedulable(RowID application, RowID architecture);
224 
227 
228  std::set<RowID> applicationIDs() const;
229  std::set<RowID> architectureIDs() const;
230  std::set<RowID> configurationIDs() const;
231  std::set<RowID> archConfigurationIDs(RowID architectureID) const;
232 
233  void writeArchitectureToFile(RowID id, const std::string& path) const;
234  void writeImplementationToFile(RowID id, const std::string& path) const;
236  const MachineConfiguration& conf, const std::string& path);
237 
238  std::vector<ConfigurationCosts> applicationCostEstimatesByConf(
239  Order ordering = ORDER_BY_CONFIGURATION) const;
240 
243 
244  int applicationCount() const;
245 private:
246  std::string architectureString(RowID id) const;
247  std::string implementationString(RowID id) const;
248 
249  /// Handle to the database.
251  /// Handle to the database connection.
253  /// The DSDB file containing the current database.
254  std::string file_;
255 };
256 
257 #endif
ILLEGAL_ROW_ID
#define ILLEGAL_ROW_ID
Definition: DSDBManager.hh:58
DSDBManager::ApplicationData::name
std::string name
Definition: DSDBManager.hh:96
DSDBManager::file_
std::string file_
The DSDB file containing the current database.
Definition: DSDBManager.hh:254
RelationalDBConnection
Definition: RelationalDBConnection.hh:48
DSDBManager::addCycleCount
void addCycleCount(RowID application, RowID architecture, ClockCycleCount count)
Definition: DSDBManager.cc:583
DSDBManager::applicationCount
int applicationCount() const
Definition: DSDBManager.cc:1666
DSDBManager::ORDER_BY_APPLICATION
@ ORDER_BY_APPLICATION
Definition: DSDBManager.hh:163
DSDBManager::appComparator
Definition: DSDBManager.hh:144
DSDBManager::addEnergyEstimate
void addEnergyEstimate(RowID application, RowID implementation, double energyEstimate)
Definition: DSDBManager.cc:477
DSDBManager::appComparator::operator()
bool operator()(ConfigurationCosts c1, ConfigurationCosts c2) const
Definition: DSDBManager.hh:145
Exception.hh
DSDBManager::writeConfigurationToFile
void writeConfigurationToFile(const MachineConfiguration &conf, const std::string &path)
Definition: DSDBManager.cc:929
DSDBManager::architecture
TTAMachine::Machine * architecture(RowID id) const
Definition: DSDBManager.cc:807
DSDBManager::MachineConfiguration::hasImplementation
bool hasImplementation
Definition: DSDBManager.hh:80
DSDBManager::ORDER_BY_ENERGY_ESTIMATE
@ ORDER_BY_ENERGY_ESTIMATE
Definition: DSDBManager.hh:162
DSDBManager::architectureIDs
std::set< RowID > architectureIDs() const
Definition: DSDBManager.cc:1416
DSDBManager::setLongestPathDelayEstimate
void setLongestPathDelayEstimate(RowID implementation, double delay)
Definition: DSDBManager.cc:617
RowID
int RowID
Type definition of row ID in relational databases.
Definition: DBTypes.hh:37
DSDBManager::MachineConfiguration::MachineConfiguration
MachineConfiguration(RowID arch, bool hasImpl, RowID impl)
Definition: DSDBManager.hh:82
DSDBManager::writeArchitectureToFile
void writeArchitectureToFile(RowID id, const std::string &path) const
Definition: DSDBManager.cc:826
CostEstimator::AreaInGates
double AreaInGates
type for area values in equivalent gates
Definition: CostEstimatorTypes.hh:35
DSDBManager::ConfigurationCosts::energyEstimate
double energyEstimate
Definition: DSDBManager.hh:103
DSDBManager::idComparator
Definition: DSDBManager.hh:109
DSDBManager::db_
SQLite * db_
Handle to the database.
Definition: DSDBManager.hh:250
DSDBManager::ApplicationData::id
std::string id
Definition: DSDBManager.hh:95
DSDBManager::MachineConfiguration::MachineConfiguration
MachineConfiguration()
Definition: DSDBManager.hh:88
SimulatorConstants.hh
DSDBManager::implementationString
std::string implementationString(RowID id) const
Definition: DSDBManager.cc:847
DBTypes.hh
DSDBManager::ORDER_BY_CYCLE_COUNT
@ ORDER_BY_CYCLE_COUNT
Definition: DSDBManager.hh:161
DSDBManager::MachineConfiguration::implementationID
RowID implementationID
Definition: DSDBManager.hh:81
CostEstimatorTypes.hh
DSDBManager::addApplication
RowID addApplication(const std::string &path)
Definition: DSDBManager.cc:440
DSDBManager::hasConfiguration
bool hasConfiguration(RowID id) const
Definition: DSDBManager.cc:1129
DSDBManager::hasApplication
bool hasApplication(RowID id) const
Definition: DSDBManager.cc:1013
DSDBManager::ParetoPointConnectivityAndCycles
boost::tuple< RowID, int, ClockCycleCount > ParetoPointConnectivityAndCycles
Definition: DSDBManager.hh:153
DSDBManager::MachineConfiguration
Definition: DSDBManager.hh:78
DSDBManager::ConfigurationCosts::cycleCount
ClockCycleCount cycleCount
Definition: DSDBManager.hh:104
DSDBManager::setAreaEstimate
void setAreaEstimate(RowID implementation, CostEstimator::AreaInGates area)
Definition: DSDBManager.cc:641
DSDBManager::isUnschedulable
bool isUnschedulable(RowID application, RowID architecture) const
Definition: DSDBManager.cc:550
DSDBManager::cycleCount
ClockCycleCount cycleCount(RowID application, RowID architecture) const
Definition: DSDBManager.cc:1261
DSDBManager::dbConnection_
RelationalDBConnection * dbConnection_
Handle to the database connection.
Definition: DSDBManager.hh:252
DSDBManager::ConfigurationCosts::longestPathDelay
double longestPathDelay
Definition: DSDBManager.hh:105
DSDBManager::Order
Order
Identifiers for ordering results.
Definition: DSDBManager.hh:159
DSDBManager::ParetoSetConnectivityAndCycles
std::set< ParetoPointConnectivityAndCycles > ParetoSetConnectivityAndCycles
Definition: DSDBManager.hh:156
DSDBManager::ApplicationData
Definition: DSDBManager.hh:94
DSDBManager::energyEstimate
double energyEstimate(RowID application, RowID implementation) const
Definition: DSDBManager.cc:1187
DSDBManager
Definition: DSDBManager.hh:76
DSDBManager::~DSDBManager
virtual ~DSDBManager()
Definition: DSDBManager.cc:128
DSDBManager::hasEnergyEstimate
bool hasEnergyEstimate(RowID application, RowID implementation) const
Definition: DSDBManager.cc:983
DSDBManager::DSDBManager
DSDBManager(const std::string &file)
Definition: DSDBManager.cc:108
DSDBManager::architectureString
std::string architectureString(RowID id) const
Definition: DSDBManager.cc:665
DSDBManager::paretoSetConnectivityAndCycles
ParetoSetConnectivityAndCycles paretoSetConnectivityAndCycles(RowID application=ILLEGAL_ROW_ID) const
Definition: DSDBManager.cc:1697
DSDBManager::addConfiguration
RowID addConfiguration(const MachineConfiguration &conf)
Definition: DSDBManager.cc:299
DSDBManager::longestPathDelayEstimate
double longestPathDelayEstimate(RowID implementation) const
Definition: DSDBManager.cc:1303
DSDBManager::archConfigurationIDs
std::set< RowID > archConfigurationIDs(RowID architectureID) const
Definition: DSDBManager.cc:1487
DSDBManager::hasCycleCount
bool hasCycleCount(RowID application, RowID architecture) const
Definition: DSDBManager.cc:1228
DSDBManager::addArchitecture
RowID addArchitecture(const TTAMachine::Machine &mom)
Definition: DSDBManager.cc:191
DSDBManager::energyComparator
Definition: DSDBManager.hh:131
DSDBManager::ConfigurationCosts::area
double area
Definition: DSDBManager.hh:106
DSDBManager::energyComparator::operator()
bool operator()(ConfigurationCosts c1, ConfigurationCosts c2) const
Definition: DSDBManager.hh:132
DSDBManager::createNew
static DSDBManager * createNew(const std::string &file)
Definition: DSDBManager.cc:141
DSDBManager::configuration
MachineConfiguration configuration(RowID id) const
Definition: DSDBManager.cc:361
DSDBManager::hasImplementation
bool hasImplementation(RowID id) const
Definition: DSDBManager.cc:1157
DSDBManager::removeConfiguration
void removeConfiguration(RowID id)
Definition: DSDBManager.cc:409
false
find Finds info of the inner loops in the false
Definition: InnerLoopFinder.cc:81
DSDBManager::setUnschedulable
void setUnschedulable(RowID application, RowID architecture)
Definition: DSDBManager.cc:515
DSDBManager::architectureId
RowID architectureId(const TTAMachine::Machine &mach) const
Definition: DSDBManager.cc:705
DSDBManager::implementation
IDF::MachineImplementation * implementation(RowID id) const
Definition: DSDBManager.cc:887
DSDBManager::ConfigurationCosts::configurationID
RowID configurationID
Definition: DSDBManager.hh:101
ClockCycleCount
CycleCount ClockCycleCount
Alias for ClockCycleCount.
Definition: SimulatorConstants.hh:57
DSDBManager::dsdbFile
std::string dsdbFile() const
Definition: DSDBManager.cc:177
DSDBManager::cycleComparator::operator()
bool operator()(ConfigurationCosts c1, ConfigurationCosts c2) const
Definition: DSDBManager.hh:119
DSDBManager::applicationPath
std::string applicationPath(RowID id) const
Definition: DSDBManager.cc:947
DSDBManager::applicationCostEstimatesByConf
std::vector< ConfigurationCosts > applicationCostEstimatesByConf(Order ordering=ORDER_BY_CONFIGURATION) const
Definition: DSDBManager.cc:1524
TTAMachine
Definition: Assembler.hh:48
DSDBManager::writeImplementationToFile
void writeImplementationToFile(RowID id, const std::string &path) const
Definition: DSDBManager.cc:906
DSDBManager::MachineConfiguration::architectureID
RowID architectureID
Definition: DSDBManager.hh:79
DSDBManager::hasArchitecture
bool hasArchitecture(RowID id) const
Definition: DSDBManager.cc:1101
SQLite
Definition: SQLite.hh:45
DSDBManager::areaEstimate
CostEstimator::AreaInGates areaEstimate(RowID implementation) const
Definition: DSDBManager.cc:1343
DSDBManager::ConfigurationCosts
Struct for configuration costs with a specified application.
Definition: DSDBManager.hh:100
DSDBManager::ORDER_BY_CONFIGURATION
@ ORDER_BY_CONFIGURATION
Definition: DSDBManager.hh:160
DSDBManager::addImplementation
RowID addImplementation(const IDF::MachineImplementation &impl, double longestPathDelay, CostEstimator::AreaInGates area)
Definition: DSDBManager.cc:252
IDF::MachineImplementation
Definition: MachineImplementation.hh:54
DSDBManager::cycleCounts
std::vector< ClockCycleCount > cycleCounts(const MachineConfiguration &conf) const
Definition: DSDBManager.cc:738
DSDBManager::configurationId
RowID configurationId(const MachineConfiguration &conf) const
Definition: DSDBManager.cc:762
IDF
Definition: DSDBManager.hh:54
DSDBManager::configurationIDs
std::set< RowID > configurationIDs() const
Definition: DSDBManager.cc:1451
DSDBManager::removeApplication
void removeApplication(RowID id)
Definition: DSDBManager.cc:1071
DSDBManager::cycleComparator
Definition: DSDBManager.hh:118
DSDBManager::applicationIDs
std::set< RowID > applicationIDs() const
Definition: DSDBManager.cc:1381
TTAMachine::Machine
Definition: Machine.hh:73
DSDBManager::idComparator::operator()
bool operator()(ConfigurationCosts c1, ConfigurationCosts c2) const
Definition: DSDBManager.hh:110
DSDBManager::ConfigurationCosts::application
std::string application
Definition: DSDBManager.hh:102