VPR-6.0
|
00001 #include <stdio.h> 00002 #include <math.h> 00003 #include "util.h" 00004 #include "vpr_types.h" 00005 #include "globals.h" 00006 00007 #define ABS_DIFF(X, Y) (((X) > (Y))? ((X) - (Y)):((Y) - (X))) 00008 #define MAX_X 50 00009 #define MAX_LEN MAX_X*2 00010 00011 typedef struct relapos_rec_s 00012 { 00013 int num_rp[MAX_LEN]; 00014 } 00015 relapos_rec_t; 00016 00017 /** Prints out the probability distribution of the relative locations of 00018 * input pins on a net -- i.e. simulates 2-point net distance probability 00019 * distribution. 00020 */ 00021 void 00022 print_relative_pos_distr(void) 00023 { 00024 00025 #ifdef PRINT_REL_POS_DISTR 00026 FILE *out_bin_file; 00027 relapos_rec_t rp_rec; 00028 #endif /* PRINT_REL_POS_DISTR */ 00029 00030 int inet, len, rp, src_x, src_y, dst_x, dst_y, del_x, del_y, min_del, 00031 sink_pin, sum; 00032 int *total_conn; 00033 int **relapos; 00034 double **relapos_distr; 00035 00036 total_conn = (int *)my_malloc((nx + ny + 1) * sizeof(int)); 00037 relapos = (int **)my_malloc((nx + ny + 1) * sizeof(int *)); 00038 relapos_distr = (double **)my_malloc((nx + ny + 1) * sizeof(double *)); 00039 for(len = 0; len <= nx + ny; len++) 00040 { 00041 relapos[len] = (int *)my_calloc(len / 2 + 1, sizeof(int)); 00042 relapos_distr[len] = 00043 (double *)my_calloc((len / 2 + 1), sizeof(double)); 00044 } 00045 00046 00047 for(inet = 0; inet < num_nets; inet++) 00048 { 00049 if(clb_net[inet].is_global == FALSE) 00050 { 00051 00052 src_x = block[clb_net[inet].node_block[0]].x; 00053 src_y = block[clb_net[inet].node_block[0]].y; 00054 00055 for(sink_pin = 1; sink_pin <= clb_net[inet].num_sinks; 00056 sink_pin++) 00057 { 00058 dst_x = block[clb_net[inet].node_block[sink_pin]].x; 00059 dst_y = block[clb_net[inet].node_block[sink_pin]].y; 00060 00061 del_x = ABS_DIFF(dst_x, src_x); 00062 del_y = ABS_DIFF(dst_y, src_y); 00063 00064 len = del_x + del_y; 00065 00066 min_del = (del_x < del_y) ? del_x : del_y; 00067 00068 if(!(min_del <= (len / 2))) 00069 { 00070 printf 00071 ("Error in calculating relative location min_del = %d, len = %d\n", 00072 min_del, len); 00073 exit(1); 00074 } 00075 else 00076 { 00077 relapos[len][min_del]++; 00078 } 00079 } 00080 } 00081 } 00082 00083 #ifdef PRINT_REL_POS_DISTR 00084 out_bin_file = 00085 fopen("/jayar/b/b5/fang/vpr_test/wirelength/relapos2.bin", "rb+"); 00086 #endif /* PRINT_REL_POS_DISTR */ 00087 00088 for(len = 0; len <= nx + ny; len++) 00089 { 00090 sum = 0; 00091 for(rp = 0; rp <= len / 2; rp++) 00092 { 00093 sum += relapos[len][rp]; 00094 } 00095 if(sum != 0) 00096 { 00097 #ifdef PRINT_REL_POS_DISTR 00098 fseek(out_bin_file, sizeof(relapos_rec_t) * len, 00099 SEEK_SET); 00100 fread(&rp_rec, sizeof(relapos_rec_t), 1, out_bin_file); 00101 #endif /* PRINT_REL_POS_DISTR */ 00102 00103 for(rp = 0; rp <= len / 2; rp++) 00104 { 00105 00106 relapos_distr[len][rp] = 00107 (double)relapos[len][rp] / (double)sum; 00108 00109 /* updating the binary record at "len" */ 00110 #ifdef PRINT_REL_POS_DISTR 00111 fprintf(stderr, "old %d increase by %d\n", 00112 rp_rec.num_rp[rp], relapos[len][rp]); 00113 rp_rec.num_rp[rp] += relapos[len][rp]; 00114 fprintf(stderr, "becomes %d\n", 00115 rp_rec.num_rp[rp]); 00116 #endif /* PRINT_REL_POS_DISTR */ 00117 } 00118 #ifdef PRINT_REL_POS_DISTR 00119 /* write back the updated record at "len" */ 00120 fseek(out_bin_file, sizeof(relapos_rec_t) * len, 00121 SEEK_SET); 00122 fwrite(&rp_rec, sizeof(relapos_rec_t), 1, out_bin_file); 00123 #endif /* PRINT_REL_POS_DISTR */ 00124 00125 } 00126 total_conn[len] = sum; 00127 } 00128 00129 fprintf(stdout, "Source to sink relative positions:\n"); 00130 for(len = 1; len <= nx + ny; len++) 00131 { 00132 if(total_conn[len] != 0) 00133 { 00134 fprintf(stdout, "Of 2-pin distance %d exists %d\n\n", len, 00135 total_conn[len]); 00136 for(rp = 0; rp <= len / 2; rp++) 00137 { 00138 fprintf(stdout, "\trp%d\t%d\t\t(%.5f)\n", rp, 00139 relapos[len][rp], relapos_distr[len][rp]); 00140 } 00141 fprintf(stdout, "----------------\n"); 00142 } 00143 } 00144 00145 free((void *)total_conn); 00146 for(len = 0; len <= nx + ny; len++) 00147 { 00148 free((void *)relapos[len]); 00149 free((void *)relapos_distr[len]); 00150 } 00151 free((void *)relapos); 00152 free((void *)relapos_distr); 00153 00154 #ifdef PRINT_REL_POS_DISTR 00155 fclose(out_bin_file); 00156 #endif /* PRINT_REL_POS_DISTR */ 00157 }