Skip to content

Commit d509ecd

Browse files
add comments and subroutines
1 parent 3fa4fa8 commit d509ecd

10 files changed

+154
-127
lines changed

libs/EXTERNAL/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ add_subdirectory(libsdcparse)
99
add_subdirectory(libblifparse)
1010
add_subdirectory(libtatum)
1111
add_subdirectory(libcatch2)
12-
13-
#SET(BUILD_DEPS ON CACHE BOOL "Build libfoo shared library")
1412
#add_subdirectory(parmys)
1513

1614
#VPR_USE_SERVER is initialized in the root CMakeLists

vpr/src/base/echo_files.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ void setEchoEnabled(bool echo_enabled) {
3232
}
3333

3434
void setAllEchoFileEnabled(bool value) {
35-
int i;
36-
for (i = 0; i < (int)E_ECHO_END_TOKEN; i++) {
35+
for (int i = 0; i < (int)E_ECHO_END_TOKEN; i++) {
3736
echoFileEnabled[i] = value;
3837
}
3938
}
@@ -67,7 +66,7 @@ void alloc_and_load_echo_file_info() {
6766
echoFileNames = new char*[(int)E_ECHO_END_TOKEN];
6867
for (auto i = 0; i < (int)E_ECHO_END_TOKEN; i++) {
6968
echoFileEnabled[i] = false;
70-
echoFileNames[i] = NULL;
69+
echoFileNames[i] = nullptr;
7170
}
7271

7372
setAllEchoFileEnabled(getEchoEnabled());
@@ -136,9 +135,8 @@ void alloc_and_load_echo_file_info() {
136135
}
137136

138137
void free_echo_file_info() {
139-
int i;
140138
if (echoFileEnabled != nullptr) {
141-
for (i = 0; i < (int)E_ECHO_END_TOKEN; i++) {
139+
for (int i = 0; i < (int)E_ECHO_END_TOKEN; i++) {
142140
if (echoFileNames[i] != nullptr) {
143141
delete[] echoFileNames[i];
144142
}
@@ -165,7 +163,7 @@ char* getOutputFileName(enum e_output_files ename) {
165163
return outputFileNames[(int)ename];
166164
}
167165

168-
void alloc_and_load_output_file_names(const std::string default_name) {
166+
void alloc_and_load_output_file_names(const std::string& default_name) {
169167
std::string name;
170168

171169
if (outputFileNames == nullptr) {
@@ -185,9 +183,8 @@ void alloc_and_load_output_file_names(const std::string default_name) {
185183
}
186184

187185
void free_output_file_names() {
188-
int i;
189186
if (outputFileNames != nullptr) {
190-
for (i = 0; i < (int)E_FILE_END_TOKEN; i++) {
187+
for (int i = 0; i < (int)E_FILE_END_TOKEN; i++) {
191188
if (outputFileNames[i] != nullptr) {
192189
delete[] outputFileNames[i];
193190
outputFileNames[i] = nullptr;

vpr/src/base/echo_files.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ void free_echo_file_info();
9292

9393
void setOutputFileName(enum e_output_files ename, const char* name, const char* default_name);
9494
char* getOutputFileName(enum e_output_files ename);
95-
void alloc_and_load_output_file_names(const std::string default_name);
95+
void alloc_and_load_output_file_names(const std::string& default_name);
9696
void free_output_file_names();
9797

9898
#endif

vpr/src/draw/draw_noc.cpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ void draw_noc(ezgl::renderer* g) {
3434
return;
3535
}
3636

37-
// check that the NoC tile has a capacity greater than 0 (can we assume it always will?) and if not then we cant draw anythign as the NoC tile wont be drawn
38-
/* since the vector of routers all have a reference positions on the grid to the corresponding physical tile, just use the first router in the vector and get its position, then use this to get the capcity of a noc router tile
37+
// check that the NoC tile has a capacity greater than 0 (can we assume it always will?) and if not then we cant draw anything as the NoC tile won't be drawn
38+
/* since the vector of routers all have a reference positions on the grid to the corresponding physical tile, just use the first router in the vector and get its position, then use this to get the capacity of a noc router tile
3939
*/
4040
const auto& type = device_ctx.grid.get_physical_type({router_list.begin()->get_router_grid_position_x(),
4141
router_list.begin()->get_router_grid_position_y(),
@@ -239,7 +239,7 @@ void draw_noc_links(ezgl::renderer* g, t_logical_block_type_ptr noc_router_logic
239239
NocLinkType link_type;
240240

241241
// get half the width and height of the noc connection marker
242-
// we will shift the links based on this parameters since the links will be drawn at the boundaries of connection marker instead of the center
242+
// we will shift the links based on these parameters since the links will be drawn at the boundaries of connection marker instead of the center
243243
double noc_connection_marker_quarter_width = (noc_connection_marker_bbox.center().x - noc_connection_marker_bbox.bottom_left().x) / 2;
244244
double noc_connection_marker_quarter_height = (noc_connection_marker_bbox.center().y - noc_connection_marker_bbox.bottom_left().y) / 2;
245245

@@ -293,15 +293,15 @@ void determine_direction_to_shift_noc_links(vtr::vector<NocLinkId, NocLinkShift>
293293

294294
int number_of_links = list_of_noc_link_shift_directions.size();
295295

296-
// store the parallel link of wach link we process
296+
// store the parallel link of each link we process
297297
NocLinkId parallel_link;
298298

299299
// go through all the noc links and assign how the link should be shifted
300300
for (int link = 0; link < number_of_links; link++) {
301301
// convert the link to a link id
302302
NocLinkId link_id(link);
303303

304-
// only assign a shift direction if we havent already
304+
// only assign a shift direction if we haven't already
305305
if (list_of_noc_link_shift_directions[link_id] == NocLinkShift::NO_SHIFT) {
306306
// the current link will always have a TOP_shift
307307
list_of_noc_link_shift_directions[link_id] = NocLinkShift::TOP_SHIFT;
@@ -310,8 +310,8 @@ void determine_direction_to_shift_noc_links(vtr::vector<NocLinkId, NocLinkShift>
310310
parallel_link = noc_ctx.noc_model.get_parallel_link(link_id);
311311

312312
// check first if a legal link id was found
313-
if (parallel_link == INVALID_LINK_ID) {
314-
// if we are here, then a parallel link wasnt found, so that means there is only a single link and there is no need to perform any shifting on the single link
313+
if (parallel_link == NocLinkId::INVALID()) {
314+
// if we are here, then a parallel link wasn't found, so that means there is only a single link and there is no need to perform any shifting on the single link
315315
list_of_noc_link_shift_directions[link_id] = NocLinkShift::NO_SHIFT;
316316

317317
continue;
@@ -334,13 +334,13 @@ NocLinkType determine_noc_link_type(ezgl::point2d link_start_point, ezgl::point2
334334
double x_coord_horizontal_start = link_start_point.x;
335335
double y_coord_horizontal_start = link_start_point.y;
336336

337-
double x_coord_horziontal_end = x_coord_horizontal_start + HORIZONTAL_LINE_LENGTH;
337+
double x_coord_horizontal_end = x_coord_horizontal_start + HORIZONTAL_LINE_LENGTH;
338338
double y_coord_horizontal_end = link_start_point.y;
339339

340340
// stores the link type
341341
NocLinkType result = NocLinkType::INVALID_TYPE;
342342

343-
// we can check quickly if the link is vertical or horizontal without calculating the dot product. If it is vertical or horizontal then we just return. Otherwise we have to calculate it.
343+
// we can check quickly if the link is vertical or horizontal without calculating the dot product. If it is vertical or horizontal then we just return. Otherwise, we have to calculate it.
344344

345345
// check if the link is vertical by determining if there is any horizontal change
346346
if (vtr::isclose(x_coord_end - x_coord_start, 0.0)) {
@@ -349,7 +349,7 @@ NocLinkType determine_noc_link_type(ezgl::point2d link_start_point, ezgl::point2
349349
return result;
350350
}
351351

352-
// check if the link is horizontal by determinig if there is any vertical shift
352+
// check if the link is horizontal by determining if there is any vertical shift
353353
if (vtr::isclose(y_coord_end - y_coord_start, 0.0)) {
354354
result = NocLinkType::HORIZONTAL;
355355

@@ -361,11 +361,11 @@ NocLinkType determine_noc_link_type(ezgl::point2d link_start_point, ezgl::point2
361361
// get the magnitude of the link
362362
double link_magnitude = sqrt(pow(x_coord_end - x_coord_start, 2.0) + pow(y_coord_end - y_coord_start, 2.0));
363363
// get the dot product of the two connecting line
364-
double dot_product_of_link_and_horizontal_line = (x_coord_end - x_coord_start) * (x_coord_horziontal_end - x_coord_horizontal_start) + (y_coord_end - y_coord_start) * (y_coord_horizontal_end - y_coord_horizontal_start);
364+
double dot_product_of_link_and_horizontal_line = (x_coord_end - x_coord_start) * (x_coord_horizontal_end - x_coord_horizontal_start) + (y_coord_end - y_coord_start) * (y_coord_horizontal_end - y_coord_horizontal_start);
365365
// calculate the angle
366366
double angle = acos(dot_product_of_link_and_horizontal_line / (link_magnitude * HORIZONTAL_LINE_LENGTH));
367367

368-
// the angle is in the first or fourth quandrant of the unit circle
368+
// the angle is in the first or fourth quadrant of the unit circle
369369
if ((angle > 0) && (angle < (PI_RADIAN / 2))) {
370370
// if the link is a positive sloped line, then its end point must be higher than its start point (must be higher than the connected horizontal line)
371371
if (y_coord_end > y_coord_horizontal_end) {
@@ -375,7 +375,7 @@ NocLinkType determine_noc_link_type(ezgl::point2d link_start_point, ezgl::point2
375375
result = NocLinkType::NEGATIVE_SLOPE;
376376
}
377377

378-
} else { // the case where the angle is in the 3rd and 4th quandrant of the unit cirle
378+
} else { // the case where the angle is in the 3rd and 4th quadrant of the unit circle
379379

380380
// if the link is a positive sloped line, then its end point must be lower than its start point (must be lower than the connected horizontal line)
381381
if (y_coord_end < y_coord_horizontal_end) {
@@ -415,7 +415,7 @@ void shift_noc_link(noc_link_draw_coords& link_coords, NocLinkShift link_shift_d
415415
link_coords.start.x += noc_connection_marker_quarter_width;
416416
link_coords.end.x += noc_connection_marker_quarter_width;
417417
}
418-
// dont change anything if we arent shifting at all
418+
// don't change anything if we aren't shifting at all
419419
break;
420420
case NocLinkType::HORIZONTAL:
421421
if (link_shift_direction == NocLinkShift::TOP_SHIFT) {
@@ -427,7 +427,7 @@ void shift_noc_link(noc_link_draw_coords& link_coords, NocLinkShift link_shift_d
427427
link_coords.start.y -= noc_connection_marker_quarter_height;
428428
link_coords.end.y -= noc_connection_marker_quarter_height;
429429
}
430-
// dont change anything if we arent shifting at all
430+
// don't change anything if we aren't shifting at all
431431
break;
432432
case NocLinkType::POSITVE_SLOPE:
433433
if (link_shift_direction == NocLinkShift::TOP_SHIFT) {
@@ -445,7 +445,7 @@ void shift_noc_link(noc_link_draw_coords& link_coords, NocLinkShift link_shift_d
445445
link_coords.start.y -= noc_connection_marker_quarter_height;
446446
link_coords.end.y -= noc_connection_marker_quarter_height;
447447
}
448-
// dont change anything if we arent shifting at all
448+
// don't change anything if we aren't shifting at all
449449
break;
450450
case NocLinkType::NEGATIVE_SLOPE:
451451
if (link_shift_direction == NocLinkShift::TOP_SHIFT) {

vpr/src/noc/noc_storage.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11

22
#include "noc_storage.h"
3+
#include "vtr_assert.h"
4+
#include "vpr_error.h"
5+
36

47
#include <algorithm>
58

@@ -20,7 +23,7 @@ const vtr::vector<NocRouterId, NocRouter>& NocStorage::get_noc_routers() const {
2023
return router_storage;
2124
}
2225

23-
int NocStorage::get_number_of_noc_routers(void) const {
26+
int NocStorage::get_number_of_noc_routers() const {
2427
return router_storage.size();
2528
}
2629

@@ -281,12 +284,12 @@ NocLinkId NocStorage::get_parallel_link(NocLinkId current_link) const {
281284
NocRouterId curr_sink_router = link_storage[current_link].get_sink_router();
282285

283286
// get the link list of the sink router
284-
const std::vector<NocLinkId>* sink_router_links = &(router_outgoing_links_list[curr_sink_router]);
287+
const std::vector<NocLinkId>& sink_router_links = router_outgoing_links_list[curr_sink_router];
285288

286-
NocLinkId parallel_link = INVALID_LINK_ID;
289+
NocLinkId parallel_link = NocLinkId::INVALID();
287290

288291
// go through the links of the sink router and the link that has the current source router as the sink router of the link is the parallel link we are looking for
289-
for (auto sink_router_link : *sink_router_links) {
292+
for (auto sink_router_link : sink_router_links) {
290293
if (link_storage[sink_router_link].get_sink_router() == curr_source_router) {
291294
parallel_link = sink_router_link;
292295
break;

vpr/src/noc/noc_storage.h

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,13 @@
3535
*
3636
*/
3737

38-
#include <iostream>
3938
#include <vector>
4039
#include <string>
4140
#include <unordered_map>
4241
#include "noc_data_types.h"
4342
#include "vtr_vector.h"
4443
#include "noc_router.h"
4544
#include "noc_link.h"
46-
#include "vtr_assert.h"
47-
#include "vpr_error.h"
48-
#include "echo_files.h"
49-
// \cond
50-
// represents the id of a link that does not exist in the NoC
51-
constexpr NocLinkId INVALID_LINK_ID(-1);
52-
// \endcond
5345

5446
class NocStorage {
5547
private:
@@ -61,10 +53,14 @@ class NocStorage {
6153
* @brief Stores outgoing links for each router in the NoC. These
6254
* links can be used by the router to communicate to other routers
6355
* in the NoC.
64-
*
6556
*/
6657
vtr::vector<NocRouterId, std::vector<NocLinkId>> router_outgoing_links_list;
6758

59+
/**
60+
* @brief Stores incoming links for each router in the NoC. These
61+
* links can be used by the router to communicate to other routers
62+
* in the NoC.
63+
*/
6864
vtr::vector<NocRouterId, std::vector<NocLinkId>> router_incoming_links_list;
6965

7066
/** Contains all the links in the NoC*/
@@ -78,7 +74,6 @@ class NocStorage {
7874
* are dense since it is used to index the routers. The datastructure
7975
* below is a conversiont able that maps the user router IDs to the
8076
* corresponding internal ones.
81-
*
8277
*/
8378
std::unordered_map<int, NocRouterId> router_id_conversion_table;
8479

@@ -180,14 +175,22 @@ class NocStorage {
180175

181176
/**
182177
* @brief Gets a vector of outgoing links for a given router
183-
* in the NoC. THe link vector cannot be modified.
178+
* in the NoC. The link vector cannot be modified.
184179
*
185180
* @param id A unique identifier that represents a router
186181
* @return A vector of links. The links are represented by a unique
187182
* identifier.
188183
*/
189184
const std::vector<NocLinkId>& get_noc_router_outgoing_links(NocRouterId id) const;
190185

186+
/**
187+
* @brief Gets a vector of incoming links for a given router
188+
* in the NoC.
189+
*
190+
* @param id A unique identifier that represents a router
191+
* @return A vector of links. The links are represented by a unique
192+
* identifier.
193+
*/
191194
const std::vector<NocLinkId>& get_noc_router_incoming_links(NocRouterId id) const;
192195

193196
/**

vpr/src/noc/turn_model_routing.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,12 @@ TurnModelRouting::Direction TurnModelRouting::select_direction_other_than(const
237237
std::vector<std::pair<NocLinkId, NocLinkId>> TurnModelRouting::get_all_illegal_turns(const NocStorage& noc_model) const {
238238
std::vector<std::pair<NocLinkId, NocLinkId>> illegal_turns;
239239

240+
/* Iterate over all sets of three routers that can be traversed in sequence.
241+
* Check if traversing these three routes involves any turns, and if so,
242+
* check if the resulting turn is illegal under the restrictions of a turn model
243+
* routing algorithm. Store all illegal turns and return them.
244+
*/
245+
240246
for (const auto& noc_router : noc_model.get_noc_routers()) {
241247
const int noc_router_user_id = noc_router.get_router_user_id();
242248
const NocRouterId noc_router_id = noc_model.convert_router_id(noc_router_user_id);

vpr/src/place/noc_place_utils.cpp

Lines changed: 53 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "noc_routing.h"
1212
#include "place_constraints.h"
1313
#include "move_transactions.h"
14+
#include "sat_routing.h"
1415

1516
#include <fstream>
1617

@@ -67,13 +68,18 @@ void initial_noc_routing(const vtr::vector<NocTrafficFlowId, std::vector<NocLink
6768
/* We need all the traffic flow ids to be able to access them. The range
6869
* of traffic flow ids go from 0 to the total number of traffic flows within
6970
* the NoC.
70-
* go through all the traffic flows and route them. Then once routed, update the links used in the routed traffic flows with their usages
71+
* Go through all the traffic flows and route them. Then once routed,
72+
* update the links used in the routed traffic flows with their usages
7173
*/
7274
for (const auto& traffic_flow_id : noc_traffic_flows_storage.get_all_traffic_flow_id()) {
7375
const t_noc_traffic_flow& curr_traffic_flow = noc_traffic_flows_storage.get_single_noc_traffic_flow(traffic_flow_id);
7476

75-
// update the traffic flow route based on where the router cluster blocks are placed
76-
const std::vector<NocLinkId>& curr_traffic_flow_route = new_traffic_flow_routes.empty() ? route_traffic_flow(traffic_flow_id, noc_ctx.noc_model, noc_traffic_flows_storage, *noc_ctx.noc_flows_router) : new_traffic_flow_routes[traffic_flow_id];
77+
/* Update the traffic flow route based on where the router cluster blocks are placed.
78+
* If the caller has not provided traffic flow routes, route traffic flow, otherwise use the provided route.
79+
*/
80+
const std::vector<NocLinkId>& curr_traffic_flow_route = new_traffic_flow_routes.empty()
81+
? route_traffic_flow(traffic_flow_id, noc_ctx.noc_model, noc_traffic_flows_storage, *noc_ctx.noc_flows_router)
82+
: new_traffic_flow_routes[traffic_flow_id];
7783

7884
if (!new_traffic_flow_routes.empty()) {
7985
noc_traffic_flows_storage.get_mutable_traffic_flow_route(traffic_flow_id) = curr_traffic_flow_route;
@@ -217,7 +223,10 @@ std::vector<NocLinkId>& route_traffic_flow(NocTrafficFlowId traffic_flow_id,
217223
return curr_traffic_flow_route;
218224
}
219225

220-
void update_traffic_flow_link_usage(const std::vector<NocLinkId>& traffic_flow_route, NocStorage& noc_model, int inc_or_dec, double traffic_flow_bandwidth) {
226+
void update_traffic_flow_link_usage(const std::vector<NocLinkId>& traffic_flow_route,
227+
NocStorage& noc_model,
228+
int inc_or_dec,
229+
double traffic_flow_bandwidth) {
221230
// go through the links within the traffic flow route and update their bandwidth usage
222231
for (auto& link_in_route_id : traffic_flow_route) {
223232
// get the link to update and its current bandwidth
@@ -920,6 +929,46 @@ bool noc_routing_has_cycle(const vtr::vector<NocTrafficFlowId, std::vector<NocLi
920929
return has_cycles;
921930
}
922931

932+
void invoke_sat_router(t_placer_costs& costs, const t_noc_opts& noc_opts, int seed) {
933+
934+
auto traffic_flow_routes = noc_sat_route(true, noc_opts, seed);
935+
936+
if (!traffic_flow_routes.empty()) {
937+
bool has_cycle = noc_routing_has_cycle(traffic_flow_routes);
938+
if (has_cycle) {
939+
VTR_LOG("SAT NoC routing has cycles.\n");
940+
}
941+
942+
reinitialize_noc_routing(costs, traffic_flow_routes);
943+
944+
print_noc_costs("\nNoC Placement Costs after SAT routing", costs, noc_opts);
945+
946+
} else {
947+
VTR_LOG("SAT routing failed.\n");
948+
}
949+
}
950+
951+
void print_noc_costs(std::string_view header, const t_placer_costs& costs, const t_noc_opts& noc_opts) {
952+
VTR_LOG("%s. "
953+
"cost: %g, "
954+
"aggregate_bandwidth_cost: %g, "
955+
"latency_cost: %g, "
956+
"n_met_latency_constraints: %d, "
957+
"latency_overrun_cost: %g, "
958+
"congestion_cost: %g, "
959+
"accum_congested_ratio: %g, "
960+
"n_congested_links: %d \n",
961+
header,
962+
calculate_noc_cost(costs.noc_cost_terms, costs.noc_cost_norm_factors, noc_opts),
963+
costs.noc_cost_terms.aggregate_bandwidth,
964+
costs.noc_cost_terms.latency,
965+
get_number_of_traffic_flows_with_latency_cons_met(),
966+
costs.noc_cost_terms.latency_overrun,
967+
costs.noc_cost_terms.congestion,
968+
get_total_congestion_bandwidth_ratio(),
969+
get_number_of_congested_noc_links());
970+
}
971+
923972
static std::vector<NocLinkId> find_affected_links_by_flow_reroute(std::vector<NocLinkId>& prev_links,
924973
std::vector<NocLinkId>& curr_links) {
925974
// Sort both link containers

0 commit comments

Comments
 (0)