From c726744154d9c03aeea044ddff338212c0c4b2e9 Mon Sep 17 00:00:00 2001 From: Lin Date: Mon, 5 Aug 2024 02:23:47 -0700 Subject: [PATCH] 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