|
| 1 | +#include <fstream> |
| 2 | + |
1 | 3 | #include "vtr_assert.h"
|
2 | 4 | #include "vtr_log.h"
|
3 | 5 | #include "vtr_memory.h"
|
@@ -61,16 +63,18 @@ void ShowSetup(const t_vpr_setup& vpr_setup) {
|
61 | 63 | }
|
62 | 64 | }
|
63 | 65 |
|
64 |
| -void printClusteredNetlistStats() { |
| 66 | +void printClusteredNetlistStats(std::string block_usage_filename) { |
65 | 67 | auto& device_ctx = g_vpr_ctx.device();
|
66 | 68 | auto& cluster_ctx = g_vpr_ctx.clustering();
|
67 | 69 |
|
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; |
69 | 71 | 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(); |
70 | 74 |
|
71 | 75 | 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); |
74 | 78 |
|
75 | 79 | /* Count I/O input and output pads */
|
76 | 80 | L_num_p_inputs = 0;
|
@@ -106,9 +110,71 @@ void printClusteredNetlistStats() {
|
106 | 110 | VTR_LOG("Netlist inputs pins: %d\n", L_num_p_inputs);
|
107 | 111 | VTR_LOG("Netlist output pins: %d\n", L_num_p_outputs);
|
108 | 112 | 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 | + |
109 | 119 | num_blocks_type.clear();
|
110 | 120 | }
|
111 | 121 |
|
| 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 | + |
112 | 178 | static void ShowAnnealSched(const t_annealing_sched& AnnealSched) {
|
113 | 179 | VTR_LOG("AnnealSched.type: ");
|
114 | 180 | switch (AnnealSched.type) {
|
|
0 commit comments