seperate xml parser and bin parser

This commit is contained in:
Lin 2024-10-09 14:32:58 +08:00
parent 5b0e52a03b
commit 4d8fae94a4
9 changed files with 305 additions and 181 deletions

View File

@ -0,0 +1,104 @@
#include <capnp/message.h>
#include <capnp/serialize.h>
#include <kj/io.h>
#include <string>
/* 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 libarchfpga */
#include "arch_error.h"
#include "command_exit_codes.h"
#include "device_rr_gsb_utils.h"
#include "mmap_file.h"
#include "openfpga_digest.h"
#include "read_unique_blocks_bin.h"
#include "read_unique_blocks_xml.h"
#include "read_xml_util.h"
#include "rr_gsb.h"
#include "unique_blocks_uxsdcxx.capnp.h"
#include "write_xml_utils.h"
/********************************************************************
* This file includes the top-level functions of this library
* which includes:
* -- reads a bin file of unique blocks to the associated
* data structures: device_rr_gsb
*******************************************************************/
namespace openfpga {
/*read the instances' coordinate of a unique block from a bin file*/
std::vector<vtr::Point<size_t>> read_bin_unique_instance_coords(
const ucap::Uniqueblockpacked::Reader& unique_block) {
std::vector<vtr::Point<size_t>> instance_coords;
if (unique_block.hasInstances()) {
auto instance_list = unique_block.getInstances();
for (auto instance : instance_list) {
int instance_x = instance.getX();
int instance_y = instance.getY();
vtr::Point<size_t> instance_coordinate(instance_x, instance_y);
instance_coords.push_back(instance_coordinate);
}
}
return instance_coords;
}
/*read the unique block coordinate from a bin file */
vtr::Point<size_t> read_bin_unique_block_coord(
const ucap::Uniqueblockpacked::Reader& unique_block, ucap::Blocktype& type) {
auto block_info = unique_block.getBlockinfo();
int block_x = block_info.getX();
int block_y = block_info.getY();
type = block_info.getType();
vtr::Point<size_t> block_coordinate(block_x, block_y);
return block_coordinate;
}
/*top-level function to read unique blocks from bin file*/
int read_bin_unique_blocks(DeviceRRGSB& device_rr_gsb, const char* file_name,
bool verbose_output) {
/* clear unique modules & reserve memory to relavant vectors */
device_rr_gsb.clear_unique_modules();
device_rr_gsb.reserve_unique_modules();
MmapFile f(file_name);
::capnp::FlatArrayMessageReader reader(f.getData());
auto root = reader.getRoot<ucap::UniqueBlocks>();
if (root.hasAtominfos()) {
auto block_list = root.getAtominfos();
for (auto unique_block : block_list) {
ucap::Blocktype type;
vtr::Point<size_t> block_coordinate = read_bin_unique_block_coord(
unique_block, type); /*get block coordinate and type*/
std::vector<vtr::Point<size_t>> instance_coords =
read_bin_unique_instance_coords(
unique_block); /* get a list of instance coordinates*/
/* get block coordinate and instance coordinate, try to setup
* device_rr_gsb */
if (type == ucap::Blocktype::SB) {
device_rr_gsb.preload_unique_sb_module(block_coordinate,
instance_coords);
} else if (type == ucap::Blocktype::CBY) {
device_rr_gsb.preload_unique_cby_module(block_coordinate,
instance_coords);
} else if (type == ucap::Blocktype::CBX) {
device_rr_gsb.preload_unique_cbx_module(block_coordinate,
instance_coords);
} else if (type == ucap::Blocktype::UXSD_INVALID) {
VTR_LOG_ERROR("Invalid block type!");
return CMD_EXEC_FATAL_ERROR;
}
}
}
device_rr_gsb.build_gsb_unique_module();
if (verbose_output) {
report_unique_module_status_read(device_rr_gsb, true);
}
return CMD_EXEC_SUCCESS;
}
} // namespace openfpga

View File

@ -0,0 +1,36 @@
#ifndef READ_XML_UNIQUE_BLOCKS_BIN_H
#define READ_XML_UNIQUE_BLOCKS_BIN_H
#include <string>
/* 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 libarchfpga */
#include "arch_error.h"
#include "device_rr_gsb_utils.h"
#include "unique_blocks_uxsdcxx.capnp.h"
/********************************************************************
* This file includes the top-level functions of this library
* which includes:
* -- reads a bin file of unique blocks to the associated
* data structures: device_rr_gsb
*******************************************************************/
namespace openfpga {
std::vector<vtr::Point<size_t>> read_bin_unique_instance_coords(
const ucap::Uniqueblockpacked::Reader& unique_block);
vtr::Point<size_t> read_bin_unique_block_coord(
const ucap::Uniqueblockpacked::Reader& unique_block, ucap::Blocktype& type);
int read_bin_unique_blocks(DeviceRRGSB& device_rr_gsb, const char* file_name,
bool verbose_output);
} // namespace openfpga
#endif

View File

@ -18,7 +18,7 @@
#include "device_rr_gsb_utils.h"
#include "mmap_file.h"
#include "openfpga_digest.h"
#include "read_unique_blocks.h"
#include "read_unique_blocks_xml.h"
#include "read_xml_util.h"
#include "rr_gsb.h"
#include "unique_blocks_uxsdcxx.capnp.h"
@ -159,73 +159,4 @@ int read_xml_unique_blocks(DeviceRRGSB& device_rr_gsb, const char* file_name,
archfpga_throw(file_name, e.line(), "%s", e.what());
}
}
/*read the instances' coordinate of a unique block from a bin file*/
std::vector<vtr::Point<size_t>> read_bin_unique_instance_coords(
const ucap::Uniqueblockpacked::Reader& unique_block) {
std::vector<vtr::Point<size_t>> instance_coords;
if (unique_block.hasInstances()) {
auto instance_list = unique_block.getInstances();
for (auto instance : instance_list) {
int instance_x = instance.getX();
int instance_y = instance.getY();
vtr::Point<size_t> instance_coordinate(instance_x, instance_y);
instance_coords.push_back(instance_coordinate);
}
}
return instance_coords;
}
/*read the unique block coordinate from a bin file */
vtr::Point<size_t> read_bin_unique_block_coord(
const ucap::Uniqueblockpacked::Reader& unique_block, ucap::Blocktype& type) {
auto block_info = unique_block.getBlockinfo();
int block_x = block_info.getX();
int block_y = block_info.getY();
type = block_info.getType();
vtr::Point<size_t> block_coordinate(block_x, block_y);
return block_coordinate;
}
/*top-level function to read unique blocks from bin file*/
int read_bin_unique_blocks(DeviceRRGSB& device_rr_gsb, const char* file_name,
bool verbose_output) {
/* clear unique modules & reserve memory to relavant vectors */
device_rr_gsb.clear_unique_modules();
device_rr_gsb.reserve_unique_modules();
MmapFile f(file_name);
::capnp::FlatArrayMessageReader reader(f.getData());
auto root = reader.getRoot<ucap::UniqueBlocks>();
if (root.hasAtominfos()) {
auto block_list = root.getAtominfos();
for (auto unique_block : block_list) {
ucap::Blocktype type;
vtr::Point<size_t> block_coordinate = read_bin_unique_block_coord(
unique_block, type); /*get block coordinate and type*/
std::vector<vtr::Point<size_t>> instance_coords =
read_bin_unique_instance_coords(
unique_block); /* get a list of instance coordinates*/
/* get block coordinate and instance coordinate, try to setup
* device_rr_gsb */
if (type == ucap::Blocktype::SB) {
device_rr_gsb.preload_unique_sb_module(block_coordinate,
instance_coords);
} else if (type == ucap::Blocktype::CBY) {
device_rr_gsb.preload_unique_cby_module(block_coordinate,
instance_coords);
} else if (type == ucap::Blocktype::CBX) {
device_rr_gsb.preload_unique_cbx_module(block_coordinate,
instance_coords);
} else if (type == ucap::Blocktype::UXSD_INVALID) {
VTR_LOG_ERROR("Invalid block type!");
return CMD_EXEC_FATAL_ERROR;
}
}
}
device_rr_gsb.build_gsb_unique_module();
if (verbose_output) {
report_unique_module_status_read(device_rr_gsb, true);
}
return CMD_EXEC_SUCCESS;
}
} // namespace openfpga

View File

@ -1,5 +1,5 @@
#ifndef READ_XML_UNIQUE_BLOCKS_H
#define READ_XML_UNIQUE_BLOCKS_H
#ifndef READ_XML_UNIQUE_BLOCKS_XML_H
#define READ_XML_UNIQUE_BLOCKS_XML_H
#include <string>
@ -35,15 +35,6 @@ void report_unique_module_status_read(const DeviceRRGSB& device_rr_gsb,
int read_xml_unique_blocks(DeviceRRGSB& device_rr_gsb, const char* file_name,
bool verbose_output);
std::vector<vtr::Point<size_t>> read_bin_unique_instance_coords(
const ucap::Uniqueblockpacked::Reader& unique_block);
vtr::Point<size_t> read_bin_unique_block_coord(
const ucap::Uniqueblockpacked::Reader& unique_block, ucap::Blocktype& type);
int read_bin_unique_blocks(DeviceRRGSB& device_rr_gsb, const char* file_name,
bool verbose_output);
} // namespace openfpga
#endif

View File

@ -0,0 +1,121 @@
#include <capnp/message.h>
#include <string>
/* Headers from pugi XML library */
#include "pugixml.hpp"
#include "pugixml_util.hpp"
#include "serdes_utils.h"
/* Headers from vtr util library */
#include "vtr_assert.h"
#include "vtr_log.h"
#include "vtr_time.h"
/* Headers from libarchfpga */
#include "arch_error.h"
#include "command_exit_codes.h"
#include "device_rr_gsb_utils.h"
#include "openfpga_digest.h"
#include "read_xml_util.h"
#include "rr_gsb.h"
#include "unique_blocks_uxsdcxx.capnp.h"
#include "write_unique_blocks_bin.h"
#include "write_unique_blocks_xml.h"
#include "write_xml_utils.h"
/********************************************************************
* This file includes the top-level functions of this library
* which includes:
* -- write the unique blocks' information in the associated data structures:
*device_rr_gsb to a bin file
*******************************************************************/
namespace openfpga {
/* write each unique block (including a single unique block info and its mirror
* instances' info)into capnp builder */
int write_bin_atom_block(const std::vector<vtr::Point<size_t>>& instance_map,
const vtr::Point<size_t>& unique_block_coord,
const ucap::Blocktype type,
ucap::Uniqueblockpacked::Builder& root) {
auto block_info = root.initBlockinfo();
block_info.setX(unique_block_coord.x());
block_info.setY(unique_block_coord.y());
block_info.setType(type);
if (instance_map.size() > 0) {
auto instance_list = root.initInstances(instance_map.size());
for (size_t instance_id = 0; instance_id < instance_map.size();
instance_id++) {
auto instance = instance_list[instance_id];
instance.setX(instance_map[instance_id].x());
instance.setY(instance_map[instance_id].y());
}
}
return openfpga::CMD_EXEC_SUCCESS;
}
/* Top-level function to write bin file of unique blocks */
int write_bin_unique_blocks(const DeviceRRGSB& device_rr_gsb, const char* fname,
bool verbose_output) {
::capnp::MallocMessageBuilder builder;
auto unique_blocks = builder.initRoot<ucap::UniqueBlocks>();
int num_unique_blocks = device_rr_gsb.get_num_sb_unique_module() +
device_rr_gsb.get_num_cb_unique_module(CHANX) +
device_rr_gsb.get_num_cb_unique_module(CHANY);
auto block_list = unique_blocks.initAtominfos(num_unique_blocks);
/*write switch blocks into bin file */
for (size_t id = 0; id < device_rr_gsb.get_num_sb_unique_module(); ++id) {
const auto unique_block_coord = device_rr_gsb.get_sb_unique_block_coord(id);
const std::vector<vtr::Point<size_t>> instance_map =
device_rr_gsb.get_sb_unique_block_instance_coord(unique_block_coord);
auto unique_block = block_list[id];
int status_code = write_bin_atom_block(instance_map, unique_block_coord,
ucap::Blocktype::SB, unique_block);
if (status_code != 0) {
VTR_LOG_ERROR("write sb unique blocks into bin file failed!");
return CMD_EXEC_FATAL_ERROR;
}
}
/*write cbx blocks into bin file */
for (size_t id = 0; id < device_rr_gsb.get_num_cb_unique_module(CHANX);
++id) {
const auto unique_block_coord =
device_rr_gsb.get_cbx_unique_block_coord(id);
const std::vector<vtr::Point<size_t>> instance_map =
device_rr_gsb.get_cbx_unique_block_instance_coord(unique_block_coord);
int block_id = id + device_rr_gsb.get_num_sb_unique_module();
auto unique_block = block_list[block_id];
int status_code = write_bin_atom_block(instance_map, unique_block_coord,
ucap::Blocktype::CBX, unique_block);
if (status_code != 0) {
VTR_LOG_ERROR("write cbx unique blocks into bin file failed!");
return CMD_EXEC_FATAL_ERROR;
}
}
/*write cby blocks into bin file */
for (size_t id = 0; id < device_rr_gsb.get_num_cb_unique_module(CHANY);
++id) {
const auto unique_block_coord =
device_rr_gsb.get_cby_unique_block_coord(id);
const std::vector<vtr::Point<size_t>> instance_map =
device_rr_gsb.get_cby_unique_block_instance_coord(unique_block_coord);
int block_id = id + device_rr_gsb.get_num_sb_unique_module() +
device_rr_gsb.get_num_cb_unique_module(CHANX);
auto unique_block = block_list[block_id];
int status_code = write_bin_atom_block(instance_map, unique_block_coord,
ucap::Blocktype::CBY, unique_block);
if (status_code != 0) {
VTR_LOG_ERROR("write cby unique blocks into bin file failed!");
return CMD_EXEC_FATAL_ERROR;
}
}
writeMessageToFile(fname, &builder);
if (verbose_output) {
report_unique_module_status_write(device_rr_gsb, true);
}
return openfpga::CMD_EXEC_SUCCESS;
}
} // namespace openfpga

View File

@ -0,0 +1,34 @@
#ifndef WRITE_XML_UNIQUE_BLOCKS_BIN_H
#define WRITE_XML_UNIQUE_BLOCKS_BIN_H
#include <string>
/* 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 libarchfpga */
#include "arch_error.h"
#include "device_rr_gsb_utils.h"
/********************************************************************
* This file includes the top-level functions of this library
* which includes:
* -- write the unique blocks' information in the associated data structures:
*device_rr_gsb to a bin file
*******************************************************************/
namespace openfpga {
int write_bin_unique_blocks(const DeviceRRGSB& device_rr_gsb, const char* fname,
bool verbose_output);
int write_bin_atom_block(const std::vector<vtr::Point<size_t>>& instance_map,
const vtr::Point<size_t>& unique_block_coord,
const ucap::Blocktype type,
ucap::Uniqueblockpacked::Builder& root);
} // namespace openfpga
#endif

View File

@ -19,7 +19,7 @@
#include "read_xml_util.h"
#include "rr_gsb.h"
#include "unique_blocks_uxsdcxx.capnp.h"
#include "write_unique_blocks.h"
#include "write_unique_blocks_xml.h"
#include "write_xml_utils.h"
/********************************************************************
@ -184,93 +184,4 @@ int write_xml_unique_blocks(const DeviceRRGSB& device_rr_gsb, const char* fname,
return CMD_EXEC_SUCCESS;
}
/* write each unique block (including a single unique block info and its mirror
* instances' info)into capnp builder */
int write_bin_atom_block(const std::vector<vtr::Point<size_t>>& instance_map,
const vtr::Point<size_t>& unique_block_coord,
const ucap::Blocktype type,
ucap::Uniqueblockpacked::Builder& root) {
auto block_info = root.initBlockinfo();
block_info.setX(unique_block_coord.x());
block_info.setY(unique_block_coord.y());
block_info.setType(type);
if (instance_map.size() > 0) {
auto instance_list = root.initInstances(instance_map.size());
for (size_t instance_id = 0; instance_id < instance_map.size();
instance_id++) {
auto instance = instance_list[instance_id];
instance.setX(instance_map[instance_id].x());
instance.setY(instance_map[instance_id].y());
}
}
return openfpga::CMD_EXEC_SUCCESS;
}
/* Top-level function to write bin file of unique blocks */
int write_bin_unique_blocks(const DeviceRRGSB& device_rr_gsb, const char* fname,
bool verbose_output) {
::capnp::MallocMessageBuilder builder;
auto unique_blocks = builder.initRoot<ucap::UniqueBlocks>();
int num_unique_blocks = device_rr_gsb.get_num_sb_unique_module() +
device_rr_gsb.get_num_cb_unique_module(CHANX) +
device_rr_gsb.get_num_cb_unique_module(CHANY);
auto block_list = unique_blocks.initAtominfos(num_unique_blocks);
/*write switch blocks into bin file */
for (size_t id = 0; id < device_rr_gsb.get_num_sb_unique_module(); ++id) {
const auto unique_block_coord = device_rr_gsb.get_sb_unique_block_coord(id);
const std::vector<vtr::Point<size_t>> instance_map =
device_rr_gsb.get_sb_unique_block_instance_coord(unique_block_coord);
auto unique_block = block_list[id];
int status_code = write_bin_atom_block(instance_map, unique_block_coord,
ucap::Blocktype::SB, unique_block);
if (status_code != 0) {
VTR_LOG_ERROR("write sb unique blocks into bin file failed!");
return CMD_EXEC_FATAL_ERROR;
}
}
/*write cbx blocks into bin file */
for (size_t id = 0; id < device_rr_gsb.get_num_cb_unique_module(CHANX);
++id) {
const auto unique_block_coord =
device_rr_gsb.get_cbx_unique_block_coord(id);
const std::vector<vtr::Point<size_t>> instance_map =
device_rr_gsb.get_cbx_unique_block_instance_coord(unique_block_coord);
int block_id = id + device_rr_gsb.get_num_sb_unique_module();
auto unique_block = block_list[block_id];
int status_code = write_bin_atom_block(instance_map, unique_block_coord,
ucap::Blocktype::CBX, unique_block);
if (status_code != 0) {
VTR_LOG_ERROR("write cbx unique blocks into bin file failed!");
return CMD_EXEC_FATAL_ERROR;
}
}
/*write cby blocks into bin file */
for (size_t id = 0; id < device_rr_gsb.get_num_cb_unique_module(CHANY);
++id) {
const auto unique_block_coord =
device_rr_gsb.get_cby_unique_block_coord(id);
const std::vector<vtr::Point<size_t>> instance_map =
device_rr_gsb.get_cby_unique_block_instance_coord(unique_block_coord);
int block_id = id + device_rr_gsb.get_num_sb_unique_module() +
device_rr_gsb.get_num_cb_unique_module(CHANX);
auto unique_block = block_list[block_id];
int status_code = write_bin_atom_block(instance_map, unique_block_coord,
ucap::Blocktype::CBY, unique_block);
if (status_code != 0) {
VTR_LOG_ERROR("write cby unique blocks into bin file failed!");
return CMD_EXEC_FATAL_ERROR;
}
}
writeMessageToFile(fname, &builder);
if (verbose_output) {
report_unique_module_status_write(device_rr_gsb, true);
}
return openfpga::CMD_EXEC_SUCCESS;
}
} // namespace openfpga

View File

@ -1,5 +1,5 @@
#ifndef WRITE_XML_UNIQUE_BLOCKS_H
#define WRITE_XML_UNIQUE_BLOCKS_H
#ifndef WRITE_XML_UNIQUE_BLOCKS_XML_H
#define WRITE_XML_UNIQUE_BLOCKS_XML_H
#include <string>
@ -33,11 +33,5 @@ void report_unique_module_status_write(
bool verbose_output); /*report status of written info*/
int write_xml_unique_blocks(const DeviceRRGSB& device_rr_gsb, const char* fname,
bool verbose_output);
int write_bin_unique_blocks(const DeviceRRGSB& device_rr_gsb, const char* fname,
bool verbose_output);
int write_bin_atom_block(const std::vector<vtr::Point<size_t>>& instance_map,
const vtr::Point<size_t>& unique_block_coord,
const ucap::Blocktype type,
ucap::Uniqueblockpacked::Builder& root);
} // namespace openfpga
#endif

View File

@ -16,7 +16,8 @@
#include "fabric_key_writer.h"
#include "globals.h"
#include "openfpga_naming.h"
#include "read_unique_blocks.h"
#include "read_unique_blocks_bin.h"
#include "read_unique_blocks_xml.h"
#include "read_xml_fabric_key.h"
#include "read_xml_io_name_map.h"
#include "read_xml_module_name_map.h"
@ -25,7 +26,8 @@
#include "report_reference.h"
#include "vtr_log.h"
#include "vtr_time.h"
#include "write_unique_blocks.h"
#include "write_unique_blocks_bin.h"
#include "write_unique_blocks_xml.h"
#include "write_xml_fabric_pin_physical_location.h"
#include "write_xml_module_name_map.h"