Skip to content

Commit 6d3713b

Browse files
comments and moving header includes to source files
1 parent 3f4ffee commit 6d3713b

14 files changed

+329
-187
lines changed

vpr/src/noc/bfs_routing.cpp

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
#
1+
2+
#include <queue>
23

34
#include "bfs_routing.h"
45

@@ -19,7 +20,7 @@ void BFSRouting::route_flow(NocRouterId src_router_id,
1920
* Keeps track of which routers have been reached already
2021
* while traversing the NoC. This variable will help prevent
2122
* the algorithm from getting stuck visiting routers that
22-
* jave already been visited.
23+
* have already been visited.
2324
*
2425
*/
2526
std::unordered_set<NocRouterId> visited_routers;
@@ -50,7 +51,7 @@ void BFSRouting::route_flow(NocRouterId src_router_id,
5051
}
5152

5253
// Explore the NoC from the starting router and try to find a path to the destination router
53-
// We finish searching when there are no more routers to process or we found the destination router
54+
// We finish searching when there are no more routers to process, or we found the destination router
5455
while (!routers_to_process.empty() && !found_sink_router) {
5556
// get the next router to process
5657
NocRouterId processing_router = routers_to_process.front();
@@ -92,13 +93,17 @@ void BFSRouting::route_flow(NocRouterId src_router_id,
9293
generate_route(sink_router_id, flow_route, noc_model, router_parent_link);
9394
} else {
9495
// a path was not found so throw an error to the user
95-
VPR_FATAL_ERROR(VPR_ERROR_OTHER, "No route could be found from starting router with id:'%d' and the destination router with id:'%d' using the breadth-first search routing algorithm.", src_router.get_router_user_id(), sink_router.get_router_user_id());
96+
VPR_FATAL_ERROR(VPR_ERROR_OTHER,
97+
"No route could be found from starting router with id:'%d' and the destination router with id:'%d' using the breadth-first search routing algorithm.",
98+
src_router.get_router_user_id(),
99+
sink_router.get_router_user_id());
96100
}
97-
98-
return;
99101
}
100102

101-
void BFSRouting::generate_route(NocRouterId start_router_id, std::vector<NocLinkId>& flow_route, const NocStorage& noc_model, const std::unordered_map<NocRouterId, NocLinkId>& router_parent_link) {
103+
void BFSRouting::generate_route(NocRouterId start_router_id,
104+
std::vector<NocLinkId>& flow_route,
105+
const NocStorage& noc_model,
106+
const std::unordered_map<NocRouterId, NocLinkId>& router_parent_link) {
102107
// The intermediate router being visited while tracing the path back from the destination router to the starting router in the flow.
103108
// Initially this is set to the router at the end of the path (destination router)
104109
NocRouterId curr_intermediate_router = start_router_id;
@@ -108,11 +113,11 @@ void BFSRouting::generate_route(NocRouterId start_router_id, std::vector<NocLink
108113
auto route_beginning = flow_route.begin();
109114

110115
// get the parent link of the start router
111-
std::unordered_map<NocRouterId, NocLinkId>::const_iterator curr_intermediate_router_parent_link = router_parent_link.find(curr_intermediate_router);
116+
auto curr_intermediate_router_parent_link = router_parent_link.find(curr_intermediate_router);
112117

113-
// keep tracking baackwards from each router in the path until a router doesn't have a parent link (this means we reached the starting router in the flow)
118+
// keep tracking backwards from each router in the path until a router doesn't have a parent link (this means we reached the starting router in the flow)
114119
while (curr_intermediate_router_parent_link != router_parent_link.end()) {
115-
// add the parent link to the path. Since we are tracing backwards we need to store the links in fron of the last link.
120+
// add the parent link to the path. Since we are tracing backwards we need to store the links in front of the last link.
116121
flow_route.emplace(route_beginning, curr_intermediate_router_parent_link->second);
117122

118123
// update the reference to the beginning of the route
@@ -123,6 +128,4 @@ void BFSRouting::generate_route(NocRouterId start_router_id, std::vector<NocLink
123128
// now get the parent of the router we moved to
124129
curr_intermediate_router_parent_link = router_parent_link.find(curr_intermediate_router);
125130
}
126-
127-
return;
128131
}

vpr/src/noc/bfs_routing.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@
1414
* traffic flow. Once the destination router is found a path from the source to
1515
* the destination router is generated. The main advantage of this algorithm is
1616
* that the found path from the source to the destination router uses the
17-
* minimum number of links required within the NoC.
18-
*
17+
* minimum number of links required within the NoC. This algorithm does not
18+
* guarantee deadlock freedom. In other words, the algorithm might generate
19+
* routes that form cycles in channel dependency graph.
1920
*/
2021

2122
#include <vector>
2223
#include <unordered_map>
23-
#include <queue>
2424

2525
#include "noc_routing.h"
2626

@@ -81,7 +81,10 @@ class BFSRouting : public NocRouting {
8181
* router in the NoC (parent link is the link used to visit the router during
8282
* the BFS routing algorithm).
8383
*/
84-
void generate_route(NocRouterId sink_router_id, std::vector<NocLinkId>& flow_route, const NocStorage& noc_model, const std::unordered_map<NocRouterId, NocLinkId>& router_parent_link);
84+
void generate_route(NocRouterId sink_router_id,
85+
std::vector<NocLinkId>& flow_route,
86+
const NocStorage& noc_model,
87+
const std::unordered_map<NocRouterId, NocLinkId>& router_parent_link);
8588
};
8689

8790
#endif

vpr/src/noc/channel_dependency_graph.h

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,53 @@
11
#ifndef VTR_CHANNEL_DEPENDENCY_GRAPH_H
22
#define VTR_CHANNEL_DEPENDENCY_GRAPH_H
33

4+
/**
5+
* @file
6+
* @brief This file declares the ChannelDependencyGraph class.
7+
*
8+
* Overview
9+
* ========
10+
* The NoC routing algorithm might generate routes that cause a deadlock.
11+
* The Channel Dependency Graph (CDG) is formed by associating a node with each
12+
* link in the NoC topology. For each traffic flow route, we consider the
13+
* consecutive links traversed to reach the destination. For each consecutively
14+
* traversed link pair (Li, Lj) in the given topology, we add an directed edge from
15+
* Vi to Vj, where Vi and Vj are nodes in CDG that are associated with Li and Lj.
16+
* Absence of cycles in the formed CDG guarantees deadlock freedom.
17+
*
18+
* To learn more about channel dependency graph, refer to the following papers:
19+
* 1) Glass, C. J., & Ni, L. M. (1992). The turn model for adaptive routing.
20+
* ACM SIGARCH Computer Architecture News, 20(2), 278-287.
21+
* 2) Dally, & Seitz. (1987). Deadlock-free message routing in multiprocessor
22+
* interconnection networks. IEEE Transactions on computers, 100(5), 547-553.
23+
*/
24+
425
#include "vtr_vector.h"
526
#include "noc_data_types.h"
627

728
class ChannelDependencyGraph {
829
public:
930
ChannelDependencyGraph() = delete;
1031

32+
/**
33+
* @brief Constructor
34+
*
35+
* @param n_links The total number of NoC links.
36+
* @param traffic_flow_routes Generated traffic flow routes by the routing
37+
* algorithm.
38+
*/
1139
ChannelDependencyGraph(size_t n_links,
1240
const vtr::vector<NocTrafficFlowId, std::vector<NocLinkId>>& traffic_flow_routes);
1341

42+
/**
43+
* @brief Checks whether CDG has any cycles.
44+
*
45+
* @return True if the CDG has any cycles, otherwise false is returned.
46+
*/
1447
bool has_cycles();
1548

1649
private:
50+
/** An adjacency list used to represent channel dependency graph.*/
1751
vtr::vector<NocLinkId, std::vector<NocLinkId>> adjacency_list_;
1852
};
1953

vpr/src/noc/noc_routing.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
#include <vector>
2525

2626
#include "noc_data_types.h"
27-
#include "noc_traffic_flows.h"
2827
#include "noc_storage.h"
2928

3029
class NocRouting {

vpr/src/noc/noc_routing_algorithm_creator.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11

22
#include "noc_routing_algorithm_creator.h"
3+
#include "xy_routing.h"
4+
#include "bfs_routing.h"
5+
#include "west_first_routing.h"
6+
#include "north_last_routing.h"
7+
#include "negative_first_routing.h"
8+
#include "odd_even_routing.h"
39
#include "vpr_error.h"
410

11+
512
std::unique_ptr<NocRouting> NocRoutingAlgorithmCreator::create_routing_algorithm(const std::string& routing_algorithm_name) {
613
std::unique_ptr<NocRouting> noc_routing_algorithm;
714

vpr/src/noc/noc_routing_algorithm_creator.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,6 @@
2121
#include <memory>
2222

2323
#include "noc_routing.h"
24-
#include "xy_routing.h"
25-
#include "bfs_routing.h"
26-
#include "west_first_routing.h"
27-
#include "north_last_routing.h"
28-
#include "negative_first_routing.h"
29-
#include "odd_even_routing.h"
3024

3125
class NocRoutingAlgorithmCreator {
3226
public:

vpr/src/noc/turn_model_routing.cpp

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
#include "turn_model_routing.h"
23

34
TurnModelRouting::~TurnModelRouting() = default;
@@ -87,9 +88,6 @@ NocLinkId TurnModelRouting::move_to_next_router(NocRouterId& curr_router_id,
8788
TurnModelRouting::Direction next_step_direction,
8889
std::unordered_set<NocRouterId>& visited_routers,
8990
const NocStorage& noc_model) {
90-
// represents the router that will be visited when taking an outgoing link
91-
NocRouterId next_router_id(-1);
92-
9391
// next link to be added to the route, initialized with INVALID
9492
auto next_link = NocLinkId();
9593

@@ -108,7 +106,7 @@ NocLinkId TurnModelRouting::move_to_next_router(NocRouterId& curr_router_id,
108106
const NocLink& curr_outgoing_link = noc_model.get_single_noc_link(connecting_link);
109107

110108
// get the next router that we will visit if we travel across the current link
111-
next_router_id = curr_outgoing_link.get_sink_router();
109+
auto next_router_id = curr_outgoing_link.get_sink_router();
112110
const NocRouter& next_router = noc_model.get_single_noc_router(next_router_id);
113111

114112
// get the coordinates of the next router
@@ -169,18 +167,17 @@ NocLinkId TurnModelRouting::move_to_next_router(NocRouterId& curr_router_id,
169167
return next_link;
170168
}
171169

172-
uint32_t TurnModelRouting::murmur_32_scramble(uint32_t k) {
173-
k *= 0xcc9e2d51;
174-
k = (k << 15) | (k >> 17);
175-
k *= 0x1b873593;
176-
return k;
177-
}
178-
179170
uint32_t TurnModelRouting::murmur3_32(const std::vector<uint32_t>& key, uint32_t seed) {
180171
uint32_t h = seed;
181172

182-
for (uint32_t k : key) {
173+
auto murmur_32_scramble = [](uint32_t k) -> uint32_t {
174+
k *= 0xcc9e2d51;
175+
k = (k << 15) | (k >> 17);
176+
k *= 0x1b873593;
177+
return k;
178+
};
183179

180+
for (uint32_t k : key) {
184181
h ^= murmur_32_scramble(k);
185182
h = (h << 13) | (h >> 19);
186183
h = h * 5 + 0xe6546b64;
@@ -224,7 +221,8 @@ TurnModelRouting::Direction TurnModelRouting::select_horizontal_direction(const
224221
return TurnModelRouting::Direction::INVALID;
225222
}
226223

227-
TurnModelRouting::Direction TurnModelRouting::select_direction_other_than(const std::vector<TurnModelRouting::Direction>& directions, TurnModelRouting::Direction other_than) {
224+
TurnModelRouting::Direction TurnModelRouting::select_direction_other_than(const std::vector<TurnModelRouting::Direction>& directions,
225+
TurnModelRouting::Direction other_than) {
228226
// Iterate over all given directions and return the first one which is not "other_than"
229227
for (const auto& direction : directions) {
230228
if (direction != other_than) {

0 commit comments

Comments
 (0)