Skip to content

Commit a142d1b

Browse files
committed
redefined static functions that were previously tested in test_vpr so its build wouldn't fail
1 parent e6332d9 commit a142d1b

File tree

1 file changed

+189
-2
lines changed

1 file changed

+189
-2
lines changed

vpr/test/test_setup_noc.cpp

Lines changed: 189 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,187 @@
88
// for comparing floats
99
#include "vtr_math.h"
1010

11+
/*Re-defining static functions in setup_noc.cpp that are tested here*/
12+
13+
14+
static void identify_and_store_noc_router_tile_positions(const DeviceGrid& device_grid, std::vector<t_noc_router_tile_position>& list_of_noc_router_tiles, std::string noc_router_tile_name) {
15+
int grid_width = device_grid.width();
16+
int grid_height = device_grid.height();
17+
18+
int curr_tile_width;
19+
int curr_tile_height;
20+
int curr_tile_width_offset;
21+
int curr_tile_height_offset;
22+
std::string curr_tile_name;
23+
24+
double curr_tile_centroid_x;
25+
double curr_tile_centroid_y;
26+
27+
// go through the device
28+
for (int i = 0; i < grid_width; i++) {
29+
for (int j = 0; j < grid_height; j++) {
30+
// get some information from the current tile
31+
curr_tile_name.assign(device_grid[i][j].type->name);
32+
curr_tile_width_offset = device_grid[i][j].width_offset;
33+
curr_tile_height_offset = device_grid[i][j].height_offset;
34+
35+
curr_tile_height = device_grid[i][j].type->height;
36+
curr_tile_width = device_grid[i][j].type->width;
37+
38+
/*
39+
* Only store the tile position if it is a noc router.
40+
* Additionally, since a router tile can span multiple grid locations, we only add the tile if the height and width offset are zero (this prevents the router from being added multiple times for each grid location it spans).
41+
*/
42+
if (!(noc_router_tile_name.compare(curr_tile_name)) && !curr_tile_width_offset && !curr_tile_height_offset) {
43+
// calculating the centroid position of the current tile
44+
curr_tile_centroid_x = (curr_tile_width - 1) / (double)2 + i;
45+
curr_tile_centroid_y = (curr_tile_height - 1) / (double)2 + j;
46+
47+
list_of_noc_router_tiles.push_back({i, j, curr_tile_centroid_x, curr_tile_centroid_y});
48+
}
49+
}
50+
}
51+
52+
return;
53+
}
54+
55+
56+
57+
static void create_noc_routers(const t_noc_inf& noc_info, NocStorage* noc_model, std::vector<t_noc_router_tile_position>& list_of_noc_router_tiles) {
58+
// keep track of the shortest distance between a logical router and the curren physical router tile
59+
// also keep track of the corresponding physical router tile index (within the list)
60+
double shortest_distance;
61+
double curr_calculated_distance;
62+
int closest_physical_router;
63+
64+
// information regarding physical router position
65+
double curr_physical_router_pos_x;
66+
double curr_physical_router_pos_y;
67+
68+
// information regarding logical router position
69+
double curr_logical_router_position_x;
70+
double curr_logical_router_position_y;
71+
72+
// keep track of the index of each physical router (this helps uniqely identify them)
73+
int curr_physical_router_index = 0;
74+
75+
// keep track of the ids of the routers that ceate the case where multiple routers
76+
// have the same distance to a physical router tile
77+
int error_case_physical_router_index_1;
78+
int error_case_physical_router_index_2;
79+
80+
// keep track of all the logical router and physical router assignments (their pairings)
81+
std::vector<int> router_assignments;
82+
router_assignments.resize(list_of_noc_router_tiles.size(), PHYSICAL_ROUTER_NOT_ASSIGNED);
83+
84+
// Below we create all the routers within the NoC //
85+
86+
// go through each logical router tile and assign it to a physical router on the FPGA
87+
for (auto logical_router = noc_info.router_list.begin(); logical_router != noc_info.router_list.end(); logical_router++) {
88+
// assign the shortest distance to a large value (this is done so that the first distance calculated and we can replace this)
89+
shortest_distance = LLONG_MAX;
90+
91+
// get position of the current logical router
92+
curr_logical_router_position_x = logical_router->device_x_position;
93+
curr_logical_router_position_y = logical_router->device_y_position;
94+
95+
closest_physical_router = 0;
96+
97+
// the starting index of the physical router list
98+
curr_physical_router_index = 0;
99+
100+
// initialze the router ids that track the error case where two physical router tiles have the same distance to a logical router
101+
// we initialize it to a in-valid index, so that it reflects the situation where we never hit this case
102+
error_case_physical_router_index_1 = INVALID_PHYSICAL_ROUTER_INDEX;
103+
error_case_physical_router_index_2 = INVALID_PHYSICAL_ROUTER_INDEX;
104+
105+
// determine the physical router tile that is closest to the current logical router
106+
for (auto physical_router = list_of_noc_router_tiles.begin(); physical_router != list_of_noc_router_tiles.end(); physical_router++) {
107+
// get the position of the current physical router tile on the FPGA device
108+
curr_physical_router_pos_x = physical_router->tile_centroid_x;
109+
curr_physical_router_pos_y = physical_router->tile_centroid_y;
110+
111+
// use euclidean distance to calculate the length between the current logical and physical routers
112+
curr_calculated_distance = sqrt(pow(abs(curr_physical_router_pos_x - curr_logical_router_position_x), 2.0) + pow(abs(curr_physical_router_pos_y - curr_logical_router_position_y), 2.0));
113+
114+
// if the current distance is the same as the previous shortest distance
115+
if (vtr::isclose(curr_calculated_distance, shortest_distance)) {
116+
// store the ids of the two physical routers
117+
error_case_physical_router_index_1 = closest_physical_router;
118+
error_case_physical_router_index_2 = curr_physical_router_index;
119+
120+
} else if (curr_calculated_distance < shortest_distance) // case where the current logical router is closest to the physical router tile
121+
{
122+
// update the shortest distance and then the closest router
123+
shortest_distance = curr_calculated_distance;
124+
closest_physical_router = curr_physical_router_index;
125+
}
126+
127+
// update the index for the next physical router
128+
curr_physical_router_index++;
129+
}
130+
131+
// check the case where two physical router tiles have the same distance to the given logical router
132+
if (error_case_physical_router_index_1 == closest_physical_router) {
133+
VPR_FATAL_ERROR(VPR_ERROR_OTHER,
134+
"Router with ID:'%d' has the same distance to physical router tiles located at position (%d,%d) and (%d,%d). Therefore, no router assignment could be made.",
135+
logical_router->id, list_of_noc_router_tiles[error_case_physical_router_index_1].grid_width_position, list_of_noc_router_tiles[error_case_physical_router_index_1].grid_height_position,
136+
list_of_noc_router_tiles[error_case_physical_router_index_2].grid_width_position, list_of_noc_router_tiles[error_case_physical_router_index_2].grid_height_position);
137+
}
138+
139+
// check if the current physical router was already assigned previously, if so then throw an error
140+
if (router_assignments[closest_physical_router] != PHYSICAL_ROUTER_NOT_ASSIGNED) {
141+
VPR_FATAL_ERROR(VPR_ERROR_OTHER, "Routers with IDs:'%d' and '%d' are both closest to physical router tile located at (%d,%d) and the physical router could not be assigned multiple times.",
142+
logical_router->id, router_assignments[closest_physical_router], list_of_noc_router_tiles[closest_physical_router].grid_width_position,
143+
list_of_noc_router_tiles[closest_physical_router].grid_height_position);
144+
}
145+
146+
// at this point, the closest logical router to the current physical router was found
147+
// so add the router to the NoC
148+
noc_model->add_router(logical_router->id, list_of_noc_router_tiles[closest_physical_router].grid_width_position,
149+
list_of_noc_router_tiles[closest_physical_router].grid_height_position);
150+
151+
// add the new assignment to the tracker
152+
router_assignments[closest_physical_router] = logical_router->id;
153+
}
154+
155+
return;
156+
}
157+
158+
static void create_noc_links(const t_noc_inf* noc_info, NocStorage* noc_model) {
159+
// the ids used to represent the routers in the NoC are not the same as the ones provided by the user in the arch desc file.
160+
// while going through the router connections, the user provided router ids are converted and then stored below before being used
161+
// in the links.
162+
NocRouterId source_router;
163+
NocRouterId sink_router;
164+
165+
// store the id of each new link we create
166+
NocLinkId created_link_id;
167+
168+
// start of by creating enough space for the list of outgoing links for each router in the NoC
169+
noc_model->make_room_for_noc_router_link_list();
170+
171+
// go through each router and add its outgoing links to the NoC
172+
for (auto router = noc_info->router_list.begin(); router != noc_info->router_list.end(); router++) {
173+
// get the converted id of the current source router
174+
source_router = noc_model->convert_router_id(router->id);
175+
176+
// go through all the routers connected to the current one and add links to the noc
177+
for (auto conn_router_id = router->connection_list.begin(); conn_router_id != router->connection_list.end(); conn_router_id++) {
178+
// get the converted id of the currently connected sink router
179+
sink_router = noc_model->convert_router_id(*conn_router_id);
180+
181+
// add the link to the Noc
182+
noc_model->add_link(source_router, sink_router);
183+
;
184+
}
185+
}
186+
187+
return;
188+
}
189+
190+
/*End of static function re-definition in setup_noc.cpp*/
191+
11192
namespace {
12193

13194
TEST_CASE("test_identify_and_store_noc_router_tile_positions", "[vpr_setup_noc]") {
@@ -796,6 +977,9 @@ TEST_CASE("test_setup_noc", "[vpr_setup_noc]") {
796977
char empty_tile_name[6] = "empty";
797978
char router_tile_name[7] = "router";
798979

980+
// assign the name used when describing a router tile in the FPGA architecture description file
981+
arch.noc->noc_router_tile_name.assign(router_tile_name);
982+
799983
// device grid parameters
800984
int test_grid_width = 10;
801985
int test_grid_height = 10;
@@ -900,7 +1084,7 @@ TEST_CASE("test_setup_noc", "[vpr_setup_noc]") {
9001084

9011085
device_ctx.grid = DeviceGrid(device_grid_name, test_grid);
9021086

903-
REQUIRE_THROWS_WITH(setup_noc(arch, router_tile_name), "The Provided NoC topology information in the architecture file has more number of routers than what is available in the FPGA device.");
1087+
REQUIRE_THROWS_WITH(setup_noc(arch), "The Provided NoC topology information in the architecture file has more number of routers than what is available in the FPGA device.");
9041088
}
9051089
SECTION("Test setup_noc when there are no physical NoC routers on the FPGA.") {
9061090
// test device grid name
@@ -910,6 +1094,9 @@ TEST_CASE("test_setup_noc", "[vpr_setup_noc]") {
9101094
char empty_tile_name[6] = "empty";
9111095
char router_tile_name[7] = "router";
9121096

1097+
// assign the name used when describing a router tile in the FPGA architecture description file
1098+
arch.noc->noc_router_tile_name.assign(router_tile_name);
1099+
9131100
// device grid parameters
9141101
int test_grid_width = 10;
9151102
int test_grid_height = 10;
@@ -948,7 +1135,7 @@ TEST_CASE("test_setup_noc", "[vpr_setup_noc]") {
9481135

9491136
device_ctx.grid = DeviceGrid(device_grid_name, test_grid);
9501137

951-
REQUIRE_THROWS_WITH(setup_noc(arch, router_tile_name), "No physical NoC routers were found on the FPGA device. Either the provided name for the physical router tile was incorrect or the FPGA device has no routers.");
1138+
REQUIRE_THROWS_WITH(setup_noc(arch), "No physical NoC routers were found on the FPGA device. Either the provided name for the physical router tile was incorrect or the FPGA device has no routers.");
9521139
}
9531140
}
9541141

0 commit comments

Comments
 (0)