add support about loading external fabric key

This commit is contained in:
tangxifan 2020-06-12 13:03:11 -06:00
parent 76b82e348f
commit a5055e9d26
9 changed files with 92 additions and 7 deletions

View File

@ -37,6 +37,10 @@ size_t FabricKey::key_value(const FabricKeyId& key_id) const {
return key_values_[key_id];
}
bool FabricKey::empty() const {
return 0 == key_ids_.size();
}
/************************************************************************
* Public Mutators
***********************************************************************/

View File

@ -36,6 +36,7 @@ class FabricKey {
public: /* Public Accessors: Basic data query */
std::string key_name(const FabricKeyId& key_id) const;
size_t key_value(const FabricKeyId& key_id) const;
bool empty() const;
public: /* Public Mutators: model-related */
void reserve_keys(const size_t& num_keys);
FabricKeyId create_key();

View File

@ -8,6 +8,9 @@
/* Headers from openfpgashell library */
#include "command_exit_codes.h"
/* Headers from fabrickey library */
#include "read_xml_fabric_key.h"
#include "device_rr_gsb.h"
#include "device_rr_gsb_utils.h"
#include "build_device_module.h"
@ -68,6 +71,7 @@ int build_fabric(OpenfpgaContext& openfpga_ctx,
CommandOptionId opt_duplicate_grid_pin = cmd.option("duplicate_grid_pin");
CommandOptionId opt_gen_random_fabric_key = cmd.option("generate_random_fabric_key");
CommandOptionId opt_write_fabric_key = cmd.option("write_fabric_key");
CommandOptionId opt_load_fabric_key = cmd.option("load_fabric_key");
CommandOptionId opt_verbose = cmd.option("verbose");
if (true == cmd_context.option_enable(cmd, opt_compress_routing)) {
@ -78,12 +82,23 @@ int build_fabric(OpenfpgaContext& openfpga_ctx,
VTR_LOG("\n");
/* Load fabric key from file */
FabricKey predefined_fabric_key;
if (true == cmd_context.option_enable(cmd, opt_load_fabric_key)) {
std::string fkey_fname = cmd_context.option_value(cmd, opt_load_fabric_key);
VTR_ASSERT(false == fkey_fname.empty());
predefined_fabric_key = read_xml_fabric_key(fkey_fname.c_str());
}
VTR_LOG("\n");
openfpga_ctx.mutable_module_graph() = build_device_module_graph(openfpga_ctx.mutable_io_location_map(),
openfpga_ctx.mutable_decoder_lib(),
const_cast<const OpenfpgaContext&>(openfpga_ctx),
g_vpr_ctx.device(),
cmd_context.option_enable(cmd, opt_compress_routing),
cmd_context.option_enable(cmd, opt_duplicate_grid_pin),
predefined_fabric_key,
cmd_context.option_enable(cmd, opt_gen_random_fabric_key),
cmd_context.option_enable(cmd, opt_verbose));

View File

@ -32,6 +32,7 @@ ModuleManager build_device_module_graph(IoLocationMap& io_location_map,
const DeviceContext& vpr_device_ctx,
const bool& compress_routing,
const bool& duplicate_grid_pin,
const FabricKey& fabric_key,
const bool& generate_random_fabric_key,
const bool& verbose) {
vtr::ScopedStartFinishTimer timer("Build fabric module graph");
@ -117,7 +118,8 @@ ModuleManager build_device_module_graph(IoLocationMap& io_location_map,
openfpga_ctx.arch().arch_direct,
openfpga_ctx.arch().config_protocol.type(),
sram_model,
compress_routing, duplicate_grid_pin, generate_random_fabric_key);
compress_routing, duplicate_grid_pin,
fabric_key, generate_random_fabric_key);
/* Now a critical correction has to be done!
* In the module construction, we always use prefix of ports because they are binded

View File

@ -6,6 +6,7 @@
*******************************************************************/
#include "vpr_context.h"
#include "openfpga_context.h"
#include "fabric_key.h"
/********************************************************************
* Function declaration
@ -20,6 +21,7 @@ ModuleManager build_device_module_graph(IoLocationMap& io_location_map,
const DeviceContext& vpr_device_ctx,
const bool& compress_routing,
const bool& duplicate_grid_pin,
const FabricKey& fabric_key,
const bool& generate_random_fabric_key,
const bool& verbose);

View File

@ -322,6 +322,7 @@ void build_top_module(ModuleManager& module_manager,
const CircuitModelId& sram_model,
const bool& compact_routing_hierarchy,
const bool& duplicate_grid_pin,
const FabricKey& fabric_key,
const bool& generate_random_fabric_key) {
vtr::ScopedStartFinishTimer timer("Build FPGA fabric module");
@ -363,12 +364,21 @@ void build_top_module(ModuleManager& module_manager,
*/
add_module_gpio_ports_from_child_modules(module_manager, top_module);
/* Organize the list of memory modules and instances */
/* Organize the list of memory modules and instances
* If we have an empty fabric key, we organize the memory modules as routine
* Otherwise, we will load the fabric key directly
*/
if (true == fabric_key.empty()) {
organize_top_module_memory_modules(module_manager, top_module,
circuit_lib, sram_orgz_type, sram_model,
grids, grid_instance_ids,
device_rr_gsb, sb_instance_ids, cb_instance_ids,
compact_routing_hierarchy);
} else {
VTR_ASSERT_SAFE(false == fabric_key.empty());
load_top_module_memory_modules_from_fabric_key(module_manager, top_module,
fabric_key);
}
/* Shuffle the configurable children in a random sequence */
if (true == generate_random_fabric_key) {

View File

@ -16,6 +16,7 @@
#include "arch_direct.h"
#include "module_manager.h"
#include "io_location_map.h"
#include "fabric_key.h"
/********************************************************************
* Function declaration
@ -37,6 +38,7 @@ void build_top_module(ModuleManager& module_manager,
const CircuitModelId& sram_model,
const bool& compact_routing_hierarchy,
const bool& duplicate_grid_pin,
const FabricKey& fabric_key,
const bool& generate_random_fabric_key);
} /* end namespace openfpga */

View File

@ -401,6 +401,50 @@ void shuffle_top_module_configurable_children(ModuleManager& module_manager,
}
}
/********************************************************************
* Load configurable children from a fabric key to top-level module
*
* Note:
* - This function will overwrite any exisiting configurable children
* under the top module
*
* Return 0 - Success
* Return 1 - Fatal errors
********************************************************************/
int load_top_module_memory_modules_from_fabric_key(ModuleManager& module_manager,
const ModuleId& top_module,
const FabricKey& fabric_key) {
/* Ensure a clean start */
module_manager.clear_configurable_children(top_module);
for (const FabricKeyId& key : fabric_key.keys()) {
/* Find if the module name exist */
ModuleId child_module = module_manager.find_module(fabric_key.key_name(key));
if (false == module_manager.valid_module_id(child_module)) {
VTR_LOGF_ERROR(__FILE__, __LINE__,
"Invalid key name '%s'!\n",
fabric_key.key_name(key).c_str());
return 1;
}
/* Find if instance id is valid */
size_t child_instance = fabric_key.key_value(key);
if (child_instance >= module_manager.num_instance(top_module, child_module)) {
VTR_LOGF_ERROR(__FILE__, __LINE__,
"Invalid key value '%ld'!\n",
child_instance);
return 1;
}
/* Now we can add the child to configurable children of the top module */
module_manager.add_configurable_child(top_module,
child_module,
child_instance);
}
return 0;
}
/********************************************************************
* Add a list of ports that are used for SRAM configuration to the FPGA
* top-level module

View File

@ -14,6 +14,7 @@
#include "decoder_library.h"
#include "device_grid.h"
#include "device_rr_gsb.h"
#include "fabric_key.h"
/********************************************************************
* Function declaration
@ -37,6 +38,10 @@ void organize_top_module_memory_modules(ModuleManager& module_manager,
void shuffle_top_module_configurable_children(ModuleManager& module_manager,
const ModuleId& top_module);
int load_top_module_memory_modules_from_fabric_key(ModuleManager& module_manager,
const ModuleId& top_module,
const FabricKey& fabric_key);
void add_top_module_sram_ports(ModuleManager& module_manager,
const ModuleId& module_id,
const CircuitLibrary& circuit_lib,