From 48a386c9b63a25401a8002a6545522093de4cb5b Mon Sep 17 00:00:00 2001 From: Lin Date: Fri, 2 Aug 2024 01:43:01 -0700 Subject: [PATCH 01/12] add read and write uniqueblocks commands --- .../src/base/openfpga_build_fabric_template.h | 44 +++++++ .../base/openfpga_setup_command_template.h | 88 +++++++++++++- .../src/fabric/read_xml_unique_blocks.cpp | 112 ++++++++++++++++++ openfpga/src/fabric/read_xml_unique_blocks.h | 16 +++ 4 files changed, 259 insertions(+), 1 deletion(-) create mode 100644 openfpga/src/fabric/read_xml_unique_blocks.cpp create mode 100644 openfpga/src/fabric/read_xml_unique_blocks.h diff --git a/openfpga/src/base/openfpga_build_fabric_template.h b/openfpga/src/base/openfpga_build_fabric_template.h index b36903a22..193aa0fef 100644 --- a/openfpga/src/base/openfpga_build_fabric_template.h +++ b/openfpga/src/base/openfpga_build_fabric_template.h @@ -25,6 +25,7 @@ #include "vtr_time.h" #include "write_xml_fabric_pin_physical_location.h" #include "write_xml_module_name_map.h" +#include "read_xml_unique_blocks.h" /* begin namespace openfpga */ namespace openfpga { @@ -472,6 +473,49 @@ int write_fabric_pin_physical_location_template( cmd_context.option_enable(cmd, opt_verbose)); } +template +int read_unique_blocks_template(const 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 + * Actually, it must be enabled as the shell interface will check + * before reaching this fuction + */ + 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 hierarchy to a file */ + return read_xml_unique_blocks(file_name.c_str(), file_type.c_str(), + cmd_context.option_enable(cmd, opt_verbose)); +} + +template +int write_unique_blocks_template(const 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 + * Actually, it must be enabled as the shell interface will check + * before reaching this fuction + */ + 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 hierarchy to a file */ + return read_xml_unique_blocks(file_name.c_str(), file_type.c_str(), + cmd_context.option_enable(cmd, opt_verbose)); +} + } /* end namespace openfpga */ #endif diff --git a/openfpga/src/base/openfpga_setup_command_template.h b/openfpga/src/base/openfpga_setup_command_template.h index 3d178ee17..42816029c 100644 --- a/openfpga/src/base/openfpga_setup_command_template.h +++ b/openfpga/src/base/openfpga_setup_command_template.h @@ -924,6 +924,79 @@ ShellCommandId add_write_fabric_pin_physical_location_command_template( return shell_cmd_id; } + +/******************************************************************** + * - Add a command to Shell environment: read_unique_blocks + * - Add associated options + * - Add command dependency + *******************************************************************/ +template +ShellCommandId add_read_unique_blocks_command_template( + openfpga::Shell& shell, const ShellCommandClassId& cmd_class_id, + const std::vector& dependent_cmds, const bool& hidden) { + Command shell_cmd("read_unique_blocks"); + + /* Add an option '--file' */ + shell_cmd.add_option( + "file", true, + "unique blocks xml file"); + + /* Add an option '--type' */ + shell_cmd.add_option("type", true, + "the file type of input file"); + + /* Add an option '--verbose' */ + shell_cmd.add_option("verbose", false, "Show verbose outputs"); + + /* Add command 'compact_routing_hierarchy' to the Shell */ + ShellCommandId shell_cmd_id = shell.add_command( + shell_cmd, "Preload unique blocks from xml file", hidden); + shell.set_command_class(shell_cmd_id, cmd_class_id); + shell.set_command_execute_function(shell_cmd_id, read_unique_blocks_template); + + /* Add command dependency to the Shell */ + shell.set_command_dependency(shell_cmd_id, dependent_cmds); + + return shell_cmd_id; +} + + +/******************************************************************** + * - Add a command to Shell environment: write_unique_blocks + * - Add associated options + * - Add command dependency + *******************************************************************/ +template +ShellCommandId add_write_unique_blocks_command_template( + openfpga::Shell& shell, const ShellCommandClassId& cmd_class_id, + const std::vector& dependent_cmds, const bool& hidden) { + Command shell_cmd("write_unique_blocks"); + + /* Add an option '--file' */ + shell_cmd.add_option( + "file", true, + "unique blocks xml file"); + + /* Add an option '--type' */ + shell_cmd.add_option("type", true, + "the file type of input file"); + + /* Add an option '--verbose' */ + shell_cmd.add_option("verbose", false, "Show verbose outputs"); + + /* Add command 'compact_routing_hierarchy' to the Shell */ + ShellCommandId shell_cmd_id = shell.add_command( + shell_cmd, "Preload unique blocks from xml file", hidden); + shell.set_command_class(shell_cmd_id, cmd_class_id); + shell.set_command_execute_function(shell_cmd_id, write_unique_blocks_template); + + /* Add command dependency to the Shell */ + shell.set_command_dependency(shell_cmd_id, dependent_cmds); + + return shell_cmd_id; +} + + template void add_setup_command_templates(openfpga::Shell& shell, const bool& hidden = false) { @@ -1175,8 +1248,21 @@ void add_setup_command_templates(openfpga::Shell& shell, add_write_fabric_pin_physical_location_command_template( shell, openfpga_setup_cmd_class, cmd_dependency_write_fabric_pin_physical_location, hidden); -} + /******************************** + * Command 'read_unique_blocks' + */ + add_read_unique_blocks_command_template( + shell, openfpga_setup_cmd_class, std::vector(), hidden); + + /******************************** + * Command 'write_unique_blocks' + */ + add_write_unique_blocks_command_template( + shell, openfpga_setup_cmd_class, std::vector(), hidden); + + +} } /* end namespace openfpga */ #endif diff --git a/openfpga/src/fabric/read_xml_unique_blocks.cpp b/openfpga/src/fabric/read_xml_unique_blocks.cpp new file mode 100644 index 000000000..8b80f7a3e --- /dev/null +++ b/openfpga/src/fabric/read_xml_unique_blocks.cpp @@ -0,0 +1,112 @@ +/******************************************************************** + * This file includes the top-level function of this library + * which reads an XML of a fabric key to the associated + * data structures + *******************************************************************/ +#include + +/* Headers from pugi XML library */ +#include "pugixml.hpp" +#include "pugixml_util.hpp" + +/* Headers from vtr util library */ +#include "vtr_assert.h" +#include "vtr_log.h" +#include "vtr_time.h" + +/* Headers from libopenfpga util library */ +#include "openfpga_port_parser.h" + +/* Headers from libarchfpga */ +#include "arch_error.h" +#include "read_xml_unique_blocks.h" +#include "read_xml_util.h" + +/******************************************************************** + * Parse XML codes of a to an object of FabricKey + *******************************************************************/ +static void read_xml_unique_block_info( + pugi::xml_node& xml_pin_constraint, const pugiutil::loc_data& loc_data) { + std::string pass = "pass here"; +// /* Create a new design constraint in the storage */ +// RepackDesignConstraintId design_constraint_id = +// repack_design_constraints.create_design_constraint( +// RepackDesignConstraints::IGNORE_NET); + +// if (false == repack_design_constraints.valid_design_constraint_id( +// design_constraint_id)) { +// archfpga_throw(loc_data.filename_c_str(), loc_data.line(xml_pin_constraint), +// "Fail to create design constraint!\n"); +// } + +// std::string pin_ctx_to_parse = +// get_attribute(xml_pin_constraint, "pin", loc_data).as_string(); +// openfpga::StringToken pin_tokenizer(pin_ctx_to_parse); +// std::vector pin_info = pin_tokenizer.split('.'); +// /* Expect two contents, otherwise error out */ +// if (pin_info.size() != 2) { +// std::string err_msg = +// std::string("Invalid content '") + pin_ctx_to_parse + +// std::string("' to skip, expect .\n"); +// VTR_LOG_ERROR(err_msg.c_str()); +// VTR_ASSERT(pin_info.size() == 2); +// } +// std::string pb_type_name = pin_info[0]; +// openfpga::PortParser port_parser(pin_info[1]); +// openfpga::BasicPort curr_port = port_parser.port(); +// if (!curr_port.is_valid()) { +// std::string err_msg = +// std::string("Invalid pin definition '") + pin_ctx_to_parse + +// std::string("', expect .[int:int]\n"); +// VTR_LOG_ERROR(err_msg.c_str()); +// VTR_ASSERT(curr_port.is_valid()); +// } +// repack_design_constraints.set_pb_type(design_constraint_id, pb_type_name); +// repack_design_constraints.set_pin(design_constraint_id, curr_port); +// repack_design_constraints.set_net( +// design_constraint_id, +// get_attribute(xml_pin_constraint, "name", loc_data).as_string()); +} + +/******************************************************************** + * Parse XML codes about to an object of + *RepackDesignConstraints + *******************************************************************/ +int read_xml_unique_blocks(const char* file_name, const char* file_type, + bool verbose) { + vtr::ScopedStartFinishTimer timer("Read unique blocks xml file"); + +// RepackDesignConstraints repack_design_constraints; + + /* Parse the file */ + pugi::xml_document doc; + pugiutil::loc_data loc_data; + + try { + loc_data = pugiutil::load_xml(doc, file_name); + + pugi::xml_node xml_root = + get_single_child(doc, "unique_blocks", loc_data); + + // size_t num_design_constraints = + // std::distance(xml_root.children().begin(), xml_root.children().end()); + // /* Reserve memory space for the region */ + // repack_design_constraints.reserve_design_constraints( + // num_design_constraints); + + for (pugi::xml_node xml_block_info : xml_root.children()) { + /* Error out if the XML child has an invalid name! */ + if (xml_block_info.name() == std::string("block")) { + read_xml_unique_block_info(xml_block_info, loc_data); + } else { + bad_tag(xml_block_info, loc_data, xml_root, + {"block"}); + return 1; + } + } + } catch (pugiutil::XmlError& e) { + archfpga_throw(file_name, e.line(), "%s", e.what()); + } + + return 0; +} diff --git a/openfpga/src/fabric/read_xml_unique_blocks.h b/openfpga/src/fabric/read_xml_unique_blocks.h new file mode 100644 index 000000000..cd89ff801 --- /dev/null +++ b/openfpga/src/fabric/read_xml_unique_blocks.h @@ -0,0 +1,16 @@ +#ifndef READ_XML_UNIQUE_BLOCKS_H +#define READ_XML_UNIQUE_BLOCKS_H + +/******************************************************************** + * Include header files that are required by function declaration + *******************************************************************/ +#include "pugixml.hpp" +#include "pugixml_util.hpp" + +/******************************************************************** + * Function declaration + *******************************************************************/ +int read_xml_unique_blocks(const char* file_name, const char* file_type, + bool verbose); + +#endif From 7f426d59394a760908402cd0d07eca94fc43dfa4 Mon Sep 17 00:00:00 2001 From: Lin Date: Fri, 2 Aug 2024 03:10:10 -0700 Subject: [PATCH 02/12] add commands --- .../base/openfpga_setup_command_template.h | 47 ++++++++++--------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/openfpga/src/base/openfpga_setup_command_template.h b/openfpga/src/base/openfpga_setup_command_template.h index 42816029c..01e2f78cb 100644 --- a/openfpga/src/base/openfpga_setup_command_template.h +++ b/openfpga/src/base/openfpga_setup_command_template.h @@ -924,7 +924,6 @@ ShellCommandId add_write_fabric_pin_physical_location_command_template( return shell_cmd_id; } - /******************************************************************** * - Add a command to Shell environment: read_unique_blocks * - Add associated options @@ -937,22 +936,24 @@ ShellCommandId add_read_unique_blocks_command_template( Command shell_cmd("read_unique_blocks"); /* Add an option '--file' */ - shell_cmd.add_option( - "file", true, - "unique blocks xml file"); + CommandOptionId opt_file = + shell_cmd.add_option("file", true, "specify the unique blocks xml file"); + shell_cmd.set_option_require_value(opt_file, openfpga::OPT_STRING); /* Add an option '--type' */ - shell_cmd.add_option("type", true, - "the file type of input file"); + CommandOptionId opt_type = shell_cmd.add_option( + "type", true, "specify the type of the unique blocks xml file"); + shell_cmd.set_option_require_value(opt_type, openfpga::OPT_STRING); /* Add an option '--verbose' */ shell_cmd.add_option("verbose", false, "Show verbose outputs"); /* Add command 'compact_routing_hierarchy' to the Shell */ - ShellCommandId shell_cmd_id = shell.add_command( - shell_cmd, "Preload unique blocks from xml file", hidden); + ShellCommandId shell_cmd_id = + shell.add_command(shell_cmd, "Preload unique blocks from xml file", hidden); shell.set_command_class(shell_cmd_id, cmd_class_id); - shell.set_command_execute_function(shell_cmd_id, read_unique_blocks_template); + shell.set_command_execute_function(shell_cmd_id, + read_unique_blocks_template); /* Add command dependency to the Shell */ shell.set_command_dependency(shell_cmd_id, dependent_cmds); @@ -960,7 +961,6 @@ ShellCommandId add_read_unique_blocks_command_template( return shell_cmd_id; } - /******************************************************************** * - Add a command to Shell environment: write_unique_blocks * - Add associated options @@ -973,22 +973,24 @@ ShellCommandId add_write_unique_blocks_command_template( Command shell_cmd("write_unique_blocks"); /* Add an option '--file' */ - shell_cmd.add_option( - "file", true, - "unique blocks xml file"); + CommandOptionId opt_file = + shell_cmd.add_option("file", true, "specify the unique blocks xml file"); + shell_cmd.set_option_require_value(opt_file, openfpga::OPT_STRING); /* Add an option '--type' */ - shell_cmd.add_option("type", true, - "the file type of input file"); + CommandOptionId opt_type = shell_cmd.add_option( + "type", true, "specify the type of the unique blocks xml file"); + shell_cmd.set_option_require_value(opt_type, openfpga::OPT_STRING); /* Add an option '--verbose' */ shell_cmd.add_option("verbose", false, "Show verbose outputs"); /* Add command 'compact_routing_hierarchy' to the Shell */ - ShellCommandId shell_cmd_id = shell.add_command( - shell_cmd, "Preload unique blocks from xml file", hidden); + ShellCommandId shell_cmd_id = + shell.add_command(shell_cmd, "Preload unique blocks from xml file", hidden); shell.set_command_class(shell_cmd_id, cmd_class_id); - shell.set_command_execute_function(shell_cmd_id, write_unique_blocks_template); + shell.set_command_execute_function(shell_cmd_id, + write_unique_blocks_template); /* Add command dependency to the Shell */ shell.set_command_dependency(shell_cmd_id, dependent_cmds); @@ -996,7 +998,6 @@ ShellCommandId add_write_unique_blocks_command_template( return shell_cmd_id; } - template void add_setup_command_templates(openfpga::Shell& shell, const bool& hidden = false) { @@ -1253,15 +1254,15 @@ void add_setup_command_templates(openfpga::Shell& shell, * Command 'read_unique_blocks' */ add_read_unique_blocks_command_template( - shell, openfpga_setup_cmd_class, std::vector(), hidden); + shell, openfpga_setup_cmd_class, std::vector(), + hidden); /******************************** * Command 'write_unique_blocks' */ add_write_unique_blocks_command_template( - shell, openfpga_setup_cmd_class, std::vector(), hidden); - - + shell, openfpga_setup_cmd_class, std::vector(), + hidden); } } /* end namespace openfpga */ From 5ac19ea62866601f6527742546a38616a4835218 Mon Sep 17 00:00:00 2001 From: Lin Date: Sun, 4 Aug 2024 20:51:27 -0700 Subject: [PATCH 03/12] read unique blocks io --- .../src/fabric/read_xml_unique_blocks.cpp | 73 ++++++------------- 1 file changed, 24 insertions(+), 49 deletions(-) diff --git a/openfpga/src/fabric/read_xml_unique_blocks.cpp b/openfpga/src/fabric/read_xml_unique_blocks.cpp index 8b80f7a3e..87845f617 100644 --- a/openfpga/src/fabric/read_xml_unique_blocks.cpp +++ b/openfpga/src/fabric/read_xml_unique_blocks.cpp @@ -1,6 +1,6 @@ /******************************************************************** * This file includes the top-level function of this library - * which reads an XML of a fabric key to the associated + * which reads an XML of unique routing blocks to the associated * data structures *******************************************************************/ #include @@ -23,49 +23,13 @@ #include "read_xml_util.h" /******************************************************************** - * Parse XML codes of a to an object of FabricKey + * Parse XML codes of a to an object of unique_blocks *******************************************************************/ -static void read_xml_unique_block_info( - pugi::xml_node& xml_pin_constraint, const pugiutil::loc_data& loc_data) { - std::string pass = "pass here"; -// /* Create a new design constraint in the storage */ -// RepackDesignConstraintId design_constraint_id = -// repack_design_constraints.create_design_constraint( -// RepackDesignConstraints::IGNORE_NET); - -// if (false == repack_design_constraints.valid_design_constraint_id( -// design_constraint_id)) { -// archfpga_throw(loc_data.filename_c_str(), loc_data.line(xml_pin_constraint), -// "Fail to create design constraint!\n"); -// } - -// std::string pin_ctx_to_parse = -// get_attribute(xml_pin_constraint, "pin", loc_data).as_string(); -// openfpga::StringToken pin_tokenizer(pin_ctx_to_parse); -// std::vector pin_info = pin_tokenizer.split('.'); -// /* Expect two contents, otherwise error out */ -// if (pin_info.size() != 2) { -// std::string err_msg = -// std::string("Invalid content '") + pin_ctx_to_parse + -// std::string("' to skip, expect .\n"); -// VTR_LOG_ERROR(err_msg.c_str()); -// VTR_ASSERT(pin_info.size() == 2); -// } -// std::string pb_type_name = pin_info[0]; -// openfpga::PortParser port_parser(pin_info[1]); -// openfpga::BasicPort curr_port = port_parser.port(); -// if (!curr_port.is_valid()) { -// std::string err_msg = -// std::string("Invalid pin definition '") + pin_ctx_to_parse + -// std::string("', expect .[int:int]\n"); -// VTR_LOG_ERROR(err_msg.c_str()); -// VTR_ASSERT(curr_port.is_valid()); -// } -// repack_design_constraints.set_pb_type(design_constraint_id, pb_type_name); -// repack_design_constraints.set_pin(design_constraint_id, curr_port); -// repack_design_constraints.set_net( -// design_constraint_id, -// get_attribute(xml_pin_constraint, "name", loc_data).as_string()); +static void read_xml_unique_instance_info(pugi::xml_node& xml_instance_info, + const pugiutil::loc_data& loc_data) { + std::string pass = "pass here"; + std::string instance_x = get_attribute(xml_instance_info, "x", loc_data).as_string(); + std::string instance_y = get_attribute(xml_instance_info, "y", loc_data).as_string(); } /******************************************************************** @@ -76,7 +40,7 @@ int read_xml_unique_blocks(const char* file_name, const char* file_type, bool verbose) { vtr::ScopedStartFinishTimer timer("Read unique blocks xml file"); -// RepackDesignConstraints repack_design_constraints; + // RepackDesignConstraints repack_design_constraints; /* Parse the file */ pugi::xml_document doc; @@ -85,8 +49,7 @@ int read_xml_unique_blocks(const char* file_name, const char* file_type, try { loc_data = pugiutil::load_xml(doc, file_name); - pugi::xml_node xml_root = - get_single_child(doc, "unique_blocks", loc_data); + pugi::xml_node xml_root = get_single_child(doc, "unique_blocks", loc_data); // size_t num_design_constraints = // std::distance(xml_root.children().begin(), xml_root.children().end()); @@ -97,12 +60,24 @@ int read_xml_unique_blocks(const char* file_name, const char* file_type, for (pugi::xml_node xml_block_info : xml_root.children()) { /* Error out if the XML child has an invalid name! */ if (xml_block_info.name() == std::string("block")) { - read_xml_unique_block_info(xml_block_info, loc_data); + std::string type = + get_attribute(xml_block_info, "type", loc_data).as_string(); + std::string block_x = + get_attribute(xml_block_info, "x", loc_data).as_string(); + std::string block_y = + get_attribute(xml_block_info, "y", loc_data).as_string(); + for (pugi::xml_node xml_instance_info : xml_block_info.children()) { + if (xml_instance_info.name() == std::string("instance")) { + read_xml_unique_instance_info(xml_instance_info, loc_data); + } + // read_xml_unique_instance_info(xml_instance_info, loc_data); + } } else { - bad_tag(xml_block_info, loc_data, xml_root, - {"block"}); + bad_tag(xml_block_info, loc_data, xml_root, {"block"}); return 1; } + // std::cout << "what is the root name: " << xml_block_info.name() << + // std::endl; } } catch (pugiutil::XmlError& e) { archfpga_throw(file_name, e.line(), "%s", e.what()); From c726744154d9c03aeea044ddff338212c0c4b2e9 Mon Sep 17 00:00:00 2001 From: Lin Date: Mon, 5 Aug 2024 02:23:47 -0700 Subject: [PATCH 04/12] add sb unique modules --- openfpga/src/annotation/device_rr_gsb.cpp | 33 ++++++ openfpga/src/annotation/device_rr_gsb.h | 3 + .../src/base/openfpga_build_fabric_template.h | 8 +- .../src/fabric/read_xml_unique_blocks.cpp | 87 --------------- openfpga/src/fabric/read_xml_unique_blocks.h | 104 +++++++++++++++++- 5 files changed, 141 insertions(+), 94 deletions(-) delete mode 100644 openfpga/src/fabric/read_xml_unique_blocks.cpp diff --git a/openfpga/src/annotation/device_rr_gsb.cpp b/openfpga/src/annotation/device_rr_gsb.cpp index 963d53bc1..a2ac6df3d 100644 --- a/openfpga/src/annotation/device_rr_gsb.cpp +++ b/openfpga/src/annotation/device_rr_gsb.cpp @@ -560,6 +560,39 @@ size_t DeviceRRGSB::get_cb_unique_module_index( } return cb_unique_module_id; +} + +void DeviceRRGSB::load_unique_cb_module_from_user_input(int x, int y){ + + + + +} + +void DeviceRRGSB::load_unique_sb_module_from_user_input(int ix, int iy){ + vtr::Point sb_coordinate(ix, iy); + bool is_unique_module = true; + + for (size_t id = 0; id < get_num_sb_unique_module(); ++id) { + /* Check whether the input module exists.*/ + if (sb_unique_module_[id].x() == ix && sb_unique_module_[id].y() == iy){ + is_unique_module = false; + sb_unique_module_id_[ix][iy] = id; + break; + } + } + if (true == is_unique_module) { + sb_unique_module_.push_back(sb_coordinate); + /* Record the id of unique mirror */ + sb_unique_module_id_[ix][iy] =sb_unique_module_.size() - 1; + } +} + +void DeviceRRGSB::load_unique_gsb_module_from_user_input(int x, int y){ + + + + } } /* End namespace openfpga*/ diff --git a/openfpga/src/annotation/device_rr_gsb.h b/openfpga/src/annotation/device_rr_gsb.h index 245b1646b..267118e00 100644 --- a/openfpga/src/annotation/device_rr_gsb.h +++ b/openfpga/src/annotation/device_rr_gsb.h @@ -95,6 +95,9 @@ class DeviceRRGSB { automatically identify and update the lists of unique mirrors and rotatable mirrors */ void clear(); /* clean the content */ + void load_unique_cb_module_from_user_input(int x, int y); + void load_unique_sb_module_from_user_input(int x, int y); + void load_unique_gsb_module_from_user_input(int x, int y); private: /* Internal cleaners */ void clear_gsb(); /* clean the content */ void clear_cb_unique_module(const t_rr_type& cb_type); /* clean the content */ diff --git a/openfpga/src/base/openfpga_build_fabric_template.h b/openfpga/src/base/openfpga_build_fabric_template.h index 193aa0fef..3ba3c1d1a 100644 --- a/openfpga/src/base/openfpga_build_fabric_template.h +++ b/openfpga/src/base/openfpga_build_fabric_template.h @@ -474,7 +474,7 @@ int write_fabric_pin_physical_location_template( } template -int read_unique_blocks_template(const T& openfpga_ctx, const Command& cmd, +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"); @@ -490,12 +490,12 @@ int read_unique_blocks_template(const T& openfpga_ctx, const Command& cmd, std::string file_name = cmd_context.option_value(cmd, opt_file); std::string file_type = cmd_context.option_value(cmd, opt_type); /* Write hierarchy to a file */ - return read_xml_unique_blocks(file_name.c_str(), file_type.c_str(), + return read_xml_unique_blocks(openfpga_ctx, file_name.c_str(), file_type.c_str(), cmd_context.option_enable(cmd, opt_verbose)); } template -int write_unique_blocks_template(const T& openfpga_ctx, const Command& cmd, +int write_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"); @@ -512,7 +512,7 @@ int write_unique_blocks_template(const T& openfpga_ctx, const Command& cmd, std::string file_type = cmd_context.option_value(cmd, opt_type); /* Write hierarchy to a file */ - return read_xml_unique_blocks(file_name.c_str(), file_type.c_str(), + return read_xml_unique_blocks(openfpga_ctx, file_name.c_str(), file_type.c_str(), cmd_context.option_enable(cmd, opt_verbose)); } diff --git a/openfpga/src/fabric/read_xml_unique_blocks.cpp b/openfpga/src/fabric/read_xml_unique_blocks.cpp deleted file mode 100644 index 87845f617..000000000 --- a/openfpga/src/fabric/read_xml_unique_blocks.cpp +++ /dev/null @@ -1,87 +0,0 @@ -/******************************************************************** - * This file includes the top-level function of this library - * which reads an XML of unique routing blocks to the associated - * data structures - *******************************************************************/ -#include - -/* Headers from pugi XML library */ -#include "pugixml.hpp" -#include "pugixml_util.hpp" - -/* Headers from vtr util library */ -#include "vtr_assert.h" -#include "vtr_log.h" -#include "vtr_time.h" - -/* Headers from libopenfpga util library */ -#include "openfpga_port_parser.h" - -/* Headers from libarchfpga */ -#include "arch_error.h" -#include "read_xml_unique_blocks.h" -#include "read_xml_util.h" - -/******************************************************************** - * Parse XML codes of a to an object of unique_blocks - *******************************************************************/ -static void read_xml_unique_instance_info(pugi::xml_node& xml_instance_info, - const pugiutil::loc_data& loc_data) { - std::string pass = "pass here"; - std::string instance_x = get_attribute(xml_instance_info, "x", loc_data).as_string(); - std::string instance_y = get_attribute(xml_instance_info, "y", loc_data).as_string(); -} - -/******************************************************************** - * Parse XML codes about to an object of - *RepackDesignConstraints - *******************************************************************/ -int read_xml_unique_blocks(const char* file_name, const char* file_type, - bool verbose) { - vtr::ScopedStartFinishTimer timer("Read unique blocks xml file"); - - // RepackDesignConstraints repack_design_constraints; - - /* Parse the file */ - pugi::xml_document doc; - pugiutil::loc_data loc_data; - - try { - loc_data = pugiutil::load_xml(doc, file_name); - - pugi::xml_node xml_root = get_single_child(doc, "unique_blocks", loc_data); - - // size_t num_design_constraints = - // std::distance(xml_root.children().begin(), xml_root.children().end()); - // /* Reserve memory space for the region */ - // repack_design_constraints.reserve_design_constraints( - // num_design_constraints); - - for (pugi::xml_node xml_block_info : xml_root.children()) { - /* Error out if the XML child has an invalid name! */ - if (xml_block_info.name() == std::string("block")) { - std::string type = - get_attribute(xml_block_info, "type", loc_data).as_string(); - std::string block_x = - get_attribute(xml_block_info, "x", loc_data).as_string(); - std::string block_y = - get_attribute(xml_block_info, "y", loc_data).as_string(); - for (pugi::xml_node xml_instance_info : xml_block_info.children()) { - if (xml_instance_info.name() == std::string("instance")) { - read_xml_unique_instance_info(xml_instance_info, loc_data); - } - // read_xml_unique_instance_info(xml_instance_info, loc_data); - } - } else { - bad_tag(xml_block_info, loc_data, xml_root, {"block"}); - return 1; - } - // std::cout << "what is the root name: " << xml_block_info.name() << - // std::endl; - } - } catch (pugiutil::XmlError& e) { - archfpga_throw(file_name, e.line(), "%s", e.what()); - } - - return 0; -} diff --git a/openfpga/src/fabric/read_xml_unique_blocks.h b/openfpga/src/fabric/read_xml_unique_blocks.h index cd89ff801..a6b7cb168 100644 --- a/openfpga/src/fabric/read_xml_unique_blocks.h +++ b/openfpga/src/fabric/read_xml_unique_blocks.h @@ -2,15 +2,113 @@ #define READ_XML_UNIQUE_BLOCKS_H /******************************************************************** - * Include header files that are required by function declaration + * This file includes the top-level function of this library + * which reads an XML of unique routing blocks to the associated + * data structures *******************************************************************/ + +#include + +/* Headers from pugi XML library */ #include "pugixml.hpp" #include "pugixml_util.hpp" +/* Headers from vtr util library */ +#include "vtr_assert.h" +#include "vtr_log.h" +#include "vtr_time.h" + +/* Headers from libopenfpga util library */ +#include "openfpga_port_parser.h" + +/* Headers from libarchfpga */ +#include "arch_error.h" +#include "read_xml_unique_blocks.h" +#include "read_xml_util.h" +#include "rr_gsb.h" + /******************************************************************** * Function declaration *******************************************************************/ -int read_xml_unique_blocks(const char* file_name, const char* file_type, - bool verbose); +template +int read_xml_unique_blocks(T& openfpga_ctx, const char* file_name, + const char* file_type, bool verbose); + +/******************************************************************** + * Parse XML codes of a to an object of unique_blocks + *******************************************************************/ +template +void read_xml_unique_instance_info(T& device_rr_gsb, + pugi::xml_node& xml_instance_info, + const pugiutil::loc_data& loc_data, + std::string type) { + std::string pass = "pass here"; + int instance_x = get_attribute(xml_instance_info, "x", loc_data).as_int(); + int instance_y = get_attribute(xml_instance_info, "y", loc_data).as_int(); + if (type == "sb") { + device_rr_gsb.load_unique_sb_module_from_user_input(instance_x, instance_y); + } else if (type == "cb") { + // read_cb_unique_blocks(); + std::cout << "By pass here" << std::endl; + } else if (type == "gsb") { + std::cout << "By pass here" << std::endl; + // read_gsb_unique_blocks(); + } +} + +/******************************************************************** + * Parse XML codes about to an object of + *RepackDesignConstraints + *******************************************************************/ +template +int read_xml_unique_blocks(T& openfpga_ctx, const char* file_name, + const char* file_type, bool verbose) { + vtr::ScopedStartFinishTimer timer("Read unique blocks xml file"); + + // RepackDesignConstraints repack_design_constraints; + + /* Parse the file */ + pugi::xml_document doc; + pugiutil::loc_data loc_data; + + try { + loc_data = pugiutil::load_xml(doc, file_name); + + pugi::xml_node xml_root = get_single_child(doc, "unique_blocks", loc_data); + + /* get device_rr_gsb data type and initialize it*/ + auto device_rr_gsb = openfpga_ctx.mutable_device_rr_gsb(); + device_rr_gsb.clear(); + + /* load unique blocks xml file and set up device_rr_gdb */ + for (pugi::xml_node xml_block_info : xml_root.children()) { + /* Error out if the XML child has an invalid name! */ + if (xml_block_info.name() == std::string("block")) { + std::string type = + get_attribute(xml_block_info, "type", loc_data).as_string(); + std::string block_x = + get_attribute(xml_block_info, "x", loc_data).as_string(); + std::string block_y = + get_attribute(xml_block_info, "y", loc_data).as_string(); + for (pugi::xml_node xml_instance_info : xml_block_info.children()) { + if (xml_instance_info.name() == std::string("instance")) { + read_xml_unique_instance_info(device_rr_gsb, xml_instance_info, + loc_data, type); + } + // read_xml_unique_instance_info(xml_instance_info, loc_data); + } + } else { + bad_tag(xml_block_info, loc_data, xml_root, {"block"}); + return 1; + } + // std::cout << "what is the root name: " << xml_block_info.name() << + // std::endl; + } + } catch (pugiutil::XmlError& e) { + archfpga_throw(file_name, e.line(), "%s", e.what()); + } + + return 0; +} #endif From 72a90a4d8fdeb86cee0f8d8e6d0f89935f955e27 Mon Sep 17 00:00:00 2001 From: Lin Date: Mon, 5 Aug 2024 19:42:21 -0700 Subject: [PATCH 05/12] add preload function --- openfpga/src/annotation/device_rr_gsb.cpp | 49 ++++++++++++++------ openfpga/src/annotation/device_rr_gsb.h | 7 +-- openfpga/src/fabric/read_xml_unique_blocks.h | 4 +- 3 files changed, 41 insertions(+), 19 deletions(-) diff --git a/openfpga/src/annotation/device_rr_gsb.cpp b/openfpga/src/annotation/device_rr_gsb.cpp index a2ac6df3d..b3189c055 100644 --- a/openfpga/src/annotation/device_rr_gsb.cpp +++ b/openfpga/src/annotation/device_rr_gsb.cpp @@ -562,20 +562,17 @@ size_t DeviceRRGSB::get_cb_unique_module_index( return cb_unique_module_id; } -void DeviceRRGSB::load_unique_cb_module_from_user_input(int x, int y){ +void DeviceRRGSB::preload_unique_cbx_module(int x, int y) {} +void DeviceRRGSB::preload_unique_cby_module(int x, int y) {} - - -} - -void DeviceRRGSB::load_unique_sb_module_from_user_input(int ix, int iy){ +void DeviceRRGSB::preload_unique_sb_module(int ix, int iy) { vtr::Point sb_coordinate(ix, iy); bool is_unique_module = true; - + for (size_t id = 0; id < get_num_sb_unique_module(); ++id) { - /* Check whether the input module exists.*/ - if (sb_unique_module_[id].x() == ix && sb_unique_module_[id].y() == iy){ + /* Check whether the input module exists.*/ + if (sb_unique_module_[id].x() == ix && sb_unique_module_[id].y() == iy) { is_unique_module = false; sb_unique_module_id_[ix][iy] = id; break; @@ -584,15 +581,39 @@ void DeviceRRGSB::load_unique_sb_module_from_user_input(int ix, int iy){ if (true == is_unique_module) { sb_unique_module_.push_back(sb_coordinate); /* Record the id of unique mirror */ - sb_unique_module_id_[ix][iy] =sb_unique_module_.size() - 1; + sb_unique_module_id_[ix][iy] = sb_unique_module_.size() - 1; } } -void DeviceRRGSB::load_unique_gsb_module_from_user_input(int x, int y){ - - - +/* need to preload after cb and sb are preloaded */ +void DeviceRRGSB::preload_unique_gsb_module(int ix, int iy) { + // vtr::Point gsb_coordinate(ix, iy); + // bool is_unique_module = true; + // for (size_t id = 0; id < get_num_gsb_unique_module(); ++id) { + // const vtr::Point& gsb_unique_module_coordinate = + // gsb_unique_module_[id]; + // if ((sb_unique_module_id_[ix][iy] == + // sb_unique_module_id_[gsb_unique_module_coordinate.x()] + // [gsb_unique_module_coordinate.y()]) && + // (cbx_unique_module_id_[ix][iy] == + // cbx_unique_module_id_[gsb_unique_module_coordinate.x()] + // [gsb_unique_module_coordinate.y()]) && + // (cby_unique_module_id_[ix][iy] == + // cby_unique_module_id_[gsb_unique_module_coordinate.x()] + // [gsb_unique_module_coordinate.y()])) { + // /* This is a mirror, raise the flag and we finish */ + // is_unique_module = false; + // /* Record the id of unique mirror */ + // gsb_unique_module_id_[ix][iy] = id; + // break; + // } + // } + // if (true == is_unique_module) { + // add_gsb_unique_module(gsb_coordinate); + // /* Record the id of unique mirror */ + // gsb_unique_module_id_[ix][iy] = get_num_gsb_unique_module() - 1; + // } } } /* End namespace openfpga*/ diff --git a/openfpga/src/annotation/device_rr_gsb.h b/openfpga/src/annotation/device_rr_gsb.h index 267118e00..911ed31c4 100644 --- a/openfpga/src/annotation/device_rr_gsb.h +++ b/openfpga/src/annotation/device_rr_gsb.h @@ -95,9 +95,10 @@ class DeviceRRGSB { automatically identify and update the lists of unique mirrors and rotatable mirrors */ void clear(); /* clean the content */ - void load_unique_cb_module_from_user_input(int x, int y); - void load_unique_sb_module_from_user_input(int x, int y); - void load_unique_gsb_module_from_user_input(int x, int y); + void preload_unique_cbx_module(int x, int y); + void preload_unique_cby_module(int x, int y); + void preload_unique_sb_module(int x, int y); + void preload_unique_gsb_module(int x, int y); private: /* Internal cleaners */ void clear_gsb(); /* clean the content */ void clear_cb_unique_module(const t_rr_type& cb_type); /* clean the content */ diff --git a/openfpga/src/fabric/read_xml_unique_blocks.h b/openfpga/src/fabric/read_xml_unique_blocks.h index a6b7cb168..b9b17ce91 100644 --- a/openfpga/src/fabric/read_xml_unique_blocks.h +++ b/openfpga/src/fabric/read_xml_unique_blocks.h @@ -42,15 +42,15 @@ void read_xml_unique_instance_info(T& device_rr_gsb, pugi::xml_node& xml_instance_info, const pugiutil::loc_data& loc_data, std::string type) { - std::string pass = "pass here"; int instance_x = get_attribute(xml_instance_info, "x", loc_data).as_int(); int instance_y = get_attribute(xml_instance_info, "y", loc_data).as_int(); if (type == "sb") { - device_rr_gsb.load_unique_sb_module_from_user_input(instance_x, instance_y); + device_rr_gsb.preload_unique_sb_module(instance_x, instance_y); } else if (type == "cb") { // read_cb_unique_blocks(); std::cout << "By pass here" << std::endl; } else if (type == "gsb") { + /* should grab coordinates first and then by pass it to preload gsb*/ std::cout << "By pass here" << std::endl; // read_gsb_unique_blocks(); } From 9c67950a752ffa5cd8a5939c1c32dd484313a3c1 Mon Sep 17 00:00:00 2001 From: Lin Date: Wed, 7 Aug 2024 03:20:45 -0700 Subject: [PATCH 06/12] preload functions --- openfpga/src/annotation/device_rr_gsb.cpp | 95 +++++++------- openfpga/src/annotation/device_rr_gsb.h | 16 ++- .../src/base/openfpga_build_fabric_template.h | 16 ++- openfpga/src/fabric/read_xml_unique_blocks.h | 120 ++++++++++++------ 4 files changed, 154 insertions(+), 93 deletions(-) diff --git a/openfpga/src/annotation/device_rr_gsb.cpp b/openfpga/src/annotation/device_rr_gsb.cpp index b3189c055..f0155e339 100644 --- a/openfpga/src/annotation/device_rr_gsb.cpp +++ b/openfpga/src/annotation/device_rr_gsb.cpp @@ -562,58 +562,63 @@ size_t DeviceRRGSB::get_cb_unique_module_index( return cb_unique_module_id; } -void DeviceRRGSB::preload_unique_cbx_module(int x, int y) {} - -void DeviceRRGSB::preload_unique_cby_module(int x, int y) {} - -void DeviceRRGSB::preload_unique_sb_module(int ix, int iy) { - vtr::Point sb_coordinate(ix, iy); - bool is_unique_module = true; - - for (size_t id = 0; id < get_num_sb_unique_module(); ++id) { - /* Check whether the input module exists.*/ - if (sb_unique_module_[id].x() == ix && sb_unique_module_[id].y() == iy) { - is_unique_module = false; - sb_unique_module_id_[ix][iy] = id; +void DeviceRRGSB::preload_unique_cb_module( + const vtr::Point block_coordinate, + const std::vector> instance_coords, + const t_rr_type& cb_type) { + /* Add to list if this is a unique mirror*/ + size_t limit_x; + size_t limit_y; + switch(cb_type){ + case CHANX: + limit_x = cby_unique_module_id_.size(); + limit_y = cby_unique_module_id_[0].size(); break; - } + case CHANY: + limit_x = cby_unique_module_id_.size(); + limit_y = cby_unique_module_id_[0].size(); + break; + default: + VTR_LOG_ERROR("Invalid type"); } - if (true == is_unique_module) { - sb_unique_module_.push_back(sb_coordinate); + + VTR_ASSERT(block_coordinate.x() < limit_x); + VTR_ASSERT(block_coordinate.y() < limit_y); + add_cb_unique_module(cb_type, block_coordinate); + /* Record the id of unique mirror */ + set_cb_unique_module_id(cb_type, block_coordinate, + get_num_cb_unique_module(cb_type) - 1); + + /* Traverse the unique_mirror list and set up its module id */ + for (auto instance_location : instance_coords) { /* Record the id of unique mirror */ - sb_unique_module_id_[ix][iy] = sb_unique_module_.size() - 1; + VTR_ASSERT(instance_location.x() < limit_x); + VTR_ASSERT(instance_location.y() < limit_y); + set_cb_unique_module_id( + cb_type, instance_location, + cbx_unique_module_id_[block_coordinate.x()][block_coordinate.y()]); } } -/* need to preload after cb and sb are preloaded */ -void DeviceRRGSB::preload_unique_gsb_module(int ix, int iy) { - // vtr::Point gsb_coordinate(ix, iy); - // bool is_unique_module = true; +void DeviceRRGSB::preload_unique_sb_module( + const vtr::Point block_coordinate, + const std::vector> instance_coords) { + /*input block coordinate should be within gsb coord range*/ + VTR_ASSERT(block_coordinate.x() < sb_unique_module_id_.size()); + VTR_ASSERT(block_coordinate.y() < sb_unique_module_id_[0].size()); + sb_unique_module_.push_back(block_coordinate); + /* Record the id of unique module */ + sb_unique_module_id_[block_coordinate.x()][block_coordinate.y()] = + sb_unique_module_.size() - 1; - // for (size_t id = 0; id < get_num_gsb_unique_module(); ++id) { - // const vtr::Point& gsb_unique_module_coordinate = - // gsb_unique_module_[id]; - // if ((sb_unique_module_id_[ix][iy] == - // sb_unique_module_id_[gsb_unique_module_coordinate.x()] - // [gsb_unique_module_coordinate.y()]) && - // (cbx_unique_module_id_[ix][iy] == - // cbx_unique_module_id_[gsb_unique_module_coordinate.x()] - // [gsb_unique_module_coordinate.y()]) && - // (cby_unique_module_id_[ix][iy] == - // cby_unique_module_id_[gsb_unique_module_coordinate.x()] - // [gsb_unique_module_coordinate.y()])) { - // /* This is a mirror, raise the flag and we finish */ - // is_unique_module = false; - // /* Record the id of unique mirror */ - // gsb_unique_module_id_[ix][iy] = id; - // break; - // } - // } - // if (true == is_unique_module) { - // add_gsb_unique_module(gsb_coordinate); - // /* Record the id of unique mirror */ - // gsb_unique_module_id_[ix][iy] = get_num_gsb_unique_module() - 1; - // } + /* each mirror instance of the unique module will have the same module id as + * the unique module */ + for (auto instance_location : instance_coords) { + VTR_ASSERT(instance_location.x() < sb_unique_module_id_.size()); + VTR_ASSERT(instance_location.y() < sb_unique_module_id_[0].size()); + sb_unique_module_id_[instance_location.x()][instance_location.y()] = + sb_unique_module_id_[block_coordinate.x()][block_coordinate.y()]; + } } } /* End namespace openfpga*/ diff --git a/openfpga/src/annotation/device_rr_gsb.h b/openfpga/src/annotation/device_rr_gsb.h index 911ed31c4..b6928e91f 100644 --- a/openfpga/src/annotation/device_rr_gsb.h +++ b/openfpga/src/annotation/device_rr_gsb.h @@ -95,12 +95,16 @@ class DeviceRRGSB { automatically identify and update the lists of unique mirrors and rotatable mirrors */ void clear(); /* clean the content */ - void preload_unique_cbx_module(int x, int y); - void preload_unique_cby_module(int x, int y); - void preload_unique_sb_module(int x, int y); - void preload_unique_gsb_module(int x, int y); - private: /* Internal cleaners */ - void clear_gsb(); /* clean the content */ + void preload_unique_cb_module( + const vtr::Point block_coordinate, + const std::vector> instance_coords, + const t_rr_type& cb_type); + void preload_unique_sb_module( + const vtr::Point block_coordinate, + const std::vector> instance_coords); + + private: /* Internal cleaners */ + void clear_gsb(); /* clean the content */ void clear_cb_unique_module(const t_rr_type& cb_type); /* clean the content */ void clear_cb_unique_module_id( const t_rr_type& cb_type); /* clean the content */ diff --git a/openfpga/src/base/openfpga_build_fabric_template.h b/openfpga/src/base/openfpga_build_fabric_template.h index 3ba3c1d1a..7566e7d7f 100644 --- a/openfpga/src/base/openfpga_build_fabric_template.h +++ b/openfpga/src/base/openfpga_build_fabric_template.h @@ -20,12 +20,12 @@ #include "read_xml_io_name_map.h" #include "read_xml_module_name_map.h" #include "read_xml_tile_config.h" +#include "read_xml_unique_blocks.h" #include "rename_modules.h" #include "vtr_log.h" #include "vtr_time.h" #include "write_xml_fabric_pin_physical_location.h" #include "write_xml_module_name_map.h" -#include "read_xml_unique_blocks.h" /* begin namespace openfpga */ namespace openfpga { @@ -490,8 +490,13 @@ int read_unique_blocks_template(T& openfpga_ctx, const Command& cmd, std::string file_name = cmd_context.option_value(cmd, opt_file); std::string file_type = cmd_context.option_value(cmd, opt_type); /* Write hierarchy to a file */ - return read_xml_unique_blocks(openfpga_ctx, file_name.c_str(), file_type.c_str(), - cmd_context.option_enable(cmd, opt_verbose)); + if (file_type == "xml") { + return read_xml_unique_blocks(openfpga_ctx, file_name.c_str(), + file_type.c_str(), + cmd_context.option_enable(cmd, opt_verbose)); + } else { + VTR_LOG_ERROR("file type %s not supported", file_type); + } } template @@ -512,8 +517,9 @@ int write_unique_blocks_template(T& openfpga_ctx, const Command& cmd, std::string file_type = cmd_context.option_value(cmd, opt_type); /* Write hierarchy to a file */ - return read_xml_unique_blocks(openfpga_ctx, file_name.c_str(), file_type.c_str(), - cmd_context.option_enable(cmd, opt_verbose)); + return read_xml_unique_blocks(openfpga_ctx, file_name.c_str(), + file_type.c_str(), + cmd_context.option_enable(cmd, opt_verbose)); } } /* end namespace openfpga */ diff --git a/openfpga/src/fabric/read_xml_unique_blocks.h b/openfpga/src/fabric/read_xml_unique_blocks.h index b9b17ce91..32cb65d8d 100644 --- a/openfpga/src/fabric/read_xml_unique_blocks.h +++ b/openfpga/src/fabric/read_xml_unique_blocks.h @@ -23,61 +23,92 @@ /* Headers from libarchfpga */ #include "arch_error.h" +#include "device_rr_gsb_utils.h" #include "read_xml_unique_blocks.h" #include "read_xml_util.h" #include "rr_gsb.h" -/******************************************************************** - * Function declaration - *******************************************************************/ -template -int read_xml_unique_blocks(T& openfpga_ctx, const char* file_name, - const char* file_type, bool verbose); - /******************************************************************** * Parse XML codes of a to an object of unique_blocks *******************************************************************/ -template -void read_xml_unique_instance_info(T& device_rr_gsb, - pugi::xml_node& xml_instance_info, - const pugiutil::loc_data& loc_data, - std::string type) { +vtr::Point read_xml_unique_instance_info( + pugi::xml_node& xml_instance_info, const pugiutil::loc_data& loc_data) { int instance_x = get_attribute(xml_instance_info, "x", loc_data).as_int(); int instance_y = get_attribute(xml_instance_info, "y", loc_data).as_int(); - if (type == "sb") { - device_rr_gsb.preload_unique_sb_module(instance_x, instance_y); - } else if (type == "cb") { - // read_cb_unique_blocks(); - std::cout << "By pass here" << std::endl; - } else if (type == "gsb") { - /* should grab coordinates first and then by pass it to preload gsb*/ - std::cout << "By pass here" << std::endl; - // read_gsb_unique_blocks(); - } + vtr::Point instance_coordinate(instance_x, instance_y); + return instance_coordinate; } +template +void report_unique_module_status(T& openfpga_ctx, bool verbose_output) { + /* Report the stats */ + VTR_LOGV( + verbose_output, + "Detected %lu unique X-direction connection blocks from a total of %d " + "(compression rate=%.2f%)\n", + openfpga_ctx.device_rr_gsb().get_num_cb_unique_module(CHANX), + find_device_rr_gsb_num_cb_modules(openfpga_ctx.device_rr_gsb(), CHANX), + 100. * + ((float)find_device_rr_gsb_num_cb_modules(openfpga_ctx.device_rr_gsb(), + CHANX) / + (float)openfpga_ctx.device_rr_gsb().get_num_cb_unique_module(CHANX) - + 1.)); + + VTR_LOGV( + verbose_output, + "Detected %lu unique Y-direction connection blocks from a total of %d " + "(compression rate=%.2f%)\n", + openfpga_ctx.device_rr_gsb().get_num_cb_unique_module(CHANY), + find_device_rr_gsb_num_cb_modules(openfpga_ctx.device_rr_gsb(), CHANY), + 100. * + ((float)find_device_rr_gsb_num_cb_modules(openfpga_ctx.device_rr_gsb(), + CHANY) / + (float)openfpga_ctx.device_rr_gsb().get_num_cb_unique_module(CHANY) - + 1.)); + + VTR_LOGV( + verbose_output, + "Detected %lu unique switch blocks from a total of %d (compression " + "rate=%.2f%)\n", + openfpga_ctx.device_rr_gsb().get_num_sb_unique_module(), + find_device_rr_gsb_num_sb_modules(openfpga_ctx.device_rr_gsb(), + g_vpr_ctx.device().rr_graph), + 100. * ((float)find_device_rr_gsb_num_sb_modules( + openfpga_ctx.device_rr_gsb(), g_vpr_ctx.device().rr_graph) / + (float)openfpga_ctx.device_rr_gsb().get_num_sb_unique_module() - + 1.)); + + VTR_LOG( + "Detected %lu unique general switch blocks from a total of %d " + "(compression " + "rate=%.2f%)\n", + openfpga_ctx.device_rr_gsb().get_num_gsb_unique_module(), + find_device_rr_gsb_num_gsb_modules(openfpga_ctx.device_rr_gsb(), + g_vpr_ctx.device().rr_graph), + 100. * ((float)find_device_rr_gsb_num_gsb_modules( + openfpga_ctx.device_rr_gsb(), g_vpr_ctx.device().rr_graph) / + (float)openfpga_ctx.device_rr_gsb().get_num_gsb_unique_module() - + 1.)); +} /******************************************************************** * Parse XML codes about to an object of *RepackDesignConstraints *******************************************************************/ template int read_xml_unique_blocks(T& openfpga_ctx, const char* file_name, - const char* file_type, bool verbose) { + const char* file_type, bool verbose_output) { vtr::ScopedStartFinishTimer timer("Read unique blocks xml file"); - - // RepackDesignConstraints repack_design_constraints; - /* Parse the file */ pugi::xml_document doc; pugiutil::loc_data loc_data; - + VTR_ASSERT(strcmp(file_type, "xml") == 0); try { loc_data = pugiutil::load_xml(doc, file_name); pugi::xml_node xml_root = get_single_child(doc, "unique_blocks", loc_data); /* get device_rr_gsb data type and initialize it*/ - auto device_rr_gsb = openfpga_ctx.mutable_device_rr_gsb(); + openfpga::DeviceRRGSB& device_rr_gsb = openfpga_ctx.mutable_device_rr_gsb(); device_rr_gsb.clear(); /* load unique blocks xml file and set up device_rr_gdb */ @@ -86,23 +117,38 @@ int read_xml_unique_blocks(T& openfpga_ctx, const char* file_name, if (xml_block_info.name() == std::string("block")) { std::string type = get_attribute(xml_block_info, "type", loc_data).as_string(); - std::string block_x = - get_attribute(xml_block_info, "x", loc_data).as_string(); - std::string block_y = - get_attribute(xml_block_info, "y", loc_data).as_string(); + int block_x = get_attribute(xml_block_info, "x", loc_data).as_int(); + int block_y = get_attribute(xml_block_info, "y", loc_data).as_int(); + vtr::Point block_coordinate(block_x, block_y); + std::vector> instance_coords; for (pugi::xml_node xml_instance_info : xml_block_info.children()) { if (xml_instance_info.name() == std::string("instance")) { - read_xml_unique_instance_info(device_rr_gsb, xml_instance_info, - loc_data, type); + auto instance_coordinate = + read_xml_unique_instance_info(xml_instance_info, loc_data); + instance_coords.push_back(instance_coordinate); } - // read_xml_unique_instance_info(xml_instance_info, loc_data); + } + /* get block coordinate and instance coordinate, try to setup device rr + * gsb */ + if (type == "sb") { + device_rr_gsb.preload_unique_sb_module(block_coordinate, + instance_coords); + } else if (type == "cby") { + device_rr_gsb.preload_unique_cb_module(block_coordinate, + instance_coords, CHANY); + } else if (type == "cbx") { + device_rr_gsb.preload_unique_cb_module(block_coordinate, + instance_coords, CHANX); + } else { + VTR_LOG_ERROR("Unexpected type!"); } } else { bad_tag(xml_block_info, loc_data, xml_root, {"block"}); return 1; } - // std::cout << "what is the root name: " << xml_block_info.name() << - // std::endl; + } + if (verbose_output) { + report_unique_module_status(openfpga_ctx, true); } } catch (pugiutil::XmlError& e) { archfpga_throw(file_name, e.line(), "%s", e.what()); From e45619b22d56dc1d4afdc923a6c514ece32c1139 Mon Sep 17 00:00:00 2001 From: Lin Date: Thu, 8 Aug 2024 01:00:35 -0700 Subject: [PATCH 07/12] write sb --- openfpga/src/annotation/device_rr_gsb.cpp | 24 +++++- openfpga/src/annotation/device_rr_gsb.h | 5 ++ .../src/base/openfpga_build_fabric_template.h | 3 +- openfpga/src/fabric/read_xml_unique_blocks.h | 73 ++++++++++++++++++- 4 files changed, 100 insertions(+), 5 deletions(-) diff --git a/openfpga/src/annotation/device_rr_gsb.cpp b/openfpga/src/annotation/device_rr_gsb.cpp index f0155e339..6af394bba 100644 --- a/openfpga/src/annotation/device_rr_gsb.cpp +++ b/openfpga/src/annotation/device_rr_gsb.cpp @@ -569,7 +569,7 @@ void DeviceRRGSB::preload_unique_cb_module( /* Add to list if this is a unique mirror*/ size_t limit_x; size_t limit_y; - switch(cb_type){ + switch (cb_type) { case CHANX: limit_x = cby_unique_module_id_.size(); limit_y = cby_unique_module_id_[0].size(); @@ -621,4 +621,26 @@ void DeviceRRGSB::preload_unique_sb_module( } } +void DeviceRRGSB::get_id_unique_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_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); + } + } +} } /* End namespace openfpga*/ diff --git a/openfpga/src/annotation/device_rr_gsb.h b/openfpga/src/annotation/device_rr_gsb.h index b6928e91f..874c08c0e 100644 --- a/openfpga/src/annotation/device_rr_gsb.h +++ b/openfpga/src/annotation/device_rr_gsb.h @@ -103,6 +103,11 @@ class DeviceRRGSB { const vtr::Point block_coordinate, const std::vector> instance_coords); + void get_id_instance_map( + std::map>>& id_instance_map) const; + void get_id_unique_block_map( + std::map>& id_unique_block_map) const; + private: /* Internal cleaners */ void clear_gsb(); /* clean the content */ void clear_cb_unique_module(const t_rr_type& cb_type); /* clean the content */ diff --git a/openfpga/src/base/openfpga_build_fabric_template.h b/openfpga/src/base/openfpga_build_fabric_template.h index 7566e7d7f..0e16efc74 100644 --- a/openfpga/src/base/openfpga_build_fabric_template.h +++ b/openfpga/src/base/openfpga_build_fabric_template.h @@ -517,11 +517,10 @@ int write_unique_blocks_template(T& openfpga_ctx, const Command& cmd, std::string file_type = cmd_context.option_value(cmd, opt_type); /* Write hierarchy to a file */ - return read_xml_unique_blocks(openfpga_ctx, file_name.c_str(), + return write_xml_unique_blocks(openfpga_ctx, file_name.c_str(), file_type.c_str(), cmd_context.option_enable(cmd, opt_verbose)); } - } /* end namespace openfpga */ #endif diff --git a/openfpga/src/fabric/read_xml_unique_blocks.h b/openfpga/src/fabric/read_xml_unique_blocks.h index 32cb65d8d..59ba8d106 100644 --- a/openfpga/src/fabric/read_xml_unique_blocks.h +++ b/openfpga/src/fabric/read_xml_unique_blocks.h @@ -27,6 +27,8 @@ #include "read_xml_unique_blocks.h" #include "read_xml_util.h" #include "rr_gsb.h" +#include "write_xml_utils.h" +#include "openfpga_digest.h" /******************************************************************** * Parse XML codes of a to an object of unique_blocks @@ -135,10 +137,10 @@ int read_xml_unique_blocks(T& openfpga_ctx, const char* file_name, instance_coords); } else if (type == "cby") { device_rr_gsb.preload_unique_cb_module(block_coordinate, - instance_coords, CHANY); + instance_coords, CHANY); } else if (type == "cbx") { device_rr_gsb.preload_unique_cb_module(block_coordinate, - instance_coords, CHANX); + instance_coords, CHANX); } else { VTR_LOG_ERROR("Unexpected type!"); } @@ -157,4 +159,71 @@ int read_xml_unique_blocks(T& openfpga_ctx, const char* file_name, return 0; } + +template +int write_xml_sb_blocks(std::fstream& fp, const T& openfpga_ctx) { + std::map> id_unique_block_map; + std::map>> id_instance_map; + openfpga_ctx.device_rr_gsb().get_id_unique_block_map(id_unique_block_map); + openfpga_ctx.device_rr_gsb().get_id_instance_map(id_instance_map); + + /* Validate the file stream */ + if (false == openfpga::valid_file_stream(fp)) { + return 2; + } + for (const auto& pair : id_unique_block_map) { + openfpga::write_tab_to_file(fp, 1); + fp << "" + << "\n"; + + for (const auto& instance_info : id_instance_map[pair.first]) { + openfpga::write_tab_to_file(fp, 2); + fp << "" + << "\n"; + } + } + + return 0; +} + +template +int write_xml_unique_blocks(const T& openfpga_ctx, const char* fname, + const char* file_type, bool verbose_output) { + vtr::ScopedStartFinishTimer timer("Write unique blocks..."); + + /* Create a file handler */ + std::fstream fp; + /* Open the file stream */ + fp.open(std::string(fname), std::fstream::out | std::fstream::trunc); + + /* Validate the file stream */ + openfpga::check_file_stream(fname, fp); + + /* Write the root node */ + fp << "" + << "\n"; + + int err_code = 0; + + err_code += write_xml_sb_blocks(fp, openfpga_ctx); + + /* Finish writing the root node */ + fp << "" + << "\n"; + + /* Close the file stream */ + fp.close(); + + return err_code; +} + #endif From 755959a890f7d155e9001204e668375099a797b9 Mon Sep 17 00:00:00 2001 From: Lin Date: Thu, 8 Aug 2024 02:54:02 -0700 Subject: [PATCH 08/12] add cb cx write function --- openfpga/src/annotation/device_rr_gsb.cpp | 51 +++++++++++++++++++- openfpga/src/annotation/device_rr_gsb.h | 12 ++++- openfpga/src/fabric/read_xml_unique_blocks.h | 48 +++++++++++------- 3 files changed, 90 insertions(+), 21 deletions(-) diff --git a/openfpga/src/annotation/device_rr_gsb.cpp b/openfpga/src/annotation/device_rr_gsb.cpp index 6af394bba..50e1cab33 100644 --- a/openfpga/src/annotation/device_rr_gsb.cpp +++ b/openfpga/src/annotation/device_rr_gsb.cpp @@ -621,7 +621,7 @@ void DeviceRRGSB::preload_unique_sb_module( } } -void DeviceRRGSB::get_id_unique_block_map( +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]; @@ -631,7 +631,7 @@ void DeviceRRGSB::get_id_unique_block_map( } } -void DeviceRRGSB::get_id_instance_map( +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) { @@ -643,4 +643,51 @@ void DeviceRRGSB::get_id_instance_map( } } } + +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 874c08c0e..513d4b003 100644 --- a/openfpga/src/annotation/device_rr_gsb.h +++ b/openfpga/src/annotation/device_rr_gsb.h @@ -103,9 +103,17 @@ class DeviceRRGSB { const vtr::Point block_coordinate, const std::vector> instance_coords); - void get_id_instance_map( + void get_id_sb_instance_map( std::map>>& id_instance_map) const; - void get_id_unique_block_map( + 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 */ diff --git a/openfpga/src/fabric/read_xml_unique_blocks.h b/openfpga/src/fabric/read_xml_unique_blocks.h index 59ba8d106..395f44afd 100644 --- a/openfpga/src/fabric/read_xml_unique_blocks.h +++ b/openfpga/src/fabric/read_xml_unique_blocks.h @@ -4,7 +4,7 @@ /******************************************************************** * This file includes the top-level function of this library * which reads an XML of unique routing blocks to the associated - * data structures + * data structures device_rr_gsb *******************************************************************/ #include @@ -24,14 +24,15 @@ /* Headers from libarchfpga */ #include "arch_error.h" #include "device_rr_gsb_utils.h" +#include "openfpga_digest.h" #include "read_xml_unique_blocks.h" #include "read_xml_util.h" #include "rr_gsb.h" #include "write_xml_utils.h" -#include "openfpga_digest.h" /******************************************************************** - * Parse XML codes of a to an object of unique_blocks + * Parse XML codes of a to an object of device_rr_gsb + * instance is the mirror module of unique module. *******************************************************************/ vtr::Point read_xml_unique_instance_info( pugi::xml_node& xml_instance_info, const pugiutil::loc_data& loc_data) { @@ -93,8 +94,7 @@ void report_unique_module_status(T& openfpga_ctx, bool verbose_output) { 1.)); } /******************************************************************** - * Parse XML codes about to an object of - *RepackDesignConstraints + * Parse XML codes about to an object of device_rr_gsb *******************************************************************/ template int read_xml_unique_blocks(T& openfpga_ctx, const char* file_name, @@ -159,14 +159,10 @@ int read_xml_unique_blocks(T& openfpga_ctx, const char* file_name, return 0; } - -template -int write_xml_sb_blocks(std::fstream& fp, const T& openfpga_ctx) { - std::map> id_unique_block_map; - std::map>> id_instance_map; - openfpga_ctx.device_rr_gsb().get_id_unique_block_map(id_unique_block_map); - openfpga_ctx.device_rr_gsb().get_id_instance_map(id_instance_map); - +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 */ if (false == openfpga::valid_file_stream(fp)) { return 2; @@ -174,11 +170,11 @@ int write_xml_sb_blocks(std::fstream& fp, const T& openfpga_ctx) { for (const auto& pair : id_unique_block_map) { openfpga::write_tab_to_file(fp, 1); fp << "" + fp << ">" << "\n"; for (const auto& instance_info : id_instance_map[pair.first]) { @@ -190,6 +186,9 @@ int write_xml_sb_blocks(std::fstream& fp, const T& openfpga_ctx) { fp << "/>" << "\n"; } + openfpga::write_tab_to_file(fp, 1); + fp << "" + << "\n"; } return 0; @@ -213,8 +212,23 @@ int write_xml_unique_blocks(const T& openfpga_ctx, const char* fname, << "\n"; int err_code = 0; - - err_code += write_xml_sb_blocks(fp, openfpga_ctx); + std::map> id_unique_block_map; + std::map>> id_instance_map; + openfpga_ctx.device_rr_gsb().get_id_unique_sb_block_map(id_unique_block_map); + openfpga_ctx.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"); + + id_unique_block_map.clear(); + id_instance_map.clear(); + openfpga_ctx.device_rr_gsb().get_id_unique_cbx_block_map(id_unique_block_map); + openfpga_ctx.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"); + + id_unique_block_map.clear(); + id_instance_map.clear(); + openfpga_ctx.device_rr_gsb().get_id_unique_cby_block_map(id_unique_block_map); + openfpga_ctx.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"); /* Finish writing the root node */ fp << "" From a785a57520b04f1a2aa1f7387f3a61c7b5b70b0d Mon Sep 17 00:00:00 2001 From: Lin Date: Sun, 18 Aug 2024 22:41:40 -0700 Subject: [PATCH 09/12] small bug mod --- openfpga/src/annotation/device_rr_gsb.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/openfpga/src/annotation/device_rr_gsb.cpp b/openfpga/src/annotation/device_rr_gsb.cpp index 50e1cab33..5831c3638 100644 --- a/openfpga/src/annotation/device_rr_gsb.cpp +++ b/openfpga/src/annotation/device_rr_gsb.cpp @@ -571,8 +571,8 @@ void DeviceRRGSB::preload_unique_cb_module( size_t limit_y; switch (cb_type) { case CHANX: - limit_x = cby_unique_module_id_.size(); - limit_y = cby_unique_module_id_[0].size(); + limit_x = cbx_unique_module_id_.size(); + limit_y = cbx_unique_module_id_[0].size(); break; case CHANY: limit_x = cby_unique_module_id_.size(); From 699131ad58c38007b1425f7a5016d94c80644b02 Mon Sep 17 00:00:00 2001 From: Lin Date: Mon, 19 Aug 2024 01:18:06 -0700 Subject: [PATCH 10/12] full flow with bugs --- openfpga/src/annotation/device_rr_gsb.cpp | 19 +++++++++++++------ openfpga/src/annotation/device_rr_gsb.h | 2 +- .../src/base/openfpga_build_fabric_template.h | 12 +++++++++--- .../base/openfpga_setup_command_template.h | 4 ++++ openfpga/src/fabric/read_xml_unique_blocks.h | 3 ++- 5 files changed, 29 insertions(+), 11 deletions(-) diff --git a/openfpga/src/annotation/device_rr_gsb.cpp b/openfpga/src/annotation/device_rr_gsb.cpp index 5831c3638..dc6c2b397 100644 --- a/openfpga/src/annotation/device_rr_gsb.cpp +++ b/openfpga/src/annotation/device_rr_gsb.cpp @@ -421,6 +421,19 @@ void DeviceRRGSB::clear() { clear_sb_unique_module_id(); } +void DeviceRRGSB::clear_unique_modules(){ + /* clean unique module lists */ + clear_cb_unique_module(CHANX); + clear_cb_unique_module_id(CHANX); + + clear_cb_unique_module(CHANY); + clear_cb_unique_module_id(CHANY); + + clear_sb_unique_module(); + clear_sb_unique_module_id(); +} + + void DeviceRRGSB::clear_gsb() { /* clean gsb array */ for (size_t x = 0; x < rr_gsb_.size(); ++x) { @@ -572,18 +585,15 @@ void DeviceRRGSB::preload_unique_cb_module( switch (cb_type) { case CHANX: limit_x = cbx_unique_module_id_.size(); - limit_y = cbx_unique_module_id_[0].size(); break; case CHANY: limit_x = cby_unique_module_id_.size(); - limit_y = cby_unique_module_id_[0].size(); break; default: VTR_LOG_ERROR("Invalid type"); } VTR_ASSERT(block_coordinate.x() < limit_x); - VTR_ASSERT(block_coordinate.y() < limit_y); add_cb_unique_module(cb_type, block_coordinate); /* Record the id of unique mirror */ set_cb_unique_module_id(cb_type, block_coordinate, @@ -593,7 +603,6 @@ void DeviceRRGSB::preload_unique_cb_module( for (auto instance_location : instance_coords) { /* Record the id of unique mirror */ VTR_ASSERT(instance_location.x() < limit_x); - VTR_ASSERT(instance_location.y() < limit_y); set_cb_unique_module_id( cb_type, instance_location, cbx_unique_module_id_[block_coordinate.x()][block_coordinate.y()]); @@ -605,7 +614,6 @@ void DeviceRRGSB::preload_unique_sb_module( const std::vector> instance_coords) { /*input block coordinate should be within gsb coord range*/ VTR_ASSERT(block_coordinate.x() < sb_unique_module_id_.size()); - VTR_ASSERT(block_coordinate.y() < sb_unique_module_id_[0].size()); sb_unique_module_.push_back(block_coordinate); /* Record the id of unique module */ sb_unique_module_id_[block_coordinate.x()][block_coordinate.y()] = @@ -615,7 +623,6 @@ void DeviceRRGSB::preload_unique_sb_module( * the unique module */ for (auto instance_location : instance_coords) { VTR_ASSERT(instance_location.x() < sb_unique_module_id_.size()); - VTR_ASSERT(instance_location.y() < sb_unique_module_id_[0].size()); sb_unique_module_id_[instance_location.x()][instance_location.y()] = sb_unique_module_id_[block_coordinate.x()][block_coordinate.y()]; } diff --git a/openfpga/src/annotation/device_rr_gsb.h b/openfpga/src/annotation/device_rr_gsb.h index 513d4b003..699119f63 100644 --- a/openfpga/src/annotation/device_rr_gsb.h +++ b/openfpga/src/annotation/device_rr_gsb.h @@ -102,7 +102,7 @@ class DeviceRRGSB { void preload_unique_sb_module( 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( diff --git a/openfpga/src/base/openfpga_build_fabric_template.h b/openfpga/src/base/openfpga_build_fabric_template.h index 0e16efc74..259e74569 100644 --- a/openfpga/src/base/openfpga_build_fabric_template.h +++ b/openfpga/src/base/openfpga_build_fabric_template.h @@ -101,6 +101,7 @@ int build_fabric_template(T& openfpga_ctx, const Command& cmd, const CommandContext& cmd_context) { CommandOptionId opt_frame_view = cmd.option("frame_view"); CommandOptionId opt_compress_routing = cmd.option("compress_routing"); + CommandOptionId opt_preload = cmd.option("preload"); CommandOptionId opt_duplicate_grid_pin = cmd.option("duplicate_grid_pin"); CommandOptionId opt_gen_random_fabric_key = cmd.option("generate_random_fabric_key"); @@ -143,13 +144,18 @@ int build_fabric_template(T& openfpga_ctx, const Command& cmd, } } - if (true == cmd_context.option_enable(cmd, opt_compress_routing)) { + if (true == cmd_context.option_enable(cmd, opt_compress_routing) && + false == cmd_context.option_enable(cmd, opt_preload)) { compress_routing_hierarchy_template( openfpga_ctx, cmd_context.option_enable(cmd, opt_verbose)); /* Update flow manager to enable compress routing */ openfpga_ctx.mutable_flow_manager().set_compress_routing(true); } + if (cmd_context.option_enable(cmd, opt_preload)){ + openfpga_ctx.mutable_flow_manager().set_compress_routing(true); + } + VTR_LOG("\n"); /* Record the execution status in curr_status for each command @@ -518,8 +524,8 @@ int write_unique_blocks_template(T& openfpga_ctx, const Command& cmd, /* Write hierarchy to a file */ return write_xml_unique_blocks(openfpga_ctx, file_name.c_str(), - file_type.c_str(), - cmd_context.option_enable(cmd, opt_verbose)); + file_type.c_str(), + cmd_context.option_enable(cmd, opt_verbose)); } } /* end namespace openfpga */ diff --git a/openfpga/src/base/openfpga_setup_command_template.h b/openfpga/src/base/openfpga_setup_command_template.h index 01e2f78cb..9d2631a61 100644 --- a/openfpga/src/base/openfpga_setup_command_template.h +++ b/openfpga/src/base/openfpga_setup_command_template.h @@ -391,6 +391,10 @@ ShellCommandId add_build_fabric_command_template( "Compress the number of unique routing modules by " "identifying the unique GSBs"); + /* Add an option '--preload' */ + shell_cmd.add_option("preload", false, + "preload unique routing modules from user input xml file"); + /* Add an option '--duplicate_grid_pin' */ shell_cmd.add_option("duplicate_grid_pin", false, "Duplicate the pins on the same side of a grid"); diff --git a/openfpga/src/fabric/read_xml_unique_blocks.h b/openfpga/src/fabric/read_xml_unique_blocks.h index 395f44afd..e132828de 100644 --- a/openfpga/src/fabric/read_xml_unique_blocks.h +++ b/openfpga/src/fabric/read_xml_unique_blocks.h @@ -111,7 +111,8 @@ int read_xml_unique_blocks(T& openfpga_ctx, const char* file_name, /* get device_rr_gsb data type and initialize it*/ openfpga::DeviceRRGSB& device_rr_gsb = openfpga_ctx.mutable_device_rr_gsb(); - device_rr_gsb.clear(); + /* clear unique modules */ + device_rr_gsb.clear_unique_modules(); /* load unique blocks xml file and set up device_rr_gdb */ for (pugi::xml_node xml_block_info : xml_root.children()) { From 913fdc043ed2f2ef9818c4ae47e35d9db54f1f3e Mon Sep 17 00:00:00 2001 From: Lin Date: Fri, 23 Aug 2024 03:52:16 -0700 Subject: [PATCH 11/12] debuged --- openfpga/src/annotation/device_rr_gsb.cpp | 130 +++++++++++++++--- openfpga/src/annotation/device_rr_gsb.h | 22 +-- .../src/base/openfpga_build_fabric_template.h | 5 +- openfpga/src/fabric/read_xml_unique_blocks.h | 35 +++-- 4 files changed, 145 insertions(+), 47 deletions(-) diff --git a/openfpga/src/annotation/device_rr_gsb.cpp b/openfpga/src/annotation/device_rr_gsb.cpp index dc6c2b397..6acd8bb3f 100644 --- a/openfpga/src/annotation/device_rr_gsb.cpp +++ b/openfpga/src/annotation/device_rr_gsb.cpp @@ -1,8 +1,12 @@ /************************************************************************ * Member functions for class DeviceRRGSB ***********************************************************************/ + #include "device_rr_gsb.h" +#include +#include + #include "rr_gsb_utils.h" #include "vtr_assert.h" #include "vtr_log.h" @@ -182,6 +186,18 @@ void DeviceRRGSB::reserve(const vtr::Point& coordinate) { cby_unique_module_id_[x].resize(coordinate.y()); } } +void DeviceRRGSB::reserve_unique_modules(const vtr::Point& coordinate) { + sb_unique_module_id_.resize(coordinate.x()); + cbx_unique_module_id_.resize(coordinate.x()); + cby_unique_module_id_.resize(coordinate.x()); + + for (size_t x = 0; x < coordinate.x(); ++x) { + sb_unique_module_id_[x].resize(coordinate.y()); + + cbx_unique_module_id_[x].resize(coordinate.y()); + cby_unique_module_id_[x].resize(coordinate.y()); + } +} /* Resize rr_switch_block array is needed*/ void DeviceRRGSB::resize_upon_need(const vtr::Point& coordinate) { @@ -351,7 +367,34 @@ void DeviceRRGSB::build_gsb_unique_module() { } } } - +void DeviceRRGSB::print_txt() { + std::ofstream outFile( + "/home/linear/project/test_data/and2/config/output_read.txt"); + outFile << "################# sb_unique_module_id_ #########" << "\n"; + for (int i = 0; i < sb_unique_module_id_.size(); i++) { + for (int j = 0; j < sb_unique_module_id_[0].size(); j++) { + outFile << i << "," << j << ":" << sb_unique_module_id_[i][j] << "\n"; + } + } + outFile << "################# cbx_unique_module_id_ #########" << "\n"; + for (int i = 0; i < cbx_unique_module_id_.size(); i++) { + for (int j = 0; j < cbx_unique_module_id_[0].size(); j++) { + outFile << i << "," << j << ":" << cbx_unique_module_id_[i][j] << "\n"; + } + } + outFile << "################# cby_unique_module_id_ #########" << "\n"; + for (int i = 0; i < cby_unique_module_id_.size(); i++) { + for (int j = 0; j < cby_unique_module_id_[0].size(); j++) { + outFile << i << "," << j << ":" << cby_unique_module_id_[i][j] << "\n"; + } + } + outFile << "################# gsb_unique_module_id_ #########" << "\n"; + for (int i = 0; i < gsb_unique_module_id_.size(); i++) { + for (int j = 0; j < gsb_unique_module_id_[0].size(); j++) { + outFile << i << "," << j << ":" << gsb_unique_module_id_[i][j] << "\n"; + } + } +} void DeviceRRGSB::build_unique_module(const RRGraphView& rr_graph) { build_sb_unique_module(rr_graph); @@ -359,6 +402,32 @@ void DeviceRRGSB::build_unique_module(const RRGraphView& rr_graph) { build_cb_unique_module(rr_graph, CHANY); build_gsb_unique_module(); + std::ofstream outFile( + "/home/linear/project/test_data/and2/config/output.txt"); + outFile << "################# sb_unique_module_id_ #########" << "\n"; + for (int i = 0; i < sb_unique_module_id_.size(); i++) { + for (int j = 0; j < sb_unique_module_id_[0].size(); j++) { + outFile << i << "," << j << ":" << sb_unique_module_id_[i][j] << "\n"; + } + } + outFile << "################# cbx_unique_module_id_ #########" << "\n"; + for (int i = 0; i < cbx_unique_module_id_.size(); i++) { + for (int j = 0; j < cbx_unique_module_id_[0].size(); j++) { + outFile << i << "," << j << ":" << cbx_unique_module_id_[i][j] << "\n"; + } + } + outFile << "################# cby_unique_module_id_ #########" << "\n"; + for (int i = 0; i < cby_unique_module_id_.size(); i++) { + for (int j = 0; j < cby_unique_module_id_[0].size(); j++) { + outFile << i << "," << j << ":" << cby_unique_module_id_[i][j] << "\n"; + } + } + outFile << "################# gsb_unique_module_id_ #########" << "\n"; + for (int i = 0; i < gsb_unique_module_id_.size(); i++) { + for (int j = 0; j < gsb_unique_module_id_[0].size(); j++) { + outFile << i << "," << j << ":" << gsb_unique_module_id_[i][j] << "\n"; + } + } } void DeviceRRGSB::add_gsb_unique_module(const vtr::Point& coordinate) { @@ -421,7 +490,7 @@ void DeviceRRGSB::clear() { clear_sb_unique_module_id(); } -void DeviceRRGSB::clear_unique_modules(){ +void DeviceRRGSB::clear_unique_modules() { /* clean unique module lists */ clear_cb_unique_module(CHANX); clear_cb_unique_module_id(CHANX); @@ -433,7 +502,6 @@ void DeviceRRGSB::clear_unique_modules(){ clear_sb_unique_module_id(); } - void DeviceRRGSB::clear_gsb() { /* clean gsb array */ for (size_t x = 0; x < rr_gsb_.size(); ++x) { @@ -575,45 +643,62 @@ size_t DeviceRRGSB::get_cb_unique_module_index( return cb_unique_module_id; } -void DeviceRRGSB::preload_unique_cb_module( +void DeviceRRGSB::preload_unique_cbx_module( const vtr::Point block_coordinate, - const std::vector> instance_coords, - const t_rr_type& cb_type) { + const std::vector> instance_coords) { /* Add to list if this is a unique mirror*/ - size_t limit_x; - size_t limit_y; - switch (cb_type) { - case CHANX: - limit_x = cbx_unique_module_id_.size(); - break; - case CHANY: - limit_x = cby_unique_module_id_.size(); - break; - default: - VTR_LOG_ERROR("Invalid type"); - } + size_t limit_x = cbx_unique_module_id_.size(); + size_t limit_y = cbx_unique_module_id_[0].size(); VTR_ASSERT(block_coordinate.x() < limit_x); - add_cb_unique_module(cb_type, block_coordinate); + VTR_ASSERT(block_coordinate.y() < limit_y); + add_cb_unique_module(CHANX, block_coordinate); /* Record the id of unique mirror */ - set_cb_unique_module_id(cb_type, block_coordinate, - get_num_cb_unique_module(cb_type) - 1); + set_cb_unique_module_id(CHANX, block_coordinate, + get_num_cb_unique_module(CHANX) - 1); /* Traverse the unique_mirror list and set up its module id */ for (auto instance_location : instance_coords) { /* Record the id of unique mirror */ VTR_ASSERT(instance_location.x() < limit_x); + VTR_ASSERT(instance_location.y() < limit_y); set_cb_unique_module_id( - cb_type, instance_location, + CHANX, instance_location, cbx_unique_module_id_[block_coordinate.x()][block_coordinate.y()]); } } +void DeviceRRGSB::preload_unique_cby_module( + const vtr::Point block_coordinate, + const std::vector> instance_coords) { + /* Add to list if this is a unique mirror*/ + size_t limit_x = cby_unique_module_id_.size(); + size_t limit_y = cby_unique_module_id_[0].size(); + + VTR_ASSERT(block_coordinate.x() < limit_x); + VTR_ASSERT(block_coordinate.y() < limit_y); + add_cb_unique_module(CHANY, block_coordinate); + /* Record the id of unique mirror */ + set_cb_unique_module_id(CHANY, block_coordinate, + get_num_cb_unique_module(CHANY) - 1); + + /* Traverse the unique_mirror list and set up its module id */ + for (auto instance_location : instance_coords) { + /* Record the id of unique mirror */ + VTR_ASSERT(instance_location.x() < limit_x); + VTR_ASSERT(instance_location.y() < limit_y); + set_cb_unique_module_id( + CHANY, instance_location, + cby_unique_module_id_[block_coordinate.x()][block_coordinate.y()]); + } +} + void DeviceRRGSB::preload_unique_sb_module( const vtr::Point block_coordinate, const std::vector> instance_coords) { /*input block coordinate should be within gsb coord range*/ VTR_ASSERT(block_coordinate.x() < sb_unique_module_id_.size()); + VTR_ASSERT(block_coordinate.y() < sb_unique_module_id_[0].size()); sb_unique_module_.push_back(block_coordinate); /* Record the id of unique module */ sb_unique_module_id_[block_coordinate.x()][block_coordinate.y()] = @@ -623,6 +708,7 @@ void DeviceRRGSB::preload_unique_sb_module( * the unique module */ for (auto instance_location : instance_coords) { VTR_ASSERT(instance_location.x() < sb_unique_module_id_.size()); + VTR_ASSERT(instance_location.y() < sb_unique_module_id_[0].size()); sb_unique_module_id_[instance_location.x()][instance_location.y()] = sb_unique_module_id_[block_coordinate.x()][block_coordinate.y()]; } diff --git a/openfpga/src/annotation/device_rr_gsb.h b/openfpga/src/annotation/device_rr_gsb.h index 699119f63..92e0f72d5 100644 --- a/openfpga/src/annotation/device_rr_gsb.h +++ b/openfpga/src/annotation/device_rr_gsb.h @@ -68,11 +68,14 @@ class DeviceRRGSB { size_t get_cb_unique_module_index(const t_rr_type& cb_type, const vtr::Point& coordinate) const; - public: /* Mutators */ + public: /* Mutators */ + void build_gsb_unique_module(); /* Add a switch block to the array, which will + automatically identify and update the lists + of unique mirrors and rotatable mirrors */ void reserve( const vtr::Point& coordinate); /* Pre-allocate the rr_switch_block array that the device requires */ - void reserve_sb_unique_submodule_id( + void reserve_unique_modules( const vtr::Point& coordinate); /* Pre-allocate the rr_sb_unique_module_id matrix that the device requires */ @@ -95,10 +98,13 @@ class DeviceRRGSB { automatically identify and update the lists of unique mirrors and rotatable mirrors */ void clear(); /* clean the content */ - void preload_unique_cb_module( + void print_txt(); + void preload_unique_cbx_module( const vtr::Point block_coordinate, - const std::vector> instance_coords, - const t_rr_type& cb_type); + const std::vector> instance_coords); + void preload_unique_cby_module( + const vtr::Point block_coordinate, + const std::vector> instance_coords); void preload_unique_sb_module( const vtr::Point block_coordinate, const std::vector> instance_coords); @@ -154,10 +160,8 @@ class DeviceRRGSB { const t_rr_type& cb_type); /* Add a switch block to the array, which will automatically identify and update the lists of unique side module */ - void build_gsb_unique_module(); /* Add a switch block to the array, which will - automatically identify and update the lists - of unique mirrors and rotatable mirrors */ - private: /* Internal Data */ + + private: /* Internal Data */ std::vector> rr_gsb_; std::vector> diff --git a/openfpga/src/base/openfpga_build_fabric_template.h b/openfpga/src/base/openfpga_build_fabric_template.h index 259e74569..d36a9312b 100644 --- a/openfpga/src/base/openfpga_build_fabric_template.h +++ b/openfpga/src/base/openfpga_build_fabric_template.h @@ -150,9 +150,8 @@ int build_fabric_template(T& openfpga_ctx, const Command& cmd, openfpga_ctx, cmd_context.option_enable(cmd, opt_verbose)); /* Update flow manager to enable compress routing */ openfpga_ctx.mutable_flow_manager().set_compress_routing(true); - } - - if (cmd_context.option_enable(cmd, opt_preload)){ + } else if (true == cmd_context.option_enable(cmd, opt_compress_routing) && + true == cmd_context.option_enable(cmd, opt_preload)){ openfpga_ctx.mutable_flow_manager().set_compress_routing(true); } diff --git a/openfpga/src/fabric/read_xml_unique_blocks.h b/openfpga/src/fabric/read_xml_unique_blocks.h index e132828de..cb021d1a3 100644 --- a/openfpga/src/fabric/read_xml_unique_blocks.h +++ b/openfpga/src/fabric/read_xml_unique_blocks.h @@ -32,7 +32,7 @@ /******************************************************************** * Parse XML codes of a to an object of device_rr_gsb - * instance is the mirror module of unique module. + * instance is the mirror module of unique module. *******************************************************************/ vtr::Point read_xml_unique_instance_info( pugi::xml_node& xml_instance_info, const pugiutil::loc_data& loc_data) { @@ -113,7 +113,9 @@ int read_xml_unique_blocks(T& openfpga_ctx, const char* file_name, openfpga::DeviceRRGSB& device_rr_gsb = openfpga_ctx.mutable_device_rr_gsb(); /* clear unique modules */ device_rr_gsb.clear_unique_modules(); - + vtr::Point grid_coord(g_vpr_ctx.device().grid.width() - 1, + g_vpr_ctx.device().grid.height() - 1); + device_rr_gsb.reserve_unique_modules(grid_coord); /* load unique blocks xml file and set up device_rr_gdb */ for (pugi::xml_node xml_block_info : xml_root.children()) { /* Error out if the XML child has an invalid name! */ @@ -137,11 +139,11 @@ int read_xml_unique_blocks(T& openfpga_ctx, const char* file_name, device_rr_gsb.preload_unique_sb_module(block_coordinate, instance_coords); } else if (type == "cby") { - device_rr_gsb.preload_unique_cb_module(block_coordinate, - instance_coords, CHANY); + device_rr_gsb.preload_unique_cby_module(block_coordinate, + instance_coords); } else if (type == "cbx") { - device_rr_gsb.preload_unique_cb_module(block_coordinate, - instance_coords, CHANX); + device_rr_gsb.preload_unique_cbx_module(block_coordinate, + instance_coords); } else { VTR_LOG_ERROR("Unexpected type!"); } @@ -150,13 +152,15 @@ int read_xml_unique_blocks(T& openfpga_ctx, const char* file_name, return 1; } } + device_rr_gsb.build_gsb_unique_module(); + device_rr_gsb.print_txt(); if (verbose_output) { report_unique_module_status(openfpga_ctx, true); } } catch (pugiutil::XmlError& e) { archfpga_throw(file_name, e.line(), "%s", e.what()); } - + return 0; } @@ -179,13 +183,18 @@ int write_xml_block( << "\n"; for (const auto& instance_info : id_instance_map[pair.first]) { - openfpga::write_tab_to_file(fp, 2); - fp << "" - << "\n"; + fp << "/>" + << "\n"; + } } openfpga::write_tab_to_file(fp, 1); fp << "" From 968824c2dd4701a9a9d2bc7d35a782b9f84a20b8 Mon Sep 17 00:00:00 2001 From: Lin Date: Sun, 25 Aug 2024 19:56:23 -0700 Subject: [PATCH 12/12] build unique blocks final version --- openfpga/src/annotation/device_rr_gsb.cpp | 55 +----------- openfpga/src/annotation/device_rr_gsb.h | 1 - .../src/base/openfpga_build_fabric_template.h | 4 +- .../base/openfpga_setup_command_template.h | 4 +- ...locks.h => read_write_xml_unique_blocks.h} | 87 ++++++++++++++----- 5 files changed, 72 insertions(+), 79 deletions(-) rename openfpga/src/fabric/{read_xml_unique_blocks.h => read_write_xml_unique_blocks.h} (78%) diff --git a/openfpga/src/annotation/device_rr_gsb.cpp b/openfpga/src/annotation/device_rr_gsb.cpp index 6acd8bb3f..9bd558e16 100644 --- a/openfpga/src/annotation/device_rr_gsb.cpp +++ b/openfpga/src/annotation/device_rr_gsb.cpp @@ -367,34 +367,7 @@ void DeviceRRGSB::build_gsb_unique_module() { } } } -void DeviceRRGSB::print_txt() { - std::ofstream outFile( - "/home/linear/project/test_data/and2/config/output_read.txt"); - outFile << "################# sb_unique_module_id_ #########" << "\n"; - for (int i = 0; i < sb_unique_module_id_.size(); i++) { - for (int j = 0; j < sb_unique_module_id_[0].size(); j++) { - outFile << i << "," << j << ":" << sb_unique_module_id_[i][j] << "\n"; - } - } - outFile << "################# cbx_unique_module_id_ #########" << "\n"; - for (int i = 0; i < cbx_unique_module_id_.size(); i++) { - for (int j = 0; j < cbx_unique_module_id_[0].size(); j++) { - outFile << i << "," << j << ":" << cbx_unique_module_id_[i][j] << "\n"; - } - } - outFile << "################# cby_unique_module_id_ #########" << "\n"; - for (int i = 0; i < cby_unique_module_id_.size(); i++) { - for (int j = 0; j < cby_unique_module_id_[0].size(); j++) { - outFile << i << "," << j << ":" << cby_unique_module_id_[i][j] << "\n"; - } - } - outFile << "################# gsb_unique_module_id_ #########" << "\n"; - for (int i = 0; i < gsb_unique_module_id_.size(); i++) { - for (int j = 0; j < gsb_unique_module_id_[0].size(); j++) { - outFile << i << "," << j << ":" << gsb_unique_module_id_[i][j] << "\n"; - } - } -} + void DeviceRRGSB::build_unique_module(const RRGraphView& rr_graph) { build_sb_unique_module(rr_graph); @@ -402,32 +375,6 @@ void DeviceRRGSB::build_unique_module(const RRGraphView& rr_graph) { build_cb_unique_module(rr_graph, CHANY); build_gsb_unique_module(); - std::ofstream outFile( - "/home/linear/project/test_data/and2/config/output.txt"); - outFile << "################# sb_unique_module_id_ #########" << "\n"; - for (int i = 0; i < sb_unique_module_id_.size(); i++) { - for (int j = 0; j < sb_unique_module_id_[0].size(); j++) { - outFile << i << "," << j << ":" << sb_unique_module_id_[i][j] << "\n"; - } - } - outFile << "################# cbx_unique_module_id_ #########" << "\n"; - for (int i = 0; i < cbx_unique_module_id_.size(); i++) { - for (int j = 0; j < cbx_unique_module_id_[0].size(); j++) { - outFile << i << "," << j << ":" << cbx_unique_module_id_[i][j] << "\n"; - } - } - outFile << "################# cby_unique_module_id_ #########" << "\n"; - for (int i = 0; i < cby_unique_module_id_.size(); i++) { - for (int j = 0; j < cby_unique_module_id_[0].size(); j++) { - outFile << i << "," << j << ":" << cby_unique_module_id_[i][j] << "\n"; - } - } - outFile << "################# gsb_unique_module_id_ #########" << "\n"; - for (int i = 0; i < gsb_unique_module_id_.size(); i++) { - for (int j = 0; j < gsb_unique_module_id_[0].size(); j++) { - outFile << i << "," << j << ":" << gsb_unique_module_id_[i][j] << "\n"; - } - } } void DeviceRRGSB::add_gsb_unique_module(const vtr::Point& coordinate) { diff --git a/openfpga/src/annotation/device_rr_gsb.h b/openfpga/src/annotation/device_rr_gsb.h index 92e0f72d5..62dd2c7f0 100644 --- a/openfpga/src/annotation/device_rr_gsb.h +++ b/openfpga/src/annotation/device_rr_gsb.h @@ -98,7 +98,6 @@ class DeviceRRGSB { automatically identify and update the lists of unique mirrors and rotatable mirrors */ void clear(); /* clean the content */ - void print_txt(); void preload_unique_cbx_module( const vtr::Point block_coordinate, const std::vector> instance_coords); diff --git a/openfpga/src/base/openfpga_build_fabric_template.h b/openfpga/src/base/openfpga_build_fabric_template.h index d36a9312b..357b70288 100644 --- a/openfpga/src/base/openfpga_build_fabric_template.h +++ b/openfpga/src/base/openfpga_build_fabric_template.h @@ -20,7 +20,7 @@ #include "read_xml_io_name_map.h" #include "read_xml_module_name_map.h" #include "read_xml_tile_config.h" -#include "read_xml_unique_blocks.h" +#include "read_write_xml_unique_blocks.h" #include "rename_modules.h" #include "vtr_log.h" #include "vtr_time.h" @@ -101,7 +101,7 @@ int build_fabric_template(T& openfpga_ctx, const Command& cmd, const CommandContext& cmd_context) { CommandOptionId opt_frame_view = cmd.option("frame_view"); CommandOptionId opt_compress_routing = cmd.option("compress_routing"); - CommandOptionId opt_preload = cmd.option("preload"); + CommandOptionId opt_preload = cmd.option("preload_unique_blocks"); CommandOptionId opt_duplicate_grid_pin = cmd.option("duplicate_grid_pin"); CommandOptionId opt_gen_random_fabric_key = cmd.option("generate_random_fabric_key"); diff --git a/openfpga/src/base/openfpga_setup_command_template.h b/openfpga/src/base/openfpga_setup_command_template.h index 9d2631a61..7dcc42338 100644 --- a/openfpga/src/base/openfpga_setup_command_template.h +++ b/openfpga/src/base/openfpga_setup_command_template.h @@ -391,8 +391,8 @@ ShellCommandId add_build_fabric_command_template( "Compress the number of unique routing modules by " "identifying the unique GSBs"); - /* Add an option '--preload' */ - shell_cmd.add_option("preload", false, + /* Add an option '--preload_unique_blocks' */ + shell_cmd.add_option("preload_unique_blocks", false, "preload unique routing modules from user input xml file"); /* Add an option '--duplicate_grid_pin' */ diff --git a/openfpga/src/fabric/read_xml_unique_blocks.h b/openfpga/src/fabric/read_write_xml_unique_blocks.h similarity index 78% rename from openfpga/src/fabric/read_xml_unique_blocks.h rename to openfpga/src/fabric/read_write_xml_unique_blocks.h index cb021d1a3..e3ab6cb90 100644 --- a/openfpga/src/fabric/read_xml_unique_blocks.h +++ b/openfpga/src/fabric/read_write_xml_unique_blocks.h @@ -1,5 +1,5 @@ -#ifndef READ_XML_UNIQUE_BLOCKS_H -#define READ_XML_UNIQUE_BLOCKS_H +#ifndef READ_WRITE_XML_UNIQUE_BLOCKS_H +#define READ_WRITE_XML_UNIQUE_BLOCKS_H /******************************************************************** * This file includes the top-level function of this library @@ -25,7 +25,7 @@ #include "arch_error.h" #include "device_rr_gsb_utils.h" #include "openfpga_digest.h" -#include "read_xml_unique_blocks.h" +#include "read_write_xml_unique_blocks.h" #include "read_xml_util.h" #include "rr_gsb.h" #include "write_xml_utils.h" @@ -43,23 +43,16 @@ vtr::Point read_xml_unique_instance_info( } template -void report_unique_module_status(T& openfpga_ctx, bool verbose_output) { +void report_unique_module_status_read(T& openfpga_ctx, bool verbose_output) { /* Report the stats */ VTR_LOGV( verbose_output, - "Detected %lu unique X-direction connection blocks from a total of %d " - "(compression rate=%.2f%)\n", - openfpga_ctx.device_rr_gsb().get_num_cb_unique_module(CHANX), - find_device_rr_gsb_num_cb_modules(openfpga_ctx.device_rr_gsb(), CHANX), - 100. * - ((float)find_device_rr_gsb_num_cb_modules(openfpga_ctx.device_rr_gsb(), - CHANX) / - (float)openfpga_ctx.device_rr_gsb().get_num_cb_unique_module(CHANX) - - 1.)); + "Read %lu unique X-direction connection blocks ", + openfpga_ctx.device_rr_gsb().get_num_cb_unique_module(CHANX)); VTR_LOGV( verbose_output, - "Detected %lu unique Y-direction connection blocks from a total of %d " + "Read %lu unique Y-direction connection blocks from a total of %d " "(compression rate=%.2f%)\n", openfpga_ctx.device_rr_gsb().get_num_cb_unique_module(CHANY), find_device_rr_gsb_num_cb_modules(openfpga_ctx.device_rr_gsb(), CHANY), @@ -71,7 +64,7 @@ void report_unique_module_status(T& openfpga_ctx, bool verbose_output) { VTR_LOGV( verbose_output, - "Detected %lu unique switch blocks from a total of %d (compression " + "Read %lu unique switch blocks from a total of %d (compression " "rate=%.2f%)\n", openfpga_ctx.device_rr_gsb().get_num_sb_unique_module(), find_device_rr_gsb_num_sb_modules(openfpga_ctx.device_rr_gsb(), @@ -82,7 +75,60 @@ void report_unique_module_status(T& openfpga_ctx, bool verbose_output) { 1.)); VTR_LOG( - "Detected %lu unique general switch blocks from a total of %d " + "Read %lu unique general switch blocks from a total of %d " + "(compression " + "rate=%.2f%)\n", + openfpga_ctx.device_rr_gsb().get_num_gsb_unique_module(), + find_device_rr_gsb_num_gsb_modules(openfpga_ctx.device_rr_gsb(), + g_vpr_ctx.device().rr_graph), + 100. * ((float)find_device_rr_gsb_num_gsb_modules( + openfpga_ctx.device_rr_gsb(), g_vpr_ctx.device().rr_graph) / + (float)openfpga_ctx.device_rr_gsb().get_num_gsb_unique_module() - + 1.)); +} + + +template +void report_unique_module_status_write(T& openfpga_ctx, bool verbose_output) { + /* Report the stats */ + VTR_LOGV( + verbose_output, + "Write %lu unique X-direction connection blocks from a total of %d " + "(compression rate=%.2f%)\n", + openfpga_ctx.device_rr_gsb().get_num_cb_unique_module(CHANX), + find_device_rr_gsb_num_cb_modules(openfpga_ctx.device_rr_gsb(), CHANX), + 100. * + ((float)find_device_rr_gsb_num_cb_modules(openfpga_ctx.device_rr_gsb(), + CHANX) / + (float)openfpga_ctx.device_rr_gsb().get_num_cb_unique_module(CHANX) - + 1.)); + + VTR_LOGV( + verbose_output, + "Write %lu unique Y-direction connection blocks from a total of %d " + "(compression rate=%.2f%)\n", + openfpga_ctx.device_rr_gsb().get_num_cb_unique_module(CHANY), + find_device_rr_gsb_num_cb_modules(openfpga_ctx.device_rr_gsb(), CHANY), + 100. * + ((float)find_device_rr_gsb_num_cb_modules(openfpga_ctx.device_rr_gsb(), + CHANY) / + (float)openfpga_ctx.device_rr_gsb().get_num_cb_unique_module(CHANY) - + 1.)); + + VTR_LOGV( + verbose_output, + "Write %lu unique switch blocks from a total of %d (compression " + "rate=%.2f%)\n", + openfpga_ctx.device_rr_gsb().get_num_sb_unique_module(), + find_device_rr_gsb_num_sb_modules(openfpga_ctx.device_rr_gsb(), + g_vpr_ctx.device().rr_graph), + 100. * ((float)find_device_rr_gsb_num_sb_modules( + openfpga_ctx.device_rr_gsb(), g_vpr_ctx.device().rr_graph) / + (float)openfpga_ctx.device_rr_gsb().get_num_sb_unique_module() - + 1.)); + + VTR_LOG( + "Write %lu unique general switch blocks from a total of %d " "(compression " "rate=%.2f%)\n", openfpga_ctx.device_rr_gsb().get_num_gsb_unique_module(), @@ -153,9 +199,8 @@ int read_xml_unique_blocks(T& openfpga_ctx, const char* file_name, } } device_rr_gsb.build_gsb_unique_module(); - device_rr_gsb.print_txt(); if (verbose_output) { - report_unique_module_status(openfpga_ctx, true); + report_unique_module_status_read(openfpga_ctx, true); } } catch (pugiutil::XmlError& e) { archfpga_throw(file_name, e.line(), "%s", e.what()); @@ -208,7 +253,7 @@ template int write_xml_unique_blocks(const T& openfpga_ctx, const char* fname, const char* file_type, bool verbose_output) { vtr::ScopedStartFinishTimer timer("Write unique blocks..."); - + VTR_ASSERT(strcmp(file_type, "xml") == 0); /* Create a file handler */ std::fstream fp; /* Open the file stream */ @@ -246,7 +291,9 @@ int write_xml_unique_blocks(const T& openfpga_ctx, const char* fname, /* Close the file stream */ fp.close(); - + if (verbose_output) { + report_unique_module_status_write(openfpga_ctx, true); + } return err_code; }