diff --git a/docs/source/manual/openfpga_shell/openfpga_commands/setup_commands.rst b/docs/source/manual/openfpga_shell/openfpga_commands/setup_commands.rst index 9bc9c6334..2722dc46d 100644 --- a/docs/source/manual/openfpga_shell/openfpga_commands/setup_commands.rst +++ b/docs/source/manual/openfpga_shell/openfpga_commands/setup_commands.rst @@ -111,6 +111,10 @@ write_gsb_to_xml Specify the output directory of the XML files. Each GSB will be written to an indepedent XML file For example, ``--file /temp/gsb_output`` + .. option:: --unique + + Only output unique GSBs to XML files + .. option:: --verbose Show verbose log diff --git a/openfpga/src/annotation/device_rr_gsb.cpp b/openfpga/src/annotation/device_rr_gsb.cpp index c10a9df9c..9abbea351 100644 --- a/openfpga/src/annotation/device_rr_gsb.cpp +++ b/openfpga/src/annotation/device_rr_gsb.cpp @@ -86,6 +86,13 @@ size_t DeviceRRGSB::get_num_gsb_unique_module() const { return gsb_unique_module_.size(); } +/* Get a rr switch block which a unique mirror */ +const RRGSB& DeviceRRGSB::get_gsb_unique_module(const size_t& index) const { + VTR_ASSERT (validate_gsb_unique_module_index(index)); + + return rr_gsb_[gsb_unique_module_[index].x()][gsb_unique_module_[index].y()]; +} + /* Get a rr switch block which a unique mirror */ const RRGSB& DeviceRRGSB::get_sb_unique_module(const size_t& index) const { VTR_ASSERT (validate_sb_unique_module_index(index)); @@ -461,6 +468,11 @@ bool DeviceRRGSB::validate_coordinate(const vtr::Point& coordinate) cons return (coordinate.y() < rr_gsb_[coordinate.x()].capacity()); } +/* Validate if the index in the range of unique_mirror vector*/ +bool DeviceRRGSB::validate_gsb_unique_module_index(const size_t& index) const { + return (index < gsb_unique_module_.size()); +} + /* Validate if the index in the range of unique_mirror vector*/ bool DeviceRRGSB::validate_sb_unique_module_index(const size_t& index) const { return (index < sb_unique_module_.size()); diff --git a/openfpga/src/annotation/device_rr_gsb.h b/openfpga/src/annotation/device_rr_gsb.h index 4d8aad401..290322079 100644 --- a/openfpga/src/annotation/device_rr_gsb.h +++ b/openfpga/src/annotation/device_rr_gsb.h @@ -32,6 +32,7 @@ class DeviceRRGSB { const RRGSB& get_gsb(const size_t& x, const size_t& y) const; /* Get a rr switch block in the array with a coordinate */ size_t get_num_gsb_unique_module() const; /* get the number of unique mirrors of GSB */ size_t get_num_sb_unique_module() const; /* get the number of unique mirrors of switch blocks */ + const RRGSB& get_gsb_unique_module(const size_t& index) const; /* Get a rr-gsb which is a unique mirror */ const RRGSB& get_sb_unique_module(const size_t& index) const; /* Get a rr switch block which a unique mirror */ const RRGSB& get_sb_unique_module(const vtr::Point& coordinate) const; /* Get a rr switch block which a unique mirror */ const RRGSB& get_cb_unique_module(const t_rr_type& cb_type, const size_t& index) const; /* Get a rr switch block which a unique mirror */ @@ -58,6 +59,7 @@ class DeviceRRGSB { private: /* Validators */ bool validate_coordinate(const vtr::Point& coordinate) const; /* Validate if the (x,y) is the range of this device */ bool validate_side(const e_side& side) const; /* validate if side is in the range of unique_side_module_ */ + bool validate_gsb_unique_module_index(const size_t& index) const; /* Validate if the index in the range of unique_mirror vector*/ bool validate_sb_unique_module_index(const size_t& index) const; /* Validate if the index in the range of unique_mirror vector*/ bool validate_cb_unique_module_index(const t_rr_type& cb_type, const size_t& index) const; /* Validate if the index in the range of unique_mirror vector*/ bool validate_cb_type(const t_rr_type& cb_type) const; diff --git a/openfpga/src/annotation/write_xml_device_rr_gsb.cpp b/openfpga/src/annotation/write_xml_device_rr_gsb.cpp index 8aa8fb3b6..566d706a8 100644 --- a/openfpga/src/annotation/write_xml_device_rr_gsb.cpp +++ b/openfpga/src/annotation/write_xml_device_rr_gsb.cpp @@ -184,6 +184,7 @@ void write_rr_switch_block_to_xml(const std::string fname_prefix, void write_device_rr_gsb_to_xml(const char* sb_xml_dir, const RRGraph& rr_graph, const DeviceRRGSB& device_rr_gsb, + const bool& unique, const bool& verbose) { std::string xml_dir_name = format_dir_path(std::string(sb_xml_dir)); @@ -195,11 +196,22 @@ void write_device_rr_gsb_to_xml(const char* sb_xml_dir, size_t gsb_counter = 0; /* For each switch block, an XML file will be outputted */ - for (size_t ix = 0; ix < sb_range.x(); ++ix) { - for (size_t iy = 0; iy < sb_range.y(); ++iy) { - const RRGSB& rr_gsb = device_rr_gsb.get_gsb(ix, iy); + if (unique) { + /* Only output unique GSB modules */ + VTR_LOG("Only output unique GSB modules to XML\n"); + for (size_t igsb = 0; igsb < device_rr_gsb.get_num_gsb_unique_module(); ++igsb) { + const RRGSB& rr_gsb = device_rr_gsb.get_gsb_unique_module(igsb); write_rr_switch_block_to_xml(xml_dir_name, rr_graph, rr_gsb, verbose); gsb_counter++; + } + } else { + /* Output all GSB instances in the fabric (some instances may share the same module) */ + for (size_t ix = 0; ix < sb_range.x(); ++ix) { + for (size_t iy = 0; iy < sb_range.y(); ++iy) { + const RRGSB& rr_gsb = device_rr_gsb.get_gsb(ix, iy); + write_rr_switch_block_to_xml(xml_dir_name, rr_graph, rr_gsb, verbose); + gsb_counter++; + } } } diff --git a/openfpga/src/annotation/write_xml_device_rr_gsb.h b/openfpga/src/annotation/write_xml_device_rr_gsb.h index a6655ab22..9d558d1f1 100644 --- a/openfpga/src/annotation/write_xml_device_rr_gsb.h +++ b/openfpga/src/annotation/write_xml_device_rr_gsb.h @@ -18,6 +18,7 @@ namespace openfpga { void write_device_rr_gsb_to_xml(const char* sb_xml_dir, const RRGraph& rr_graph, const DeviceRRGSB& device_rr_gsb, + const bool& unique, const bool& verbose); } /* end namespace openfpga */ diff --git a/openfpga/src/base/openfpga_setup_command.cpp b/openfpga/src/base/openfpga_setup_command.cpp index 517ed364a..7293c82e7 100644 --- a/openfpga/src/base/openfpga_setup_command.cpp +++ b/openfpga/src/base/openfpga_setup_command.cpp @@ -209,6 +209,9 @@ ShellCommandId add_openfpga_write_gsb_command(openfpga::Shell& shell_cmd.set_option_short_name(opt_file, "f"); shell_cmd.set_option_require_value(opt_file, openfpga::OPT_STRING); + /* Add an option '--unique' */ + shell_cmd.add_option("unique", false, "Only output unique GSB blocks"); + /* Add an option '--verbose' */ shell_cmd.add_option("verbose", false, "Show verbose outputs"); diff --git a/openfpga/src/base/openfpga_write_gsb.cpp b/openfpga/src/base/openfpga_write_gsb.cpp index cdb833c75..0a783cc01 100644 --- a/openfpga/src/base/openfpga_write_gsb.cpp +++ b/openfpga/src/base/openfpga_write_gsb.cpp @@ -33,6 +33,7 @@ int write_gsb(const OpenfpgaContext& openfpga_ctx, VTR_ASSERT(true == cmd_context.option_enable(cmd, opt_file)); VTR_ASSERT(false == cmd_context.option_value(cmd, opt_file).empty()); + CommandOptionId opt_unique = cmd.option("unique"); CommandOptionId opt_verbose = cmd.option("verbose"); std::string sb_file_name = cmd_context.option_value(cmd, opt_file); @@ -40,6 +41,7 @@ int write_gsb(const OpenfpgaContext& openfpga_ctx, write_device_rr_gsb_to_xml(sb_file_name.c_str(), g_vpr_ctx.device().rr_graph, openfpga_ctx.device_rr_gsb(), + cmd_context.option_enable(cmd, opt_unique), cmd_context.option_enable(cmd, opt_verbose)); /* TODO: should identify the error code from internal function execution */