From 4392c6bc3aa1030eed14a32a8ac115722856d30b Mon Sep 17 00:00:00 2001 From: tangxifan Date: Tue, 2 Jul 2019 15:34:59 -0600 Subject: [PATCH] bug fixing in fpga_flow scripts and add more print-out message for VPR --- fpga_flow/scripts/fpga_flow.pl | 21 +- fpga_flow/scripts/pro_blif.pl | 10 +- fpga_flow/scripts/rewrite_path_in_file.pl | 4 +- .../rr_graph/rr_graph_builder_utils.cpp | 179 ++++++++++++++++++ .../device/rr_graph/rr_graph_builder_utils.h | 2 + .../rr_graph/tileable_rr_graph_builder.cpp | 2 +- vpr7_x2p/vpr/SRC/route/rr_graph.c | 4 + 7 files changed, 207 insertions(+), 15 deletions(-) diff --git a/fpga_flow/scripts/fpga_flow.pl b/fpga_flow/scripts/fpga_flow.pl index 92111bb87..79edc0d15 100644 --- a/fpga_flow/scripts/fpga_flow.pl +++ b/fpga_flow/scripts/fpga_flow.pl @@ -20,6 +20,7 @@ my $mydate = gmctime(); my $cwd = getcwd(); # Global Variants +my ($max_route_width_retry) = (1000); # input Option Hash my %opt_h; my $opt_ptr = \%opt_h; @@ -112,7 +113,7 @@ sub generate_path($) mkpath "$mypath"; print "Path($mypath) does not exist...Create it.\n"; } - return 1; + return 0; } # Print the usage @@ -267,7 +268,7 @@ sub read_opt_into_hash($ $ $) } } } - return 1; + return 0; } # Read options @@ -370,7 +371,7 @@ sub opts_read() &print_opts(); - return 1; + return 0; } # List the options @@ -381,7 +382,7 @@ sub print_opts() while(my ($key,$value) = each(%opt_h)) {print "$key : $value\n";} - return 1; + return 0; } @@ -429,7 +430,7 @@ sub check_keywords_conf() {die "Error: Keyword($mctgy[$imcg],$sctgy[$imcg]->[$iscg]) is missing!\n";} } } - return 1; + return 0; } # Read the configuration file @@ -467,7 +468,7 @@ sub read_conf() print "Checking these keywords..."; print "Successfully\n"; close(CONF); - return 1; + return 0; } sub read_benchmarks() @@ -499,7 +500,7 @@ sub read_benchmarks() foreach my $temp(@benchmark_names) {print "$temp\n";} close(FCONF); - return 1; + return 0; } # Input program path is like "~/program_dir/program_name" @@ -1744,6 +1745,9 @@ sub run_vpr_in_flow($ $ $ $ $ $ $ $ $ $ $ $) { if (-e $vpr_route) { print "INFO: try route_chan_width($min_chan_width) success!\n"; last; #Jump out + } elsif ($max_route_width_retry < $min_chan_width) { + # I set a threshold of 1000 as it is the limit of VPR + die "ERROR: Route Fail for $abc_blif_out with a min_chan_width of $min_chan_width!\n"; } else { print "INFO: try route_chan_width($min_chan_width) failed! Retry with +2...\n"; $min_chan_width += 2; @@ -1767,6 +1771,9 @@ sub run_vpr_in_flow($ $ $ $ $ $ $ $ $ $ $ $) { if (-e $vpr_route) { print "INFO: try route_chan_width($fix_chan_width) success!\n"; last; #Jump out + } elsif ($max_route_width_retry < $fix_chan_width) { + # I set a threshold of 1000 as it is the limit of VPR + die "ERROR: Route Fail for $abc_blif_out with a min_chan_width of $fix_chan_width!\n"; } else { print "INFO: try route_chan_width($fix_chan_width) failed! Retry with +2...\n"; $fix_chan_width += 2; diff --git a/fpga_flow/scripts/pro_blif.pl b/fpga_flow/scripts/pro_blif.pl index 25d44816f..d48bc54a5 100755 --- a/fpga_flow/scripts/pro_blif.pl +++ b/fpga_flow/scripts/pro_blif.pl @@ -29,7 +29,7 @@ sub print_usage() print " -add_default_clk\n"; print " -initial_blif \n"; print "\n"; - return 1; + return 0; } sub opts_read() @@ -53,7 +53,7 @@ sub opts_read() } } } - return 1; + return 0; } # Print a line of blif netlist @@ -432,15 +432,15 @@ sub scan_blif() } close($FIN2); close($FOUT); - return 1; + return 0; } sub main() { &opts_read(); &scan_blif(); - return 1; + return 0; } &main(); -exit(1); +exit(0); diff --git a/fpga_flow/scripts/rewrite_path_in_file.pl b/fpga_flow/scripts/rewrite_path_in_file.pl index b65868f60..5c2248913 100644 --- a/fpga_flow/scripts/rewrite_path_in_file.pl +++ b/fpga_flow/scripts/rewrite_path_in_file.pl @@ -90,7 +90,7 @@ sub findPath(){ } else { $path = "$path"."/"."$folders[$count]"; if($folders[$count] eq $folder_top){ - print "$path\n"; + #print "$path\n"; return $path; } } @@ -135,4 +135,4 @@ sub main() } &main(); -exit(1); +exit(0); diff --git a/vpr7_x2p/vpr/SRC/device/rr_graph/rr_graph_builder_utils.cpp b/vpr7_x2p/vpr/SRC/device/rr_graph/rr_graph_builder_utils.cpp index 40d89ee6e..d7d2fcd34 100644 --- a/vpr7_x2p/vpr/SRC/device/rr_graph/rr_graph_builder_utils.cpp +++ b/vpr7_x2p/vpr/SRC/device/rr_graph/rr_graph_builder_utils.cpp @@ -506,3 +506,182 @@ void print_rr_graph_stats(const t_rr_graph& rr_graph) { return; } + +/************************************************************************ + * Print statistics of a rr_graph + * 1. We print number of nodes by types + * 2. Print the number of edges + ************************************************************************/ +void print_rr_graph_stats() { + + /* Print number of nodes */ + vpr_printf(TIO_MESSAGE_INFO, "Statistics on number of RR nodes (by node type): \n"); + + /* Count the number of nodes */ + std::vector num_nodes_per_type; + num_nodes_per_type.resize(NUM_RR_TYPES); + num_nodes_per_type.assign(NUM_RR_TYPES, 0); + + for (int inode = 0; inode < num_rr_nodes; ++inode) { + num_nodes_per_type[rr_node[inode].type]++; + } + + /* Get the largest string size of rr_node_typename */ + size_t max_str_typename = 0; + for (int type = 0; type < NUM_RR_TYPES; ++type) { + max_str_typename = std::max(max_str_typename, strlen(rr_node_typename[type])); + } + + /* Constant strings */ + char* type_str = " Type "; + char* total_str = " Total "; + char* node_str = " No. of nodes "; + char* edge_str = " No. of edges "; + + /* Count the number of characters per line: + * we check the string length of each node type + * Then we plus two reserved strings "type" and "total" + */ + size_t num_char_per_line = 0; + for (int type = 0; type < NUM_RR_TYPES; ++type) { + num_char_per_line += 6 + max_str_typename; + } + num_char_per_line += strlen(type_str); + num_char_per_line += strlen(total_str); + + /* Print splitter */ + for (size_t ichar = 0; ichar < num_char_per_line; ++ichar) { + vpr_printf(TIO_MESSAGE_INFO, "-"); + } + vpr_printf(TIO_MESSAGE_INFO, "\n"); + + /* Print node type */ + vpr_printf(TIO_MESSAGE_INFO, "%s", type_str); + for (int type = 0; type < NUM_RR_TYPES; ++type) { + vpr_printf(TIO_MESSAGE_INFO, " %s ", rr_node_typename[type]); + } + vpr_printf(TIO_MESSAGE_INFO, "%s", total_str); + vpr_printf(TIO_MESSAGE_INFO, "\n"); + + /* Print node numbers */ + int total_num_nodes = 0; + vpr_printf(TIO_MESSAGE_INFO, "%s", node_str); + for (int type = 0; type < NUM_RR_TYPES; ++type) { + vpr_printf(TIO_MESSAGE_INFO, " %10lu ", num_nodes_per_type[type]); + total_num_nodes += num_nodes_per_type[type]; + } + vpr_printf(TIO_MESSAGE_INFO, " %10lu ", num_rr_nodes); + vpr_printf(TIO_MESSAGE_INFO, "\n"); + + /* Check we have the same number as stated in rr_graph */ + assert (total_num_nodes == num_rr_nodes); + + /* Count the number of edges */ + size_t num_edges = 0; + std::vector num_edges_per_type; + num_edges_per_type.resize(NUM_RR_TYPES); + num_edges_per_type.assign(NUM_RR_TYPES, 0); + + for (int inode = 0; inode < num_rr_nodes; ++inode) { + num_edges_per_type[rr_node[inode].type] += rr_node[inode].num_edges; + } + for (int inode = 0; inode < num_rr_nodes; ++inode) { + num_edges += rr_node[inode].num_edges; + } + + /* Print number of edges */ + vpr_printf(TIO_MESSAGE_INFO, "%s", edge_str); + for (int type = 0; type < NUM_RR_TYPES; ++type) { + vpr_printf(TIO_MESSAGE_INFO, " %10lu ", num_edges_per_type[type]); + } + vpr_printf(TIO_MESSAGE_INFO, " %10lu ", num_edges); + vpr_printf(TIO_MESSAGE_INFO, "\n"); + + /* Print splitter */ + for (size_t ichar = 0; ichar < num_char_per_line; ++ichar) { + vpr_printf(TIO_MESSAGE_INFO, "-"); + } + vpr_printf(TIO_MESSAGE_INFO, "\n"); + + /* Print MUX size distribution */ + /* Get the maximum SB mux size */ + short max_sb_mux_size = 0; + for (int inode = 0; inode < num_rr_nodes; ++inode) { + /* MUX multiplexers for SBs */ + if ( (CHANX == rr_node[inode].type) + || (CHANY == rr_node[inode].type) ) { + max_sb_mux_size = std::max(rr_node[inode].fan_in, max_sb_mux_size); + } + } + /* Get the minimum SB mux size */ + short min_sb_mux_size = max_sb_mux_size; + for (int inode = 0; inode < num_rr_nodes; ++inode) { + /* MUX multiplexers for SBs */ + if ( (CHANX == rr_node[inode].type) + || (CHANY == rr_node[inode].type) ) { + min_sb_mux_size = std::min(rr_node[inode].fan_in, min_sb_mux_size); + } + } + + /* Get the minimum SB mux size */ + int num_sb_mux = 0; + short avg_sb_mux_size = 0; + for (int inode = 0; inode < num_rr_nodes; ++inode) { + /* MUX multiplexers for SBs */ + if ( (CHANX == rr_node[inode].type) + || (CHANY == rr_node[inode].type) ) { + avg_sb_mux_size += rr_node[inode].fan_in; + num_sb_mux++; + } + } + avg_sb_mux_size /= num_sb_mux; + /* Print statistics */ + vpr_printf(TIO_MESSAGE_INFO, "------------------------------------------------\n"); + vpr_printf(TIO_MESSAGE_INFO, "Total No. of Switch Block Multiplexer size:%d\n", num_sb_mux); + vpr_printf(TIO_MESSAGE_INFO, "Maximum Switch Block Multiplexer size:%d\n", max_sb_mux_size); + vpr_printf(TIO_MESSAGE_INFO, "Minimum Switch Block Multiplexer size:%d\n", min_sb_mux_size); + vpr_printf(TIO_MESSAGE_INFO, "Average Switch Block Multiplexer size:%d\n", avg_sb_mux_size); + vpr_printf(TIO_MESSAGE_INFO, "------------------------------------------------\n"); + + /* Get the maximum SB mux size */ + short max_cb_mux_size = 0; + for (int inode = 0; inode < num_rr_nodes; ++inode) { + /* MUX multiplexers for SBs */ + if (IPIN == rr_node[inode].type) { + max_cb_mux_size = std::max(rr_node[inode].fan_in, max_cb_mux_size); + } + } + /* Get the minimum SB mux size */ + short min_cb_mux_size = max_cb_mux_size; + for (int inode = 0; inode < num_rr_nodes; ++inode) { + /* MUX multiplexers for SBs */ + if (IPIN == rr_node[inode].type) { + min_cb_mux_size = std::min(rr_node[inode].fan_in, min_cb_mux_size); + } + } + + /* Get the minimum SB mux size */ + int num_cb_mux = 0; + short avg_cb_mux_size = 0; + for (int inode = 0; inode < num_rr_nodes; ++inode) { + /* MUX multiplexers for SBs */ + if (IPIN == rr_node[inode].type) { + avg_cb_mux_size += rr_node[inode].fan_in; + num_cb_mux++; + } + } + avg_cb_mux_size /= num_cb_mux; + vpr_printf(TIO_MESSAGE_INFO, "------------------------------------------------\n"); + vpr_printf(TIO_MESSAGE_INFO, "Total No. of Connection Block Multiplexer size:%d\n", num_cb_mux); + vpr_printf(TIO_MESSAGE_INFO, "Maximum Connection Block Multiplexer size:%d\n", max_cb_mux_size); + vpr_printf(TIO_MESSAGE_INFO, "Minimum Connection Block Multiplexer size:%d\n", min_cb_mux_size); + vpr_printf(TIO_MESSAGE_INFO, "Average Connection Block Multiplexer size:%d\n", avg_cb_mux_size); + vpr_printf(TIO_MESSAGE_INFO, "------------------------------------------------\n"); + + + return; +} + +/************************************************************************ + * End of file : rr_graph_builder_utils.cpp + ***********************************************************************/ diff --git a/vpr7_x2p/vpr/SRC/device/rr_graph/rr_graph_builder_utils.h b/vpr7_x2p/vpr/SRC/device/rr_graph/rr_graph_builder_utils.h index 46021ee6b..c213546d5 100644 --- a/vpr7_x2p/vpr/SRC/device/rr_graph/rr_graph_builder_utils.h +++ b/vpr7_x2p/vpr/SRC/device/rr_graph/rr_graph_builder_utils.h @@ -43,5 +43,7 @@ short get_track_rr_node_end_track_id(const t_rr_node* track_rr_node); void print_rr_graph_stats(const t_rr_graph& rr_graph); +void print_rr_graph_stats(); + #endif diff --git a/vpr7_x2p/vpr/SRC/device/rr_graph/tileable_rr_graph_builder.cpp b/vpr7_x2p/vpr/SRC/device/rr_graph/tileable_rr_graph_builder.cpp index 2e56e693f..25fa5929a 100644 --- a/vpr7_x2p/vpr/SRC/device/rr_graph/tileable_rr_graph_builder.cpp +++ b/vpr7_x2p/vpr/SRC/device/rr_graph/tileable_rr_graph_builder.cpp @@ -1038,7 +1038,7 @@ void build_tileable_unidir_rr_graph(INP const int L_num_types, build_rr_graph_direct_connections(&rr_graph, device_size, grids, delayless_switch, num_directs, directs, clb_to_clb_directs); - print_rr_graph_stats(rr_graph); + //print_rr_graph_stats(rr_graph); /* Clear driver switches of the rr_graph */ clear_rr_graph_driver_switch(&rr_graph); diff --git a/vpr7_x2p/vpr/SRC/route/rr_graph.c b/vpr7_x2p/vpr/SRC/route/rr_graph.c index afe937e9a..d6edcf7fd 100755 --- a/vpr7_x2p/vpr/SRC/route/rr_graph.c +++ b/vpr7_x2p/vpr/SRC/route/rr_graph.c @@ -17,6 +17,7 @@ #include "ReadOptions.h" #include "tileable_rr_graph_builder.h" +#include "rr_graph_builder_utils.h" /* Xifan TANG: SWSEG SUPPORT */ #include "rr_graph_swseg.h" @@ -245,6 +246,9 @@ void build_rr_graph(INP t_graph_type graph_type, INP int L_num_types, } + /* Print statistics of RR graph */ + print_rr_graph_stats(); + return; }