Go to the documentation of this file.
34 #include <boost/format.hpp>
35 #include <boost/tuple/tuple_comparison.hpp>
60 "CREATE TABLE architecture ("
61 " id INTEGER PRIMARY KEY,"
62 " connection_count INTEGER DEFAULT NULL, "
67 "CREATE TABLE implementation ("
68 " id INTEGER PRIMARY KEY,"
74 "CREATE TABLE machine_configuration ("
75 " id INTEGER PRIMARY KEY,"
76 " architecture REFERENCES architecture(id) NOT NULL,"
77 " implementation REFERENCES implementation(id))";
80 "CREATE TABLE application ("
81 " id INTEGER PRIMARY KEY,"
85 "CREATE TABLE cycle_count ("
86 " architecture REFERENCES architecture(id) NOT NULL,"
87 " application REFERENCES application(id) NOT NULL,"
90 " unschedulable BOOL DEFAULT 0,"
91 " cycles BIGINT DEFAULT NULL)";
94 "CREATE TABLE energy_estimate ("
95 " implementation REFERENCES implementation(id) NOT NULL,"
96 " application REFERENCES application(id) NOT NULL,"
97 " energy_estimate DOUBLE NOT NULL)";
109 : db_(new
SQLite()), dbConnection_(NULL), file_(file) {
111 string msg =
"File '" + file +
"' doesn't exist.";
143 const string procName =
"DSDBManager::createNew";
159 db.
close(connection);
162 std::string(
"Initialization of DSDB failed. ") +
208 if (adf.size() >= 5000000) {
211 "ADF size too big.");
223 "INSERT INTO architecture(id, adf_hash, adf_xml, "
224 "connection_count) VALUES"
225 "(NULL, \'%s\', \'%s\', %d);") %
268 "INSERT INTO implementation("
269 "id, idf_xml, lpd, area) VALUES"
270 "(NULL,\'" + idf +
"\'," +
307 "Architecture with ID " +
315 "Implementation with ID " +
332 "INSERT INTO machine_configuration("
333 "id, architecture, implementation) VALUES"
363 const std::string error = (boost::format(
364 "DSDP file '%s' has no configuration with id '%d'.")
373 "SELECT architecture, implementation FROM "
374 "machine_configuration WHERE id=" +
411 const std::string error = (boost::format(
412 "DSDP file '%s' has no configuration with id '%d'.")
421 "DELETE FROM machine_configuration "
447 "INSERT INTO application(id, path) VALUES"
450 ((path.substr(path.length() - 1)
452 path.substr(0,path.length()-1) :
480 const std::string error = (boost::format(
481 "DSDP file '%s' has no application with id '%d'."
482 "Can't add an energy estimate.")
483 %
file_ % application).str();
487 const std::string error = (boost::format(
488 "DSDP file '%s' has no implementation with id '%d'."
489 "Can't add an energy estimate.")
495 "INSERT INTO energy_estimate ("
496 "application, implementation, energy_estimate) VALUES(" +
517 const std::string error = (boost::format(
518 "DSDB file '%s' has no application with id '%d'."
519 "Can't add a cycle count.")
520 %
file_ % application).str();
524 const std::string error = (boost::format(
525 "DSDB file '%s' has no architecture with id '%d'."
526 "Can't add a cycle count.")
532 "INSERT INTO cycle_count(application, architecture, "
533 "unschedulable) VALUES(" +
551 RowID application,
RowID architecture)
const {
557 "SELECT unschedulable FROM cycle_count WHERE application=" +
560 "AND unschedulable = 1;");
586 const std::string error = (boost::format(
587 "DSDB file '%s' has no application with id '%d'."
588 "Can't add a cycle count.")
589 %
file_ % application).str();
593 const std::string error = (boost::format(
594 "DSDB file '%s' has no architecture with id '%d'."
595 "Can't add a cycle count.")
601 "INSERT INTO cycle_count(application, architecture, cycles, "
602 "unschedulable) VALUES(" +
619 const std::string error = (boost::format(
620 "DSDP file '%s' has no implementation with id '%d'.")
626 "UPDATE implementation SET "
643 const std::string error = (boost::format(
644 "DSDP file '%s' has no implementation with id '%d'.")
650 "UPDATE implementation SET "
667 const std::string error = (boost::format(
668 "DSDP file '%s' has no architecture with id '%d'.")
676 "SELECT adf_xml FROM architecture WHERE id=" +
710 TCEString(
"SELECT id FROM architecture WHERE adf_hash = \'") +
711 mach.
hash() +
"\';");
737 std::vector<ClockCycleCount>
740 std::vector<ClockCycleCount> ccs;
742 for (std::set<RowID>::const_iterator appI = appIds.begin();
743 appI != appIds.end(); ++appI) {
770 "SELECT id FROM machine_configuration "
771 "WHERE architecture = %d AND implementation = %d;")
776 "SELECT id FROM machine_configuration "
777 "WHERE architecture = %d AND implementation IS NULL;")
849 const std::string error = (boost::format(
850 "DSDP file '%s' has no implementation with id '%d'.")
859 "SELECT idf_xml FROM implementation WHERE id=" +
907 RowID id,
const std::string& path)
const {
931 const std::string adfFile = path +
".adf";
932 const std::string idfFile = path +
".idf";
949 const std::string error = (boost::format(
950 "DSDP file '%s' has no application with id '%d'.")
958 "SELECT path FROM application WHERE id=" +
990 "SELECT energy_estimate FROM energy_estimate WHERE application=" +
1019 "SELECT path FROM application WHERE id=" +
1046 "SELECT * FROM application WHERE path='" +
1073 const std::string error = (boost::format(
1074 "DSDP file '%s' has no application with id '%d'.")
1075 %
file_ % id).str();
1083 "DELETE FROM application "
1107 "SELECT id FROM architecture WHERE id=" +
1135 "SELECT id FROM machine_configuration WHERE id=" +
1163 "SELECT id FROM implementation WHERE id=" +
1189 const std::string error = (boost::format(
1190 "DSDP file '%s' has no energy estimate with an application id "
1191 "'%d', and with an implementation id '%d'.")
1200 "SELECT energy_estimate FROM energy_estimate WHERE application=" +
1234 "SELECT cycles FROM cycle_count WHERE cycles IS NOT NULL AND "
1263 const std::string error = (boost::format(
1264 "No cycle count found for application in DSDB file '%s'")
1273 "SELECT cycles FROM cycle_count WHERE application=" +
1305 const std::string error = (boost::format(
1306 "DSDP file '%s' has no implementation with id '%d'.")
1315 "SELECT lpd FROM implementation WHERE id=" +
1345 const std::string error = (boost::format(
1346 "DSDP file '%s' has no implementation with id '%d'.")
1355 "SELECT area FROM implementation WHERE id=" +
1386 std::string theQuery =
1387 std::string(
"SELECT id FROM application;");
1398 std::set<RowID> ids;
1421 std::string theQuery =
1422 std::string(
"SELECT id FROM architecture;");
1433 std::set<RowID> ids;
1435 while (queryResult->
hasNext()) {
1436 queryResult->
next();
1456 std::string theQuery =
1457 std::string(
"SELECT id FROM machine_configuration;");
1468 std::set<RowID> ids;
1470 while (queryResult->
hasNext()) {
1471 queryResult->
next();
1491 std::string theQuery =
1492 "SELECT id FROM machine_configuration WHERE architecture=" +
1504 std::set<RowID> ids;
1506 while (queryResult->
hasNext()) {
1507 queryResult->
next();
1523 std::vector<DSDBManager::ConfigurationCosts>
1534 vector<ApplicationData> appData;
1536 while (appResult->
hasNext()) {
1541 appData.push_back(data);
1547 "SELECT id from machine_configuration;");
1553 vector<ConfigurationCosts> res;
1555 set<ConfigurationCosts, idComparator> results;
1557 while (queryResult->
hasNext()) {
1558 queryResult->
next();
1559 for (
unsigned int i = 0; i < appData.size(); i++) {
1567 "select lpd, area from implementation, machine_configuration "
1568 "where machine_configuration.id=" + queryResult->
data(0).
stringValue() +
1569 " and machine_configuration.implementation = implementation.id limit 1;");
1585 "select energy_estimate from energy_estimate, machine_configuration, application "
1586 "where application.id=" + appData[i].
id +
" and machine_configuration.id="
1587 + queryResult->
data(0).
stringValue() +
" and machine_configuration.implementation="
1588 "energy_estimate.implementation and application.id=energy_estimate.application;");
1590 delete energyResult;
1593 if (energyResult->
hasNext()) {
1594 energyResult->
next();
1599 delete energyResult;
1604 "select cycles from cycle_count, application, machine_configuration where application.id="
1605 + appData.at(i).id +
" and machine_configuration.id=" +
1607 " and machine_configuration.architecture=cycle_count.architecture and application.id="
1608 "cycle_count.application;");
1614 cycleResult->
next();
1626 set<ConfigurationCosts, cycleComparator> cycleResults;
1627 for (set<ConfigurationCosts, idComparator>::iterator i = results.begin(); i != results.end(); i++) {
1628 cycleResults.insert(*i);
1631 for (set<ConfigurationCosts, cycleComparator>::iterator i = cycleResults.begin(); i != cycleResults.end(); i++) {
1636 set<ConfigurationCosts, appComparator> appResults;
1637 for (set<ConfigurationCosts, idComparator>::iterator i = results.begin(); i != results.end(); i++) {
1638 appResults.insert(*i);
1640 for (set<ConfigurationCosts, appComparator>::iterator i = appResults.begin(); i != appResults.end(); i++) {
1644 set<ConfigurationCosts, energyComparator> energyResults;
1645 for (set<ConfigurationCosts, idComparator>::iterator i = results.begin(); i != results.end(); i++) {
1646 energyResults.insert(*i);
1648 for (set<ConfigurationCosts, energyComparator>::iterator i = energyResults.begin(); i != energyResults.end(); i++) {
1652 for (set<ConfigurationCosts, idComparator>::iterator i = results.begin(); i != results.end(); i++) {
1671 std::string theQuery =
1672 "SELECT COUNT(id) FROM application;";
1685 queryResult->
next();
1702 application = *ids.begin();
1713 "SELECT machine_configuration.id AS id, connection_count, "
1715 "FROM application, architecture, machine_configuration, "
1717 "WHERE machine_configuration.architecture = "
1718 " cycle_count.architecture AND "
1719 " cycle_count.unschedulable = 0 AND "
1720 " cycle_count.cycles IS NOT NULL AND "
1721 " cycle_count.application = %d AND "
1722 " architecture.id = cycle_count.architecture;") %
1733 while (queryResult->
hasNext()) {
1734 queryResult->
next();
1743 bool dominated =
false;
1744 for (ParetoSetConnectivityAndCycles::iterator i = paretoSet.begin();
1745 i != paretoSet.end(); ) {
1747 if (newPoint.get<1>() <= oldPoint.get<1>() &&
1748 newPoint.get<2>() <= oldPoint.get<2>() &&
1749 (newPoint.get<1>() < oldPoint.get<1>() ||
1750 newPoint.get<2>() < oldPoint.get<2>())) {
1752 paretoSet.erase(i++);
1754 }
else if (oldPoint.get<1>() <= newPoint.get<1>() &&
1755 oldPoint.get<2>() <= newPoint.get<2>() &&
1756 (oldPoint.get<1>() < newPoint.get<1>() ||
1757 oldPoint.get<2>() < newPoint.get<2>())) {
1765 if (!dominated) paretoSet.insert(newPoint);
virtual void rollback()=0
std::string file_
The DSDB file containing the current database.
void addCycleCount(RowID application, RowID architecture, ClockCycleCount count)
int applicationCount() const
virtual ObjectState * readState()
virtual RowID lastInsertRowID()=0
virtual int updateQuery(const std::string &queryString)=0
virtual void loadState(const ObjectState *state)
void addEnergyEstimate(RowID application, RowID implementation, double energyEstimate)
void writeConfigurationToFile(const MachineConfiguration &conf, const std::string &path)
IDF::MachineImplementation * implementation
the implementation definition of the estimated processor
TTAMachine::Machine * architecture(RowID id) const
virtual std::string stringValue() const
virtual const DataObject & data(std::size_t column) const =0
const string CREATE_ARCH_TABLE
@ ORDER_BY_ENERGY_ESTIMATE
std::set< RowID > architectureIDs() const
void setLongestPathDelayEstimate(RowID implementation, double delay)
int RowID
Type definition of row ID in relational databases.
void writeArchitectureToFile(RowID id, const std::string &path) const
double AreaInGates
type for area values in equivalent gates
const string CREATE_ENERGY_ESTIMATE_TABLE
static std::string absolutePathOf(const std::string &pathName)
SQLite * db_
Handle to the database.
static std::string toString(const T &source)
virtual RelationalDBConnection & connect(const std::string &database, const std::string &login="", const std::string &password="", bool readOnly=false)
virtual void loadState(const ObjectState *state)
static bool fileIsCreatable(const std::string fileName)
virtual double doubleValue() const
const string CREATE_APPLICATION_TABLE
#define assert(condition)
virtual ObjectState * saveState() const
std::string implementationString(RowID id) const
virtual int integerValue() const
RowID addApplication(const std::string &path)
bool hasConfiguration(RowID id) const
bool hasApplication(RowID id) const
boost::tuple< RowID, int, ClockCycleCount > ParetoPointConnectivityAndCycles
#define abortWithError(message)
static int totalConnectionCount(const TTAMachine::Machine &mach)
ClockCycleCount cycleCount
void setAreaEstimate(RowID implementation, CostEstimator::AreaInGates area)
bool isUnschedulable(RowID application, RowID architecture) const
ClockCycleCount cycleCount(RowID application, RowID architecture) const
RelationalDBConnection * dbConnection_
Handle to the database connection.
virtual bool isNull() const
void setDestinationFile(const std::string &fileName)
Order
Identifiers for ordering results.
std::set< ParetoPointConnectivityAndCycles > ParetoSetConnectivityAndCycles
virtual ObjectState * saveState() const
virtual RelationalDBQueryResult * query(const std::string &queryString, bool init=true)=0
double energyEstimate(RowID application, RowID implementation) const
virtual void beginTransaction()=0
bool hasEnergyEstimate(RowID application, RowID implementation) const
std::string errorMessage() const
virtual void close(const RelationalDBConnection &connection)
DSDBManager(const std::string &file)
ObjectState * readState()
std::string architectureString(RowID id) const
ParetoSetConnectivityAndCycles paretoSetConnectivityAndCycles(RowID application=ILLEGAL_ROW_ID) const
static const std::string DIRECTORY_SEPARATOR
RowID addConfiguration(const MachineConfiguration &conf)
double longestPathDelayEstimate(RowID implementation) const
std::set< RowID > archConfigurationIDs(RowID architectureID) const
bool hasCycleCount(RowID application, RowID architecture) const
RowID addArchitecture(const TTAMachine::Machine &mom)
const string CREATE_MACHINE_CFG_TABLE
void setDestinationString(std::string &destination)
static DSDBManager * createNew(const std::string &file)
MachineConfiguration configuration(RowID id) const
bool hasImplementation(RowID id) const
virtual void DDLQuery(const std::string &queryString)=0
const string CREATE_IMPL_TABLE
void removeConfiguration(RowID id)
static bool fileExists(const std::string fileName)
void setUnschedulable(RowID application, RowID architecture)
void writeState(const ObjectState *machineState)
RowID architectureId(const TTAMachine::Machine &mach) const
IDF::MachineImplementation * implementation(RowID id) const
CycleCount ClockCycleCount
Alias for ClockCycleCount.
std::string dsdbFile() const
std::string applicationPath(RowID id) const
const string CREATE_CYCLE_COUNT_TABLE
void setSourceString(const std::string &source)
std::vector< ConfigurationCosts > applicationCostEstimatesByConf(Order ordering=ORDER_BY_CONFIGURATION) const
void writeImplementationToFile(RowID id, const std::string &path) const
bool hasArchitecture(RowID id) const
CostEstimator::AreaInGates areaEstimate(RowID implementation) const
Struct for configuration costs with a specified application.
RowID addImplementation(const IDF::MachineImplementation &impl, double longestPathDelay, CostEstimator::AreaInGates area)
std::vector< ClockCycleCount > cycleCounts(const MachineConfiguration &conf) const
RowID configurationId(const MachineConfiguration &conf) const
virtual void writeState(const ObjectState *state)
std::set< RowID > configurationIDs() const
void removeApplication(RowID id)
std::set< RowID > applicationIDs() const