Skip to content

Commit 924fd89

Browse files
authored
Merge pull request #2315 from verilog-to-routing/noc_refactor
NoC Placement Code Improvement
2 parents 2ca711e + cbc5b0b commit 924fd89

18 files changed

+321
-366
lines changed

vpr/src/base/vpr_context.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ struct NocContext : public Context {
519519
/**
520520
* @brief Stores all the communication happening between routers in the NoC
521521
*
522-
* Contains all of the traffic flows that ddescribe which pairs of logical routers are communicating and also some metrics and constraints on the data transfer between the two routers.
522+
* Contains all of the traffic flows that describe which pairs of logical routers are communicating and also some metrics and constraints on the data transfer between the two routers.
523523
*
524524
*
525525
* This is created from a user supplied .flows file.

vpr/src/noc/noc_link.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ class NocLink {
8484

8585
/**
8686
* @brief Can be used to set the sink router of the link to a different router.
87-
* @param source_router The identifier representing the router that should be the sibk of
87+
* @param sink_router The identifier representing the router that should be the sink of
8888
* this link
8989
*/
9090
void set_sink_router(NocRouterId sink);

vpr/src/noc/noc_router.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
class NocRouter {
4040
private:
4141
/** this represents a unique id provided by the user when describing the NoC topology in the arch file. The intended
42-
* use is to report errors with rouer ids the user understands*/
42+
* use is to report errors with router ids the user understands*/
4343
int router_user_id;
4444

4545
// device position of the physical router tile

vpr/src/noc/noc_routing.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class NocRouting {
4747
* @param sink_router_id The destination router of a traffic flow.
4848
* Identifies the ending point of the route within the NoC.This represents a
4949
* physical router on the FPGA.
50-
* @param flow_route Stores the path returned by this fuction
50+
* @param flow_route Stores the path returned by this function
5151
* as a series of NoC links found by
5252
* a NoC routing algorithm between two routers in a traffic flow.
5353
* The function will clear any

vpr/src/noc/noc_storage.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,23 +70,23 @@ NocRouterId NocStorage::get_router_at_grid_location(const t_pl_loc& hard_router_
7070

7171
// setters for the NoC
7272

73-
void NocStorage::add_router(int id, int grid_position_x, int grid_posistion_y) {
73+
void NocStorage::add_router(int id, int grid_position_x, int grid_position_y) {
7474
VTR_ASSERT_MSG(!built_noc, "NoC already built, cannot modify further.");
7575

76-
router_storage.emplace_back(id, grid_position_x, grid_posistion_y);
76+
router_storage.emplace_back(id, grid_position_x, grid_position_y);
7777

7878
/* Get the corresponding NocRouterId for the newly added router and
7979
* add it to the conversion table.
8080
* Since the router is added at the end of the list, the id is equivalent to the last element index.
81-
* We build the conversion table here as it gurantees only unique routers
81+
* We build the conversion table here as it guarantees only unique routers
8282
* in the NoC are added.
8383
*/
8484
NocRouterId converted_id((int)(router_storage.size() - 1));
8585
router_id_conversion_table.emplace(id, converted_id);
8686

8787
/* need to associate the current router with its grid position */
8888
// get the key to identify the current router
89-
int router_key = generate_router_key_from_grid_location(grid_position_x, grid_posistion_y);
89+
int router_key = generate_router_key_from_grid_location(grid_position_x, grid_position_y);
9090
grid_location_to_router_id.insert(std::pair<int, NocRouterId>(router_key, converted_id));
9191

9292
return;
@@ -127,20 +127,20 @@ bool NocStorage::remove_link(NocRouterId src_router_id, NocRouterId sink_router_
127127
// This status variable is used to report externally whether the link was removed or not
128128
bool link_removed_status = false;
129129

130-
// check if the src router for the link to remove exists (within the id ranges). Otherwise there is no point looking for the link
130+
// check if the src router for the link to remove exists (within the id ranges). Otherwise, there is no point looking for the link
131131
if ((size_t)src_router_id < router_storage.size()) {
132132
// get all the outgoing links of the provided sourcer router
133133
std::vector<NocLinkId>* source_router_outgoing_links = &router_link_list[src_router_id];
134134

135-
// keeps track of the position of each outgoing link for the provided src router. When the id of the link to remove is found, this index can be used to remove it from the ougoing link vector.
135+
// keeps track of the position of each outgoing link for the provided src router. When the id of the link to remove is found, this index can be used to remove it from the outgoing link vector.
136136
int outgoing_link_index = 0;
137137

138138
// go through each outgoing link of the source router and see if there is a link that also has the corresponding sink router.
139139
// Save this link index and remove it
140140
for (auto outgoing_link_id = source_router_outgoing_links->begin(); outgoing_link_id != source_router_outgoing_links->end(); outgoing_link_id++) {
141141
// check to see if the current link id matches the id of the link to remove
142142
if (link_storage[*outgoing_link_id].get_sink_router() == sink_router_id) {
143-
// found the link we need to remove so we delete it here
143+
// found the link we need to remove, so we delete it here
144144
//change the link to be invalid
145145
link_storage[*outgoing_link_id].set_source_router(NocRouterId::INVALID());
146146
link_storage[*outgoing_link_id].set_sink_router(NocRouterId::INVALID());

vpr/src/noc/noc_storage.h

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
* A link is a component of the NoC ans is defined by the
2828
* NocLink class. Links are connections between two routers.
2929
* Links are used by routers to communicate with other routers
30-
* in the NoC. Thye can be thought of as edges in a graph. Links
30+
* in the NoC. They can be thought of as edges in a graph. Links
3131
* have a source router where they exit from and sink router where
3232
* they enter. It is important to note that the links are not
3333
* unidirectional, the legal way to traverse a link is from the
@@ -69,10 +69,10 @@ class NocStorage {
6969
* @brief The user provides an ID for the router when describing the NoC
7070
* in the architecture file. This ID system will be different than the
7171
* NocRouterIds assigned to each router. The user ID system will be
72-
* arbritary but the internal ID system used here will start at 0 and
72+
* arbitrary but the internal ID system used here will start at 0 and
7373
* are dense since it is used to index the routers. The datastructure
7474
* below is a conversiont able that maps the user router IDs to the
75-
* correspondint internal ones.
75+
* corresponding internal ones.
7676
*
7777
*/
7878
std::unordered_map<int, NocRouterId> router_id_conversion_table;
@@ -84,9 +84,9 @@ class NocStorage {
8484
* logical router was moved is known.
8585
* Using this datastructure, the grid location can be used to
8686
* identify the corresponding hard router block positioned at that grid
87-
* location. The NocROuterId uniqely identifies hard router blocks and
87+
* location. The NocROuterId uniquely identifies hard router blocks and
8888
* can be used to retrieve the hard router block information using
89-
* the router_storage datastructurre above. This can also be used to
89+
* the router_storage data structure above. This can also be used to
9090
* access the connectivity graph datastructure above.
9191
*
9292
* It is important to know the specific hard router block because
@@ -96,7 +96,7 @@ class NocStorage {
9696
* the placement cost of the moved logical router block.
9797
*
9898
* The intended use is when trying to re-route a traffic flow. The current
99-
* location of a logical router block can be used in conjuction with this
99+
* location of a logical router block can be used in conjunction with this
100100
* datastructure to identify the corresponding hard router block.
101101
*
102102
*/
@@ -105,7 +105,7 @@ class NocStorage {
105105
/**
106106
* @brief A flag that indicates whether the NoC has been built. If this
107107
* flag is true, then the NoC cannot be modified, meaning that routers and
108-
* links cannot be added or removed. The inteded use of this flag is to
108+
* links cannot be added or removed. The intended use of this flag is to
109109
* set it after you complete building the NoC (adding routers and links).
110110
* This flag can then acts as a check so that the NoC is not modified
111111
* later on after building it.
@@ -144,7 +144,7 @@ class NocStorage {
144144
void operator=(const NocStorage&) = delete;
145145

146146
public:
147-
// default contructor (cleare all the elements in the vectors)
147+
// default constructor (clear all the elements in the vectors)
148148
NocStorage();
149149

150150
// getters for the NoC
@@ -153,7 +153,7 @@ class NocStorage {
153153
* @brief Gets a vector of outgoing links for a given router
154154
* in the NoC. THe link vector cannot be modified.
155155
*
156-
* @param id A unique indetifier that represents a router
156+
* @param id A unique identifier that represents a router
157157
* @return A vector of links. The links are represented by a unique
158158
* identifier.
159159
*/
@@ -193,7 +193,7 @@ class NocStorage {
193193
* @brief Get the maximum allowable bandwidth for a link
194194
* within the NoC.
195195
*
196-
* @return a numeric value that represents the link bandwith in bps
196+
* @return a numeric value that represents the link bandwidth in bps
197197
*/
198198

199199
double get_noc_link_bandwidth(void) const;
@@ -266,7 +266,7 @@ class NocStorage {
266266
* router block positioned on that grid location.
267267
*
268268
* @param hard_router_location A struct that contains the grid location
269-
* of an arbirtary hard router block on the FPGA.
269+
* of an arbitrary hard router block on the FPGA.
270270
* @return NocRouterId The hard router block "id"
271271
* located at the given grid location.
272272
*/
@@ -283,9 +283,9 @@ class NocStorage {
283283
* the NoC.
284284
*
285285
* @param id The user supplied identification for the router.
286-
* @param grid_position_x The horizontal position on the FPGA of the phyical
286+
* @param grid_position_x The horizontal position on the FPGA of the physical
287287
* tile that this router represents.
288-
* @param grid_position_y The vertical position on the FPGA of the phyical
288+
* @param grid_position_y The vertical position on the FPGA of the physical
289289
* tile that this router represents.
290290
*/
291291
void add_router(int id, int grid_position_x, int grid_position_y);
@@ -336,15 +336,15 @@ class NocStorage {
336336

337337
void set_device_grid_width(int grid_width);
338338

339-
// general utiliy functions
339+
// general utility functions
340340
/**
341341
* @brief The link is removed from the outgoing vector of links for
342342
* the source router. The link is not removed from the vector of all
343343
* links as this will require a re-indexing of all link ids. Instead,
344344
* the link is set to being invalid by. The link
345345
* is still removed since it will be considered invalid when used
346346
* externally. THe link is identified by going through the vector
347-
* outgoing links of the supplied source router, for each outgoin link
347+
* outgoing links of the supplied source router, for each outgoing link
348348
* the sink router is compared the supplied sink router and the link to
349349
* remove is identified if there is a match.
350350
* If the link doesn't exist in the
@@ -353,7 +353,7 @@ class NocStorage {
353353
*
354354
* @param src_router_id The source router of the traffic flow to delete
355355
* @param sink_router_id The sink router of the traffic flow to delete
356-
* @return true The link was succesfully removed
356+
* @return true The link was successfully removed
357357
* @return false The link was not removed
358358
*/
359359
bool remove_link(NocRouterId src_router_id, NocRouterId sink_router_id);
@@ -369,8 +369,8 @@ class NocStorage {
369369
void finished_building_noc(void);
370370

371371
/**
372-
* @brief Resets the NoC by clearning all internal datastructures.
373-
* This includes deleteing all routers and links. Also all internal
372+
* @brief Resets the NoC by clearing all internal datastructures.
373+
* This includes deleting all routers and links. Also all internal
374374
* IDs are removed (the is conversion table is cleared). It is
375375
* recommended to run this function before building the NoC.
376376
*
@@ -431,17 +431,17 @@ class NocStorage {
431431
* The key will be generated as follows:
432432
* key = y * device_grid.width() + x
433433
*
434-
* @param grid_position_x The horizontal position on the FPGA of the phyical
434+
* @param grid_position_x The horizontal position on the FPGA of the physical
435435
* tile that this router represents.
436-
* @param grid_position_y The vertical position on the FPGA of the phyical
436+
* @param grid_position_y The vertical position on the FPGA of the physical
437437
* tile that this router represents.
438438
* @return int Represents a unique key that can be used to identify a
439439
* hard router block.
440440
*/
441441
int generate_router_key_from_grid_location(int grid_position_x, int grid_position_y) const;
442442

443443
/**
444-
* @brief Writes out the NocStirage class infromation to a file.
444+
* @brief Writes out the NocStorage class information to a file.
445445
* This includes the list of routers and their connections
446446
* to other routers in the NoC.
447447
*

vpr/src/noc/noc_traffic_flows.cpp

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,14 @@ std::vector<NocLinkId>& NocTrafficFlows::get_mutable_traffic_flow_route(NocTraff
4444
return traffic_flow_routes[traffic_flow_id];
4545
}
4646

47-
const std::unordered_set<ClusterBlockId>& NocTrafficFlows::get_router_clusters_in_netlist(void) const {
47+
const std::vector<ClusterBlockId>& NocTrafficFlows::get_router_clusters_in_netlist(void) const {
4848
return router_cluster_in_netlist;
4949
}
5050

51+
const std::vector<NocTrafficFlowId>& NocTrafficFlows::get_all_traffic_flow_id(void) const {
52+
return noc_traffic_flows_ids;
53+
}
54+
5155
// setters for the traffic flows
5256

5357
void NocTrafficFlows::create_noc_traffic_flow(std::string source_router_module_name, std::string sink_router_module_name, ClusterBlockId source_router_cluster_id, ClusterBlockId sink_router_cluster_id, double traffic_flow_bandwidth, double traffic_flow_latency, int traffic_flow_priority) {
@@ -58,22 +62,26 @@ void NocTrafficFlows::create_noc_traffic_flow(std::string source_router_module_n
5862

5963
//since the new traffic flow was added to the back of the vector, its id will be the index of the last element
6064
NocTrafficFlowId curr_traffic_flow_id = (NocTrafficFlowId)(noc_traffic_flows.size() - 1);
65+
noc_traffic_flows_ids.emplace_back(curr_traffic_flow_id);
6166

6267
// now add the new traffic flow to flows associated with the current source and sink router
6368
add_traffic_flow_to_associated_routers(curr_traffic_flow_id, source_router_cluster_id);
6469
add_traffic_flow_to_associated_routers(curr_traffic_flow_id, sink_router_cluster_id);
6570

66-
// insert the clusters to the local collection of all router clusters in the netlist
67-
// duplicates should not be added multiple times
68-
router_cluster_in_netlist.insert(source_router_cluster_id);
69-
router_cluster_in_netlist.insert(sink_router_cluster_id);
70-
7171
return;
7272
}
7373

74+
void NocTrafficFlows::set_router_cluster_in_netlist(const std::vector<ClusterBlockId>& routers_cluster_id_in_netlist) {
75+
router_cluster_in_netlist.clear();
76+
//copy the input vector to the internal vector
77+
for (auto router_id : routers_cluster_id_in_netlist) {
78+
router_cluster_in_netlist.emplace_back(router_id);
79+
}
80+
}
81+
7482
// utility functions for the noc traffic flows
7583

76-
void NocTrafficFlows::finshed_noc_traffic_flows_setup(void) {
84+
void NocTrafficFlows::finished_noc_traffic_flows_setup(void) {
7785
// all the traffic flows have been added, so indicate that the class has been constructed and cannot be modified anymore
7886
built_traffic_flows = true;
7987

@@ -87,6 +95,7 @@ void NocTrafficFlows::finshed_noc_traffic_flows_setup(void) {
8795
void NocTrafficFlows::clear_traffic_flows(void) {
8896
// delete any information from internal datastructures
8997
noc_traffic_flows.clear();
98+
noc_traffic_flows_ids.clear();
9099
router_cluster_in_netlist.clear();
91100
traffic_flows_associated_to_router_blocks.clear();
92101
traffic_flow_routes.clear();
@@ -100,7 +109,7 @@ void NocTrafficFlows::clear_traffic_flows(void) {
100109
bool NocTrafficFlows::check_if_cluster_block_has_traffic_flows(ClusterBlockId block_id) {
101110
auto traffic_flows = get_traffic_flows_associated_to_router_block(block_id);
102111

103-
// indicate whether a vector of traffic flows were found that are associated to the curre cluster block
112+
// indicate whether a vector of traffic flows were found that are associated to the current cluster block
104113
return (traffic_flows != nullptr);
105114
}
106115

@@ -110,7 +119,7 @@ void NocTrafficFlows::add_traffic_flow_to_associated_routers(NocTrafficFlowId tr
110119
// get a reference to the traffic flows associated with the current router
111120
auto router_traffic_flows = traffic_flows_associated_to_router_blocks.find(associated_router_id);
112121

113-
// check if a vector asssociated traffic flows exists
122+
// check if a vector associated traffic flows exists
114123
if (router_traffic_flows == traffic_flows_associated_to_router_blocks.end()) {
115124
// there exists no associated traffic flows for this router, so we add it with the newly created traffic flow id
116125
traffic_flows_associated_to_router_blocks.insert(std::pair<ClusterBlockId, std::vector<NocTrafficFlowId>>(associated_router_id, {traffic_flow_id}));
@@ -150,7 +159,7 @@ void NocTrafficFlows::echo_noc_traffic_flows(char* file_name) {
150159
fprintf(fp, "Traffic flow bandwidth: %f bps\n", traffic_flow->traffic_flow_bandwidth);
151160
fprintf(fp, "Traffic flow latency: %f seconds\n", traffic_flow->max_traffic_flow_latency);
152161

153-
// seperate the next link information
162+
// separate the next link information
154163
fprintf(fp, "\n");
155164

156165
// update the id for the next traffic flow
@@ -177,7 +186,7 @@ void NocTrafficFlows::echo_noc_traffic_flows(char* file_name) {
177186
fprintf(fp, "%lu ", (size_t)*traffic_flow);
178187
}
179188

180-
// seperate to the next cluster associated traffic flows information
189+
// separate to the next cluster associated traffic flows information
181190
fprintf(fp, "\n\n");
182191
}
183192

0 commit comments

Comments
 (0)