Skip to content

Commit 9a5d3b1

Browse files
author
Nathan Shreve
committed
Fixed bug in FourAryHeap::get_heap_head and make FourAryHeap default heap implementation
1 parent 7d869d2 commit 9a5d3b1

9 files changed

+52
-16
lines changed

utils/route_diag/src/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ static void do_one_route(const Netlist<>& net_list,
104104
is_flat);
105105

106106
ConnectionRouter<FourAryHeap> router(
107-
device_ctx.grid,
108-
*router_lookahead,
107+
device_ctx.grid,
108+
*router_lookahead,
109109
device_ctx.rr_graph.rr_nodes(),
110110
&device_ctx.rr_graph,
111111
device_ctx.rr_rc_data,

vpr/src/base/ShowSetup.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,9 @@ static void ShowRouterOpts(const t_router_opts& RouterOpts) {
410410
case e_heap_type::BINARY_HEAP:
411411
VTR_LOG("BINARY_HEAP\n");
412412
break;
413+
case e_heap_type::FOUR_ARY_HEAP:
414+
VTR_LOG("FOUR_ARY_HEAP\n");
415+
break;
413416
case e_heap_type::BUCKET_HEAP_APPROXIMATION:
414417
VTR_LOG("BUCKET_HEAP_APPROXIMATION\n");
415418
break;
@@ -553,6 +556,9 @@ static void ShowRouterOpts(const t_router_opts& RouterOpts) {
553556
case e_heap_type::BINARY_HEAP:
554557
VTR_LOG("BINARY_HEAP\n");
555558
break;
559+
case e_heap_type::FOUR_ARY_HEAP:
560+
VTR_LOG("FOUR_ARY_HEAP:\n");
561+
break;
556562
case e_heap_type::BUCKET_HEAP_APPROXIMATION:
557563
VTR_LOG("BUCKET_HEAP_APPROXIMATION\n");
558564
break;

vpr/src/base/read_options.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,6 +1061,8 @@ struct ParseRouterHeap {
10611061
ConvertedValue<e_heap_type> conv_value;
10621062
if (str == "binary")
10631063
conv_value.set_value(e_heap_type::BINARY_HEAP);
1064+
else if (str == "four_ary")
1065+
conv_value.set_value(e_heap_type::FOUR_ARY_HEAP);
10641066
else if (str == "bucket")
10651067
conv_value.set_value(e_heap_type::BUCKET_HEAP_APPROXIMATION);
10661068
else {
@@ -1075,6 +1077,8 @@ struct ParseRouterHeap {
10751077
ConvertedValue<std::string> conv_value;
10761078
if (val == e_heap_type::BINARY_HEAP)
10771079
conv_value.set_value("binary");
1080+
else if (val == e_heap_type::FOUR_ARY_HEAP)
1081+
conv_value.set_value("four_ary");
10781082
else {
10791083
VTR_ASSERT(val == e_heap_type::BUCKET_HEAP_APPROXIMATION);
10801084
conv_value.set_value("bucket");
@@ -1083,7 +1087,7 @@ struct ParseRouterHeap {
10831087
}
10841088

10851089
std::vector<std::string> default_choices() {
1086-
return {"binary", "bucket"};
1090+
return {"binary", "four_ary", "bucket"};
10871091
}
10881092
};
10891093

@@ -2648,11 +2652,12 @@ argparse::ArgumentParser create_arg_parser(const std::string& prog_name, t_optio
26482652
.help(
26492653
"Controls what type of heap to use for timing driven router.\n"
26502654
" * binary: A binary heap is used.\n"
2655+
" * four_ary: A four_ary heap is used.\n"
26512656
" * bucket: A bucket heap approximation is used. The bucket heap\n"
26522657
" * is faster because it is only a heap approximation.\n"
26532658
" * Testing has shown the approximation results in\n"
2654-
" * similiar QoR with less CPU work.\n")
2655-
.default_value("binary")
2659+
" * similar QoR with less CPU work.\n")
2660+
.default_value("four_ary")
26562661
.show_in(argparse::ShowIn::HELP_ONLY);
26572662

26582663
route_timing_grp.add_argument(args.router_first_iteration_timing_report_file, "--router_first_iter_timing_report")

vpr/src/route/binary_heap.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
static inline size_t left(size_t i) { return i << 1; }
66
static inline size_t right(size_t i) { return (i << 1) + 1; }
77

8-
size_t BinaryHeap::parent(size_t i) const { return i >> 1; }
8+
inline size_t BinaryHeap::parent(size_t i) const { return i >> 1; }
99

1010
bool BinaryHeap::is_valid() const {
1111
if (heap_.empty()) {

vpr/src/route/connection_router.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "connection_router.h"
22
#include "rr_graph.h"
33

4+
#include "binary_heap.h"
45
#include "four_ary_heap.h"
56
#include "bucket.h"
67
#include "rr_graph_fwd.h"
@@ -1155,6 +1156,16 @@ std::unique_ptr<ConnectionRouterInterface> make_connection_router(e_heap_type he
11551156
bool is_flat) {
11561157
switch (heap_type) {
11571158
case e_heap_type::BINARY_HEAP:
1159+
return std::make_unique<ConnectionRouter<BinaryHeap>>(
1160+
grid,
1161+
router_lookahead,
1162+
rr_nodes,
1163+
rr_graph,
1164+
rr_rc_data,
1165+
rr_switch_inf,
1166+
rr_node_route_inf,
1167+
is_flat);
1168+
case e_heap_type::FOUR_ARY_HEAP:
11581169
return std::make_unique<ConnectionRouter<FourAryHeap>>(
11591170
grid,
11601171
router_lookahead,

vpr/src/route/four_ary_heap.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33

44
static inline size_t first_child(size_t i) { return (i << 2) - 2; }
55

6-
size_t FourAryHeap::parent(size_t i) const { return (i + 2) >> 2; }
6+
inline size_t FourAryHeap::parent(size_t i) const { return (i + 2) >> 2; }
77

8-
size_t FourAryHeap::smallest_child(size_t i) const {
9-
// Returns heap_tail_ if i has no children
8+
inline size_t FourAryHeap::smallest_child(size_t i) const {
9+
// Returns first_child(i) if i has no children
1010

1111
size_t child_1 = first_child(i);
1212
size_t child_2 = child_1 + 1;
@@ -27,10 +27,8 @@ size_t FourAryHeap::smallest_child(size_t i) const {
2727
}
2828
case 2:
2929
return (heap_[child_1].cost < heap_[child_2].cost) ? child_1 : child_2;
30-
case 1:
31-
return child_1;
3230
default:
33-
return heap_tail_;
31+
return child_1;
3432
}
3533
}
3634

@@ -75,9 +73,11 @@ t_heap* FourAryHeap::get_heap_head() {
7573
--heap_tail_;
7674

7775
while (child < heap_tail_) {
76+
child = smallest_child(hole);
77+
7878
heap_[hole] = heap_[child];
7979
hole = child;
80-
child = smallest_child(child);
80+
child = first_child(hole);
8181
}
8282

8383
sift_up(hole, heap_[heap_tail_]);
@@ -89,14 +89,13 @@ t_heap* FourAryHeap::get_heap_head() {
8989
// make a heap rooted at index hole by **sifting down** in O(lgn) time
9090
void FourAryHeap::sift_down(size_t hole) {
9191
heap_elem head{heap_[hole]};
92-
9392
size_t child{smallest_child(hole)};
9493

9594
while (child < heap_tail_) {
9695
if (heap_[child].cost < head.cost) {
9796
heap_[hole] = heap_[child];
9897
hole = child;
99-
child = smallest_child(child);
98+
child = smallest_child(hole);
10099
} else
101100
break;
102101
}

vpr/src/route/k_ary_heap.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ size_t KAryHeap::size() const { return heap_tail_ - 1; } // heap[0] is not valid
6262
// runs in O(n) time by sifting down; the least work is done on the most elements: 1 swap for bottom layer, 2 swap for 2nd, ... lgn swap for top
6363
// 1*(n/2) + 2*(n/4) + 3*(n/8) + ... + lgn*1 = 2n (sum of i/2^i)
6464
void KAryHeap::build_heap() {
65-
// second half of heap are leaves
6665
for (size_t i = parent(heap_tail_); i != 0; --i)
6766
sift_down(i);
6867
}

vpr/src/route/netlist_routers.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
* of this interface. */
1717

1818
#include "NetPinTimingInvalidator.h"
19+
#include "binary_heap.h"
1920
#include "four_ary_heap.h"
2021
#include "bucket.h"
2122
#include "clustered_netlist_utils.h"
@@ -154,6 +155,20 @@ inline std::unique_ptr<NetlistRouter> make_netlist_router(
154155
const vtr::vector<ParentNetId, std::vector<std::unordered_map<RRNodeId, int>>>& choking_spots,
155156
bool is_flat) {
156157
if (router_opts.router_heap == e_heap_type::BINARY_HEAP) {
158+
return make_netlist_router_with_heap<BinaryHeap>(
159+
net_list,
160+
router_lookahead,
161+
router_opts,
162+
connections_inf,
163+
net_delay,
164+
netlist_pin_lookup,
165+
timing_info,
166+
pin_timing_invalidator,
167+
budgeting_inf,
168+
routing_predictor,
169+
choking_spots,
170+
is_flat);
171+
} else if (router_opts.router_heap == e_heap_type::FOUR_ARY_HEAP) {
157172
return make_netlist_router_with_heap<FourAryHeap>(
158173
net_list,
159174
router_lookahead,

vpr/src/route/router_delay_profiling.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define ROUTER_DELAY_PROFILING_H_
33

44
#include "vpr_types.h"
5+
#include "binary_heap.h"
56
#include "four_ary_heap.h"
67
#include "connection_router.h"
78

0 commit comments

Comments
 (0)