Skip to content

Commit f73212c

Browse files
committed
[Router] Fixed No source in route tree in ParallelConnectionRouter
The `No source in route tree` bug in ParallelConnectionRouter (since commit 875b98e) has been fixed. It turns out that putting another member variable `MultiQueueDAryHeap<HeapImplementation::arg_D> heap_` in the derived class ParallelConnectionRouter together with the existing `HeapImplementation heap_` in the base class ConnectionRouter causes the issue. The solution is to keep `heap_` only in the base class and use `ConnectionRouter<MultiQueueDAryHeap<HeapImplementation::arg_D>>` rather than `ConnectionRouter<HeapImplementation>` for deriving the parallel connection router. Please note that ParallelConnectionRouter still has some bugs (i.e., getting stuck in the MultiQueue pop). This commit is not fully working. Please do not use it for any experiments. Updated the previously incorrect command-line options for the parallel connection router in the regression tests.
1 parent b109d13 commit f73212c

File tree

12 files changed

+54
-56
lines changed

12 files changed

+54
-56
lines changed

vpr/src/route/NestedNetlistRouter.h

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "vtr_thread_pool.h"
77
#include "serial_connection_router.h"
88
#include "parallel_connection_router.h"
9+
#include <memory>
910
#include <unordered_map>
1011

1112
/* Add cmd line option for this later */
@@ -51,11 +52,7 @@ class NestedNetlistRouter : public NetlistRouter {
5152
, _choking_spots(choking_spots)
5253
, _is_flat(is_flat)
5354
, _thread_pool(MAX_THREADS) {}
54-
~NestedNetlistRouter() {
55-
for (auto& [_, router] : _routers_th) {
56-
delete router;
57-
}
58-
}
55+
~NestedNetlistRouter() {}
5956

6057
/** Run a single iteration of netlist routing for this->_net_list. This usually means calling
6158
* \ref route_net for each net, which will handle other global updates.
@@ -73,15 +70,15 @@ class NestedNetlistRouter : public NetlistRouter {
7370
/** Route all nets in a PartitionTree node and add its children to the task queue. */
7471
void route_partition_tree_node(PartitionTreeNode& node);
7572

76-
ConnectionRouter<HeapType>* _make_router(const RouterLookahead* router_lookahead,
77-
const t_router_opts& router_opts,
78-
bool is_flat) {
73+
std::shared_ptr<ConnectionRouterInterface> _make_router(const RouterLookahead* router_lookahead,
74+
const t_router_opts& router_opts,
75+
bool is_flat) {
7976
auto& device_ctx = g_vpr_ctx.device();
8077
auto& route_ctx = g_vpr_ctx.mutable_routing();
8178

8279
if (!router_opts.enable_parallel_connection_router) {
8380
// Serial Connection Router
84-
return new SerialConnectionRouter<HeapType>(
81+
return std::make_shared<SerialConnectionRouter<HeapType>>(
8582
device_ctx.grid,
8683
*router_lookahead,
8784
device_ctx.rr_graph.rr_nodes(),
@@ -92,7 +89,7 @@ class NestedNetlistRouter : public NetlistRouter {
9289
is_flat);
9390
} else {
9491
// Parallel Connection Router
95-
return new ParallelConnectionRouter<HeapType>(
92+
return std::make_shared<ParallelConnectionRouter<HeapType>>(
9693
device_ctx.grid,
9794
*router_lookahead,
9895
device_ctx.rr_graph.rr_nodes(),
@@ -134,13 +131,13 @@ class NestedNetlistRouter : public NetlistRouter {
134131

135132
/* Thread-local storage.
136133
* These are maps because thread::id is a random integer instead of 1, 2, ... */
137-
std::unordered_map<std::thread::id, ConnectionRouter<HeapType>*> _routers_th;
134+
std::unordered_map<std::thread::id, std::shared_ptr<ConnectionRouterInterface>> _routers_th;
138135
std::unordered_map<std::thread::id, RouteIterResults> _results_th;
139136
std::mutex _storage_mutex;
140137

141138
/** Get a thread-local ConnectionRouter. We lock the id->router lookup, but this is
142139
* accessed once per partition so the overhead should be small */
143-
ConnectionRouter<HeapType>* get_thread_router() {
140+
std::shared_ptr<ConnectionRouterInterface> get_thread_router() {
144141
auto id = std::this_thread::get_id();
145142
std::lock_guard<std::mutex> lock(_storage_mutex);
146143
if (!_routers_th.count(id)) {

vpr/src/route/SerialNetlistRouter.h

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,25 +34,23 @@ class SerialNetlistRouter : public NetlistRouter {
3434
, _routing_predictor(routing_predictor)
3535
, _choking_spots(choking_spots)
3636
, _is_flat(is_flat) {}
37-
~SerialNetlistRouter() {
38-
delete _router;
39-
}
37+
~SerialNetlistRouter() {}
4038

4139
RouteIterResults route_netlist(int itry, float pres_fac, float worst_neg_slack);
4240
void handle_bb_updated_nets(const std::vector<ParentNetId>& nets);
4341
void set_rcv_enabled(bool x);
4442
void set_timing_info(std::shared_ptr<SetupHoldTimingInfo> timing_info);
4543

4644
private:
47-
ConnectionRouter<HeapType>* _make_router(const RouterLookahead* router_lookahead,
48-
const t_router_opts& router_opts,
49-
bool is_flat) {
45+
std::unique_ptr<ConnectionRouterInterface> _make_router(const RouterLookahead* router_lookahead,
46+
const t_router_opts& router_opts,
47+
bool is_flat) {
5048
auto& device_ctx = g_vpr_ctx.device();
5149
auto& route_ctx = g_vpr_ctx.mutable_routing();
5250

5351
if (!router_opts.enable_parallel_connection_router) {
5452
// Serial Connection Router
55-
return new SerialConnectionRouter<HeapType>(
53+
return std::make_unique<SerialConnectionRouter<HeapType>>(
5654
device_ctx.grid,
5755
*router_lookahead,
5856
device_ctx.rr_graph.rr_nodes(),
@@ -63,7 +61,7 @@ class SerialNetlistRouter : public NetlistRouter {
6361
is_flat);
6462
} else {
6563
// Parallel Connection Router
66-
return new ParallelConnectionRouter<HeapType>(
64+
return std::make_unique<ParallelConnectionRouter<HeapType>>(
6765
device_ctx.grid,
6866
*router_lookahead,
6967
device_ctx.rr_graph.rr_nodes(),
@@ -78,7 +76,7 @@ class SerialNetlistRouter : public NetlistRouter {
7876
}
7977
}
8078
/* Context fields */
81-
ConnectionRouter<HeapType>* _router;
79+
std::unique_ptr<ConnectionRouterInterface> _router;
8280
const Netlist<>& _net_list;
8381
const t_router_opts& _router_opts;
8482
CBRR& _connections_inf;

vpr/src/route/connection_router.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -332,9 +332,6 @@ class ConnectionRouter : public ConnectionRouterInterface {
332332
/** Is flat router enabled or not? */
333333
bool is_flat_;
334334

335-
/** Node IDs of modified nodes in rr_node_route_inf */
336-
std::vector<RRNodeId> modified_rr_node_inf_;
337-
338335
/** Router statistics (e.g., heap push/pop counts) */
339336
RouterStats* router_stats_;
340337

vpr/src/route/multi_queue_d_ary_heap.h

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@
2020
#ifndef _MULTI_QUEUE_D_ARY_HEAP_H
2121
#define _MULTI_QUEUE_D_ARY_HEAP_H
2222

23-
#include <tuple>
2423
#include "device_grid.h"
2524
#include "heap_type.h"
2625
#include "multi_queue_d_ary_heap.tpp"
26+
#include <tuple>
27+
#include <memory>
2728

2829
using MQHeapNode = std::tuple<HeapNodePriority, uint32_t /*FIXME*/>;
2930

@@ -40,20 +41,24 @@ class MultiQueueDAryHeap {
4041
using MQ_IO = MultiQueueIO<D, MQHeapNode, MQHeapNodeTupleComparator, HeapNodePriority>;
4142

4243
MultiQueueDAryHeap() {
43-
pq_ = new MQ_IO(2, 1, 0); // Serial (#threads=1, #queues=2) by default
44+
set_num_threads_and_queues(2, 1); // Serial (#threads=1, #queues=2) by default
4445
}
4546

4647
MultiQueueDAryHeap(size_t num_threads, size_t num_queues) {
47-
pq_ = new MQ_IO(num_queues, num_threads, 0 /*Dont care (batch size for only popBatch)*/);
48+
set_num_threads_and_queues(num_threads, num_queues);
4849
}
4950

50-
~MultiQueueDAryHeap() {
51-
delete pq_;
51+
~MultiQueueDAryHeap() {}
52+
53+
void set_num_threads_and_queues(size_t num_threads, size_t num_queues) {
54+
pq_.reset();
55+
pq_ = std::make_unique<MQ_IO>(num_threads, num_queues, 0 /*Dont care (batch size for only popBatch)*/);
5256
}
5357

5458
void init_heap(const DeviceGrid& grid) {
5559
(void)grid;
5660
// TODO: Reserve storage for MQ_IO
61+
// Note: This function could be called before setting num_threads/num_queues
5762
}
5863

5964
bool try_pop(HeapNode& heap_node) {
@@ -119,7 +124,7 @@ class MultiQueueDAryHeap {
119124
#endif
120125

121126
private:
122-
MQ_IO* pq_;
127+
std::unique_ptr<MQ_IO> pq_;
123128
};
124129

125130
#endif

vpr/src/route/parallel_connection_router.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -394,12 +394,12 @@ void ParallelConnectionRouter<Heap>::timing_driven_add_to_heap(const t_conn_cost
394394
if (to_node == target_node) {
395395
#ifdef MQ_IO_ENABLE_CLEAR_FOR_POP
396396
if (multi_queue_direct_draining_) {
397-
heap_.setMinPrioForPop(new_total_cost);
397+
this->heap_.setMinPrioForPop(new_total_cost);
398398
}
399399
#endif
400400
return;
401401
}
402-
heap_.add_to_heap({new_total_cost, to_node});
402+
this->heap_.add_to_heap({new_total_cost, to_node});
403403
}
404404

405405
template<typename Heap>

vpr/src/route/parallel_connection_router.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ using barrier_t = barrier_spin_t; // Using the spin-based thread barrier
153153
* Dec. 2024.
154154
*/
155155
template<typename HeapImplementation>
156-
class ParallelConnectionRouter : public ConnectionRouter<HeapImplementation> {
156+
class ParallelConnectionRouter : public ConnectionRouter<MultiQueueDAryHeap<HeapImplementation::arg_D>> {
157157
public:
158158
ParallelConnectionRouter(
159159
const DeviceGrid& grid,
@@ -167,13 +167,14 @@ class ParallelConnectionRouter : public ConnectionRouter<HeapImplementation> {
167167
int multi_queue_num_threads,
168168
int multi_queue_num_queues,
169169
bool multi_queue_direct_draining)
170-
: ConnectionRouter<HeapImplementation>(grid, router_lookahead, rr_nodes, rr_graph, rr_rc_data, rr_switch_inf, rr_node_route_inf, is_flat)
170+
: ConnectionRouter<MultiQueueDAryHeap<HeapImplementation::arg_D>>(grid, router_lookahead, rr_nodes, rr_graph, rr_rc_data, rr_switch_inf, rr_node_route_inf, is_flat)
171171
, modified_rr_node_inf_(multi_queue_num_threads)
172-
, heap_(multi_queue_num_threads, multi_queue_num_queues)
173172
, thread_barrier_(multi_queue_num_threads)
174173
, is_router_destroying_(false)
175174
, locks_(rr_node_route_inf.size())
176175
, multi_queue_direct_draining_(multi_queue_direct_draining) {
176+
// Set the MultiQueue parameters
177+
this->heap_.set_num_threads_and_queues(multi_queue_num_threads, multi_queue_num_queues);
177178
// Initialize the thread barrier
178179
this->thread_barrier_.init();
179180
// Instantiate (multi_queue_num_threads - 1) helper threads
@@ -400,9 +401,6 @@ class ParallelConnectionRouter : public ConnectionRouter<HeapImplementation> {
400401
/** Node IDs of modified nodes in rr_node_route_inf for each thread*/
401402
std::vector<std::vector<RRNodeId>> modified_rr_node_inf_;
402403

403-
/** MultiQueue-based parallel heap */
404-
MultiQueueDAryHeap<HeapImplementation::arg_D> heap_;
405-
406404
/** Helper threads */
407405
std::vector<std::thread> sub_threads_;
408406

vpr/src/route/serial_connection_router.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,9 @@ class SerialConnectionRouter : public ConnectionRouter<HeapImplementation> {
231231
vtr::vector<RRNodeId, RTExploredNode> timing_driven_find_all_shortest_paths_from_heap(
232232
const t_conn_cost_params& cost_params,
233233
const t_bb& bounding_box) final;
234+
235+
/** Node IDs of modified nodes in rr_node_route_inf */
236+
std::vector<RRNodeId> modified_rr_node_inf_;
234237
};
235238

236239
/** Construct a serial connection router that uses the specified heap type.

vtr_flow/tasks/regression_tests/vtr_reg_strong/koios_test/config/config.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,6 @@ pass_requirements_file=pass_requirements.txt
3838
script_params_common=-track_memory_usage
3939
script_params_list_add =
4040
script_params_list_add = --router_algorithm parallel
41-
script_params_list_add = --enable_parallel_connection_router
42-
script_params_list_add = --enable_parallel_connection_router --multi_queue_num_threads 4 --multi_queue_num_queues 16
43-
script_params_list_add = --enable_parallel_connection_router --multi_queue_num_threads 2 --multi_queue_num_queues 4 --multi_queue_direct_draining
41+
script_params_list_add = --enable_parallel_connection_router on
42+
script_params_list_add = --enable_parallel_connection_router on --multi_queue_num_threads 4 --multi_queue_num_queues 16
43+
script_params_list_add = --enable_parallel_connection_router on --multi_queue_num_threads 2 --multi_queue_num_queues 4 --multi_queue_direct_draining on

vtr_flow/tasks/regression_tests/vtr_reg_strong/strong_flat_router/config/config.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ pass_requirements_file=pass_requirements.txt
2727
script_params_common=-track_memory_usage --route_chan_width 100 --max_router_iterations 100 --router_lookahead map --flat_routing on
2828
script_params_list_add =
2929
script_params_list_add = --router_algorithm parallel --num_workers 4
30-
script_params_list_add = --enable_parallel_connection_router
31-
script_params_list_add = --enable_parallel_connection_router --multi_queue_num_threads 4 --multi_queue_num_queues 16
32-
script_params_list_add = --enable_parallel_connection_router --multi_queue_num_threads 2 --multi_queue_num_queues 4 --multi_queue_direct_draining
30+
script_params_list_add = --enable_parallel_connection_router on
31+
script_params_list_add = --enable_parallel_connection_router on --multi_queue_num_threads 4 --multi_queue_num_queues 16
32+
script_params_list_add = --enable_parallel_connection_router on --multi_queue_num_threads 2 --multi_queue_num_queues 4 --multi_queue_direct_draining on

vtr_flow/tasks/regression_tests/vtr_reg_strong/strong_multiclock/config/config.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ pass_requirements_file=pass_requirements_multiclock.txt
2727
script_params_common=-starting_stage vpr -sdc_file tasks/regression_tests/vtr_reg_strong/strong_multiclock/config/multiclock.sdc
2828
script_params_list_add =
2929
script_params_list_add = --router_algorithm parallel --num_workers 4
30-
script_params_list_add = --enable_parallel_connection_router
31-
script_params_list_add = --enable_parallel_connection_router --multi_queue_num_threads 4 --multi_queue_num_queues 16
32-
script_params_list_add = --enable_parallel_connection_router --multi_queue_num_threads 2 --multi_queue_num_queues 4 --multi_queue_direct_draining
30+
script_params_list_add = --enable_parallel_connection_router on
31+
script_params_list_add = --enable_parallel_connection_router on --multi_queue_num_threads 4 --multi_queue_num_queues 16
32+
script_params_list_add = --enable_parallel_connection_router on --multi_queue_num_threads 2 --multi_queue_num_queues 4 --multi_queue_direct_draining on

vtr_flow/tasks/regression_tests/vtr_reg_strong/strong_timing/config/config.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ pass_requirements_file=pass_requirements.txt
2727
script_params_common = -track_memory_usage
2828
script_params_list_add =
2929
script_params_list_add = --router_algorithm parallel --num_workers 4
30-
script_params_list_add = --enable_parallel_connection_router
31-
script_params_list_add = --enable_parallel_connection_router --multi_queue_num_threads 4 --multi_queue_num_queues 16
32-
script_params_list_add = --enable_parallel_connection_router --multi_queue_num_threads 2 --multi_queue_num_queues 4 --multi_queue_direct_draining
30+
script_params_list_add = --enable_parallel_connection_router on
31+
script_params_list_add = --enable_parallel_connection_router on --multi_queue_num_threads 4 --multi_queue_num_queues 16
32+
script_params_list_add = --enable_parallel_connection_router on --multi_queue_num_threads 2 --multi_queue_num_queues 4 --multi_queue_direct_draining on

vtr_flow/tasks/regression_tests/vtr_reg_strong/strong_timing_update_type/config/config.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ script_params_list_add = --timing_update_type incremental
3131
script_params_list_add = --timing_update_type incremental --quench_recompute_divider 999999999 #Do post-move incremental STA during quench
3232
script_params_list_add = --timing_update_type incremental --router_algorithm parallel --num_workers 4 # rarely exercised code path
3333
script_params_list_add = --timing_update_type full --router_algorithm parallel --num_workers 4
34-
script_params_list_add = --timing_update_type incremental --enable_parallel_connection_router
35-
script_params_list_add = --timing_update_type incremental --enable_parallel_connection_router --multi_queue_num_threads 4 --multi_queue_num_queues 16
36-
script_params_list_add = --timing_update_type incremental --enable_parallel_connection_router --multi_queue_num_threads 2 --multi_queue_num_queues 4 --multi_queue_direct_draining
37-
script_params_list_add = --timing_update_type full --enable_parallel_connection_router
38-
script_params_list_add = --timing_update_type full --enable_parallel_connection_router --multi_queue_num_threads 4 --multi_queue_num_queues 16
39-
script_params_list_add = --timing_update_type full --enable_parallel_connection_router --multi_queue_num_threads 2 --multi_queue_num_queues 4 --multi_queue_direct_draining
34+
script_params_list_add = --timing_update_type incremental --enable_parallel_connection_router on
35+
script_params_list_add = --timing_update_type incremental --enable_parallel_connection_router on --multi_queue_num_threads 4 --multi_queue_num_queues 16
36+
script_params_list_add = --timing_update_type incremental --enable_parallel_connection_router on --multi_queue_num_threads 2 --multi_queue_num_queues 4 --multi_queue_direct_draining on
37+
script_params_list_add = --timing_update_type full --enable_parallel_connection_router on
38+
script_params_list_add = --timing_update_type full --enable_parallel_connection_router on --multi_queue_num_threads 4 --multi_queue_num_queues 16
39+
script_params_list_add = --timing_update_type full --enable_parallel_connection_router on --multi_queue_num_threads 2 --multi_queue_num_queues 4 --multi_queue_direct_draining on

0 commit comments

Comments
 (0)