Skip to content

Commit f63d188

Browse files
committed
vpr: base: optionally write block usage summary JSON or XML file
Signed-off-by: Paweł Czarnecki <[email protected]>
1 parent 1333ba7 commit f63d188

File tree

7 files changed

+88
-7
lines changed

7 files changed

+88
-7
lines changed

vpr/src/base/SetupVPR.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ void SetupVPR(const t_options* Options,
9898
FileNameOpts->out_file_prefix = Options->out_file_prefix;
9999
FileNameOpts->read_vpr_constraints_file = Options->read_vpr_constraints_file;
100100
FileNameOpts->write_vpr_constraints_file = Options->write_vpr_constraints_file;
101+
FileNameOpts->write_block_usage = Options->write_block_usage;
101102

102103
FileNameOpts->verify_file_digests = Options->verify_file_digests;
103104

vpr/src/base/ShowSetup.cpp

Lines changed: 70 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#include <fstream>
2+
13
#include "vtr_assert.h"
24
#include "vtr_log.h"
35
#include "vtr_memory.h"
@@ -61,16 +63,18 @@ void ShowSetup(const t_vpr_setup& vpr_setup) {
6163
}
6264
}
6365

64-
void printClusteredNetlistStats() {
66+
void printClusteredNetlistStats(std::string block_usage_filename) {
6567
auto& device_ctx = g_vpr_ctx.device();
6668
auto& cluster_ctx = g_vpr_ctx.clustering();
6769

68-
int j, L_num_p_inputs, L_num_p_outputs;
70+
int j, L_num_p_inputs, L_num_p_outputs, num_nets, num_blocks;
6971
std::vector<int> num_blocks_type(device_ctx.logical_block_types.size(), 0);
72+
num_nets = (int)cluster_ctx.clb_nlist.nets().size();
73+
num_blocks = (int)cluster_ctx.clb_nlist.blocks().size();
7074

7175
VTR_LOG("\n");
72-
VTR_LOG("Netlist num_nets: %d\n", (int)cluster_ctx.clb_nlist.nets().size());
73-
VTR_LOG("Netlist num_blocks: %d\n", (int)cluster_ctx.clb_nlist.blocks().size());
76+
VTR_LOG("Netlist num_nets: %d\n", num_nets);
77+
VTR_LOG("Netlist num_blocks: %d\n", num_blocks);
7478

7579
/* Count I/O input and output pads */
7680
L_num_p_inputs = 0;
@@ -106,9 +110,71 @@ void printClusteredNetlistStats() {
106110
VTR_LOG("Netlist inputs pins: %d\n", L_num_p_inputs);
107111
VTR_LOG("Netlist output pins: %d\n", L_num_p_outputs);
108112
VTR_LOG("\n");
113+
if (!block_usage_filename.empty())
114+
writeClusteredNetlistStats(block_usage_filename, num_nets, num_blocks,
115+
L_num_p_inputs, L_num_p_outputs,
116+
num_blocks_type,
117+
device_ctx.logical_block_types);
118+
109119
num_blocks_type.clear();
110120
}
111121

122+
void writeClusteredNetlistStats(std::string block_usage_filename,
123+
int num_nets,
124+
int num_blocks,
125+
int L_num_p_inputs,
126+
int L_num_p_outputs,
127+
std::vector<int> num_blocks_type,
128+
std::vector<t_logical_block_type> logical_block_types) {
129+
if (vtr::check_file_name_extension(block_usage_filename.c_str(), ".json")) {
130+
// write report in JSON format
131+
std::fstream fp;
132+
fp.open(block_usage_filename, std::fstream::out | std::fstream::trunc);
133+
fp << "{\n";
134+
135+
fp << " \"num_nets\": \"" << num_nets << "\",\n";
136+
fp << " \"num_blocks\": \"" << num_blocks << "\",\n";
137+
138+
fp << " \"input_pins\": \"" << L_num_p_inputs << "\",\n";
139+
fp << " \"output_pins\": \"" << L_num_p_outputs << "\",\n";
140+
141+
fp << " \"blocks\": {\n";
142+
143+
for (const auto& type : logical_block_types) {
144+
fp << " \"" << type.name << "\": " << num_blocks_type[type.index];
145+
if ((int)type.index < (int)logical_block_types.size() - 1)
146+
fp << ",\n";
147+
else
148+
fp << "\n";
149+
}
150+
fp << " }\n";
151+
fp << "}\n";
152+
} else if (vtr::check_file_name_extension(block_usage_filename.c_str(), ".xml")) {
153+
// write report in XML format
154+
std::fstream fp;
155+
fp.open(block_usage_filename, std::fstream::out | std::fstream::trunc);
156+
fp << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
157+
fp << "<block_usage_report>\n";
158+
159+
fp << " <nets num=\"" << num_nets << "\"></nets>\n";
160+
fp << " <blocks num=\"" << num_blocks << "\">\n";
161+
162+
for (const auto& type : logical_block_types) {
163+
fp << " <block type=\"" << type.name << "\" usage=\"" << num_blocks_type[type.index] << "\"></block>\n";
164+
}
165+
fp << " </blocks>\n";
166+
167+
fp << " <input_pins num=\"" << L_num_p_inputs << "\"></input_pins>\n";
168+
fp << " <output_pins num=\"" << L_num_p_outputs << "\"></output_pins>\n";
169+
170+
fp << "</block_usage_report>\n";
171+
} else {
172+
VPR_FATAL_ERROR(VPR_ERROR_PACK,
173+
"Unknown extension on output %s",
174+
block_usage_filename.c_str());
175+
}
176+
}
177+
112178
static void ShowAnnealSched(const t_annealing_sched& AnnealSched) {
113179
VTR_LOG("AnnealSched.type: ");
114180
switch (AnnealSched.type) {

vpr/src/base/ShowSetup.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22
#define SHOWSETUP_H
33

44
void ShowSetup(const t_vpr_setup& vpr_setup);
5-
void printClusteredNetlistStats();
5+
void printClusteredNetlistStats(std::string block_usage_filename);
6+
void writeClusteredNetlistStats(std::string block_usage_filename,
7+
int num_nets,
8+
int num_blocks,
9+
int L_num_p_inputs,
10+
int L_num_p_outputs,
11+
std::vector<int> num_blocks_type,
12+
std::vector<t_logical_block_type> logical_block_types);
613

714
#endif

vpr/src/base/read_options.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1490,6 +1490,10 @@ argparse::ArgumentParser create_arg_parser(std::string prog_name, t_options& arg
14901490
.help("Prefix for output files")
14911491
.show_in(argparse::ShowIn::HELP_ONLY);
14921492

1493+
file_grp.add_argument(args.write_block_usage, "--write_block_usage")
1494+
.help("Writes the packing block types usage summary to the specified JSON or XML file.")
1495+
.show_in(argparse::ShowIn::HELP_ONLY);
1496+
14931497
auto& netlist_grp = parser.add_argument_group("netlist options");
14941498

14951499
netlist_grp.add_argument<bool, ParseOnOff>(args.absorb_buffer_luts, "--absorb_buffer_luts")

vpr/src/base/read_options.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ struct t_options {
3636
argparse::ArgValue<std::string> write_router_lookahead;
3737
argparse::ArgValue<std::string> read_router_lookahead;
3838

39+
argparse::ArgValue<std::string> write_block_usage;
40+
3941
/* Stage Options */
4042
argparse::ArgValue<bool> do_packing;
4143
argparse::ArgValue<bool> do_placement;

vpr/src/base/vpr_api.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -516,8 +516,8 @@ bool vpr_pack_flow(t_vpr_setup& vpr_setup, const t_arch& arch) {
516516
/* Sanity check the resulting netlist */
517517
check_netlist(packer_opts.pack_verbosity);
518518

519-
/* Output the netlist stats to console. */
520-
printClusteredNetlistStats();
519+
/* Output the netlist stats to console and optionally to file. */
520+
printClusteredNetlistStats(vpr_setup.FileNameOpts.write_block_usage.c_str());
521521

522522
// print the total number of used physical blocks for each
523523
// physical block type after finishing the packing stage

vpr/src/base/vpr_types.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -755,6 +755,7 @@ struct t_file_name_opts {
755755
std::string out_file_prefix;
756756
std::string read_vpr_constraints_file;
757757
std::string write_vpr_constraints_file;
758+
std::string write_block_usage;
758759
bool verify_file_digests;
759760
};
760761

0 commit comments

Comments
 (0)