VPR-7.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
SetupGrid.h File Reference
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define SETUPGRID_H
 

Functions

void alloc_and_load_grid (INOUTP int *num_instances_type)
 
void freeGrid (void)
 

Macro Definition Documentation

#define SETUPGRID_H

Definition at line 2 of file SetupGrid.h.

Function Documentation

void alloc_and_load_grid ( INOUTP int *  num_instances_type)

Definition at line 22 of file SetupGrid.c.

22  {
23 
24  int i, j;
26 
27 #ifdef SHOW_ARCH
28  FILE *dump;
29 #endif
30 
31  /* To remove this limitation, change ylow etc. in t_rr_node to *
32  * * be ints instead. Used shorts to save memory. */
33  if ((nx > 32766) || (ny > 32766)) {
34  vpr_printf(TIO_MESSAGE_ERROR, "nx and ny must be less than 32767, since the router uses shorts (16-bit) to store coordinates.\n");
35  vpr_printf(TIO_MESSAGE_ERROR, "nx: %d, ny: %d\n", nx, ny);
36  exit(1);
37  }
38 
39  assert(nx >= 1 && ny >= 1);
40 
41  grid = (struct s_grid_tile **) alloc_matrix(0, (nx + 1), 0, (ny + 1),
42  sizeof(struct s_grid_tile));
43 
44  /* Clear the full grid to have no type (NULL), no capacity, etc */
45  for (i = 0; i <= (nx + 1); ++i) {
46  for (j = 0; j <= (ny + 1); ++j) {
47  memset(&grid[i][j], 0, (sizeof(struct s_grid_tile)));
48  }
49  }
50 
51  for (i = 0; i < num_types; i++) {
52  num_instances_type[i] = 0;
53  }
54 
55  /* Nothing goes in the corners. */
56  grid[0][0].type = grid[nx + 1][0].type = EMPTY_TYPE;
57  grid[0][ny + 1].type = grid[nx + 1][ny + 1].type = EMPTY_TYPE;
58  num_instances_type[EMPTY_TYPE->index] = 4;
59 
60  for (i = 1; i <= nx; i++) {
61  grid[i][0].blocks = (int *) my_malloc(sizeof(int) * IO_TYPE->capacity);
62  grid[i][0].type = IO_TYPE;
63 
64  grid[i][ny + 1].blocks = (int *) my_malloc(
65  sizeof(int) * IO_TYPE->capacity);
66  grid[i][ny + 1].type = IO_TYPE;
67 
68  for (j = 0; j < IO_TYPE->capacity; j++) {
69  grid[i][0].blocks[j] = EMPTY;
70  grid[i][ny + 1].blocks[j] = EMPTY;
71  }
72  }
73 
74  for (i = 1; i <= ny; i++) {
75  grid[0][i].blocks = (int *) my_malloc(sizeof(int) * IO_TYPE->capacity);
76  grid[0][i].type = IO_TYPE;
77 
78  grid[nx + 1][i].blocks = (int *) my_malloc(
79  sizeof(int) * IO_TYPE->capacity);
80  grid[nx + 1][i].type = IO_TYPE;
81  for (j = 0; j < IO_TYPE->capacity; j++) {
82  grid[0][i].blocks[j] = EMPTY;
83  grid[nx + 1][i].blocks[j] = EMPTY;
84  }
85  }
86 
87  num_instances_type[IO_TYPE->index] = 2 * IO_TYPE->capacity * (nx + ny);
88 
89  for (i = 1; i <= nx; i++) { /* Interior (LUT) cells */
90  type = find_type_col(i);
91  for (j = 1; j <= ny; j++) {
92  grid[i][j].type = type;
93  grid[i][j].offset = (j - 1) % type->height;
94  if (j + grid[i][j].type->height - 1 - grid[i][j].offset > ny) {
95  grid[i][j].type = EMPTY_TYPE;
96  grid[i][j].offset = 0;
97  }
98 
99  if (type->capacity > 1) {
100  vpr_printf(TIO_MESSAGE_ERROR, "in FillArch(), expected core blocks to have capacity <= 1 but (%d, %d) has type '%s' and capacity %d.\n",
101  i, j, grid[i][j].type->name, grid[i][j].type->capacity);
102  exit(1);
103  }
104 
105  grid[i][j].blocks = (int *) my_malloc(sizeof(int));
106  grid[i][j].blocks[0] = EMPTY;
107  if (grid[i][j].offset == 0) {
108  num_instances_type[grid[i][j].type->index]++;
109  }
110  }
111  }
112 
113  CheckGrid();
114 
115 #ifdef SHOW_ARCH
116  /* DEBUG code */
117  dump = my_fopen("grid_type_dump.txt", "w", 0);
118  for (j = (ny + 1); j >= 0; --j)
119  {
120  for (i = 0; i <= (nx + 1); ++i)
121  {
122  fprintf(dump, "%c", grid[i][j].type->name[1]);
123  }
124  fprintf(dump, "\n");
125  }
126  fclose(dump);
127 #endif
128 }
t_type_ptr type
Definition: vpr_types.h:522
FILE * my_fopen(const char *fname, const char *flag, int prompt)
Definition: util.c:54
void ** alloc_matrix(int nrmin, int nrmax, int ncmin, int ncmax, size_t elsize)
Definition: util.c:551
t_type_ptr EMPTY_TYPE
Definition: globals.c:41
#define EMPTY
Definition: vpr_types.h:90
static void * my_malloc(int ibytes)
Definition: graphics.c:499
int nx
Definition: globals.c:46
static void CheckGrid(void)
Definition: SetupGrid.c:145
struct s_grid_tile ** grid
Definition: globals.c:59
int * blocks
Definition: vpr_types.h:525
int num_types
Definition: globals.c:37
t_type_ptr IO_TYPE
Definition: globals.c:40
static t_type_ptr find_type_col(INP int x)
Definition: SetupGrid.c:176
int ny
Definition: globals.c:47
messagelogger vpr_printf
Definition: util.c:17

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void freeGrid ( void  )

Definition at line 130 of file SetupGrid.c.

130  {
131  int i, j;
132  if (grid == NULL) {
133  return;
134  }
135 
136  for (i = 0; i <= (nx + 1); ++i) {
137  for (j = 0; j <= (ny + 1); ++j) {
138  free(grid[i][j].blocks);
139  }
140  }
141  free_matrix(grid, 0, nx + 1, 0, sizeof(struct s_grid_tile));
142  grid = NULL;
143 }
void free_matrix(void *vptr, int nrmin, int nrmax, int ncmin, size_t elsize)
Definition: util.c:573
int nx
Definition: globals.c:46
struct s_grid_tile ** grid
Definition: globals.c:59
int * blocks
Definition: vpr_types.h:525
int ny
Definition: globals.c:47

+ Here is the call graph for this function:

+ Here is the caller graph for this function: