diff --git a/openfpga/src/annotation/device_rr_gsb.cpp b/openfpga/src/annotation/device_rr_gsb.cpp index c044ffebf..ced7e6b9d 100644 --- a/openfpga/src/annotation/device_rr_gsb.cpp +++ b/openfpga/src/annotation/device_rr_gsb.cpp @@ -96,6 +96,80 @@ size_t DeviceRRGSB::get_num_sb_unique_module() const { return sb_unique_module_.size(); } +vtr::Point DeviceRRGSB::get_sb_unique_block_coord(size_t id) const { + return sb_unique_module_[id]; +} + +std::vector> DeviceRRGSB::get_sb_unique_block_instance_coord( + const vtr::Point& unique_block_coord) const { + auto unique_module_id = + sb_unique_module_id_[unique_block_coord.x()][unique_block_coord.y()]; + std::vector> instance_map; + for (size_t location_x = 0; location_x < sb_unique_module_id_.size(); + ++location_x) { + for (size_t location_y = 0; location_y < sb_unique_module_id_[0].size(); + ++location_y) { + auto unique_module_id_instance = + sb_unique_module_id_[location_x][location_y]; + if (unique_module_id_instance == unique_module_id) { + vtr::Point instance_coord(location_x, location_y); + instance_map.push_back(instance_coord); + } + } + } + return instance_map; +} + +vtr::Point DeviceRRGSB::get_cbx_unique_block_coord(size_t id) const { + return cbx_unique_module_[id]; +} + +std::vector> +DeviceRRGSB::get_cbx_unique_block_instance_coord( + const vtr::Point& unique_block_coord) const { + auto unique_module_id = + cbx_unique_module_id_[unique_block_coord.x()][unique_block_coord.y()]; + std::vector> instance_map; + for (size_t location_x = 0; location_x < cbx_unique_module_id_.size(); + ++location_x) { + for (size_t location_y = 0; location_y < cbx_unique_module_id_[0].size(); + ++location_y) { + auto unique_module_id_instance = + cbx_unique_module_id_[location_x][location_y]; + if (unique_module_id_instance == unique_module_id) { + vtr::Point instance_coord(location_x, location_y); + instance_map.push_back(instance_coord); + } + } + } + return instance_map; +} + +vtr::Point DeviceRRGSB::get_cby_unique_block_coord(size_t id) const { + return cby_unique_module_[id]; +} + +std::vector> +DeviceRRGSB::get_cby_unique_block_instance_coord( + const vtr::Point& unique_block_coord) const { + auto unique_module_id = + cby_unique_module_id_[unique_block_coord.x()][unique_block_coord.y()]; + std::vector> instance_map; + for (size_t location_x = 0; location_x < cby_unique_module_id_.size(); + ++location_x) { + for (size_t location_y = 0; location_y < cby_unique_module_id_[0].size(); + ++location_y) { + auto unique_module_id_instance = + cby_unique_module_id_[location_x][location_y]; + if (unique_module_id_instance == unique_module_id) { + vtr::Point instance_coord(location_x, location_y); + instance_map.push_back(instance_coord); + } + } + } + return instance_map; +} + /* get the number of unique mirrors of switch blocks */ size_t DeviceRRGSB::get_num_gsb_unique_module() const { return gsb_unique_module_.size(); @@ -173,8 +247,8 @@ void DeviceRRGSB::reserve(const vtr::Point& coordinate) { } } void DeviceRRGSB::reserve_unique_modules() { - /* As rr_gsb_ has been built, it has valid size. Will reserve space for unique - * blocks according to rr_gsb_'s size*/ + /* As rr_gsb_ has been built, it has valid size. Will reserve space for + * unique blocks according to rr_gsb_'s size*/ sb_unique_module_id_.resize(rr_gsb_.size()); cbx_unique_module_id_.resize(rr_gsb_.size()); cby_unique_module_id_.resize(rr_gsb_.size()); @@ -206,8 +280,8 @@ void DeviceRRGSB::resize_upon_need(const vtr::Point& coordinate) { } } -/* Add a switch block to the array, which will automatically identify and update - * the lists of unique mirrors and rotatable mirrors */ +/* Add a switch block to the array, which will automatically identify and + * update the lists of unique mirrors and rotatable mirrors */ void DeviceRRGSB::add_rr_gsb(const vtr::Point& coordinate, const RRGSB& rr_gsb) { /* Resize upon needs*/ @@ -229,8 +303,8 @@ RRGSB& DeviceRRGSB::get_mutable_gsb(const size_t& x, const size_t& y) { return get_mutable_gsb(coordinate); } -/* Add a switch block to the array, which will automatically identify and update - * the lists of unique mirrors and rotatable mirrors */ +/* Add a switch block to the array, which will automatically identify and + * update the lists of unique mirrors and rotatable mirrors */ void DeviceRRGSB::build_cb_unique_module(const RRGraphView& rr_graph, const t_rr_type& cb_type) { /* Make sure a clean start */ @@ -246,7 +320,8 @@ void DeviceRRGSB::build_cb_unique_module(const RRGraphView& rr_graph, continue; } - /* Traverse the unique_mirror list and check it is an mirror of another */ + /* Traverse the unique_mirror list and check it is an mirror of another + */ for (size_t id = 0; id < get_num_cb_unique_module(cb_type); ++id) { const RRGSB& unique_module = get_cb_unique_module(cb_type, id); if (true == is_cb_mirror(rr_graph, device_annotation_, rr_gsb_[ix][iy], @@ -269,8 +344,8 @@ void DeviceRRGSB::build_cb_unique_module(const RRGraphView& rr_graph, } } -/* Add a switch block to the array, which will automatically identify and update - * the lists of unique mirrors and rotatable mirrors */ +/* Add a switch block to the array, which will automatically identify and + * update the lists of unique mirrors and rotatable mirrors */ void DeviceRRGSB::build_sb_unique_module(const RRGraphView& rr_graph) { /* Make sure a clean start */ clear_sb_unique_module(); @@ -281,7 +356,8 @@ void DeviceRRGSB::build_sb_unique_module(const RRGraphView& rr_graph) { bool is_unique_module = true; vtr::Point sb_coordinate(ix, iy); - /* Traverse the unique_mirror list and check it is an mirror of another */ + /* Traverse the unique_mirror list and check it is an mirror of another + */ for (size_t id = 0; id < get_num_sb_unique_module(); ++id) { /* Check if the two modules have the same submodules, * if so, these two modules are the same, indicating the sb is not @@ -308,8 +384,8 @@ void DeviceRRGSB::build_sb_unique_module(const RRGraphView& rr_graph) { } } -/* Add a switch block to the array, which will automatically identify and update - * the lists of unique mirrors and rotatable mirrors */ +/* Add a switch block to the array, which will automatically identify and + * update the lists of unique mirrors and rotatable mirrors */ /* Find repeatable GSB block in the array */ void DeviceRRGSB::build_gsb_unique_module() { @@ -321,11 +397,12 @@ void DeviceRRGSB::build_gsb_unique_module() { bool is_unique_module = true; vtr::Point gsb_coordinate(ix, iy); - /* Traverse the unique_mirror list and check it is an mirror of another */ + /* Traverse the unique_mirror list and check it is an mirror of another + */ for (size_t id = 0; id < get_num_gsb_unique_module(); ++id) { /* We have alreay built sb and cb unique module list - * We just need to check if the unique module id of SBs, CBX and CBY are - * the same or not + * We just need to check if the unique module id of SBs, CBX and CBY + * are the same or not */ const vtr::Point& gsb_unique_module_coordinate = gsb_unique_module_[id]; @@ -650,79 +727,4 @@ void DeviceRRGSB::preload_unique_sb_module( sb_unique_module_id_[block_coordinate.x()][block_coordinate.y()]; } } - -/*The following four functions will allow us to get -The map between (id,mirror instance coord), (id, unique block coord) -As the unique block and its mirror instances share the same id, we can get the -map between (unique block coord, mirror instance coord) -*/ -void DeviceRRGSB::get_id_unique_sb_block_map( - std::map>& id_unique_block_map) const { - for (size_t id = 0; id < get_num_sb_unique_module(); ++id) { - const auto& unique_block_coord = sb_unique_module_[id]; - auto unique_module_id = - sb_unique_module_id_[unique_block_coord.x()][unique_block_coord.y()]; - id_unique_block_map[unique_module_id] = unique_block_coord; - } -} - -void DeviceRRGSB::get_id_sb_instance_map( - std::map>>& id_instance_map) const { - for (size_t location_x = 0; location_x < sb_unique_module_id_.size(); - ++location_x) { - for (size_t location_y = 0; location_y < sb_unique_module_id_[0].size(); - ++location_y) { - auto unique_module_id = sb_unique_module_id_[location_x][location_y]; - vtr::Point instance_coord(location_x, location_y); - id_instance_map[unique_module_id].push_back(instance_coord); - } - } -} - -void DeviceRRGSB::get_id_unique_cbx_block_map( - std::map>& id_unique_block_map) const { - for (size_t id = 0; id < get_num_cb_unique_module(CHANX); ++id) { - const auto& unique_block_coord = cbx_unique_module_[id]; - auto unique_module_id = - cbx_unique_module_id_[unique_block_coord.x()][unique_block_coord.y()]; - id_unique_block_map[unique_module_id] = unique_block_coord; - } -} - -void DeviceRRGSB::get_id_cbx_instance_map( - std::map>>& id_instance_map) const { - for (size_t location_x = 0; location_x < cbx_unique_module_id_.size(); - ++location_x) { - for (size_t location_y = 0; location_y < cbx_unique_module_id_[0].size(); - ++location_y) { - auto unique_module_id = cbx_unique_module_id_[location_x][location_y]; - vtr::Point instance_coord(location_x, location_y); - id_instance_map[unique_module_id].push_back(instance_coord); - } - } -} - -void DeviceRRGSB::get_id_unique_cby_block_map( - std::map>& id_unique_block_map) const { - for (size_t id = 0; id < get_num_cb_unique_module(CHANY); ++id) { - const auto& unique_block_coord = cby_unique_module_[id]; - auto unique_module_id = - cby_unique_module_id_[unique_block_coord.x()][unique_block_coord.y()]; - id_unique_block_map[unique_module_id] = unique_block_coord; - } -} - -void DeviceRRGSB::get_id_cby_instance_map( - std::map>>& id_instance_map) const { - for (size_t location_x = 0; location_x < cby_unique_module_id_.size(); - ++location_x) { - for (size_t location_y = 0; location_y < cby_unique_module_id_[0].size(); - ++location_y) { - auto unique_module_id = cby_unique_module_id_[location_x][location_y]; - vtr::Point instance_coord(location_x, location_y); - id_instance_map[unique_module_id].push_back(instance_coord); - } - } -} - } /* End namespace openfpga*/ diff --git a/openfpga/src/annotation/device_rr_gsb.h b/openfpga/src/annotation/device_rr_gsb.h index b042fe689..e40a81892 100644 --- a/openfpga/src/annotation/device_rr_gsb.h +++ b/openfpga/src/annotation/device_rr_gsb.h @@ -43,8 +43,19 @@ class DeviceRRGSB { const vtr::Point& coordinate) const; size_t get_num_gsb_unique_module() const; /* get the number of unique mirrors of GSB */ - size_t get_num_sb_unique_module() - const; /* get the number of unique mirrors of switch blocks */ + + size_t get_num_sb_unique_module() const; + vtr::Point get_sb_unique_block_coord(size_t id) const; + std::vector> get_sb_unique_block_instance_coord( + const vtr::Point& unique_block_coord) const; + + vtr::Point get_cbx_unique_block_coord(size_t id) const; + std::vector> get_cbx_unique_block_instance_coord( + const vtr::Point& unique_block_coord) const; + vtr::Point get_cby_unique_block_coord(size_t id) const; + std::vector> get_cby_unique_block_instance_coord( + const vtr::Point& unique_block_coord) const; + const RRGSB& get_gsb_unique_module( const size_t& index) const; /* Get a rr-gsb which is a unique mirror */ const RRGSB& get_sb_unique_module(const size_t& index) @@ -107,18 +118,6 @@ class DeviceRRGSB { const vtr::Point& block_coordinate, const std::vector>& instance_coords); void clear_unique_modules(); - void get_id_sb_instance_map( - std::map>>& id_instance_map) const; - void get_id_unique_sb_block_map( - std::map>& id_unique_block_map) const; - void get_id_cbx_instance_map( - std::map>>& id_instance_map) const; - void get_id_unique_cbx_block_map( - std::map>& id_unique_block_map) const; - void get_id_cby_instance_map( - std::map>>& id_instance_map) const; - void get_id_unique_cby_block_map( - std::map>& id_unique_block_map) const; private: /* Internal cleaners */ void clear_gsb(); /* clean the content */ diff --git a/openfpga/src/annotation/write_xml_unique_blocks.cpp b/openfpga/src/annotation/write_xml_unique_blocks.cpp index 65c69e355..3550af531 100644 --- a/openfpga/src/annotation/write_xml_unique_blocks.cpp +++ b/openfpga/src/annotation/write_xml_unique_blocks.cpp @@ -32,45 +32,41 @@ * instance is the mirror of unique module. *******************************************************************/ namespace openfpga { - -int write_xml_block( - std::map>& id_unique_block_map, - std::map>>& id_instance_map, - std::fstream& fp, std::string type) { - /* Validate the file stream */ +int write_xml_atom_block(std::fstream& fp, + const std::vector>& instance_map, + const vtr::Point& unique_block_coord, + std::string type) { if (false == openfpga::valid_file_stream(fp)) { return CMD_EXEC_FATAL_ERROR; } - for (const auto& pair : id_unique_block_map) { - openfpga::write_tab_to_file(fp, 1); - fp << "" - << "\n"; + openfpga::write_tab_to_file(fp, 1); + fp << "" + << "\n"; - fp << "/>" - << "\n"; - } + for (const auto& instance_info : instance_map) { + if (instance_info.x() == unique_block_coord.x() && + instance_info.y() == unique_block_coord.y()) { + ; + } else { + openfpga::write_tab_to_file(fp, 2); + fp << "" + << "\n"; } - openfpga::write_tab_to_file(fp, 1); - fp << "" - << "\n"; } - - return CMD_EXEC_SUCCESS; + openfpga::write_tab_to_file(fp, 1); + fp << "" + << "\n"; + return openfpga::CMD_EXEC_SUCCESS; } void report_unique_module_status_write(const DeviceRRGSB& device_rr_gsb, @@ -139,24 +135,45 @@ int write_xml_unique_blocks(const DeviceRRGSB& device_rr_gsb, const char* fname, fp << "" << "\n"; - int err_code = 0; - std::map> id_unique_block_map; - std::map>> id_instance_map; - device_rr_gsb.get_id_unique_sb_block_map(id_unique_block_map); - device_rr_gsb.get_id_sb_instance_map(id_instance_map); - err_code += write_xml_block(id_unique_block_map, id_instance_map, fp, "sb"); + for (size_t id = 0; id < device_rr_gsb.get_num_sb_unique_module(); ++id) { + const auto unique_block_coord = device_rr_gsb.get_sb_unique_block_coord(id); + const std::vector> instance_map = + device_rr_gsb.get_sb_unique_block_instance_coord(unique_block_coord); + int status_code = + write_xml_atom_block(fp, instance_map, unique_block_coord, "sb"); + if (status_code != 0) { + VTR_LOG_ERROR("write sb unique blocks into xml file failed!"); + return CMD_EXEC_FATAL_ERROR; + } + } - id_unique_block_map.clear(); - id_instance_map.clear(); - device_rr_gsb.get_id_unique_cbx_block_map(id_unique_block_map); - device_rr_gsb.get_id_cbx_instance_map(id_instance_map); - err_code += write_xml_block(id_unique_block_map, id_instance_map, fp, "cbx"); + for (size_t id = 0; id < device_rr_gsb.get_num_cb_unique_module(CHANX); + ++id) { + const auto unique_block_coord = + device_rr_gsb.get_cbx_unique_block_coord(id); + const std::vector> instance_map = + device_rr_gsb.get_cbx_unique_block_instance_coord(unique_block_coord); + int status_code = + write_xml_atom_block(fp, instance_map, unique_block_coord, "cbx"); + if (status_code != 0) { + VTR_LOG_ERROR("write cbx unique blocks into xml file failed!"); + return CMD_EXEC_FATAL_ERROR; + } + } - id_unique_block_map.clear(); - id_instance_map.clear(); - device_rr_gsb.get_id_unique_cby_block_map(id_unique_block_map); - device_rr_gsb.get_id_cby_instance_map(id_instance_map); - err_code += write_xml_block(id_unique_block_map, id_instance_map, fp, "cby"); + for (size_t id = 0; id < device_rr_gsb.get_num_cb_unique_module(CHANY); + ++id) { + const auto unique_block_coord = + device_rr_gsb.get_cby_unique_block_coord(id); + const std::vector> instance_map = + device_rr_gsb.get_cby_unique_block_instance_coord(unique_block_coord); + int status_code = + write_xml_atom_block(fp, instance_map, unique_block_coord, "cby"); + if (status_code != 0) { + VTR_LOG_ERROR("write cby unique blocks into xml file failed!"); + return CMD_EXEC_FATAL_ERROR; + } + } /* Finish writing the root node */ fp << "" @@ -168,10 +185,6 @@ int write_xml_unique_blocks(const DeviceRRGSB& device_rr_gsb, const char* fname, report_unique_module_status_write(device_rr_gsb, true); } - if (err_code >= 1) { - return CMD_EXEC_FATAL_ERROR; - } else { - return CMD_EXEC_SUCCESS; - } + return CMD_EXEC_SUCCESS; } } // namespace openfpga diff --git a/openfpga/src/annotation/write_xml_unique_blocks.h b/openfpga/src/annotation/write_xml_unique_blocks.h index f8aa5959d..7eb8422ae 100644 --- a/openfpga/src/annotation/write_xml_unique_blocks.h +++ b/openfpga/src/annotation/write_xml_unique_blocks.h @@ -30,10 +30,10 @@ *******************************************************************/ namespace openfpga { -int write_xml_block( - std::map>& id_unique_block_map, - std::map>>& id_instance_map, - std::fstream& fp, std::string type); +int write_xml_atom_block(std::fstream& fp, + const std::vector>& instance_map, + const vtr::Point& unique_block_coord, + std::string type); void report_unique_module_status_write(const DeviceRRGSB& device_rr_gsb, bool verbose_output); int write_xml_unique_blocks(const DeviceRRGSB& device_rr_gsb, const char* fname, diff --git a/openfpga/src/base/openfpga_build_fabric_template.h b/openfpga/src/base/openfpga_build_fabric_template.h index 88ed6a336..671b2043d 100644 --- a/openfpga/src/base/openfpga_build_fabric_template.h +++ b/openfpga/src/base/openfpga_build_fabric_template.h @@ -479,15 +479,14 @@ int write_fabric_pin_physical_location_template( cmd_context.option_enable(cmd, opt_verbose)); } - template int read_unique_blocks_template(T& openfpga_ctx, const Command& cmd, const CommandContext& cmd_context) { CommandOptionId opt_verbose = cmd.option("verbose"); CommandOptionId opt_file = cmd.option("file"); CommandOptionId opt_type = cmd.option("type"); - - /* Check the option '--file' is enabled or not + + /* Check the option '--file' is enabled or not * Actually, it must be enabled as the shell interface will check * before reaching this fuction */ @@ -520,7 +519,7 @@ int write_unique_blocks_template(T& openfpga_ctx, const Command& cmd, */ VTR_ASSERT(true == cmd_context.option_enable(cmd, opt_file)); VTR_ASSERT(false == cmd_context.option_value(cmd, opt_file).empty()); - + std::string file_name = cmd_context.option_value(cmd, opt_file); std::string file_type = cmd_context.option_value(cmd, opt_type); /* Write unique blocks to a file */ @@ -534,7 +533,6 @@ int write_unique_blocks_template(T& openfpga_ctx, const Command& cmd, return CMD_EXEC_FATAL_ERROR; } } - /******************************************************************** * Report reference to a file diff --git a/openfpga/src/base/openfpga_setup_command_template.h b/openfpga/src/base/openfpga_setup_command_template.h index eb534fcb7..66ea3deb1 100644 --- a/openfpga/src/base/openfpga_setup_command_template.h +++ b/openfpga/src/base/openfpga_setup_command_template.h @@ -939,7 +939,7 @@ ShellCommandId add_write_fabric_pin_physical_location_command_template( /******************************************************************** * - Add a command to Shell environment: read_unique_blocks - * - Add associated options + * - Add associated options * - Add command dependency *******************************************************************/ template @@ -1015,8 +1015,7 @@ ShellCommandId add_write_unique_blocks_command_template( return shell_cmd_id; } - - /****************************************************************** +/****************************************************************** * - Add a command to Shell environment: report_reference * - Add associated options * - Add command dependency