VPR-7.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
place_stats.c
Go to the documentation of this file.
1 #include <stdio.h>
2 #include <math.h>
3 #include "util.h"
4 #include "vpr_types.h"
5 #include "globals.h"
6 
7 #define ABS_DIFF(X, Y) (((X) > (Y))? ((X) - (Y)):((Y) - (X)))
8 #define MAX_X 50
9 #define MAX_LEN MAX_X*2
10 
11 typedef struct relapos_rec_s {
14 
15 #ifdef PRINT_REL_POS_DISTR
16 void
17 print_relative_pos_distr(void)
18 {
19 
20  /* Prints out the probability distribution of the relative locations of *
21  * input pins on a net -- i.e. simulates 2-point net distance probability *
22  * distribution. */
23 #ifdef PRINT_REL_POS_DISTR
24  FILE *out_bin_file;
25  relapos_rec_t rp_rec;
26 #endif /* PRINT_REL_POS_DISTR */
27 
28  int inet, len, rp, src_x, src_y, dst_x, dst_y, del_x, del_y, min_del,
29  sink_pin, sum;
30  int *total_conn;
31  int **relapos;
32  double **relapos_distr;
33 
34  total_conn = (int *)my_malloc((nx + ny + 1) * sizeof(int));
35  relapos = (int **)my_malloc((nx + ny + 1) * sizeof(int *));
36  relapos_distr = (double **)my_malloc((nx + ny + 1) * sizeof(double *));
37  for (len = 0; len <= nx + ny; len++)
38  {
39  relapos[len] = (int *)my_calloc(len / 2 + 1, sizeof(int));
40  relapos_distr[len] =
41  (double *)my_calloc((len / 2 + 1), sizeof(double));
42  }
43 
44  for (inet = 0; inet < num_nets; inet++)
45  {
46  if (clb_net[inet].is_global == FALSE)
47  {
48 
49  src_x = block[clb_net[inet].node_block[0]].x;
50  src_y = block[clb_net[inet].node_block[0]].y;
51 
52  for (sink_pin = 1; sink_pin <= clb_net[inet].num_sinks;
53  sink_pin++)
54  {
55  dst_x = block[clb_net[inet].node_block[sink_pin]].x;
56  dst_y = block[clb_net[inet].node_block[sink_pin]].y;
57 
58  del_x = ABS_DIFF(dst_x, src_x);
59  del_y = ABS_DIFF(dst_y, src_y);
60 
61  len = del_x + del_y;
62 
63  min_del = (del_x < del_y) ? del_x : del_y;
64 
65  if (!(min_del <= (len / 2)))
66  {
67  vpr_printf(TIO_MESSAGE_ERROR, "Error calculating relative location min_del = %d, len = %d\n",
68  min_del, len);
69  exit(1);
70  }
71  else
72  {
73  relapos[len][min_del]++;
74  }
75  }
76  }
77  }
78 
79 #ifdef PRINT_REL_POS_DISTR
80  out_bin_file =
81  fopen("/jayar/b/b5/fang/vpr_test/wirelength/relapos2.bin", "rb+");
82 #endif /* PRINT_REL_POS_DISTR */
83 
84  for (len = 0; len <= nx + ny; len++)
85  {
86  sum = 0;
87  for (rp = 0; rp <= len / 2; rp++)
88  {
89  sum += relapos[len][rp];
90  }
91  if (sum != 0)
92  {
93 #ifdef PRINT_REL_POS_DISTR
94  fseek(out_bin_file, sizeof(relapos_rec_t) * len,
95  SEEK_SET);
96  fread(&rp_rec, sizeof(relapos_rec_t), 1, out_bin_file);
97 #endif /* PRINT_REL_POS_DISTR */
98 
99  for (rp = 0; rp <= len / 2; rp++)
100  {
101 
102  relapos_distr[len][rp] =
103  (double)relapos[len][rp] / (double)sum;
104 
105  /* updating the binary record at "len" */
106 #ifdef PRINT_REL_POS_DISTR
107  vpr_printf(TIO_MESSAGE_ERROR, "old %d increased by %d\n", rp_rec.num_rp[rp], relapos[len][rp]);
108  rp_rec.num_rp[rp] += relapos[len][rp];
109  vpr_printf(TIO_MESSAGE_ERROR, "becomes %d\n", rp_rec.num_rp[rp]);
110 #endif /* PRINT_REL_POS_DISTR */
111  }
112 #ifdef PRINT_REL_POS_DISTR
113  /* write back the updated record at "len" */
114  fseek(out_bin_file, sizeof(relapos_rec_t) * len,
115  SEEK_SET);
116  fwrite(&rp_rec, sizeof(relapos_rec_t), 1, out_bin_file);
117 #endif /* PRINT_REL_POS_DISTR */
118 
119  }
120  total_conn[len] = sum;
121  }
122 
123  fprintf(stdout, "Source to sink relative positions:\n");
124  for (len = 1; len <= nx + ny; len++)
125  {
126  if (total_conn[len] != 0)
127  {
128  fprintf(stdout, "Of 2-pin distance %d exists %d\n\n", len,
129  total_conn[len]);
130  for (rp = 0; rp <= len / 2; rp++)
131  {
132  fprintf(stdout, "\trp%d\t%d\t\t(%.5f)\n", rp,
133  relapos[len][rp], relapos_distr[len][rp]);
134  }
135  fprintf(stdout, "----------------\n");
136  }
137  }
138 
139  free((void *)total_conn);
140  for (len = 0; len <= nx + ny; len++)
141  {
142  free((void *)relapos[len]);
143  free((void *)relapos_distr[len]);
144  }
145  free((void *)relapos);
146  free((void *)relapos_distr);
147 
148 #ifdef PRINT_REL_POS_DISTR
149  fclose(out_bin_file);
150 #endif /* PRINT_REL_POS_DISTR */
151 }
152 #endif
int x
Definition: vpr_types.h:563
int num_rp[MAX_LEN]
Definition: place_stats.c:12
void * my_calloc(size_t nelem, size_t size)
Definition: util.c:132
int num_nets
Definition: globals.c:27
int * node_block
Definition: vpr_types.h:507
Definition: util.h:12
#define MAX_LEN
Definition: place_stats.c:9
int y
Definition: vpr_types.h:564
static void * my_malloc(int ibytes)
Definition: graphics.c:499
boolean * is_global
struct s_block * block
Definition: globals.c:31
struct s_net * clb_net
Definition: globals.c:28
int nx
Definition: globals.c:46
#define ABS_DIFF(X, Y)
Definition: place_stats.c:7
int ny
Definition: globals.c:47
messagelogger vpr_printf
Definition: util.c:17
int num_sinks
Definition: vpr_types.h:506
struct relapos_rec_s relapos_rec_t