diff -r 28fe13ecd030 -r 71de0404ef2e ext/dsent/CMakeLists.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ext/dsent/CMakeLists.txt Thu Sep 18 16:33:29 2014 -0500 @@ -0,0 +1,20 @@ +cmake_minimum_required (VERSION 2.6) + +project (DSENT) +# find out all the file that need to be compiled +file(GLOB_RECURSE SRCS "*.h" "*.cc") + +# add the library +add_library(dsent MODULE ${SRCS}) + +SET(PYTHON_CONFIG "python-config") + +# add the binary tree to the search path for include files +include_directories("${CMAKE_SOURCE_DIR}" "`${PYTHON_CONFIG} --includes`") +EXEC_PROGRAM(${PYTHON_CONFIG} ARGS --cflags OUTPUT_VARIABLE PYTHON_CFLAGS) +EXEC_PROGRAM(${PYTHON_CONFIG} ARGS --ldflags OUTPUT_VARIABLE PYTHON_LFLAGS) + +set_target_properties(dsent PROPERTIES + PREFIX "" + COMPILE_FLAGS "${PYTHON_CFLAGS} -std=c++11" + LINK_FLAGS "${PYTHON_LFLAGS}") diff -r 28fe13ecd030 -r 71de0404ef2e ext/dsent/DSENT.h --- a/ext/dsent/DSENT.h Thu Sep 18 16:32:03 2014 -0500 +++ b/ext/dsent/DSENT.h Thu Sep 18 16:33:29 2014 -0500 @@ -1,11 +1,12 @@ #ifndef __DSENT_DSENT_H__ #define __DSENT_DSENT_H__ +#include +#include + // For DSENT operations -#include "libutil/OptionParser.h" #include "libutil/Calculator.h" #include "util/CommonType.h" -#include "util/Config.h" #include "util/Result.h" #include "model/Model.h" #include "model/ModelGen.h" @@ -19,46 +20,29 @@ namespace DSENT { - using LibUtil::OptionParser; using LibUtil::Calculator; - class DSENT + class DSENTCalculator : public Calculator { - protected: - class DSENTCalculator : public Calculator - { - public: - DSENTCalculator(); - virtual ~DSENTCalculator(); - - protected: - virtual double getEnvVar(const String& var_name_) const; - }; // class DSENTCalculator - public: - static void run(int argc_, char** argv_); + DSENTCalculator(); + virtual ~DSENTCalculator(); protected: - static void setRuntimeOptions(OptionParser* option_parser_); - static void initialize(int argc_, char** argv_); - static void buildModel(); - static void processQuery(); - static const void* processQuery(const String& query_str_, bool is_print_); - static void finalize(); + virtual double getEnvVar( + const String& var_name_, + const std::map &Config, + Model *ms_model) const; + }; - static void performTimingOpt(); - static void reportTiming(); + Model *initialize(const char *config_file_name, + std::map &config); - static void processEvaluate(); + void finalize(std::map &config, + Model *ms_model); - protected: - static Model* ms_model_; - - static bool ms_is_verbose_; - - }; // class DSENT - + void run(const std::map &config, Model *ms_model, + std::map &outputs); } // namespace DSENT #endif // __DSENT_DSENT_H__ - diff -r 28fe13ecd030 -r 71de0404ef2e ext/dsent/DSENT.cc --- a/ext/dsent/DSENT.cc Thu Sep 18 16:32:03 2014 -0500 +++ b/ext/dsent/DSENT.cc Thu Sep 18 16:33:29 2014 -0500 @@ -1,237 +1,188 @@ -#include "DSENT.h" - #include #include +#include "DSENT.h" +#include "model/std_cells/StdCellLib.h" + +using namespace std; + namespace DSENT { - Model* DSENT::ms_model_ = NULL; - bool DSENT::ms_is_verbose_ = false; + static void performTimingOpt(const map ¶ms, + Model *ms_model) + { + // Get the frequency it is optimizing to + double freq = params.at("Frequency").toDouble(); - void DSENT::run(int argc_, char** argv_) - { - // Initialize DSENT framework (setup log file, config file, ...) - initialize(argc_, argv_); + // Get all the starting net names + const vector& start_net_names = + params.at("TimingOptimization->StartNetNames").split("[,]"); - // Build the specified model in the config file - buildModel(); + ASSERT((start_net_names.size() > 0), + "[Error] Expecting net names in TimingOptimization->StartNetNames"); - // Process the specified queries - processQuery(); - // Process the specified evaluation - processEvaluate(); + if(start_net_names[0] == "*") + { + // Optimize from all input ports + ElectricalModel* electrical_model = (ElectricalModel*)ms_model; - // Finalize DSENT framework (close log file, ...) - finalize(); - return; + ElectricalTimingOptimizer timing_optimizer( + "Optimizer", electrical_model->getTechModel()); + timing_optimizer.setModel(electrical_model); + timing_optimizer.construct(); + timing_optimizer.update(); + + ElectricalTimingTree timing_tree( + timing_optimizer.getInstanceName(), &timing_optimizer); + + const Map* input_ports = timing_optimizer.getInputs(); + Map::ConstIterator it_begin = input_ports->begin(); + Map::ConstIterator it_end = input_ports->end(); + Map::ConstIterator it; + for(it = it_begin; it != it_end; ++it) + { + const String& net_name = it->first; + Log::printLine("Optimizing net: " + net_name); + timing_tree.performTimingOpt( + timing_optimizer.getNet(net_name, makeNetIndex(0)), 1.0 / freq); + } + + // Loop the second times + for(it = it_begin; it != it_end; ++it) + { + const String& net_name = it->first; + Log::printLine("Optimizing net: " + net_name); + } + } + else + { + // TODO : parse the net name so that we could do hierarchical optimization + // Currently we can only optimize timing at the top level + ElectricalModel* electrical_model = (ElectricalModel*)ms_model; + ElectricalTimingTree timing_tree( + electrical_model->getInstanceName(), electrical_model); + + for(unsigned int i = 0; i < start_net_names.size(); ++i) + { + const String& net_name = start_net_names[i]; + timing_tree.performTimingOpt( + electrical_model->getNet(net_name), 1.0 / freq); + } + } } - void DSENT::setRuntimeOptions(OptionParser* option_parser_) + static void reportTiming(const map ¶ms, Model *ms_model) { - option_parser_->addOption("-cfg", "ConfigFilename", true, "filename", false, "", - "Specify the config filename."); + // Get all the starting net names + const vector& start_net_names = + params.at("ReportTiming->StartNetNames").split("[,]"); - option_parser_->addOption("-available_models", "IsListModels", false, "", true, "false", - "List available DSENT models."); + ElectricalModel* electrical_model = (ElectricalModel*)ms_model; + ElectricalTimingTree timing_tree( + electrical_model->getInstanceName(), electrical_model); - option_parser_->addOption("-log", "LogFilename", true, "filename", true, "./dsent.log", - "Specify the log filename."); - - option_parser_->addOption("-overwrite", "OverwriteString", true, "options", true, "", - "Overwrite dynamically the options set in the config file. Options are separated by a comma (;)."); - - option_parser_->addOption("-overwrite_tech", "OverwriteTechString", true, "options", true, "", - "Overwrite dynamically the options set in the technology file. Options are separated by a comma (;)."); - - option_parser_->addOption("-print_config", "IsPrintConfig", false, "", true, "false", - "Print the config used at DSENT runtime."); - - option_parser_->addOption("-query", "QueryString", true, "query string", true, "", - "Specify the list of items to query. This command is the same as owerwriting the 'QueryString'."); - - option_parser_->addOption("-eval", "EvaluateString", true, "evaluate string", true, "", - "Specify the list of statements to evaluate. This command is the same as owerwriting the 'EvaluateString'."); - - option_parser_->addOption("-verbose", "IsVerbose", false, "", true, "false", - "Enable verbose mode which prints out more detailed messages."); - return; + cout << "Report timing:" << endl; + cout << "==============" << endl; + for(unsigned int i = 0; i < start_net_names.size(); ++i) + { + const String& net_name = start_net_names[i]; + double timing = timing_tree.performCritPathExtract(electrical_model->getNet(net_name)); + cout << net_name << " = " << timing << endl; + } + cout << "==============" << endl; } - void DSENT::initialize(int argc_, char** argv_) + static Model *buildModel(const map ¶ms, + TechModel *tech_model) { - OptionParser* option_parser = new OptionParser(); + // Create the model specified + const String& model_name = params.at("ModelName"); + Model *ms_model = ModelGen::createModel(model_name, model_name, + tech_model); - // Init the option parser and setup available options - setRuntimeOptions(option_parser); - - // Parse the options - option_parser->parseArguments(argc_, argv_); - - // If -available_models is specified, print out a list of available - // models and exit DSENT. - if(option_parser->get("IsListModels").toBool()) + // Construct the model + // Read all parameters the model requires + const vector* parameter_names = ms_model->getParameterNames(); + // For all parameters, grab values from the config file + for(vector::const_iterator it = parameter_names->begin(); + it != parameter_names->end(); ++it) { - ModelGen::printAvailableModels(); - exit(0); - } - - // Init the log file - Log::allocate(option_parser->get("LogFilename")); - - // Init the config file - Config::allocate(option_parser->get("ConfigFilename")); - Config* dsent_config = Config::getSingleton(); - - // Overwrite the existing options - dsent_config->readString(option_parser->get("OverwriteString")); - - // Overwrite the technology file - dsent_config->constructTechModel(option_parser->get("OverwriteTechString")); - - ms_is_verbose_ = option_parser->get("IsVerbose").toBool(); - - // Overwrite the query string if it is specified from command line - if(option_parser->get("QueryString").size() != 0) - { - dsent_config->set("QueryString", option_parser->get("QueryString")); - } - // Overwrite the evaluation string if it is specified from command line - if(option_parser->get("EvaluateString").size() != 0) - { - dsent_config->set("EvaluateString", option_parser->get("EvaluateString")); - } - - // Print the config used for this run - if(option_parser->get("IsPrintConfig").toBool()) - { - if(ms_is_verbose_) + const String& parameter_name = *it; + // If it exists in the config file, set the parameter + if(params.count(parameter_name) > 0) { - cout << "Configuration:" << endl; - cout << "==============" << endl; - } - cout << *dsent_config; - - if(ms_is_verbose_) - { - cout << "==============" << endl; + ms_model->setParameter(parameter_name, + params.at(parameter_name)); } } - delete option_parser; - return; - } - - void DSENT::buildModel() - { - Config* dsent_config = Config::getSingleton(); - - // Create the model specified - const String& model_name = dsent_config->get("ModelName"); - ms_model_ = ModelGen::createModel(model_name, model_name, dsent_config->getTechModel()); - - // Construct the model - // Read all parameters the model requires - const vector* parameter_names = ms_model_->getParameterNames(); - // For all parameters, grab values from the config file - for(vector::const_iterator it = parameter_names->begin(); it != parameter_names->end(); ++it) - { - const String& parameter_name = *it; - // If it exists in the config file, set the parameter - if(dsent_config->keyExist(parameter_name)) - { - ms_model_->setParameter(parameter_name, dsent_config->get(parameter_name)); - } - } - ms_model_->construct(); + ms_model->construct(); // Update the model // Read all properties the model requires - const vector* property_names = ms_model_->getPropertyNames(); + const vector* property_names = ms_model->getPropertyNames(); // For all properties, grab values from the config file - for(vector::const_iterator it = property_names->begin(); it != property_names->end(); ++it) + for(vector::const_iterator it = property_names->begin(); + it != property_names->end(); ++it) { const String& property_name = *it; // If it exists in the config file, set the parameter - if(dsent_config->keyExist(property_name)) + if(params.count(property_name) > 0) { - ms_model_->setProperty(property_name, dsent_config->get(property_name)); + ms_model->setProperty(property_name, + params.at(property_name)); } } - ms_model_->update(); + ms_model->update(); // Evaluate the model // Perform timing optimization if needed - if(dsent_config->getIfKeyExist("IsPerformTimingOptimization", "false").toBool()) + if(params.find("IsPerformTimingOptimization") != params.end() && + params.at("IsPerformTimingOptimization").toBool()) { - performTimingOpt(); + performTimingOpt(params, ms_model); } - ms_model_->evaluate(); + ms_model->evaluate(); // Report timing if needed - if(dsent_config->getIfKeyExist("IsReportTiming", "false").toBool()) + if(params.count("IsReportTiming") > 0 && + params.at("IsReportTiming") != "false") { - reportTiming(); + reportTiming(params, ms_model); } - return; + return ms_model; } - void DSENT::processQuery() - { - Config* dsent_config = Config::getSingleton(); - vector queries = dsent_config->get("QueryString").split(" ;\r\n"); - - if(ms_is_verbose_) - { - cout << "Query results:" << endl; - cout << "==============" << endl; - } - - for(unsigned int i = 0; i < queries.size(); ++i) - { - const String& curr_query = queries[i]; - - if(ms_is_verbose_) - { - String str = "Process query: '" + curr_query + "'"; - cout << str << endl; - cout << String(str.size(), '-') << endl; - } - - processQuery(curr_query, true); - - if(ms_is_verbose_) - { - cout << endl; - } - } - if(ms_is_verbose_) - { - cout << "==============" << endl; - } - return; - } - - const void* DSENT::processQuery(const String& query_str_, bool is_print_) + static const void* processQuery(const String& query_str_, + Model *ms_model, bool is_print_) { vector type_split = query_str_.splitByString(Model::TYPE_SEPARATOR); ASSERT((type_split.size() == 2), "[Error] Invalid query format: " + query_str_); String query_type = type_split[0]; - vector detail_split = type_split[1].splitByString(Model::DETAIL_SEPARATOR); + vector detail_split = + type_split[1].splitByString(Model::DETAIL_SEPARATOR); + ASSERT((detail_split.size() == 2), "[Error] Invalid query format: " + query_str_); String query_detail = detail_split[1]; - vector subfield_split = detail_split[0].splitByString(Model::SUBFIELD_SEPARATOR); - ASSERT(((subfield_split.size() == 2) || (subfield_split.size() == 1)), "[Error] Invalid query format: " + query_str_); + vector subfield_split = + detail_split[0].splitByString(Model::SUBFIELD_SEPARATOR); + + ASSERT(((subfield_split.size() == 2) || (subfield_split.size() == 1)), + "[Error] Invalid query format: " + query_str_); + String query_hier = subfield_split[0]; String query_subfield = ""; + if(subfield_split.size() == 2) { query_subfield = subfield_split[1]; } - const void* query_result = ms_model_->parseQuery(query_type, query_hier, query_subfield); + const void* query_result = ms_model->parseQuery(query_type, query_hier, + query_subfield); if(query_type == "Property") { const PropertyMap* property = (const PropertyMap*)query_result; @@ -268,156 +219,104 @@ return query_result; } - void DSENT::finalize() + void processQuery(const vector &queries, + Model *ms_model, vector &outputs) { - // Release the constructed model - delete ms_model_; - ms_model_ = NULL; + for(unsigned int i = 0; i < queries.size(); ++i) + { + const String& curr_query = queries[i]; + processQuery(curr_query, ms_model, true); - // Release the config file - Config::release(); + } + } + + static TechModel* constructTechModel(const map& params) + { + // Allocate static TechModel instance + const String& electrical_tech_model_filename = + params.at("ElectricalTechModelFilename"); + + TechModel* tech_model = new TechModel(); + tech_model->readFile(electrical_tech_model_filename); + + if (params.count("PhotonicTechModelFilename") != 0) { + const String& photonic_tech_model_filename = + params.at("PhotonicTechModelFilename"); + tech_model->readFile(photonic_tech_model_filename); + } + + // Allocate static StdCellLib instance + StdCellLib* std_cell_lib = new StdCellLib(tech_model); + + // Set the StdCellLib pointer in static TechModel instance + tech_model->setStdCellLib(std_cell_lib); + return tech_model; + } + + Model *initialize(const char *config_file_name, map &config) + { + // Init the log file + Log::allocate("/tmp/dsent.log"); + + // Init the config file + LibUtil::readFile(config_file_name, config); + + // Overwrite the technology file + TechModel *tech_model = constructTechModel(config); + + // Build the specified model in the config file + return buildModel(config, tech_model); + } + + void finalize(map &config, Model *ms_model) + { + // Delete the model + delete ms_model; + + // Discard all the (key, value) pairs. + config.clear(); // Release the log file Log::release(); - - return; } - void DSENT::performTimingOpt() + void run(const map ¶ms, Model *ms_model, + map &outputs) { - Config* dsent_config = Config::getSingleton(); + // Process the specified queries + const auto &it = params.find("EvaluateString"); + if(it == params.end()) { + return; + } - // Get the frequency it is optimizing to - double freq = dsent_config->get("Frequency").toDouble(); + String eval_str = it->second; - // Get all the starting net names - const vector& start_net_names = dsent_config->get("TimingOptimization->StartNetNames").split("[,]"); + if (eval_str == "") { + return; + } - ASSERT((start_net_names.size() > 0), "[Error] Expecting net names in TimingOptimization->StartNetNames"); - - if(start_net_names[0] == "*") - { - // Optimize from all input ports - ElectricalModel* electrical_model = (ElectricalModel*)ms_model_; - - ElectricalTimingOptimizer timing_optimizer("Optimizer", electrical_model->getTechModel()); - timing_optimizer.setModel(electrical_model); - timing_optimizer.construct(); - timing_optimizer.update(); - - ElectricalTimingTree timing_tree(timing_optimizer.getInstanceName(), &timing_optimizer); - - const Map* input_ports = timing_optimizer.getInputs(); - Map::ConstIterator it_begin = input_ports->begin(); - Map::ConstIterator it_end = input_ports->end(); - Map::ConstIterator it; - for(it = it_begin; it != it_end; ++it) - { - const String& net_name = it->first; - Log::printLine("Optimizing net: " + net_name); - timing_tree.performTimingOpt(timing_optimizer.getNet(net_name, makeNetIndex(0)), 1.0 / freq); - //timing_tree.performTimingOpt(electrical_model->getNet(net_name, makeNetIndex(0)), 1.0 / freq); - } - // Loop the second times - for(it = it_begin; it != it_end; ++it) - { - const String& net_name = it->first; - Log::printLine("Optimizing net: " + net_name); - //timing_tree.performTimingOpt(timing_optimizer.getNet(net_name, makeNetIndex(0)), 1.0 / freq); - } - } - else - { - // TODO : parse the net name so that we could do hierarchical optimization - // Currently we can only optimize timing at the top level - ElectricalModel* electrical_model = (ElectricalModel*)ms_model_; - ElectricalTimingTree timing_tree(electrical_model->getInstanceName(), electrical_model); - for(unsigned int i = 0; i < start_net_names.size(); ++i) - { - const String& net_name = start_net_names[i]; - timing_tree.performTimingOpt(electrical_model->getNet(net_name), 1.0 / freq); - } - } - return; + DSENTCalculator calc; + calc.evaluateString(eval_str, params, ms_model, outputs); } - void DSENT::reportTiming() + DSENTCalculator::DSENTCalculator() {} + + DSENTCalculator::~DSENTCalculator() {} + + double DSENTCalculator::getEnvVar(const String& var_name_, + const map &config, + Model *ms_model) const { - Config* dsent_config = Config::getSingleton(); - - // Get all the starting net names - const vector& start_net_names = dsent_config->get("ReportTiming->StartNetNames").split("[,]"); - - ElectricalModel* electrical_model = (ElectricalModel*)ms_model_; - ElectricalTimingTree timing_tree(electrical_model->getInstanceName(), electrical_model); - - cout << "Report timing:" << endl; - cout << "==============" << endl; - for(unsigned int i = 0; i < start_net_names.size(); ++i) - { - const String& net_name = start_net_names[i]; - double timing = timing_tree.performCritPathExtract(electrical_model->getNet(net_name)); - cout << net_name << " = " << timing << endl; - } - cout << "==============" << endl; - return; - } - - void DSENT::processEvaluate() - { - Config* dsent_config = Config::getSingleton(); - - // Return if EvaluatString is empty or not exists - if(!dsent_config->keyExist("EvaluateString")) return; - - String eval_str = dsent_config->get("EvaluateString"); - - if(eval_str == "") return; - - if(ms_is_verbose_) - { - cout << "Eval results:" << endl; - cout << "==============" << endl; - } - - //if(ms_is_verbose_) - //{ - // String str = "Process evaluation: '" + eval_str + "'"; - // cout << str << endl; - // cout << String(str.size(), '-') << endl; - //} - DSENTCalculator calc; - calc.evaluateString(eval_str); - - if(ms_is_verbose_) - { - cout << "==============" << endl; - } - return; - return; - } - - DSENT::DSENTCalculator::DSENTCalculator() - {} - - DSENT::DSENTCalculator::~DSENTCalculator() - {} - - double DSENT::DSENTCalculator::getEnvVar(const String& var_name_) const - { - if(m_var_.keyExist(var_name_)) - { + if (m_var_.keyExist(var_name_)) { return m_var_.get(var_name_); - } - else if(Config::getSingleton()->keyExist(var_name_)) - { - return Config::getSingleton()->get(var_name_); - } - else - { - const Result* result = (const Result*)DSENT::processQuery(var_name_ + "@0", false); + } else if (config.count(var_name_) > 0) { + return config.at(var_name_); + } else { + // Wish there was a way to not have to pass in a stream if we aren't + // doing anything with it + const Result* result = (const Result*)DSENT::processQuery( + var_name_ + "@0", ms_model, false); return result->calculateSum(); } } } // namespace DSENT - diff -r 28fe13ecd030 -r 71de0404ef2e ext/dsent/Makefile --- a/ext/dsent/Makefile Thu Sep 18 16:32:03 2014 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,55 +0,0 @@ - -# Define the directories that will be compiled -DIRS_TO_COMPILE := util tech io \ - model model/timing_graph \ - model/std_cells \ - model/electrical \ - model/electrical/router \ - model/optical \ - model/optical_graph \ - model/network \ - model/network/ATAC - -DIRS = $(patsubst %,$(CURDIR)/%,$(DIRS_TO_COMPILE)) - -SRCS = $(foreach dir, $(DIRS), $(wildcard $(dir)/*.cc)) - -OBJS = $(SRCS:%.cc=%.o) - -DEF_FLAGS = -INCLUDE_FLAGS = -I$(CURDIR) -OPT_FLAGS = -O2 -g -WARN_FLAGS = -pedantic -Wall -W #-Wextra -Werror -Wno-write-strings -CXXFLAGS = $(OPT_FLAGS) $(WARN_FLAGS) $(INCLUDE_FLAGS) $(DEF_FLAGS) - -LD_LIBS += -lutil -LD_FLAGS += -Llibutil - -# Other libraries used -LIB_UTIL = libutil/libutil.a - -#TARGET = $(CURDIR)/libdsent.a -TARGET = $(CURDIR)/dsent - -all: $(TARGET) - -#$(TARGET): $(OBJS) -# ar rcs $@ $^ -$(TARGET): main.o DSENT.o $(LIB_UTIL) $(OBJS) - $(CXX) $(CXXFLAGS) $(LD_FLAGS) $(OBJS) main.o DSENT.o -o $(TARGET) $(LD_LIBS) - -# For general c++ compilation -%.o: %.cc - $(CXX) $(CXXFLAGS) -c $< -o $@ - -$(LIB_UTIL): - $(MAKE) -C $(CURDIR)/libutil - -%/created: - mkdir -p $(dir $@) - touch $@ - -.phony: clean -clean: - $(RM) -rf main.o DSENT.o $(OBJS) $(TARGET) - $(MAKE) -C $(CURDIR)/libutil clean diff -r 28fe13ecd030 -r 71de0404ef2e ext/dsent/configs/electrical-link.cfg --- a/ext/dsent/configs/electrical-link.cfg Thu Sep 18 16:32:03 2014 -0500 +++ b/ext/dsent/configs/electrical-link.cfg Thu Sep 18 16:33:29 2014 -0500 @@ -19,7 +19,7 @@ print " Leakage power: " link_static; \ # Technology file (see models in tech/models) -ElectricalTechModelFilename = tech/tech_models/Bulk45LVT.model +ElectricalTechModelFilename = ext/dsent/tech/tech_models/Bulk45LVT.model ############################################################################### # Timing optimization diff -r 28fe13ecd030 -r 71de0404ef2e ext/dsent/configs/router.cfg --- a/ext/dsent/configs/router.cfg Thu Sep 18 16:32:03 2014 -0500 +++ b/ext/dsent/configs/router.cfg Thu Sep 18 16:33:29 2014 -0500 @@ -65,7 +65,7 @@ print " Other: " other_area; \ # Technology file (see other models in tech/models) -ElectricalTechModelFilename = tech/tech_models/Bulk45LVT.model +ElectricalTechModelFilename = ext/dsent/tech/tech_models/Bulk45LVT.model ############################################################################### # Timing optimization diff -r 28fe13ecd030 -r 71de0404ef2e ext/dsent/interface.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ext/dsent/interface.cc Thu Sep 18 16:33:29 2014 -0500 @@ -0,0 +1,186 @@ +#include +#include + +#include "DSENT.h" +#include "libutil/String.h" +#include "model/Model.h" + +using namespace std; +using namespace LibUtil; + +static PyObject *DSENTError; +static PyObject* dsent_initialize(PyObject*, PyObject*); +static PyObject* dsent_finalize(PyObject*, PyObject*); +static PyObject* dsent_computeRouterPowerAndArea(PyObject*, PyObject*); +static PyObject* dsent_computeLinkPower(PyObject*, PyObject*); + +// Create DSENT configuration map. This map is supposed to retain all +// the information between calls to initialize() and finalize(). +map params; +DSENT::Model *ms_model; + + +static PyMethodDef DSENTMethods[] = { + {"initialize", dsent_initialize, METH_O, + "initialize dsent using a config file."}, + + {"finalize", dsent_finalize, METH_NOARGS, + "finalize dsent by dstroying the config object"}, + + {"computeRouterPowerAndArea", dsent_computeRouterPowerAndArea, + METH_VARARGS, "compute quantities related power consumption of a router"}, + + {"computeLinkPower", dsent_computeLinkPower, METH_O, + "compute quantities related power consumption of a link"}, + + {NULL, NULL, 0, NULL} +}; + + +PyMODINIT_FUNC +initdsent(void) +{ + PyObject *m; + + m = Py_InitModule("dsent", DSENTMethods); + if (m == NULL) return; + + DSENTError = PyErr_NewException("dsent.error", NULL, NULL); + Py_INCREF(DSENTError); + PyModule_AddObject(m, "error", DSENTError); + + ms_model = nullptr; +} + + +static PyObject * +dsent_initialize(PyObject *self, PyObject *arg) +{ + const char *config_file = PyString_AsString(arg); + //Read the arguments sent from the python script + if (!config_file) { + Py_RETURN_NONE; + } + + // Initialize DSENT + ms_model = DSENT::initialize(config_file, params); + Py_RETURN_NONE; +} + + +static PyObject * +dsent_finalize(PyObject *self, PyObject *args) +{ + // Finalize DSENT + DSENT::finalize(params, ms_model); + ms_model = nullptr; + Py_RETURN_NONE; +} + + +static PyObject * +dsent_computeRouterPowerAndArea(PyObject *self, PyObject *args) +{ + uint64_t frequency; + unsigned int num_in_port; + unsigned int num_out_port; + unsigned int num_vclass; + unsigned int num_vchannels; + unsigned int num_buffers; + + unsigned int flit_width; + const char *input_port_buffer_model; + const char *crossbar_model; + const char *sa_arbiter_model; + const char *clk_tree_model; + unsigned int clk_tree_num_levels; + const char *clk_tree_wire_layer; + double clk_tree_wire_width_mult; + + // Read the arguments sent from the python script + if (!PyArg_ParseTuple(args, "KIIIIII", &frequency, &num_in_port, + &num_out_port, &num_vclass, &num_vchannels, + &num_buffers, &flit_width)) { + Py_RETURN_NONE; + } + + assert(frequency > 0.0); + assert(num_in_port != 0); + assert(num_out_port != 0); + assert(num_vclass != 0); + assert(flit_width != 0); + + vector num_vchannels_vec(num_vclass, num_vchannels); + vector num_buffers_vec(num_vclass, num_buffers); + // DSENT outputs + map outputs; + + params["Frequency"] = String(frequency); + params["NumberInputPorts"] = String(num_in_port); + params["NumberOutputPorts"] = String(num_out_port); + params["NumberVirtualNetworks"] = String(num_vclass); + params["NumberVirtualChannelsPerVirtualNetwork"] = + vectorToString(num_vchannels_vec); + params["NumberBuffersPerVirtualChannel"] = + vectorToString(num_buffers_vec); + params["NumberBitsPerFlit"] = String(flit_width); + + // Run DSENT + DSENT::run(params, ms_model, outputs); + + // Store outputs + PyObject *r = PyTuple_New(outputs.size()); + int index = 0; + + // Prepare the output. The assumption is that all the output + for (const auto &it : outputs) { + PyObject *s = PyTuple_New(2); + PyTuple_SetItem(s, 0, PyString_FromString(it.first.c_str())); + PyTuple_SetItem(s, 1, PyFloat_FromDouble(it.second)); + + PyTuple_SetItem(r, index, s); + index++; + } + + return r; +} + + +static PyObject * +dsent_computeLinkPower(PyObject *self, PyObject *arg) +{ + uint64_t frequency = PyLong_AsLongLong(arg); + + // Read the arguments sent from the python script + if (frequency == -1) { + Py_RETURN_NONE; + } + + // DSENT outputs + map outputs; + params["Frequency"] = String(frequency); + + // Run DSENT + DSENT::run(params, ms_model, outputs); + + // Store outputs + PyObject *r = PyTuple_New(outputs.size()); + int index = 0; + + // Prepare the output. The assumption is that all the output + for (const auto &it : outputs) { + PyObject *s = PyTuple_New(2); + PyTuple_SetItem(s, 0, PyString_FromString(it.first.c_str())); + PyTuple_SetItem(s, 1, PyFloat_FromDouble(it.second)); + + PyTuple_SetItem(r, index, s); + index++; + } + + return r; +} + +static PyObject * +dsent_printAvailableModels(PyObject* self, PyObject *args) +{ +} diff -r 28fe13ecd030 -r 71de0404ef2e ext/dsent/libutil/Calculator.h --- a/ext/dsent/libutil/Calculator.h Thu Sep 18 16:32:03 2014 -0500 +++ b/ext/dsent/libutil/Calculator.h Thu Sep 18 16:33:29 2014 -0500 @@ -3,6 +3,7 @@ #include +#include "model/Model.h" #include "String.h" #include "Map.h" #include "Assert.h" @@ -10,6 +11,7 @@ namespace LibUtil { using std::istringstream; + using std::ostringstream; /* * program: @@ -63,14 +65,30 @@ public: void reset(); - void evaluateString(const String& str_); + void evaluateString(const String& str_, + const std::map &config, + DSENT::Model *ms_model, + std::map &outputs); protected: Token getToken(istringstream& ist_); - double prim(istringstream& ist_, bool is_get_); - double term(istringstream& ist_, bool is_get_); - double expr(istringstream& ist_, bool is_get_); - virtual double getEnvVar(const String& var_name_) const; + + double prim(istringstream& ist_, bool is_get_, + const std::map &config, + DSENT::Model *ms_model); + + double term(istringstream& ist_, bool is_get_, + const std::map &config, + DSENT::Model *ms_model); + + double expr(istringstream& ist_, bool is_get_, + const std::map &config, + DSENT::Model *ms_model); + + virtual double getEnvVar( + const String& var_name_, + const std::map &config, + DSENT::Model *ms_model) const; protected: String m_reserved_chars_; @@ -79,7 +97,7 @@ Token m_curr_token_; double m_value_number_; String m_value_string_; - }; // class Calculator + }; } // namespace LibUtil #endif // __LIBUTIL_CALCULATOR_H__ diff -r 28fe13ecd030 -r 71de0404ef2e ext/dsent/libutil/Calculator.cc --- a/ext/dsent/libutil/Calculator.cc Thu Sep 18 16:32:03 2014 -0500 +++ b/ext/dsent/libutil/Calculator.cc Thu Sep 18 16:33:29 2014 -0500 @@ -23,9 +23,13 @@ return; } - void Calculator::evaluateString(const String& str_) + void Calculator::evaluateString(const String& str_, + const map &config, + DSENT::Model *ms_model, + map &outputs) { istringstream ist(str_); + while(ist) { getToken(ist); @@ -42,26 +46,28 @@ getToken(ist); if(m_curr_token_ == SEP) { + outputs[print_str] = 0; cout << print_str << endl; } else { - double v = expr(ist, false); - cout << scientific << print_str << v << endl; + double v = expr(ist, false, config, ms_model); + outputs[print_str] = v; + cout << print_str << v << endl; } } else { - double v = expr(ist, false); - cout << scientific << v << endl; + double v = expr(ist, false, config, ms_model); + outputs["Missing Expression"] = v; + cout << v << endl; } } else { - expr(ist, false); + expr(ist, false, config, ms_model); } } - return; } Calculator::Token Calculator::getToken(istringstream& ist_) @@ -146,7 +152,9 @@ } } - double Calculator::prim(istringstream& ist_, bool is_get_) + double Calculator::prim(istringstream& ist_, bool is_get_, + const map &config, + DSENT::Model *ms_model) { if(is_get_) { @@ -164,7 +172,7 @@ if(getToken(ist_) == ASSIGN) { String var_name = m_value_string_; - v = expr(ist_, true); + v = expr(ist_, true, config, ms_model); m_var_.set(var_name, v); } else @@ -173,13 +181,13 @@ } return v; case NAME2: - v = getEnvVar(m_value_string_); + v = getEnvVar(m_value_string_, config, ms_model); getToken(ist_); return v; case MINUS: - return -prim(ist_, true); + return -prim(ist_, true, config, ms_model); case LP: - v = expr(ist_, true); + v = expr(ist_, true, config, ms_model); ASSERT((m_curr_token_ == RP), "[Error] ')' expected"); getToken(ist_); return v; @@ -188,9 +196,11 @@ } } - double Calculator::term(istringstream& ist_, bool is_get_) + double Calculator::term(istringstream& ist_, bool is_get_, + const map &config, + DSENT::Model *ms_model) { - double left = prim(ist_, is_get_); + double left = prim(ist_, is_get_, config, ms_model); while(1) { @@ -198,10 +208,10 @@ switch(m_curr_token_) { case MUL: - left *= prim(ist_, true); + left *= prim(ist_, true, config, ms_model); break; case DIV: - d = prim(ist_, true); + d = prim(ist_, true, config, ms_model); ASSERT(d, "[Error] divided by 0"); left /= d; break; @@ -211,19 +221,21 @@ } } - double Calculator::expr(istringstream& ist_, bool is_get_) + double Calculator::expr(istringstream& ist_, bool is_get_, + const map &config, + DSENT::Model *ms_model) { - double left = term(ist_, is_get_); + double left = term(ist_, is_get_, config, ms_model); while(1) { switch(m_curr_token_) { case PLUS: - left += term(ist_, true); + left += term(ist_, true, config, ms_model); break; case MINUS: - left -= term(ist_, true); + left -= term(ist_, true, config, ms_model); break; default: return left; @@ -231,9 +243,10 @@ } } - double Calculator::getEnvVar(const String& var_name_) const + double Calculator::getEnvVar(const String& var_name_, + const map &config, + DSENT::Model *ms_model) const { return m_var_.get(var_name_); } } // namespace LibUtil - diff -r 28fe13ecd030 -r 71de0404ef2e ext/dsent/libutil/Config.h --- a/ext/dsent/libutil/Config.h Thu Sep 18 16:32:03 2014 -0500 +++ b/ext/dsent/libutil/Config.h Thu Sep 18 16:33:29 2014 -0500 @@ -2,35 +2,14 @@ #define __LIBUTIL_CONFIG_H__ #include +#include -#include "Map.h" +#include "libutil/String.h" namespace LibUtil { - class Config : public StringMap - { - public: - Config(const String& delimiter_ = "=", const String& comment_ = "#", const String& sentry_ = "End"); - Config(const Config& config_); - virtual ~Config(); - - public: - // Make a copy of this instance - virtual Config* clone() const; - // Load the config from file - virtual void readFile(const String& filename_); - // Parse string and overwrite the Config instance if keys exist - virtual void readString(const String& str_); - - // Write or read map using standard IO - friend std::ostream& operator<<(std::ostream& ost_, const Config& config_); - friend std::istream& operator>>(std::istream& ist_, Config& config_); - - protected: - String mDelimiter; - String mComment; - String mSentry; - }; + // Load the config from file + void readFile(const char *filename_, std::map &config); } #endif // __LIBUTIL_CONFIG_H__ diff -r 28fe13ecd030 -r 71de0404ef2e ext/dsent/libutil/Config.cc --- a/ext/dsent/libutil/Config.cc Thu Sep 18 16:32:03 2014 -0500 +++ b/ext/dsent/libutil/Config.cc Thu Sep 18 16:33:29 2014 -0500 @@ -1,69 +1,23 @@ -#include "Config.h" - #include #include "Assert.h" +#include "Config.h" + +using namespace std; namespace LibUtil { - Config::Config(const String& delimiter_, const String& comment_, const String& sentry_) - : mDelimiter(delimiter_), mComment(comment_), mSentry(sentry_) - {} + void readFile(const char *filename_, map &config) + { + std::ifstream ist_(filename_); - Config::Config(const Config& config_) - : StringMap(config_) - { - mDelimiter = config_.mDelimiter; - mComment = config_.mComment; - mSentry = config_.mSentry; - } - - Config::~Config() - {} - - Config* Config::clone() const - { - return new Config(*this); - } - - void Config::readFile(const String& filename_) - { - std::ifstream fin(filename_.c_str()); - - ASSERT(fin, "File not found: " + filename_); - fin >> (*this); - return; - } - - void Config::readString(const String& str_) - { - String newString = str_; - newString.substitute(";", "\n"); - std::istringstream iss(newString, std::istringstream::in); - - iss >> (*this); - } - - std::ostream& operator<<(std::ostream& ost_, const Config& config_) - { - Config::ConstIterator it; - for(it = config_.begin(); it != config_.end(); it++) - { - ost_ << it->first << " " << config_.mDelimiter << " "; - ost_ << it->second << std::endl; - } - return ost_; - } - - std::istream& operator>>(std::istream& ist_, Config& config_) - { // Set a Config from ist_ // Read in keys and values, keeping internal whitespace typedef String::size_type pos; - const String& delim = config_.mDelimiter; // separator - const String& comm = config_.mComment; // comment - const String& sentry = config_.mSentry; // end of file sentry - const pos skip = delim.length(); // length of separator + const String& delimiter = "="; + const String& comment = "#"; + const String& sentry = "End"; + const pos skip = delimiter.length(); // length of separator String nextline = ""; // might need to read ahead to see where value ends @@ -83,17 +37,17 @@ } // Ignore comments and the spaces on both ends - line = line.substr(0, line.find(comm)); + line = line.substr(0, line.find(comment)); line.trim(); // Check for end of file sentry - if((sentry != "") && (line.find(sentry) != String::npos)) return ist_; + if((sentry != "") && (line.find(sentry) != String::npos)) return; if(line.length() == 0) continue; // Parse the line if it contains a delimiter - pos delimPos = line.find(delim); + pos delimPos = line.find(delimiter); ASSERT((delimPos < String::npos), "Invalid config line: '" + line + "'"); // Extract the key @@ -119,7 +73,7 @@ nlcopy.trim(); if(nlcopy == "") continue; - nextline = nextline.substr(0, nextline.find(comm)); + nextline = nextline.substr(0, nextline.find(comment)); //if(nextline.find(delim) != String::npos) // continue; if((sentry != "") && (nextline.find(sentry) != String::npos)) @@ -136,9 +90,8 @@ // Store key and value key.trim(); line.trim(); - config_.set(key, line); // overwrites if key is repeated + config[key] = line; // overwrites if key is repeated } - return ist_; } } diff -r 28fe13ecd030 -r 71de0404ef2e ext/dsent/libutil/Makefile --- a/ext/dsent/libutil/Makefile Thu Sep 18 16:32:03 2014 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,43 +0,0 @@ - -# Define the directories that will be compiled -DIRS_TO_COMPILE := . \ - -DIRS = $(patsubst %,$(CURDIR)/%,$(DIRS_TO_COMPILE)) - -SRCS = $(foreach dir, $(DIRS), $(wildcard $(dir)/*.cc)) - -OBJS = $(SRCS:%.cc=%.o) - -DEF_FLAGS = - -ifdef LIBUTIL_IS_LOG - LIBUTIL_IS_LOG = true -else - LIBUTIL_IS_LOG = false -endif -DEF_FLAGS += -DLIBUTIL_IS_LOG=$(LIBUTIL_IS_LOG) - -INCLUDE_FLAGS = $(foreach dir, $(DIRS), -I$(dir)) -OPT_FLAGS = -O2 -g -WARN_FLAGS = -pedantic -Wall -W -Wextra -Werror -CXXFLAGS = $(OPT_FLAGS) $(WARN_FLAGS) $(INCLUDE_FLAGS) $(DEF_FLAGS) - -TARGET = $(CURDIR)/libutil.a - -all: $(TARGET) - -$(TARGET): $(OBJS) - ar rcs $@ $^ -#$(TARGET): $(OBJS) -# $(CXX) $(CXXFLAGS) $^ -o $(TARGET) - -%.o: %.cc - $(CXX) $(CXXFLAGS) -c $< -o $@ - -%/created: - mkdir -p $(dir $@) - touch $@ - -clean: - $(RM) -rf $(OBJS) $(TARGET) - diff -r 28fe13ecd030 -r 71de0404ef2e ext/dsent/libutil/OptionParser.h --- a/ext/dsent/libutil/OptionParser.h Thu Sep 18 16:32:03 2014 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,57 +0,0 @@ -#ifndef __LIBUTIL_OPTION_PARSER_H__ -#define __LIBUTIL_OPTION_PARSER_H__ - -#include - -#include "Map.h" - -namespace LibUtil -{ - using std::vector; - - // Simple option parser - class OptionParser : public StringMap - { - private: - class OptionInfo - { - public: - OptionInfo(const String& var_name_, bool has_arg_, const String& arg_name_, bool has_default_arg_value_, const String& default_arg_value_, const String& description_); - ~OptionInfo(); - - public: - inline const String& getVarName() const { return m_var_name_; } - inline bool hasArg() const { return m_has_arg_; } - inline const String& getArgName() const { return m_arg_name_; } - inline bool hasDefaultArgValue() const { return m_has_default_arg_value_; } - inline const String& getDefaultArgValue() const { return m_default_arg_value_; } - inline const String& getDescription() const { return m_description_; } - - private: - String m_var_name_; - bool m_has_arg_; - String m_arg_name_; - bool m_has_default_arg_value_; - String m_default_arg_value_; - String m_description_; - }; // class Option - - public: - OptionParser(); - virtual ~OptionParser(); - - public: - void addOption(const String& option_name_, const String& var_name_, bool has_arg_, const String& arg_name_, bool has_default_arg_value_, const String& default_arg_value_, const String& description_); - - void parseArguments(int argc_, char** argv_); - - void printOptions() const; - - protected: - vector m_option_names_; - Map m_option_infos_; - }; // class OptionParser -} // LibUtil - -#endif // __LIBUTIL_OPTION_PARSER_H__ - diff -r 28fe13ecd030 -r 71de0404ef2e ext/dsent/libutil/OptionParser.cc --- a/ext/dsent/libutil/OptionParser.cc Thu Sep 18 16:32:03 2014 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,177 +0,0 @@ -#include "OptionParser.h" - -#include -#include - -namespace LibUtil -{ - using std::cout; - using std::cerr; - using std::endl; - - OptionParser::OptionInfo::OptionInfo( - const String& var_name_, - bool has_arg_, - const String& arg_name_, - bool has_default_arg_value_, - const String& default_arg_value_, - const String& description_ - ) - : m_var_name_(var_name_), - m_has_arg_(has_arg_), - m_arg_name_(arg_name_), - m_has_default_arg_value_(has_default_arg_value_), - m_default_arg_value_(default_arg_value_), - m_description_(description_) - {} - - OptionParser::OptionInfo::~OptionInfo() - { - } - - OptionParser::OptionParser() - {} - - OptionParser::~OptionParser() - { - clearPtrMap(&m_option_infos_); - } - - void OptionParser::addOption( - const String& option_name_, - const String& var_name_, - bool has_arg_, - const String& arg_name_, - bool has_default_arg_value_, - const String& default_arg_value_, - const String& description_) - { - OptionInfo* option_info = new OptionInfo(var_name_, has_arg_, arg_name_, - has_default_arg_value_, default_arg_value_, description_); - - ASSERT(!m_option_infos_.keyExist(option_name_), "Option exists: " + option_name_); - - // Add the option name to an array for sorting - m_option_names_.push_back(option_name_); - - // Add option info - m_option_infos_.set(option_name_, option_info); - - // Set the default argument value - if(has_default_arg_value_) - { - set(var_name_, default_arg_value_); - } - - return; - } - - void OptionParser::parseArguments(int argc_, char** argv_) - { - bool is_print_options = false; - int arg_idx = 0; - - while(arg_idx < argc_) - { - String option_name = String(argv_[arg_idx]); - - // Print the options page if -help is specified - if(option_name == "-help") - { - is_print_options = true; - break; - } - else if(m_option_infos_.keyExist(option_name)) - { - const OptionInfo* option_info = m_option_infos_.get(option_name); - const String& var_name = option_info->getVarName(); - if(option_info->hasArg()) - { - if((arg_idx + 1) >= argc_) - { - cerr << "[Error] Missing argument for option: '" << option_name << "'" << endl; - is_print_options = true; - break; - } - - String option_arg = String(argv_[arg_idx + 1]); - set(var_name, option_arg); - - arg_idx += 2; - } - else - { - // If the option does not require an argument - // then set it to true - set(var_name, "true"); - - arg_idx += 1; - } - } - else - { - cerr << "[Error] Unknown option: '" << option_name << "'" << endl; - is_print_options = true; - break; - } - } - - // Check if all required options are set (the ones without default values) - vector::const_iterator it; - for(it = m_option_names_.begin(); it != m_option_names_.end(); ++it) - { - const String& option_name = *it; - const OptionInfo* option_info = m_option_infos_.get(option_name); - - if(!option_info->hasDefaultArgValue()) - { - const String& var_name = option_info->getVarName(); - if(!keyExist(var_name)) - { - cerr << "[Error] Missing required option: '" << option_name << "'" << endl; - is_print_options = true; - } - } - } - - if(is_print_options) - { - printOptions(); - exit(0); - } - return; - } - - void OptionParser::printOptions() const - { - cout << endl; - cout << "Available options:" << endl; - cout << "==================" << endl << endl; - - vector::const_iterator it; - for(it = m_option_names_.begin(); it != m_option_names_.end(); ++it) - { - const String& option_name = *it; - const OptionInfo* option_info = m_option_infos_.get(option_name); - - cout << option_name; - if(option_info->hasArg()) - { - cout << " <" << option_info->getArgName() << ">"; - } - cout << endl; - - cout << " " << option_info->getDescription() << endl; - if(option_info->hasArg() && option_info->hasDefaultArgValue()) - { - cout << " " << "Default: " << option_info->getDefaultArgValue() << endl; - } - cout << endl; - } - cout << "-help" << endl; - cout << " " << "Print this page" << endl; - cout << endl; - return; - } - -} // namespace LibUtil diff -r 28fe13ecd030 -r 71de0404ef2e ext/dsent/main.cc --- a/ext/dsent/main.cc Thu Sep 18 16:32:03 2014 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,10 +0,0 @@ - -#include "DSENT.h" - -int main(int argc, char** argv) -{ - DSENT::DSENT::run(argc-1, argv+1); - - return 0; -} - diff -r 28fe13ecd030 -r 71de0404ef2e ext/dsent/tech/TechModel.h --- a/ext/dsent/tech/TechModel.h Thu Sep 18 16:32:03 2014 -0500 +++ b/ext/dsent/tech/TechModel.h Thu Sep 18 16:33:29 2014 -0500 @@ -15,7 +15,7 @@ using std::vector; using LibUtil::String; - class TechModel : public LibUtil::Config + class TechModel { public: typedef std::set::const_iterator ConstWireLayerIterator; @@ -25,6 +25,9 @@ virtual ~TechModel(); public: + // Get the value_ corresponding to the key_ + const String& get(const String& key_) const; + // Set the pointer to a standard cell library void setStdCellLib(const StdCellLib* std_cell_lib_); // Get the pointer to the standard cell library @@ -64,8 +67,9 @@ const StdCellLib* m_std_cell_lib_; // A set of available wire layers std::set* m_available_wire_layers_; + // A map of model's parameters + std::map params; }; // class TechModel } // namespace DSENT #endif // __DSENT_TECH_TECH_MODEL_H__ - diff -r 28fe13ecd030 -r 71de0404ef2e ext/dsent/tech/TechModel.cc --- a/ext/dsent/tech/TechModel.cc Thu Sep 18 16:32:03 2014 -0500 +++ b/ext/dsent/tech/TechModel.cc Thu Sep 18 16:33:29 2014 -0500 @@ -7,12 +7,17 @@ namespace DSENT { TechModel::TechModel() - : Config(), m_std_cell_lib_(NULL), m_available_wire_layers_(NULL) + : m_std_cell_lib_(NULL), m_available_wire_layers_(NULL) {} TechModel::~TechModel() {} + const String& TechModel::get(const String &key_) const + { + return params.at(key_); + } + void TechModel::setStdCellLib(const StdCellLib* std_cell_lib_) { m_std_cell_lib_ = std_cell_lib_; @@ -32,17 +37,16 @@ void TechModel::readFile(const String& filename_) { // Read the main technology file - LibUtil::Config::readFile(filename_); + LibUtil::readFile(filename_, params); // Search for "INCLUDE" to include more technology files - StringMap::ConstIterator it; - for(it = begin(); it != end(); ++it) + for (const auto &it : params) { - const String& key = it->first; + const String& key = it.first; if(key.compare(0, 8, "INCLUDE_") == 0) { - const String& include_filename = it->second; - LibUtil::Config::readFile(include_filename); + const String& include_filename = it.second; + LibUtil::readFile(include_filename, params); } } @@ -53,7 +57,6 @@ { m_available_wire_layers_->insert(available_wire_layer_vector[i]); } - return; } //------------------------------------------------------------------------- @@ -314,7 +317,7 @@ //------------------------------------------------------------------------- TechModel::TechModel(const TechModel& tech_model_) - : Config(tech_model_), m_std_cell_lib_(tech_model_.m_std_cell_lib_) + : m_std_cell_lib_(tech_model_.m_std_cell_lib_), + params(tech_model_.params) {} } // namespace DSENT - diff -r 28fe13ecd030 -r 71de0404ef2e ext/dsent/util/Config.h --- a/ext/dsent/util/Config.h Thu Sep 18 16:32:03 2014 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,40 +0,0 @@ -#ifndef __DSENT_UTIL_CONFIG_H__ -#define __DSENT_UTIL_CONFIG_H__ - -#include "util/CommonType.h" - -namespace DSENT -{ - class TechModel; - class StdCellLib; - - class Config : public LibUtil::Config - { - public: - static void allocate(const String& cfg_file_name_); - static void release(); - static Config* getSingleton(); - - protected: - static Config* ms_singleton_; - - public: - Config(); - ~Config(); - - public: - void setTechModel(const TechModel* tech_model_); - const TechModel* getTechModel() const; - - void constructTechModel(const String& overwrite_str_); - - protected: - void readFile(const String& file_name_); - - protected: - const TechModel* m_tech_model_; - }; // class Config -} // namespace DSENT - -#endif // __DSENT_UTIL_CONFIG_H__ - diff -r 28fe13ecd030 -r 71de0404ef2e ext/dsent/util/Config.cc --- a/ext/dsent/util/Config.cc Thu Sep 18 16:32:03 2014 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,105 +0,0 @@ -#include "util/Config.h" - -#include "model/std_cells/StdCellLib.h" - -namespace DSENT -{ - - Config* Config::ms_singleton_ = NULL; - - void Config::allocate(const String& cfg_file_name_) - { - Log::printLine("Config::allocate"); - - // Allocate static Config instance - ASSERT(!ms_singleton_, "Config singleton is allocated"); - ms_singleton_ = new Config(); - ms_singleton_->readFile(cfg_file_name_); - - Log::printLine("Config::allocate - End"); - return; - } - - void Config::release() - { - Log::printLine("Config::release"); - - // Release static Config instance - ASSERT(ms_singleton_, "Config singleton is not allocated"); - delete ms_singleton_; - ms_singleton_ = NULL; - - Log::printLine("Config::release - End"); - return; - } - - Config* Config::getSingleton() - { - ASSERT(ms_singleton_, "Config singleton is not allocated"); - return ms_singleton_; - } - - Config::Config() - : m_tech_model_(NULL) - {} - - Config::~Config() - { - delete m_tech_model_; - } - - void Config::setTechModel(const TechModel* tech_model_) - { - ASSERT((tech_model_ != NULL), "tech_model_ is null"); - - m_tech_model_ = tech_model_; - return; - } - - const TechModel* Config::getTechModel() const - { - ASSERT((m_tech_model_ != NULL), "m_tech_model_ is null"); - - return m_tech_model_; - } - - void Config::readFile(const String& file_name_) - { - Log::printLine("Config::readFile"); - - LibUtil::Config::readFile(file_name_); - - Log::printLine("Config::readFile - End"); - return; - } - - void Config::constructTechModel(const String& overwrite_str_) - { - Log::printLine("Config::constructTechModel"); - - // Allocate static TechModel instance - const String& electrical_tech_model_filename = get("ElectricalTechModelFilename"); - - TechModel* tech_model = new TechModel(); - tech_model->readFile(electrical_tech_model_filename); - if(keyExist("PhotonicTechModelFilename")) - { - const String& photonic_tech_model_filename = get("PhotonicTechModelFilename"); - tech_model->readFile(photonic_tech_model_filename); - } - - // Overwrite the settings at runtime - tech_model->readString(overwrite_str_); - - // Allocate static StdCellLib instance - StdCellLib* std_cell_lib = new StdCellLib(tech_model); - - // Set the StdCellLib pointer in static TechModel instance - tech_model->setStdCellLib(std_cell_lib); - - m_tech_model_ = tech_model; - Log::printLine("Config::constructTechModel - End"); - return; - } -} // namespace DSENT -