add fabric key writer for top-level module

This commit is contained in:
tangxifan 2020-06-12 10:41:34 -06:00
parent f081cef495
commit 3499b4d3e7
6 changed files with 148 additions and 10 deletions

View File

@ -19,29 +19,44 @@
/********************************************************************
* A writer to output a component key to XML format
*
* Return 0 if successful
* Return 1 if there are more serious bugs in the architecture
* Return 2 if fail when creating files
*******************************************************************/
static
void write_xml_fabric_component_key(std::fstream& fp,
const char* fname,
const FabricKey& fabric_key,
const FabricKeyId& component_key) {
int write_xml_fabric_component_key(std::fstream& fp,
const FabricKey& fabric_key,
const FabricKeyId& component_key) {
/* Validate the file stream */
openfpga::check_file_stream(fname, fp);
if (false == openfpga::valid_file_stream(fp)) {
return 2;
}
fp << "\t" << "<key";
if (false == fabric_key.valid_key_id(component_key)) {
return 1;
}
write_xml_attribute(fp, "id", size_t(component_key));
write_xml_attribute(fp, "name", fabric_key.key_name(component_key).c_str());
write_xml_attribute(fp, "value", fabric_key.key_value(component_key));
fp << "/>" << "\n";
return 0;
}
/********************************************************************
* A writer to output a fabric key to XML format
*
* Return 0 if successful
* Return 1 if there are more serious bugs in the architecture
* Return 2 if fail when creating files
*******************************************************************/
void write_xml_fabric_key(const char* fname,
const FabricKey& fabric_key) {
int write_xml_fabric_key(const char* fname,
const FabricKey& fabric_key) {
vtr::ScopedStartFinishTimer timer("Write Fabric Key");
@ -56,9 +71,14 @@ void write_xml_fabric_key(const char* fname,
/* Write the root node */
fp << "<fabric_key>" << "\n";
int err_code = 0;
/* Write component by component */
for (const FabricKeyId& key : fabric_key.keys()) {
write_xml_fabric_component_key(fp, fname, fabric_key, key);
err_code = write_xml_fabric_component_key(fp, fabric_key, key);
if (0 != err_code) {
return err_code;
}
}
/* Finish writing the root node */
@ -66,4 +86,6 @@ void write_xml_fabric_key(const char* fname,
/* Close the file stream */
fp.close();
return err_code;
}

View File

@ -10,7 +10,7 @@
/********************************************************************
* Function declaration
*******************************************************************/
void write_xml_fabric_key(const char* fname,
const FabricKey& fabric_key);
int write_xml_fabric_key(const char* fname,
const FabricKey& fabric_key);
#endif

View File

@ -22,6 +22,7 @@ target_link_libraries(libopenfpga
libarchopenfpga
libopenfpgashell
libopenfpgautil
libfabrickey
libini
libvtrutil
libvpr8)

View File

@ -12,6 +12,7 @@
#include "device_rr_gsb_utils.h"
#include "build_device_module.h"
#include "fabric_hierarchy_writer.h"
#include "fabric_key_writer.h"
#include "openfpga_build_fabric.h"
/* Include global variables of VPR */
@ -65,6 +66,7 @@ int build_fabric(OpenfpgaContext& openfpga_ctx,
CommandOptionId opt_compress_routing = cmd.option("compress_routing");
CommandOptionId opt_duplicate_grid_pin = cmd.option("duplicate_grid_pin");
CommandOptionId opt_write_fabric_key = cmd.option("write_fabric_key");
CommandOptionId opt_verbose = cmd.option("verbose");
if (true == cmd_context.option_enable(cmd, opt_compress_routing)) {
@ -83,6 +85,16 @@ int build_fabric(OpenfpgaContext& openfpga_ctx,
cmd_context.option_enable(cmd, opt_duplicate_grid_pin),
cmd_context.option_enable(cmd, opt_verbose));
/* Output fabric key if user requested */
if (true == cmd_context.option_enable(cmd, opt_write_fabric_key)) {
std::string fkey_fname = cmd_context.option_value(cmd, opt_write_fabric_key);
VTR_ASSERT(false == fkey_fname.empty());
write_fabric_key_to_xml_file(openfpga_ctx.module_graph(),
fkey_fname,
cmd_context.option_enable(cmd, opt_verbose));
}
/* TODO: should identify the error code from internal function execution */
return CMD_EXEC_SUCCESS;
}

View File

@ -0,0 +1,80 @@
/***************************************************************************************
* Output fabric key of Module Graph to file formats
***************************************************************************************/
/* Headers from vtrutil library */
#include "vtr_log.h"
#include "vtr_assert.h"
#include "vtr_time.h"
/* Headers from openfpgautil library */
#include "openfpga_digest.h"
/* Headers from archopenfpga library */
#include "write_xml_fabric_key.h"
#include "openfpga_naming.h"
#include "fabric_key_writer.h"
/* begin namespace openfpga */
namespace openfpga {
/***************************************************************************************
* Write the fabric key of top module to an XML file
* We will use the writer API in libfabrickey
*
* Return 0 if successful
* Return 1 if there are more serious bugs in the architecture
* Return 2 if fail when creating files
***************************************************************************************/
int write_fabric_key_to_xml_file(const ModuleManager& module_manager,
const std::string& fname,
const bool& verbose) {
std::string timer_message = std::string("Write fabric key to XML file '") + fname + std::string("'");
std::string dir_path = format_dir_path(find_path_dir_name(fname));
/* Create directories */
create_directory(dir_path);
/* Start time count */
vtr::ScopedStartFinishTimer timer(timer_message);
/* Use default name if user does not provide one */
VTR_ASSERT(true != fname.empty());
/* Find top-level module */
std::string top_module_name = generate_fpga_top_module_name();
ModuleId top_module = module_manager.find_module(top_module_name);
if (true != module_manager.valid_module_id(top_module)) {
VTR_LOGV_ERROR(verbose,
"Unable to find the top-level module '%s'!\n",
top_module_name.c_str());
return 1;
}
/* Build a fabric key database by visiting all the configurable children */
FabricKey fabric_key;
const size_t& num_keys = module_manager.configurable_children(top_module).size();
fabric_key.reserve_keys(num_keys);
for (size_t ichild = 0; ichild < num_keys; ++ichild) {
const ModuleId& child_module = module_manager.configurable_children(top_module)[ichild];
const size_t& child_instance = module_manager.configurable_child_instances(top_module)[ichild];
FabricKeyId key = fabric_key.create_key();
fabric_key.set_key_name(key, module_manager.module_name(child_module));
fabric_key.set_key_value(key, child_instance);
}
VTR_LOGV(verbose,
"Created %lu keys for the top module %s.\n",
num_keys, top_module_name.c_str());
/* Call the XML writer for fabric key */
int err_code = write_xml_fabric_key(fname.c_str(), fabric_key);
return err_code;
}
} /* end namespace openfpga */

View File

@ -0,0 +1,23 @@
#ifndef FABRIC_KEY_WRITER_H
#define FABRIC_KEY_WRITER_H
/********************************************************************
* Include header files that are required by function declaration
*******************************************************************/
#include "vpr_context.h"
#include "openfpga_context.h"
/********************************************************************
* Function declaration
*******************************************************************/
/* begin namespace openfpga */
namespace openfpga {
int write_fabric_key_to_xml_file(const ModuleManager& module_manager,
const std::string& fname,
const bool& verbose);
} /* end namespace openfpga */
#endif