Skip to content

Commit 8e2283e

Browse files
check turn legality in odd-even routing unit test
1 parent ae70992 commit 8e2283e

File tree

2 files changed

+33
-16
lines changed

2 files changed

+33
-16
lines changed

vpr/src/noc/turn_model_routing.h

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,19 @@ class TurnModelRouting : public NocRouting {
102102
*/
103103
std::vector<std::pair<NocLinkId, NocLinkId>> get_all_illegal_turns(const NocStorage& noc_model) const;
104104

105+
/**
106+
* @brief Determines whether a turn specified by 3 NoC routers visited in the turn
107+
* is legal. Turn model routing algorithms forbid specific turns in the mesh topology
108+
* to guarantee deadlock-freedom. In addition to turns forbidden by the turn model algorithm,
109+
* 180-degree turns are also illegal.
110+
*
111+
* @param noc_routers Three NoC routers visited in a turn.
112+
* @param noc_is_3d Specifies whether the NoC is 2D or 3D.
113+
* @return True if the turn is legal, otherwise false.
114+
*/
115+
virtual bool is_turn_legal(const std::array<std::reference_wrapper<const NocRouter>, 3>& noc_routers,
116+
const NocStorage& noc_model) const = 0;
117+
105118
protected:
106119
/**
107120
* @brief This enum describes the all the possible
@@ -254,19 +267,6 @@ class TurnModelRouting : public NocRouting {
254267
NocTrafficFlowId traffic_flow_id,
255268
const NocStorage& noc_model);
256269

257-
/**
258-
* @brief Determines whether a turn specified by 3 NoC routers visited in the turn
259-
* is legal. Turn model routing algorithms forbid specific turns in the mesh topology
260-
* to guarantee deadlock-freedom. In addition to turns forbidden by the turn model algorithm,
261-
* 180-degree turns are also illegal.
262-
*
263-
* @param noc_routers Three NoC routers visited in a turn.
264-
* @param noc_is_3d Specifies whether the NoC is 2D or 3D.
265-
* @return True if the turn is legal, otherwise false.
266-
*/
267-
virtual bool is_turn_legal(const std::array<std::reference_wrapper<const NocRouter>, 3>& noc_routers,
268-
const NocStorage& noc_model) const = 0;
269-
270270
protected:
271271
// get_legal_directions() return a reference to this vector to avoid allocating a new vector
272272
// each time it is called

vpr/test/test_odd_even_routing.cpp

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,24 @@ void compare_routes(const std::vector<NocLink>& golden_path,
3737
}
3838
}
3939

40+
41+
void check_turn_legality(const vtr::vector<NocTrafficFlowId, std::vector<NocLinkId>>& traffic_flow_routes,
42+
const NocStorage& noc_model,
43+
const TurnModelRouting& routing_algorithm) {
44+
45+
for (const auto& traffic_flow_route : traffic_flow_routes) {
46+
for (size_t i = 0; i < traffic_flow_route.size() - 1; i++) {
47+
const NocLink& noc_link1 = noc_model.get_single_noc_link(traffic_flow_route[i]);
48+
const NocLink& noc_link2 = noc_model.get_single_noc_link(traffic_flow_route[i + 1]);
49+
REQUIRE(noc_link1.get_sink_router() == noc_link2.get_source_router());
50+
const NocRouter& router_1 = noc_model.get_single_noc_router(noc_link1.get_source_router());
51+
const NocRouter& router_2 = noc_model.get_single_noc_router(noc_link1.get_sink_router());
52+
const NocRouter& router_3 = noc_model.get_single_noc_router(noc_link2.get_sink_router());
53+
REQUIRE(routing_algorithm.is_turn_legal({router_1, router_2, router_3}, noc_model) == true);
54+
}
55+
}
56+
}
57+
4058
TEST_CASE("test_route_flow", "[vpr_noc_odd_even_routing]") {
4159
/* Creating a test FPGA device below. The NoC itself will be a 10x10 mesh where
4260
* they will span over a grid size of 10x10. So this FPGA will only consist of NoC routers */
@@ -207,7 +225,7 @@ TEST_CASE("test_route_flow", "[vpr_noc_odd_even_routing]") {
207225
compare_routes(golden_path, found_path, noc_model);
208226
}
209227

210-
SECTION("To be named ") {
228+
SECTION("Test case where multiple traffic flows are router, and routes are checked for turn legality and deadlock freedom.") {
211229
std::random_device device;
212230
std::mt19937 rand_num_gen(device());
213231
std::uniform_int_distribution<std::mt19937::result_type> dist(0, 99);
@@ -242,9 +260,8 @@ TEST_CASE("test_route_flow", "[vpr_noc_odd_even_routing]") {
242260

243261
REQUIRE(cdg.has_cycles() == false);
244262

263+
check_turn_legality(traffic_flow_routes, noc_model, routing_algorithm);
245264
}
246-
247-
248265
}
249266

250267
}

0 commit comments

Comments
 (0)