[OpenFPGA Tool] Bug fix for long runtime

This commit is contained in:
tangxifan 2020-09-28 20:42:18 -06:00
parent 47f3c79927
commit e179a58b15
6 changed files with 22 additions and 47 deletions

View File

@ -122,7 +122,6 @@ int build_fabric(OpenfpgaContext& openfpga_ctx,
VTR_ASSERT(false == fkey_fname.empty()); VTR_ASSERT(false == fkey_fname.empty());
curr_status = write_fabric_key_to_xml_file(openfpga_ctx.module_graph(), curr_status = write_fabric_key_to_xml_file(openfpga_ctx.module_graph(),
fkey_fname, fkey_fname,
openfpga_ctx.arch().config_protocol.type(),
cmd_context.option_enable(cmd, opt_verbose)); cmd_context.option_enable(cmd, opt_verbose));
/* If there is any error, final status cannot be overwritten by a success flag */ /* If there is any error, final status cannot be overwritten by a success flag */
if (CMD_EXEC_SUCCESS != curr_status) { if (CMD_EXEC_SUCCESS != curr_status) {

View File

@ -221,6 +221,8 @@ void build_top_module_configurable_regions(ModuleManager& module_manager,
const ModuleId& top_module, const ModuleId& top_module,
const ConfigProtocol& config_protocol) { const ConfigProtocol& config_protocol) {
vtr::ScopedStartFinishTimer timer("Build configurable regions for the top module");
/* Ensure we have valid configurable children */ /* Ensure we have valid configurable children */
VTR_ASSERT(false == module_manager.configurable_children(top_module).empty()); VTR_ASSERT(false == module_manager.configurable_children(top_module).empty());
@ -240,7 +242,7 @@ void build_top_module_configurable_regions(ModuleManager& module_manager,
size_t region_child_counter = 0; size_t region_child_counter = 0;
bool create_region = true; bool create_region = true;
ConfigRegionId curr_region = ConfigRegionId::INVALID(); ConfigRegionId curr_region = ConfigRegionId::INVALID();
for (size_t ichild = 0; ichild < num_configurable_children; ++ichild) { for (size_t ichild = 0; ichild < module_manager.configurable_children(top_module).size(); ++ichild) {
if (true == create_region) { if (true == create_region) {
curr_region = module_manager.add_config_region(top_module); curr_region = module_manager.add_config_region(top_module);
} }
@ -249,7 +251,8 @@ void build_top_module_configurable_regions(ModuleManager& module_manager,
module_manager.add_configurable_child_to_region(top_module, module_manager.add_configurable_child_to_region(top_module,
curr_region, curr_region,
module_manager.configurable_children(top_module)[ichild], module_manager.configurable_children(top_module)[ichild],
module_manager.configurable_child_instances(top_module)[ichild]); module_manager.configurable_child_instances(top_module)[ichild],
ichild);
/* See if the current region is full or not: /* See if the current region is full or not:
* For the last region, we will keep adding until we finish all the children * For the last region, we will keep adding until we finish all the children
@ -262,6 +265,9 @@ void build_top_module_configurable_regions(ModuleManager& module_manager,
region_child_counter = 0; region_child_counter = 0;
} }
} }
/* Ensure that the number of configurable regions created matches the definition */
VTR_ASSERT((size_t)config_protocol.num_regions() == module_manager.regions(top_module).size());
} }
/******************************************************************** /********************************************************************
@ -500,7 +506,8 @@ void shuffle_top_module_configurable_children(ModuleManager& module_manager,
orig_configurable_child_instances[shuffled_keys[ikey]]); orig_configurable_child_instances[shuffled_keys[ikey]]);
} }
/* Split memory modules into different regions */ /* Reset configurable regions */
module_manager.clear_config_region(top_module);
build_top_module_configurable_regions(module_manager, top_module, config_protocol); build_top_module_configurable_regions(module_manager, top_module, config_protocol);
} }
@ -520,6 +527,8 @@ int load_top_module_memory_modules_from_fabric_key(ModuleManager& module_manager
/* Ensure a clean start */ /* Ensure a clean start */
module_manager.clear_configurable_children(top_module); module_manager.clear_configurable_children(top_module);
size_t curr_configurable_child_id = 0;
for (const FabricRegionId& region : fabric_key.regions()) { for (const FabricRegionId& region : fabric_key.regions()) {
/* Create a configurable region in the top module */ /* Create a configurable region in the top module */
ConfigRegionId top_module_config_region = module_manager.add_config_region(top_module); ConfigRegionId top_module_config_region = module_manager.add_config_region(top_module);
@ -572,7 +581,9 @@ int load_top_module_memory_modules_from_fabric_key(ModuleManager& module_manager
module_manager.add_configurable_child_to_region(top_module, module_manager.add_configurable_child_to_region(top_module,
top_module_config_region, top_module_config_region,
instance_info.first, instance_info.first,
instance_info.second); instance_info.second,
curr_configurable_child_id);
curr_configurable_child_id++;
} }
} }

View File

@ -29,7 +29,6 @@ namespace openfpga {
***************************************************************************************/ ***************************************************************************************/
int write_fabric_key_to_xml_file(const ModuleManager& module_manager, int write_fabric_key_to_xml_file(const ModuleManager& module_manager,
const std::string& fname, const std::string& fname,
const e_config_protocol_type& config_protocol_type,
const bool& verbose) { const bool& verbose) {
std::string timer_message = std::string("Write fabric key to XML file '") + fname + std::string("'"); std::string timer_message = std::string("Write fabric key to XML file '") + fname + std::string("'");
@ -58,13 +57,6 @@ int write_fabric_key_to_xml_file(const ModuleManager& module_manager,
FabricKey fabric_key; FabricKey fabric_key;
size_t num_keys = module_manager.configurable_children(top_module).size(); size_t num_keys = module_manager.configurable_children(top_module).size();
/* Exclude configuration-related modules in the keys */
if (CONFIG_MEM_MEMORY_BANK == config_protocol_type) {
num_keys -= 2;
} else if (CONFIG_MEM_FRAME_BASED == config_protocol_type) {
num_keys -= 1;
}
fabric_key.reserve_keys(num_keys); fabric_key.reserve_keys(num_keys);
size_t num_regions = module_manager.regions(top_module).size(); size_t num_regions = module_manager.regions(top_module).size();
@ -75,7 +67,7 @@ int write_fabric_key_to_xml_file(const ModuleManager& module_manager,
FabricRegionId fabric_region = fabric_key.create_region(); FabricRegionId fabric_region = fabric_key.create_region();
fabric_key.reserve_region_keys(fabric_region, module_manager.region_configurable_children(top_module, config_region).size()); fabric_key.reserve_region_keys(fabric_region, module_manager.region_configurable_children(top_module, config_region).size());
for (size_t ichild = 0; ichild < num_keys; ++ichild) { for (size_t ichild = 0; ichild < module_manager.region_configurable_children(top_module, config_region).size(); ++ichild) {
ModuleId child_module = module_manager.region_configurable_children(top_module, config_region)[ichild]; ModuleId child_module = module_manager.region_configurable_children(top_module, config_region)[ichild];
size_t child_instance = module_manager.region_configurable_child_instances(top_module, config_region)[ichild]; size_t child_instance = module_manager.region_configurable_child_instances(top_module, config_region)[ichild];

View File

@ -16,7 +16,6 @@ namespace openfpga {
int write_fabric_key_to_xml_file(const ModuleManager& module_manager, int write_fabric_key_to_xml_file(const ModuleManager& module_manager,
const std::string& fname, const std::string& fname,
const e_config_protocol_type& config_protocol_type,
const bool& verbose); const bool& verbose);
} /* end namespace openfpga */ } /* end namespace openfpga */

View File

@ -737,31 +737,16 @@ ConfigRegionId ModuleManager::add_config_region(const ModuleId& module) {
void ModuleManager::add_configurable_child_to_region(const ModuleId& parent_module, void ModuleManager::add_configurable_child_to_region(const ModuleId& parent_module,
const ConfigRegionId& config_region, const ConfigRegionId& config_region,
const ModuleId& child_module, const ModuleId& child_module,
const size_t& child_instance) { const size_t& child_instance,
const size_t& config_child_id) {
/* Validate the module id */ /* Validate the module id */
VTR_ASSERT ( valid_module_id(parent_module) ); VTR_ASSERT ( valid_module_id(parent_module) );
VTR_ASSERT ( valid_module_id(child_module) ); VTR_ASSERT ( valid_module_id(child_module) );
VTR_ASSERT ( valid_region_id(parent_module, config_region) ); VTR_ASSERT ( valid_region_id(parent_module, config_region) );
/* Ensure that the child module is in the configurable children list */ /* Ensure that the child module is in the configurable children list */
size_t config_child_id = configurable_children(parent_module).size(); VTR_ASSERT(child_module == configurable_children(parent_module)[config_child_id]);
for (size_t ichild = 0; ichild < configurable_children(parent_module).size(); ++ichild) { VTR_ASSERT(child_instance == configurable_child_instances(parent_module)[config_child_id]);
if ( (child_module == configurable_children(parent_module)[ichild])
&& (child_instance == configurable_child_instances(parent_module)[ichild]) ) {
config_child_id = ichild;
break;
}
}
/* Error out as the child is not valid */
if (config_child_id == configurable_children(parent_module).size()) {
VTR_LOGF_ERROR(__FILE__, __LINE__,
"Try to add an invalid configurable child '%s[%lu]' to region '%lu'!\n",
module_name(child_module).c_str(),
child_instance,
size_t(config_region));
exit(1);
}
/* If the child is already in another region, error out */ /* If the child is already in another region, error out */
if ( (true == valid_region_id(parent_module, configurable_child_regions_[parent_module][config_child_id])) if ( (true == valid_region_id(parent_module, configurable_child_regions_[parent_module][config_child_id]))
@ -775,18 +760,6 @@ void ModuleManager::add_configurable_child_to_region(const ModuleId& parent_modu
exit(1); exit(1);
} }
/* Ensure that the child is not in the list */
if (config_region_children_[parent_module][config_region].end() != std::find(config_region_children_[parent_module][config_region].begin(),
config_region_children_[parent_module][config_region].end(),
config_child_id)) {
VTR_LOGF_ERROR(__FILE__, __LINE__,
"The configurable child '%s[%lu]' is already in the region '%lu'! Skip adding\n",
module_name(child_module).c_str(),
child_instance,
size_t(config_region));
return;
}
/* Passed all the checks, add the child to the region */ /* Passed all the checks, add the child to the region */
config_region_children_[parent_module][config_region].push_back(config_child_id); config_region_children_[parent_module][config_region].push_back(config_child_id);
} }

View File

@ -263,7 +263,8 @@ class ModuleManager {
void add_configurable_child_to_region(const ModuleId& parent_module, void add_configurable_child_to_region(const ModuleId& parent_module,
const ConfigRegionId& config_region, const ConfigRegionId& config_region,
const ModuleId& child_module, const ModuleId& child_module,
const size_t& child_instance); const size_t& child_instance,
const size_t& config_child_id);
/* Reserved a number of module nets for a given module /* Reserved a number of module nets for a given module
* for memory efficiency * for memory efficiency