From e45619b22d56dc1d4afdc923a6c514ece32c1139 Mon Sep 17 00:00:00 2001 From: Lin Date: Thu, 8 Aug 2024 01:00:35 -0700 Subject: [PATCH] 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