write bin function works now
This commit is contained in:
parent
3fcdc10d3a
commit
ef18d04a3a
|
@ -1,12 +1,10 @@
|
|||
Capnproto usage in VTR
|
||||
Capnproto usage in Openfpga
|
||||
======================
|
||||
|
||||
Capnproto is a data serialization framework designed for portabliity and speed.
|
||||
In VPR, capnproto is used to provide binary formats for internal data
|
||||
In Openfpga, capnproto is used to provide binary formats for internal data
|
||||
structures that can be computed once, and used many times. Specific examples:
|
||||
- rrgraph
|
||||
- Router lookahead data
|
||||
- Place matrix delay estimates
|
||||
- preload unique blocks
|
||||
|
||||
What is capnproto?
|
||||
==================
|
||||
|
@ -29,56 +27,48 @@ These source and header files combined with the capnproto C++ library, enables
|
|||
C++ code to read and write the messages matching a particular schema. The C++
|
||||
library API can be found here: https://capnproto.org/cxx.html
|
||||
|
||||
Contents of libvtrcapnproto
|
||||
Contents of libopenfpgacapnproto
|
||||
===========================
|
||||
|
||||
libvtrcapnproto should contain two elements:
|
||||
- Utilities for working capnproto messages in VTR
|
||||
- Generate source and header files of all capnproto messages used in VTR
|
||||
libopenfpgacapnproto should contain two elements:
|
||||
- Utilities for working capnproto messages in Openfpga
|
||||
- Generate source and header files of all capnproto messages used in Openfpga
|
||||
|
||||
I/O Utilities
|
||||
-------------
|
||||
|
||||
Capnproto does not provide IO support, instead it works from arrays (or file
|
||||
descriptors). To avoid re-writing this code, libvtrcapnproto provides two
|
||||
descriptors). To avoid re-writing this code, libopenfpgacapnproto provides two
|
||||
utilities that should be used whenever reading or writing capnproto message to
|
||||
disk:
|
||||
disk. These two files are copied :
|
||||
- `serdes_utils.h` provides the writeMessageToFile function - Writes a
|
||||
capnproto message to disk.
|
||||
- `mmap_file.h` provides MmapFile object - Maps a capnproto message from the
|
||||
disk as a flat array.
|
||||
|
||||
NdMatrix Utilities
|
||||
------------------
|
||||
|
||||
A common datatype which appears in many data structures that VPR might want to
|
||||
serialize is the generic type `vtr::NdMatrix`. `ndmatrix_serdes.h` provides
|
||||
generic functions ToNdMatrix and FromNdMatrix, which can be used to generically
|
||||
convert between the provideid capnproto message `Matrix` and `vtr::NdMatrix`.
|
||||
|
||||
Capnproto schemas
|
||||
-----------------
|
||||
|
||||
libvtrcapnproto should contain all capnproto schema definitions used within
|
||||
libopenfpgacapnproto should contain all capnproto schema definitions used within
|
||||
VTR. To add a new schema:
|
||||
1. Add the schema to git in `libs/libvtrcapnproto/`
|
||||
1. Add the schema to git in `libs/libopenfpgacapnproto/`
|
||||
2. Add the schema file name to `capnp_generate_cpp` invocation in
|
||||
`libs/libvtrcapnproto/CMakeLists.txt`.
|
||||
`libs/libopenfpgacapnproto/CMakeLists.txt`.
|
||||
|
||||
The schema will be available in the header file `schema filename>.h`. The
|
||||
actual header file will appear in the CMake build directory
|
||||
`libs/libvtrcapnproto` after `libvtrcapnproto` has been rebuilt.
|
||||
`libs/libopenfpgacapnproto` after `libopenfpgacapnproto` has been rebuilt.
|
||||
|
||||
Writing capnproto binary files to text
|
||||
======================================
|
||||
|
||||
The `capnp` tool (found in the CMake build directiory
|
||||
`libs/EXTERNAL/capnproto/c++/src/capnp`) can be used to convert from a binary
|
||||
`/vtr-verilog-to-routing/libs/EXTERNAL/capnproto/c++/src/capnp`) can be used to convert from a binary
|
||||
capnp message to a textual form.
|
||||
|
||||
Example converting VprOverrideDelayModel from binary to text:
|
||||
Example converting UniqueBlockCompactInfo from binary to text:
|
||||
|
||||
```
|
||||
capnp convert binary:text place_delay_model.capnp VprOverrideDelayModel \
|
||||
< place_delay.bin > place_delay.txt
|
||||
capnp convert binary:text unique_blocks_uxsdcxx.capnp UniqueBlockCompactInfo \
|
||||
< test.bin > test.txt
|
||||
```
|
||||
|
|
|
@ -116,7 +116,9 @@ std::vector<vtr::Point<size_t>> DeviceRRGSB::get_sb_unique_block_instance_coord(
|
|||
sb_unique_module_id_[location_x][location_y];
|
||||
if (unique_module_id_instance == unique_module_id) {
|
||||
vtr::Point<size_t> instance_coord(location_x, location_y);
|
||||
instance_map.push_back(instance_coord);
|
||||
if (instance_coord != unique_block_coord){
|
||||
instance_map.push_back(instance_coord);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -144,7 +146,9 @@ DeviceRRGSB::get_cbx_unique_block_instance_coord(
|
|||
cbx_unique_module_id_[location_x][location_y];
|
||||
if (unique_module_id_instance == unique_module_id) {
|
||||
vtr::Point<size_t> instance_coord(location_x, location_y);
|
||||
instance_map.push_back(instance_coord);
|
||||
if (instance_coord != unique_block_coord){
|
||||
instance_map.push_back(instance_coord);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -172,7 +176,9 @@ DeviceRRGSB::get_cby_unique_block_instance_coord(
|
|||
cby_unique_module_id_[location_x][location_y];
|
||||
if (unique_module_id_instance == unique_module_id) {
|
||||
vtr::Point<size_t> instance_coord(location_x, location_y);
|
||||
instance_map.push_back(instance_coord);
|
||||
if (instance_coord != unique_block_coord){
|
||||
instance_map.push_back(instance_coord);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -50,18 +50,14 @@ int write_xml_atom_block(std::fstream& fp,
|
|||
<< "\n";
|
||||
|
||||
for (const auto& instance_info : instance_map) {
|
||||
if (instance_info.x() == unique_block_coord.x() &&
|
||||
instance_info.y() == unique_block_coord.y()) {
|
||||
;
|
||||
} else {
|
||||
openfpga::write_tab_to_file(fp, 2);
|
||||
fp << "<instance";
|
||||
write_xml_attribute(fp, "x", instance_info.x());
|
||||
write_xml_attribute(fp, "y", instance_info.y());
|
||||
openfpga::write_tab_to_file(fp, 2);
|
||||
fp << "<instance";
|
||||
write_xml_attribute(fp, "x", instance_info.x());
|
||||
write_xml_attribute(fp, "y", instance_info.y());
|
||||
|
||||
fp << "/>"
|
||||
<< "\n";
|
||||
}
|
||||
fp << "/>"
|
||||
<< "\n";
|
||||
|
||||
}
|
||||
openfpga::write_tab_to_file(fp, 1);
|
||||
fp << "</block>"
|
||||
|
@ -190,126 +186,97 @@ int write_xml_unique_blocks(const DeviceRRGSB& device_rr_gsb, const char* fname,
|
|||
return CMD_EXEC_SUCCESS;
|
||||
}
|
||||
|
||||
// int write_bin_atom_block(const std::vector<vtr::Point<size_t>>& instance_map,
|
||||
// const vtr::Point<size_t>& unique_block_coord,
|
||||
// const uniqueblockcap::BlockType type,
|
||||
// uniqueblockcap::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);
|
||||
// auto instance_list = root.initInstanceList(instance_map.size());
|
||||
// for (size_t instance_id = 0; instance_id < instance_map; instance_id++) {
|
||||
// if (instance_map[instance_id].x() == unique_block_coord.x() &&
|
||||
// instance_map[instance_id].y() == unique_block_coord.y()) {
|
||||
// ;
|
||||
// } else {
|
||||
// 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;
|
||||
// }
|
||||
/* 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 uniqueblockcap::BlockType type,
|
||||
uniqueblockcap::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.initInstanceList(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<uniqueblockcap::UniqueBlockCompactInfo>();
|
||||
void* context;
|
||||
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.initAtomInfo(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);
|
||||
|
||||
std::cout << "what is instance size: " << instance_map.size() << std::endl;
|
||||
auto unique_block = block_list[id];
|
||||
|
||||
auto block_info = unique_block.initBlockInfo();
|
||||
block_info.setX(unique_block_coord.x());
|
||||
block_info.setY(unique_block_coord.y());
|
||||
block_info.setType(uniqueblockcap::BlockType::SB);
|
||||
auto instance_list = unique_block.initInstanceList(instance_map.size());
|
||||
for (size_t instance_id = 0; instance_id < instance_map; instance_id++) {
|
||||
if (instance_map[instance_id].x() == unique_block_coord.x() &&
|
||||
instance_map[instance_id].y() == unique_block_coord.y()) {
|
||||
;
|
||||
} else {
|
||||
auto instance = instance_list[instance_id];
|
||||
instance.setX(instance_map[instance_id].x());
|
||||
instance.setY(instance_map[instance_id].y());
|
||||
}
|
||||
int status_code =
|
||||
write_bin_atom_block(instance_map, unique_block_coord,
|
||||
uniqueblockcap::BlockType::SB, unique_block);
|
||||
if (status_code != 0) {
|
||||
VTR_LOG_ERROR("write sb unique blocks into bin file failed!");
|
||||
return CMD_EXEC_FATAL_ERROR;
|
||||
}
|
||||
|
||||
// int status_code = write_bin_atom_block(instance_map, unique_block_coord,
|
||||
// uniqueblockcap::BlockType::SB, unique_block);
|
||||
// if (status_code != 0) {
|
||||
// VTR_LOG_ERROR("write cbx unique blocks into xml file failed!");
|
||||
// return CMD_EXEC_FATAL_ERROR;
|
||||
// }
|
||||
}
|
||||
|
||||
// for (size_t id = device_rr_gsb.get_num_sb_unique_module();
|
||||
// id < device_rr_gsb.get_num_sb_unique_module() +
|
||||
// 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);
|
||||
/*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,
|
||||
uniqueblockcap::BlockType::CBX, unique_block);
|
||||
if (status_code != 0) {
|
||||
VTR_LOG_ERROR("write cbx unique blocks into bin file failed!");
|
||||
return CMD_EXEC_FATAL_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
// auto unique_block = unique_blocks[id];
|
||||
// auto block_info = unique_block.initBlockInfo();
|
||||
// block_info.setX(unique_block_coord.x());
|
||||
// block_info.setY(unique_block_coord.y());
|
||||
// block_info.setType(SB);
|
||||
// auto instance_list = unique_block.initInstanceList(instance_map.size());
|
||||
// for (size_t instance_id = 0; instance_id < instance_map; instance_id++) {
|
||||
// if (instance_map[instance_id].x() == unique_block_coord.x() &&
|
||||
// instance_map[instance_id].y() == unique_block_coord.y()) {
|
||||
// ;
|
||||
// } else {
|
||||
// auto instance = instance_list[instance_id];
|
||||
// instance.setX(instance_map[instance_id].x());
|
||||
// instance.setY(instance_map[instance_id].y());
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
/*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,
|
||||
uniqueblockcap::BlockType::CBY, unique_block);
|
||||
if (status_code != 0) {
|
||||
VTR_LOG_ERROR("write cby unique blocks into bin file failed!");
|
||||
return CMD_EXEC_FATAL_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
// for (size_t id = device_rr_gsb.get_num_sb_unique_module();
|
||||
// id < device_rr_gsb.get_num_sb_unique_module() +
|
||||
// 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);
|
||||
|
||||
// auto unique_block = unique_blocks[id];
|
||||
// auto block_info = unique_block.initBlockInfo();
|
||||
// block_info.setX(unique_block_coord.x());
|
||||
// block_info.setY(unique_block_coord.y());
|
||||
// block_info.setType(SB);
|
||||
// auto instance_list = unique_block.initInstanceList(instance_map.size());
|
||||
// for (size_t instance_id = 0; instance_id < instance_map; instance_id++) {
|
||||
// if (instance_map[instance_id].x() == unique_block_coord.x() &&
|
||||
// instance_map[instance_id].y() == unique_block_coord.y()) {
|
||||
// ;
|
||||
// } else {
|
||||
// auto instance = instance_list[instance_id];
|
||||
// instance.setX(instance_map[instance_id].x());
|
||||
// instance.setY(instance_map[instance_id].y());
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
writeMessageToFile(fname, &builder);
|
||||
return 0;
|
||||
if (verbose_output) {
|
||||
report_unique_module_status_write(device_rr_gsb, true);
|
||||
}
|
||||
return openfpga::CMD_EXEC_SUCCESS;
|
||||
}
|
||||
|
||||
} // namespace openfpga
|
||||
|
|
|
@ -35,10 +35,9 @@ 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 ::uniqueblockcap::BlockType type,
|
||||
// uniqueblockcap::UniqueBlockPacked::Builder &root);
|
||||
int write_bin_atom_block(const std::vector<vtr::Point<size_t>>& instance_map,
|
||||
const vtr::Point<size_t>& unique_block_coord,
|
||||
const uniqueblockcap::BlockType type,
|
||||
uniqueblockcap::UniqueBlockPacked::Builder& root);
|
||||
} // namespace openfpga
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue