Skip to content

Commit b2ad5d9

Browse files
addressed some pr comments
1 parent 023239a commit b2ad5d9

File tree

3 files changed

+63
-7
lines changed

3 files changed

+63
-7
lines changed

vpr/src/noc/odd_even_routing.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ const std::vector<TurnModelRouting::Direction>& OddEvenRouting::get_legal_direct
4949
/* The implementation below is a carbon copy of the Fig. 2 in the following paper
5050
* Chiu GM. The odd-even turn model for adaptive routing.
5151
* IEEE Transactions on parallel and distributed systems. 2000 Jul;11(7):729-38.
52+
* In summary, the odd-even algorithm forbids NW and SW turns in odd columns,
53+
* while EN and ES turns are forbidden in even columns.
5254
*/
5355
if (diff_x == 0) { // the same column as the destination. Only north or south are allowed
5456
if (diff_y > 0) {
@@ -61,6 +63,8 @@ const std::vector<TurnModelRouting::Direction>& OddEvenRouting::get_legal_direct
6163
if (diff_y == 0) { // already in the same row as the destination. Just move to the east
6264
returned_legal_direction.push_back(TurnModelRouting::Direction::RIGHT);
6365
} else {
66+
/* Since EN and ES turns are forbidden in even columns, we move along the vertical
67+
* direction only in we are in an odd column. */
6468
if (is_odd(compressed_curr_loc.x) || compressed_curr_loc.x == compressed_src_loc.x) {
6569
if (diff_y > 0) {
6670
returned_legal_direction.push_back(TurnModelRouting::Direction::UP);
@@ -75,6 +79,8 @@ const std::vector<TurnModelRouting::Direction>& OddEvenRouting::get_legal_direct
7579
}
7680
} else { // westbound message
7781
returned_legal_direction.push_back(TurnModelRouting::Direction::LEFT);
82+
/* Since NW and SW turns are forbidden in odd columns, we allow
83+
* moving along vertical axis only in even columns */
7884
if (is_even(compressed_curr_loc.x)) {
7985
if (diff_y > 0) {
8086
returned_legal_direction.push_back(TurnModelRouting::Direction::UP);

vpr/src/noc/odd_even_routing.h

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,27 @@
33

44
#include "turn_model_routing.h"
55

6+
/**
7+
* @file
8+
* @brief This file declares the OddEvenRouting class, which implements
9+
* the odd-even routing algorithm.
10+
*
11+
* Overview
12+
* ========
13+
* The OddEvenRouting class performs packet routing between routers in the
14+
* NoC using the odd-even routing algorithm. Unlike other turn model algorithms
15+
* that forbid at least two turns, the odd-even algorithm does not forbid
16+
* any turns, but only limits the column where the turn can be taken.
17+
* More specifically, the odd-even routing algorithms forbids NW and SW turns
18+
* in odd columns, while EN and ES turns are not allowed in even columns.
19+
*/
20+
621
class OddEvenRouting : public TurnModelRouting{
722
public:
823
~OddEvenRouting() override;
924

1025
private:
26+
1127
const std::vector<TurnModelRouting::Direction>& get_legal_directions(NocRouterId src_router_id,
1228
NocRouterId curr_router_id,
1329
NocRouterId dst_router_id,
@@ -19,8 +35,18 @@ class OddEvenRouting : public TurnModelRouting{
1935
NocRouterId curr_router_id,
2036
NocTrafficFlowId traffic_flow_id,
2137
const NocStorage& noc_model) override;
22-
38+
/**
39+
* Checks whether the given umber is odd.
40+
* @param number An integer number
41+
* @return True if the passed number of odd, otherwise false.
42+
*/
2343
static inline bool is_odd(int number);
44+
45+
/**
46+
* Checks whether the given umber is even.
47+
* @param number An integer number
48+
* @return True if the passed number of even, otherwise false.
49+
*/
2450
static inline bool is_even(int number);
2551
};
2652

vpr/src/noc/turn_model_routing.h

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,23 @@
1111
* Overview
1212
* ========
1313
* The TurnModelRouting class abstracts Turn Model routing algorithms.
14+
* The route_flow() method implemented in this class, routes a traffic flow
15+
* by adding a NoC link at a time to form a route between two NoC routers.
16+
* The destination router of the last added NoC link is called the current
17+
* NoC router.
1418
* The main idea in Turn Model algorithm is to forbid specific turns
15-
* for traffic flows based on the source, destination, and current NoC
19+
* for traffic flows to avoid deadlock. If at least one clockwise turn
20+
* and one anticlockwise turn are forbidden, no cyclic dependency can
21+
* happen, making deadlock impossible. Turn model algorithms forbid
22+
* specific turns based on the source, destination, and current NoC
1623
* router locations in a mesh or torus topology. TurnModelRouting class
1724
* exposes a shared interface for all Turn Model routing algorithms.
1825
* Derived classes can implement specific routing algorithms by implementing
1926
* their override of the exposed interface. More specifically,
20-
* get_legal_directions() method returns legal directions that a
21-
* traffic flow can follow based on the source, destination, and current
27+
* the get_legal_directions() method returns legal directions that a
28+
* traffic flow can follow based on where the source, destination, and current
2229
* NoC routers are located. select_next_direction() selects one of these
23-
* legal directions. TurnModelRouting() method does not implement these
30+
* legal directions. The TurnModelRouting() class does not implement these
2431
* methods, but calls them in route_flow(). For example, XYRouting can be
2532
* implemented by overriding these two methods. get_legal_directions()
2633
* should return horizontal directions when the current router and the
@@ -30,6 +37,16 @@
3037
* select_next_direction() selects one of two available directions to get
3138
* closer to the destination.
3239
*
40+
* When the routing algorithm presents two possible direction choices
41+
* at a router, we use a biased coin flip to randomly select one of them.
42+
* This random decision is biased towards choosing the direction in which
43+
* the distance to the destination is longer. For example, if the last router
44+
* added to a partial route is located at (3, 5) while the route is destined
45+
* for (7, 7), the random decision favors the X-direction twice as much as
46+
* the Y-direction. This approach distributes the chance of selecting
47+
* a shortest path more evenly among all possible paths between two
48+
* NoC routers.
49+
*
3350
* TurnModelRouting also provides multiple helper methods that can be used
3451
* by derived classes.
3552
*/
@@ -142,7 +159,8 @@ class TurnModelRouting : public NocRouting {
142159
* sure that the link chosen points in the intended direction.
143160
*
144161
* @param curr_router_id The physical router on the FPGA that the routing
145-
* algorithm is currently visiting.
162+
* algorithm is currently visiting. This argument is updated in this method
163+
* returned by reference.
146164
* @param curr_router_position The grid position of the router that is
147165
* currently being visited on the FPGA
148166
* @param next_step_direction The direction to travel next
@@ -164,7 +182,13 @@ class TurnModelRouting : public NocRouting {
164182

165183
/**
166184
* @brief Computes MurmurHash3 for an array of 32-bit words initialized
167-
* with seed.
185+
* with seed. As discussed in the comment at the top of this file,
186+
* when two possible directions are presented by get_legal_directions(),
187+
* we flip a biased coin by favoring the direction along which the distance
188+
* to the destination is longer. This hash function is used to generate
189+
* a hash value, which is treated as random value. The generated
190+
* hash value is compared with a threshold to determine the next
191+
* direction to be taken
168192
* @param key Contains elements to be hashed
169193
* @param seed The initialization value.
170194
* @return uint32_t Computed hash value.

0 commit comments

Comments
 (0)