Skip to content

Commit 3e53a93

Browse files
authored
Merge pull request #2721 from verilog-to-routing/update_wire_cost_map
Update Wire Cost Map
2 parents 8dd5a3b + aaca726 commit 3e53a93

File tree

4 files changed

+56
-55
lines changed

4 files changed

+56
-55
lines changed

vpr/src/route/router_lookahead_map.cpp

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -478,12 +478,13 @@ static util::Cost_Entry get_wire_cost_entry(e_rr_type rr_type, int seg_index, in
478478
chan_index = 1;
479479
}
480480

481-
VTR_ASSERT_SAFE(from_layer_num < (int)f_wire_cost_map.dim_size(0));
482-
VTR_ASSERT_SAFE(to_layer_num < (int)f_wire_cost_map.dim_size(3));
483-
VTR_ASSERT_SAFE(delta_x < (int)f_wire_cost_map.dim_size(4));
484-
VTR_ASSERT_SAFE(delta_y < (int)f_wire_cost_map.dim_size(5));
481+
VTR_ASSERT_SAFE(from_layer_num < static_cast<int>(f_wire_cost_map.dim_size(0)));
482+
VTR_ASSERT_SAFE(to_layer_num < static_cast<int>(f_wire_cost_map.dim_size(1)));
483+
VTR_ASSERT_SAFE(seg_index < static_cast<int>(f_wire_cost_map.dim_size(3)));
484+
VTR_ASSERT_SAFE(delta_x < static_cast<int>(f_wire_cost_map.dim_size(4)));
485+
VTR_ASSERT_SAFE(delta_y < static_cast<int>(f_wire_cost_map.dim_size(5)));
485486

486-
return f_wire_cost_map[from_layer_num][chan_index][seg_index][to_layer_num][delta_x][delta_y];
487+
return f_wire_cost_map[from_layer_num][to_layer_num][chan_index][seg_index][delta_x][delta_y];
487488
}
488489

489490
static void compute_router_wire_lookahead(const std::vector<t_segment_inf>& segment_inf_vec) {
@@ -494,12 +495,12 @@ static void compute_router_wire_lookahead(const std::vector<t_segment_inf>& segm
494495
auto& grid = device_ctx.grid;
495496

496497
//Re-allocate
497-
f_wire_cost_map = t_wire_cost_map({static_cast<unsigned long>(grid.get_num_layers()),
498-
2,
499-
segment_inf_vec.size(),
500-
static_cast<unsigned long>(grid.get_num_layers()),
501-
device_ctx.grid.width(),
502-
device_ctx.grid.height()});
498+
f_wire_cost_map = t_wire_cost_map({static_cast<unsigned long>(grid.get_num_layers()),
499+
static_cast<unsigned long>(grid.get_num_layers()),
500+
2,
501+
segment_inf_vec.size(),
502+
device_ctx.grid.width(),
503+
device_ctx.grid.height()});
503504

504505
int longest_seg_length = 0;
505506
for (const auto& seg_inf : segment_inf_vec) {
@@ -550,7 +551,7 @@ static void set_lookahead_map_costs(int from_layer_num, int segment_index, e_rr_
550551
for (unsigned iy = 0; iy < routing_cost_map.dim_size(2); iy++) {
551552
util::Expansion_Cost_Entry& expansion_cost_entry = routing_cost_map[to_layer][ix][iy];
552553

553-
f_wire_cost_map[from_layer_num][chan_index][segment_index][to_layer][ix][iy] = expansion_cost_entry.get_representative_cost_entry(util::e_representative_entry_method::SMALLEST);
554+
f_wire_cost_map[from_layer_num][to_layer][chan_index][segment_index][ix][iy] = expansion_cost_entry.get_representative_cost_entry(util::e_representative_entry_method::SMALLEST);
554555
}
555556
}
556557
}
@@ -567,7 +568,7 @@ static void fill_in_missing_lookahead_entries(int segment_index, e_rr_type chan_
567568
for (int to_layer_num = 0; to_layer_num < device_ctx.grid.get_num_layers(); ++to_layer_num) {
568569
for (unsigned ix = 0; ix < device_ctx.grid.width(); ix++) {
569570
for (unsigned iy = 0; iy < device_ctx.grid.height(); iy++) {
570-
util::Cost_Entry cost_entry = f_wire_cost_map[from_layer_num][chan_index][segment_index][to_layer_num][ix][iy];
571+
util::Cost_Entry cost_entry = f_wire_cost_map[from_layer_num][to_layer_num][chan_index][segment_index][ix][iy];
571572

572573
if (std::isnan(cost_entry.delay) && std::isnan(cost_entry.congestion)) {
573574
util::Cost_Entry copied_entry = get_nearby_cost_entry_average_neighbour(from_layer_num,
@@ -576,7 +577,7 @@ static void fill_in_missing_lookahead_entries(int segment_index, e_rr_type chan_
576577
to_layer_num,
577578
segment_index,
578579
chan_index);
579-
f_wire_cost_map[from_layer_num][chan_index][segment_index][to_layer_num][ix][iy] = copied_entry;
580+
f_wire_cost_map[from_layer_num][to_layer_num][chan_index][segment_index][ix][iy] = copied_entry;
580581
}
581582
}
582583
}
@@ -612,7 +613,7 @@ static util::Cost_Entry get_nearby_cost_entry(int from_layer_num, int x, int y,
612613
copy_y = std::max(copy_y, 0); //Clip to zero
613614
copy_x = std::max(copy_x, 0); //Clip to zero
614615

615-
util::Cost_Entry copy_entry = f_wire_cost_map[from_layer_num][chan_index][segment_index][to_layer_num][copy_x][copy_y];
616+
util::Cost_Entry copy_entry = f_wire_cost_map[from_layer_num][to_layer_num][chan_index][segment_index][copy_x][copy_y];
616617

617618
/* if the entry to be copied is also empty, recurse */
618619
if (std::isnan(copy_entry.delay) && std::isnan(copy_entry.congestion)) {
@@ -640,8 +641,8 @@ static util::Cost_Entry get_nearby_cost_entry_average_neighbour(int from_layer_n
640641
int segment_index,
641642
int chan_index) {
642643
// Make sure that the given location doesn't have a valid entry
643-
VTR_ASSERT(std::isnan(f_wire_cost_map[from_layer_num][chan_index][segment_index][to_layer_num][missing_dx][missing_dy].delay));
644-
VTR_ASSERT(std::isnan(f_wire_cost_map[from_layer_num][chan_index][segment_index][to_layer_num][missing_dx][missing_dy].congestion));
644+
VTR_ASSERT(std::isnan(f_wire_cost_map[from_layer_num][to_layer_num][chan_index][segment_index][missing_dx][missing_dy].delay));
645+
VTR_ASSERT(std::isnan(f_wire_cost_map[from_layer_num][to_layer_num][chan_index][segment_index][missing_dx][missing_dy].congestion));
645646

646647
int neighbour_num = 0; // Number of neighbours with valid entry
647648
float neighbour_delay_sum = 0; // Acc of valid delay costs
@@ -657,7 +658,7 @@ static util::Cost_Entry get_nearby_cost_entry_average_neighbour(int from_layer_n
657658
if (neighbour_y < 0 || neighbour_y >= (int)f_wire_cost_map.dim_size(5)) {
658659
continue;
659660
}
660-
util::Cost_Entry copy_entry = f_wire_cost_map[from_layer_num][chan_index][segment_index][to_layer_num][neighbour_x][neighbour_y];
661+
util::Cost_Entry copy_entry = f_wire_cost_map[from_layer_num][to_layer_num][chan_index][segment_index][neighbour_x][neighbour_y];
661662
if (std::isnan(copy_entry.delay) || std::isnan(copy_entry.congestion)) {
662663
continue;
663664
}
@@ -779,10 +780,10 @@ static void min_chann_global_cost_map(vtr::NdMatrix<util::Cost_Entry, 4>& distan
779780
for (int dx = 0; dx < width; dx++) {
780781
for (int dy = 0; dy < height; dy++) {
781782
util::Cost_Entry min_cost(std::numeric_limits<float>::max(), std::numeric_limits<float>::max());
782-
for (int chan_idx = 0; chan_idx < (int)f_wire_cost_map.dim_size(1); chan_idx++) {
783-
for (int seg_idx = 0; seg_idx < (int)f_wire_cost_map.dim_size(2); seg_idx++) {
784-
auto cost = util::Cost_Entry(f_wire_cost_map[from_layer_num][chan_idx][seg_idx][to_layer_num][dx][dy].delay,
785-
f_wire_cost_map[from_layer_num][chan_idx][seg_idx][to_layer_num][dx][dy].congestion);
783+
for (int chan_idx = 0; chan_idx < (int)f_wire_cost_map.dim_size(2); chan_idx++) {
784+
for (int seg_idx = 0; seg_idx < (int)f_wire_cost_map.dim_size(3); seg_idx++) {
785+
auto cost = util::Cost_Entry(f_wire_cost_map[from_layer_num][to_layer_num][chan_idx][seg_idx][dx][dy].delay,
786+
f_wire_cost_map[from_layer_num][to_layer_num][chan_idx][seg_idx][dx][dy].congestion);
786787
if (cost.delay < min_cost.delay) {
787788
min_cost.delay = cost.delay;
788789
min_cost.congestion = cost.congestion;

vpr/src/route/router_lookahead_map.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,12 @@ class MapLookahead : public RouterLookahead {
4444
/* provides delay/congestion estimates to travel specified distances
4545
* in the x/y direction */
4646
// This is a 6D array storing the cost to travel from a node of type CHANX/CHANY to a point that is dx, dy further, and is on the "layer_num" layer.
47-
// To store this information, the first index is the layer number that the node under consideration is on, the second index represents the type of channel (X/Y)
48-
// that the node under consideration belongs to, the third is the segment type (specified in the architecture file under the "segmentlist" tag), the fourth is the
47+
// To store this information, the first index is the layer number that the node under consideration is on, the second index is the layer number of the target node, the third index represents the type of channel (X/Y)
48+
// that the node under consideration belongs to, the forth is the segment type (specified in the architecture file under the "segmentlist" tag), the fourth is the
4949
// target "layer_num" mentioned above, the fifth is dx, and the last one is dy.
50-
typedef vtr::NdMatrix<util::Cost_Entry, 6> t_wire_cost_map; //[0..num_layers][0..1][[0..num_seg_types-1][0..num_layers][0..device_ctx.grid.width()-1][0..device_ctx.grid.height()-1]
50+
typedef vtr::NdMatrix<util::Cost_Entry, 6> t_wire_cost_map; //[0..num_layers][0..num_layers][0..1][[0..num_seg_types-1][0..device_ctx.grid.width()-1][0..device_ctx.grid.height()-1]
5151
//[0..1] entry distinguish between CHANX/CHANY start nodes respectively
52-
// The first index is the layer number that the node under consideration is on, and the forth index
52+
// The first index is the layer number that the node under consideration is on, and the second index
5353
// is the layer number that the target node is on.
5454

5555
void read_router_lookahead(const std::string& file);

vpr/src/route/router_lookahead_map_utils.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -893,30 +893,30 @@ void dump_readable_router_lookahead_map(const std::string& file_name, const std:
893893
}
894894

895895
VTR_ASSERT(dim_sizes[0] == num_layers);
896-
VTR_ASSERT(dim_sizes[1] == 2);
897-
VTR_ASSERT(dim_sizes[3] == num_layers);
896+
VTR_ASSERT(dim_sizes[1] == num_layers);
897+
VTR_ASSERT(dim_sizes[2] == 2);
898898
VTR_ASSERT(dim_sizes.size() == 5 || (dim_sizes.size() == 6 && dim_sizes[4] == grid_width && dim_sizes[5] == grid_height));
899899

900900
ofs << "from_layer,"
901+
"to_layer,"
901902
"chan_type,"
902903
"seg_type,"
903-
"to_layer,"
904904
"delta_x,"
905905
"delta_y,"
906906
"cong_cost,"
907907
"delay_cost\n";
908908

909909
for (int from_layer_num = 0; from_layer_num < num_layers; from_layer_num++) {
910-
for (e_rr_type chan_type : {CHANX, CHANY}) {
911-
for (int seg_index = 0; seg_index < dim_sizes[2]; seg_index++) {
912-
for (int to_layer_num = 0; to_layer_num < num_layers; to_layer_num++) {
910+
for (int to_layer_num = 0; to_layer_num < num_layers; to_layer_num++) {
911+
for (e_rr_type chan_type : {CHANX, CHANY}) {
912+
for (int seg_index = 0; seg_index < dim_sizes[3]; seg_index++) {
913913
for (int dx = 0; dx < grid_width; dx++) {
914914
for (int dy = 0; dy < grid_height; dy++) {
915915
auto cost = wire_cost_func(chan_type, seg_index, from_layer_num, dx, dy, to_layer_num);
916916
ofs << from_layer_num << ","
917+
<< to_layer_num << ","
917918
<< rr_node_typename[chan_type] << ","
918919
<< seg_index << ","
919-
<< to_layer_num << ","
920920
<< dx << ","
921921
<< dy << ","
922922
<< cost.congestion << ","

vpr/test/test_map_lookahead_serdes.cpp

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,17 @@ static constexpr const char kMapLookaheadBin[] = "test_map_lookahead.bin";
1111

1212
TEST_CASE("round_trip_map_lookahead", "[vpr]") {
1313
constexpr size_t num_layers = 1;
14-
constexpr std::array<size_t, 6> kDim({num_layers, 10, 12, num_layers, 15, 16});
14+
constexpr std::array<size_t, 6> kDim({num_layers, num_layers, 10, 12, 15, 16});
1515

1616
f_wire_cost_map.resize(kDim);
1717
for (size_t from_layer = 0; from_layer < kDim[0]; from_layer++) {
18-
for (size_t x = 0; x < kDim[1]; ++x) {
19-
for (size_t y = 0; y < kDim[2]; ++y) {
20-
for (size_t to_layer = 0; to_layer < kDim[3]; to_layer++) {
21-
for (size_t z = 0; z < kDim[4]; ++z) {
22-
for (size_t w = 0; w < kDim[5]; ++w) {
23-
f_wire_cost_map[from_layer][x][y][to_layer][z][w].delay = (x + 1) * (y + 1) * (z + 1) * (w + 1);
24-
f_wire_cost_map[from_layer][x][y][to_layer][z][w].congestion = 2 * (x + 1) * (y + 1) * (z + 1) * (w + 1);
18+
for (size_t to_layer = 0; to_layer < kDim[1]; to_layer++) {
19+
for (size_t z = 0; z < kDim[2]; ++z) {
20+
for (size_t w = 0; w < kDim[3]; ++w) {
21+
for (size_t x = 0; x < kDim[4]; ++x) {
22+
for (size_t y = 0; y < kDim[5]; ++y) {
23+
f_wire_cost_map[from_layer][to_layer][z][w][x][y].delay = (x + 1) * (y + 1) * (z + 1) * (w + 1);
24+
f_wire_cost_map[from_layer][to_layer][z][w][x][y].congestion = 2 * (x + 1) * (y + 1) * (z + 1) * (w + 1);
2525
}
2626
}
2727
}
@@ -32,13 +32,13 @@ TEST_CASE("round_trip_map_lookahead", "[vpr]") {
3232
write_router_lookahead(kMapLookaheadBin);
3333

3434
for (size_t from_layer = 0; from_layer < kDim[0]; from_layer++) {
35-
for (size_t x = 0; x < kDim[1]; ++x) {
36-
for (size_t y = 0; y < kDim[2]; ++y) {
37-
for (size_t to_layer = 0; to_layer < kDim[3]; to_layer++) {
38-
for (size_t z = 0; z < kDim[4]; ++z) {
39-
for (size_t w = 0; w < kDim[5]; ++w) {
40-
f_wire_cost_map[from_layer][x][y][to_layer][z][w].delay = 0.f;
41-
f_wire_cost_map[from_layer][x][y][to_layer][z][w].congestion = 0.f;
35+
for (size_t to_layer = 0; to_layer < kDim[1]; to_layer++) {
36+
for (size_t z = 0; z < kDim[2]; ++z) {
37+
for (size_t w = 0; w < kDim[3]; ++w) {
38+
for (size_t x = 0; x < kDim[4]; ++x) {
39+
for (size_t y = 0; y < kDim[5]; ++y) {
40+
f_wire_cost_map[from_layer][to_layer][z][w][x][y].delay = 0.f;
41+
f_wire_cost_map[from_layer][to_layer][z][w][x][y].congestion = 0.f;
4242
}
4343
}
4444
}
@@ -55,13 +55,13 @@ TEST_CASE("round_trip_map_lookahead", "[vpr]") {
5555
}
5656

5757
for (size_t from_layer = 0; from_layer < kDim[0]; from_layer++) {
58-
for (size_t x = 0; x < kDim[1]; ++x) {
59-
for (size_t y = 0; y < kDim[2]; ++y) {
60-
for (size_t to_layer = 0; to_layer < kDim[3]; to_layer++) {
61-
for (size_t z = 0; z < kDim[4]; ++z) {
62-
for (size_t w = 0; w < kDim[5]; ++w) {
63-
REQUIRE(f_wire_cost_map[from_layer][x][y][to_layer][z][w].delay == (x + 1) * (y + 1) * (z + 1) * (w + 1));
64-
REQUIRE(f_wire_cost_map[from_layer][x][y][to_layer][z][w].congestion == 2 * (x + 1) * (y + 1) * (z + 1) * (w + 1));
58+
for (size_t to_layer = 0; to_layer < kDim[1]; to_layer++) {
59+
for (size_t z = 0; z < kDim[2]; ++z) {
60+
for (size_t w = 0; w < kDim[3]; ++w) {
61+
for (size_t x = 0; x < kDim[4]; ++x) {
62+
for (size_t y = 0; y < kDim[5]; ++y) {
63+
REQUIRE(f_wire_cost_map[from_layer][to_layer][z][w][x][y].delay == (x + 1) * (y + 1) * (z + 1) * (w + 1));
64+
REQUIRE(f_wire_cost_map[from_layer][to_layer][z][w][x][y].congestion == 2 * (x + 1) * (y + 1) * (z + 1) * (w + 1));
6565
}
6666
}
6767
}

0 commit comments

Comments
 (0)