From 2de4a460a813987cdd60d68f1cc7def98a96767d Mon Sep 17 00:00:00 2001 From: tangxifan Date: Fri, 24 Sep 2021 15:15:32 -0700 Subject: [PATCH] [Engine] Rework the function that counts the number of configurable children for fabric key writer and bitstream generator --- openfpga/src/base/openfpga_build_fabric.cpp | 2 +- openfpga/src/fabric/fabric_key_writer.cpp | 4 ++-- openfpga/src/fabric/fabric_key_writer.h | 7 ++++--- .../src/fpga_bitstream/build_device_bitstream.cpp | 12 ++++++------ openfpga/src/utils/memory_utils.cpp | 15 +++++++++++---- openfpga/src/utils/memory_utils.h | 3 ++- 6 files changed, 26 insertions(+), 17 deletions(-) diff --git a/openfpga/src/base/openfpga_build_fabric.cpp b/openfpga/src/base/openfpga_build_fabric.cpp index 2c3f491f9..146520624 100644 --- a/openfpga/src/base/openfpga_build_fabric.cpp +++ b/openfpga/src/base/openfpga_build_fabric.cpp @@ -132,7 +132,7 @@ int build_fabric(OpenfpgaContext& openfpga_ctx, VTR_ASSERT(false == fkey_fname.empty()); curr_status = write_fabric_key_to_xml_file(openfpga_ctx.module_graph(), fkey_fname, - openfpga_ctx.arch().config_protocol.type(), + openfpga_ctx.arch().config_protocol, cmd_context.option_enable(cmd, opt_verbose)); /* If there is any error, final status cannot be overwritten by a success flag */ if (CMD_EXEC_SUCCESS != curr_status) { diff --git a/openfpga/src/fabric/fabric_key_writer.cpp b/openfpga/src/fabric/fabric_key_writer.cpp index d6bea0527..38cb599db 100644 --- a/openfpga/src/fabric/fabric_key_writer.cpp +++ b/openfpga/src/fabric/fabric_key_writer.cpp @@ -31,7 +31,7 @@ namespace openfpga { ***************************************************************************************/ int write_fabric_key_to_xml_file(const ModuleManager& module_manager, const std::string& fname, - const e_config_protocol_type& config_protocol_type, + const ConfigProtocol& config_protocol, const bool& verbose) { std::string timer_message = std::string("Write fabric key to XML file '") + fname + std::string("'"); @@ -71,7 +71,7 @@ int write_fabric_key_to_xml_file(const ModuleManager& module_manager, /* Each configuration protocol has some child which should not be in the list. They are typically decoders */ size_t curr_region_num_config_child = module_manager.region_configurable_children(top_module, config_region).size(); - size_t num_child_to_skip = estimate_num_configurable_children_to_skip_by_config_protocol(config_protocol_type, curr_region_num_config_child); + size_t num_child_to_skip = estimate_num_configurable_children_to_skip_by_config_protocol(config_protocol, curr_region_num_config_child); curr_region_num_config_child -= num_child_to_skip; fabric_key.reserve_region_keys(fabric_region, curr_region_num_config_child); diff --git a/openfpga/src/fabric/fabric_key_writer.h b/openfpga/src/fabric/fabric_key_writer.h index 3062db15a..bdb860354 100644 --- a/openfpga/src/fabric/fabric_key_writer.h +++ b/openfpga/src/fabric/fabric_key_writer.h @@ -4,8 +4,9 @@ /******************************************************************** * Include header files that are required by function declaration *******************************************************************/ -#include "vpr_context.h" -#include "openfpga_context.h" +#include +#include "module_manager.h" +#include "config_protocol.h" /******************************************************************** * Function declaration @@ -16,7 +17,7 @@ namespace openfpga { int write_fabric_key_to_xml_file(const ModuleManager& module_manager, const std::string& fname, - const e_config_protocol_type& config_protocol_type, + const ConfigProtocol& config_protocol, const bool& verbose); } /* end namespace openfpga */ diff --git a/openfpga/src/fpga_bitstream/build_device_bitstream.cpp b/openfpga/src/fpga_bitstream/build_device_bitstream.cpp index 1c81e2cb3..8c89c3aaf 100644 --- a/openfpga/src/fpga_bitstream/build_device_bitstream.cpp +++ b/openfpga/src/fpga_bitstream/build_device_bitstream.cpp @@ -64,7 +64,7 @@ static size_t rec_estimate_device_bitstream_num_bits(const ModuleManager& module_manager, const ModuleId& top_module, const ModuleId& parent_module, - const e_config_protocol_type& config_protocol_type) { + const ConfigProtocol& config_protocol) { size_t num_bits = 0; /* If a child module has no configurable children, this is a leaf node @@ -85,13 +85,13 @@ size_t rec_estimate_device_bitstream_num_bits(const ModuleManager& module_manage if (parent_module == top_module) { for (const ConfigRegionId& config_region : module_manager.regions(parent_module)) { size_t curr_region_num_config_child = module_manager.region_configurable_children(parent_module, config_region).size(); - size_t num_child_to_skip = estimate_num_configurable_children_to_skip_by_config_protocol(config_protocol_type, curr_region_num_config_child); + size_t num_child_to_skip = estimate_num_configurable_children_to_skip_by_config_protocol(config_protocol, curr_region_num_config_child); curr_region_num_config_child -= num_child_to_skip; /* Visit all the children in a recursively way */ for (size_t ichild = 0; ichild < curr_region_num_config_child; ++ichild) { ModuleId child_module = module_manager.region_configurable_children(parent_module, config_region)[ichild]; - num_bits += rec_estimate_device_bitstream_num_bits(module_manager, top_module, child_module, config_protocol_type); + num_bits += rec_estimate_device_bitstream_num_bits(module_manager, top_module, child_module, config_protocol); } } } else { @@ -102,14 +102,14 @@ size_t rec_estimate_device_bitstream_num_bits(const ModuleManager& module_manage /* Frame-based configuration protocol will have 1 decoder * if there are more than 1 configurable children */ - if ( (CONFIG_MEM_FRAME_BASED == config_protocol_type) + if ( (CONFIG_MEM_FRAME_BASED == config_protocol.type()) && (2 <= num_configurable_children)) { num_configurable_children--; } for (size_t ichild = 0; ichild < num_configurable_children; ++ichild) { ModuleId child_module = module_manager.configurable_children(parent_module)[ichild]; - num_bits += rec_estimate_device_bitstream_num_bits(module_manager, top_module, child_module, config_protocol_type); + num_bits += rec_estimate_device_bitstream_num_bits(module_manager, top_module, child_module, config_protocol); } } @@ -157,7 +157,7 @@ BitstreamManager build_device_bitstream(const VprContext& vpr_ctx, size_t num_bits_to_reserve = rec_estimate_device_bitstream_num_bits(openfpga_ctx.module_graph(), top_module, top_module, - openfpga_ctx.arch().config_protocol.type()); + openfpga_ctx.arch().config_protocol); bitstream_manager.reserve_bits(num_bits_to_reserve); VTR_LOGV(verbose, "Reserved %lu configuration bits\n", num_bits_to_reserve); diff --git a/openfpga/src/utils/memory_utils.cpp b/openfpga/src/utils/memory_utils.cpp index e5e44b99c..71c2c60ef 100644 --- a/openfpga/src/utils/memory_utils.cpp +++ b/openfpga/src/utils/memory_utils.cpp @@ -429,13 +429,13 @@ size_t generate_pb_sram_port_size(const e_config_protocol_type sram_orgz_type, return sram_port_size; } -size_t estimate_num_configurable_children_to_skip_by_config_protocol(e_config_protocol_type config_protocol_type, +size_t estimate_num_configurable_children_to_skip_by_config_protocol(const ConfigProtocol& config_protocol, size_t curr_region_num_config_child) { size_t num_child_to_skip = 0; /* Frame-based configuration protocol will have 1 decoder * if there are more than 1 configurable children */ - if ( (CONFIG_MEM_FRAME_BASED == config_protocol_type) + if ( (CONFIG_MEM_FRAME_BASED == config_protocol.type()) && (2 <= curr_region_num_config_child)) { num_child_to_skip = 1; } @@ -443,10 +443,17 @@ size_t estimate_num_configurable_children_to_skip_by_config_protocol(e_config_pr /* Memory configuration protocol will have 2 decoders * at the top-level */ - if (CONFIG_MEM_MEMORY_BANK == config_protocol_type - || CONFIG_MEM_QL_MEMORY_BANK == config_protocol_type) { + if (CONFIG_MEM_MEMORY_BANK == config_protocol.type() + || CONFIG_MEM_QL_MEMORY_BANK == config_protocol.type()) { VTR_ASSERT(2 <= curr_region_num_config_child); num_child_to_skip = 2; + /* If flatten bus is used, BL/WL may not need decoders */ + if (BLWL_PROTOCOL_FLATTEN == config_protocol.bl_protocol_type()) { + num_child_to_skip--; + } + if (BLWL_PROTOCOL_FLATTEN == config_protocol.wl_protocol_type()) { + num_child_to_skip--; + } } return num_child_to_skip; diff --git a/openfpga/src/utils/memory_utils.h b/openfpga/src/utils/memory_utils.h index d34e5f0ce..bf092b81a 100644 --- a/openfpga/src/utils/memory_utils.h +++ b/openfpga/src/utils/memory_utils.h @@ -7,6 +7,7 @@ #include #include "openfpga_port.h" #include "circuit_types.h" +#include "config_protocol.h" #include "module_manager.h" /******************************************************************** @@ -46,7 +47,7 @@ size_t generate_pb_sram_port_size(const e_config_protocol_type sram_orgz_type, * (they are included in the list for bitstream generator usage) * The number of decoders depends on the type of configuration protocol. */ -size_t estimate_num_configurable_children_to_skip_by_config_protocol(e_config_protocol_type config_protocol_type, +size_t estimate_num_configurable_children_to_skip_by_config_protocol(const ConfigProtocol& config_protocol, size_t curr_region_num_config_child); } /* end namespace openfpga */