rewrite write_xml function

This commit is contained in:
Lin 2024-09-11 18:08:51 +08:00
parent b2a5bd8437
commit 55611dbfe7
6 changed files with 179 additions and 168 deletions

View File

@ -96,6 +96,80 @@ size_t DeviceRRGSB::get_num_sb_unique_module() const {
return sb_unique_module_.size(); return sb_unique_module_.size();
} }
vtr::Point<size_t> DeviceRRGSB::get_sb_unique_block_coord(size_t id) const {
return sb_unique_module_[id];
}
std::vector<vtr::Point<size_t>> DeviceRRGSB::get_sb_unique_block_instance_coord(
const vtr::Point<size_t>& unique_block_coord) const {
auto unique_module_id =
sb_unique_module_id_[unique_block_coord.x()][unique_block_coord.y()];
std::vector<vtr::Point<size_t>> 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<size_t> instance_coord(location_x, location_y);
instance_map.push_back(instance_coord);
}
}
}
return instance_map;
}
vtr::Point<size_t> DeviceRRGSB::get_cbx_unique_block_coord(size_t id) const {
return cbx_unique_module_[id];
}
std::vector<vtr::Point<size_t>>
DeviceRRGSB::get_cbx_unique_block_instance_coord(
const vtr::Point<size_t>& unique_block_coord) const {
auto unique_module_id =
cbx_unique_module_id_[unique_block_coord.x()][unique_block_coord.y()];
std::vector<vtr::Point<size_t>> 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<size_t> instance_coord(location_x, location_y);
instance_map.push_back(instance_coord);
}
}
}
return instance_map;
}
vtr::Point<size_t> DeviceRRGSB::get_cby_unique_block_coord(size_t id) const {
return cby_unique_module_[id];
}
std::vector<vtr::Point<size_t>>
DeviceRRGSB::get_cby_unique_block_instance_coord(
const vtr::Point<size_t>& unique_block_coord) const {
auto unique_module_id =
cby_unique_module_id_[unique_block_coord.x()][unique_block_coord.y()];
std::vector<vtr::Point<size_t>> 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<size_t> instance_coord(location_x, location_y);
instance_map.push_back(instance_coord);
}
}
}
return instance_map;
}
/* get the number of unique mirrors of switch blocks */ /* get the number of unique mirrors of switch blocks */
size_t DeviceRRGSB::get_num_gsb_unique_module() const { size_t DeviceRRGSB::get_num_gsb_unique_module() const {
return gsb_unique_module_.size(); return gsb_unique_module_.size();
@ -173,8 +247,8 @@ void DeviceRRGSB::reserve(const vtr::Point<size_t>& coordinate) {
} }
} }
void DeviceRRGSB::reserve_unique_modules() { void DeviceRRGSB::reserve_unique_modules() {
/* As rr_gsb_ has been built, it has valid size. Will reserve space for unique /* As rr_gsb_ has been built, it has valid size. Will reserve space for
* blocks according to rr_gsb_'s size*/ * unique blocks according to rr_gsb_'s size*/
sb_unique_module_id_.resize(rr_gsb_.size()); sb_unique_module_id_.resize(rr_gsb_.size());
cbx_unique_module_id_.resize(rr_gsb_.size()); cbx_unique_module_id_.resize(rr_gsb_.size());
cby_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<size_t>& coordinate) {
} }
} }
/* Add a switch block to the array, which will automatically identify and update /* Add a switch block to the array, which will automatically identify and
* the lists of unique mirrors and rotatable mirrors */ * update the lists of unique mirrors and rotatable mirrors */
void DeviceRRGSB::add_rr_gsb(const vtr::Point<size_t>& coordinate, void DeviceRRGSB::add_rr_gsb(const vtr::Point<size_t>& coordinate,
const RRGSB& rr_gsb) { const RRGSB& rr_gsb) {
/* Resize upon needs*/ /* 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); return get_mutable_gsb(coordinate);
} }
/* Add a switch block to the array, which will automatically identify and update /* Add a switch block to the array, which will automatically identify and
* the lists of unique mirrors and rotatable mirrors */ * update the lists of unique mirrors and rotatable mirrors */
void DeviceRRGSB::build_cb_unique_module(const RRGraphView& rr_graph, void DeviceRRGSB::build_cb_unique_module(const RRGraphView& rr_graph,
const t_rr_type& cb_type) { const t_rr_type& cb_type) {
/* Make sure a clean start */ /* Make sure a clean start */
@ -246,7 +320,8 @@ void DeviceRRGSB::build_cb_unique_module(const RRGraphView& rr_graph,
continue; 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) { 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); const RRGSB& unique_module = get_cb_unique_module(cb_type, id);
if (true == is_cb_mirror(rr_graph, device_annotation_, rr_gsb_[ix][iy], 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 /* Add a switch block to the array, which will automatically identify and
* the lists of unique mirrors and rotatable mirrors */ * update the lists of unique mirrors and rotatable mirrors */
void DeviceRRGSB::build_sb_unique_module(const RRGraphView& rr_graph) { void DeviceRRGSB::build_sb_unique_module(const RRGraphView& rr_graph) {
/* Make sure a clean start */ /* Make sure a clean start */
clear_sb_unique_module(); clear_sb_unique_module();
@ -281,7 +356,8 @@ void DeviceRRGSB::build_sb_unique_module(const RRGraphView& rr_graph) {
bool is_unique_module = true; bool is_unique_module = true;
vtr::Point<size_t> sb_coordinate(ix, iy); vtr::Point<size_t> 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) { for (size_t id = 0; id < get_num_sb_unique_module(); ++id) {
/* Check if the two modules have the same submodules, /* Check if the two modules have the same submodules,
* if so, these two modules are the same, indicating the sb is not * 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 /* Add a switch block to the array, which will automatically identify and
* the lists of unique mirrors and rotatable mirrors */ * update the lists of unique mirrors and rotatable mirrors */
/* Find repeatable GSB block in the array */ /* Find repeatable GSB block in the array */
void DeviceRRGSB::build_gsb_unique_module() { void DeviceRRGSB::build_gsb_unique_module() {
@ -321,11 +397,12 @@ void DeviceRRGSB::build_gsb_unique_module() {
bool is_unique_module = true; bool is_unique_module = true;
vtr::Point<size_t> gsb_coordinate(ix, iy); vtr::Point<size_t> 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) { for (size_t id = 0; id < get_num_gsb_unique_module(); ++id) {
/* We have alreay built sb and cb unique module list /* 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 * We just need to check if the unique module id of SBs, CBX and CBY
* the same or not * are the same or not
*/ */
const vtr::Point<size_t>& gsb_unique_module_coordinate = const vtr::Point<size_t>& gsb_unique_module_coordinate =
gsb_unique_module_[id]; gsb_unique_module_[id];
@ -650,79 +727,4 @@ void DeviceRRGSB::preload_unique_sb_module(
sb_unique_module_id_[block_coordinate.x()][block_coordinate.y()]; 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<int, vtr::Point<size_t>>& 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<int, std::vector<vtr::Point<size_t>>>& 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<size_t> 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<int, vtr::Point<size_t>>& 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<int, std::vector<vtr::Point<size_t>>>& 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<size_t> 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<int, vtr::Point<size_t>>& 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<int, std::vector<vtr::Point<size_t>>>& 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<size_t> instance_coord(location_x, location_y);
id_instance_map[unique_module_id].push_back(instance_coord);
}
}
}
} /* End namespace openfpga*/ } /* End namespace openfpga*/

View File

@ -43,8 +43,19 @@ class DeviceRRGSB {
const vtr::Point<size_t>& coordinate) const; const vtr::Point<size_t>& coordinate) const;
size_t get_num_gsb_unique_module() size_t get_num_gsb_unique_module()
const; /* get the number of unique mirrors of GSB */ 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<size_t> get_sb_unique_block_coord(size_t id) const;
std::vector<vtr::Point<size_t>> get_sb_unique_block_instance_coord(
const vtr::Point<size_t>& unique_block_coord) const;
vtr::Point<size_t> get_cbx_unique_block_coord(size_t id) const;
std::vector<vtr::Point<size_t>> get_cbx_unique_block_instance_coord(
const vtr::Point<size_t>& unique_block_coord) const;
vtr::Point<size_t> get_cby_unique_block_coord(size_t id) const;
std::vector<vtr::Point<size_t>> get_cby_unique_block_instance_coord(
const vtr::Point<size_t>& unique_block_coord) const;
const RRGSB& get_gsb_unique_module( const RRGSB& get_gsb_unique_module(
const size_t& index) const; /* Get a rr-gsb which is a unique mirror */ const size_t& index) const; /* Get a rr-gsb which is a unique mirror */
const RRGSB& get_sb_unique_module(const size_t& index) const RRGSB& get_sb_unique_module(const size_t& index)
@ -107,18 +118,6 @@ class DeviceRRGSB {
const vtr::Point<size_t>& block_coordinate, const vtr::Point<size_t>& block_coordinate,
const std::vector<vtr::Point<size_t>>& instance_coords); const std::vector<vtr::Point<size_t>>& instance_coords);
void clear_unique_modules(); void clear_unique_modules();
void get_id_sb_instance_map(
std::map<int, std::vector<vtr::Point<size_t>>>& id_instance_map) const;
void get_id_unique_sb_block_map(
std::map<int, vtr::Point<size_t>>& id_unique_block_map) const;
void get_id_cbx_instance_map(
std::map<int, std::vector<vtr::Point<size_t>>>& id_instance_map) const;
void get_id_unique_cbx_block_map(
std::map<int, vtr::Point<size_t>>& id_unique_block_map) const;
void get_id_cby_instance_map(
std::map<int, std::vector<vtr::Point<size_t>>>& id_instance_map) const;
void get_id_unique_cby_block_map(
std::map<int, vtr::Point<size_t>>& id_unique_block_map) const;
private: /* Internal cleaners */ private: /* Internal cleaners */
void clear_gsb(); /* clean the content */ void clear_gsb(); /* clean the content */

View File

@ -32,28 +32,26 @@
* instance is the mirror of unique module. * instance is the mirror of unique module.
*******************************************************************/ *******************************************************************/
namespace openfpga { namespace openfpga {
int write_xml_atom_block(std::fstream& fp,
int write_xml_block( const std::vector<vtr::Point<size_t>>& instance_map,
std::map<int, vtr::Point<size_t>>& id_unique_block_map, const vtr::Point<size_t>& unique_block_coord,
std::map<int, std::vector<vtr::Point<size_t>>>& id_instance_map, std::string type) {
std::fstream& fp, std::string type) {
/* Validate the file stream */
if (false == openfpga::valid_file_stream(fp)) { if (false == openfpga::valid_file_stream(fp)) {
return CMD_EXEC_FATAL_ERROR; return CMD_EXEC_FATAL_ERROR;
} }
for (const auto& pair : id_unique_block_map) {
openfpga::write_tab_to_file(fp, 1); openfpga::write_tab_to_file(fp, 1);
fp << "<block"; fp << "<block";
write_xml_attribute(fp, "type", type.c_str()); write_xml_attribute(fp, "type", type.c_str());
write_xml_attribute(fp, "x", pair.second.x()); write_xml_attribute(fp, "x", unique_block_coord.x());
write_xml_attribute(fp, "y", pair.second.y()); write_xml_attribute(fp, "y", unique_block_coord.y());
fp << ">" fp << ">"
<< "\n"; << "\n";
for (const auto& instance_info : id_instance_map[pair.first]) { for (const auto& instance_info : instance_map) {
if (instance_info.x() == pair.second.x() && if (instance_info.x() == unique_block_coord.x() &&
instance_info.y() == pair.second.y()) { instance_info.y() == unique_block_coord.y()) {
; ;
} else { } else {
openfpga::write_tab_to_file(fp, 2); openfpga::write_tab_to_file(fp, 2);
@ -68,9 +66,7 @@ int write_xml_block(
openfpga::write_tab_to_file(fp, 1); openfpga::write_tab_to_file(fp, 1);
fp << "</block>" fp << "</block>"
<< "\n"; << "\n";
} return openfpga::CMD_EXEC_SUCCESS;
return CMD_EXEC_SUCCESS;
} }
void report_unique_module_status_write(const DeviceRRGSB& device_rr_gsb, 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 << "<unique_blocks>" fp << "<unique_blocks>"
<< "\n"; << "\n";
int err_code = 0; for (size_t id = 0; id < device_rr_gsb.get_num_sb_unique_module(); ++id) {
std::map<int, vtr::Point<size_t>> id_unique_block_map; const auto unique_block_coord = device_rr_gsb.get_sb_unique_block_coord(id);
std::map<int, std::vector<vtr::Point<size_t>>> id_instance_map; const std::vector<vtr::Point<size_t>> instance_map =
device_rr_gsb.get_id_unique_sb_block_map(id_unique_block_map); device_rr_gsb.get_sb_unique_block_instance_coord(unique_block_coord);
device_rr_gsb.get_id_sb_instance_map(id_instance_map); int status_code =
err_code += write_xml_block(id_unique_block_map, id_instance_map, fp, "sb"); 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(); for (size_t id = 0; id < device_rr_gsb.get_num_cb_unique_module(CHANX);
id_instance_map.clear(); ++id) {
device_rr_gsb.get_id_unique_cbx_block_map(id_unique_block_map); const auto unique_block_coord =
device_rr_gsb.get_id_cbx_instance_map(id_instance_map); device_rr_gsb.get_cbx_unique_block_coord(id);
err_code += write_xml_block(id_unique_block_map, id_instance_map, fp, "cbx"); const std::vector<vtr::Point<size_t>> 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(); for (size_t id = 0; id < device_rr_gsb.get_num_cb_unique_module(CHANY);
id_instance_map.clear(); ++id) {
device_rr_gsb.get_id_unique_cby_block_map(id_unique_block_map); const auto unique_block_coord =
device_rr_gsb.get_id_cby_instance_map(id_instance_map); device_rr_gsb.get_cby_unique_block_coord(id);
err_code += write_xml_block(id_unique_block_map, id_instance_map, fp, "cby"); const std::vector<vtr::Point<size_t>> 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 */ /* Finish writing the root node */
fp << "</unique_blocks>" fp << "</unique_blocks>"
@ -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); 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 } // namespace openfpga

View File

@ -30,10 +30,10 @@
*******************************************************************/ *******************************************************************/
namespace openfpga { namespace openfpga {
int write_xml_block( int write_xml_atom_block(std::fstream& fp,
std::map<int, vtr::Point<size_t>>& id_unique_block_map, const std::vector<vtr::Point<size_t>>& instance_map,
std::map<int, std::vector<vtr::Point<size_t>>>& id_instance_map, const vtr::Point<size_t>& unique_block_coord,
std::fstream& fp, std::string type); std::string type);
void report_unique_module_status_write(const DeviceRRGSB& device_rr_gsb, void report_unique_module_status_write(const DeviceRRGSB& device_rr_gsb,
bool verbose_output); bool verbose_output);
int write_xml_unique_blocks(const DeviceRRGSB& device_rr_gsb, const char* fname, int write_xml_unique_blocks(const DeviceRRGSB& device_rr_gsb, const char* fname,

View File

@ -479,7 +479,6 @@ int write_fabric_pin_physical_location_template(
cmd_context.option_enable(cmd, opt_verbose)); cmd_context.option_enable(cmd, opt_verbose));
} }
template <class T> template <class T>
int read_unique_blocks_template(T& openfpga_ctx, const Command& cmd, int read_unique_blocks_template(T& openfpga_ctx, const Command& cmd,
const CommandContext& cmd_context) { const CommandContext& cmd_context) {
@ -535,7 +534,6 @@ int write_unique_blocks_template(T& openfpga_ctx, const Command& cmd,
} }
} }
/******************************************************************** /********************************************************************
* Report reference to a file * Report reference to a file
*******************************************************************/ *******************************************************************/

View File

@ -1015,8 +1015,7 @@ ShellCommandId add_write_unique_blocks_command_template(
return shell_cmd_id; return shell_cmd_id;
} }
/******************************************************************
/******************************************************************
* - Add a command to Shell environment: report_reference * - Add a command to Shell environment: report_reference
* - Add associated options * - Add associated options
* - Add command dependency * - Add command dependency