From 8c61356566ca3aeb363999781b8bc9191ec82d2e Mon Sep 17 00:00:00 2001 From: amin1377 Date: Thu, 12 Sep 2024 18:36:14 -0400 Subject: [PATCH 1/5] [vpr][route][lookahead] fix comment to show that the second index in wire_cost_map index is target layer --- vpr/src/route/router_lookahead_map.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vpr/src/route/router_lookahead_map.h b/vpr/src/route/router_lookahead_map.h index a8617b30643..34dc851ede0 100644 --- a/vpr/src/route/router_lookahead_map.h +++ b/vpr/src/route/router_lookahead_map.h @@ -47,9 +47,9 @@ class MapLookahead : public RouterLookahead { // 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) // 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 // target "layer_num" mentioned above, the fifth is dx, and the last one is dy. -typedef vtr::NdMatrix 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] +typedef vtr::NdMatrix 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] //[0..1] entry distinguish between CHANX/CHANY start nodes respectively - // The first index is the layer number that the node under consideration is on, and the forth index + // The first index is the layer number that the node under consideration is on, and the second index // is the layer number that the target node is on. void read_router_lookahead(const std::string& file); From de5790c65872ad6a2664799d8a233d2dfe25255a Mon Sep 17 00:00:00 2001 From: amin1377 Date: Thu, 12 Sep 2024 18:39:40 -0400 Subject: [PATCH 2/5] [vpr][route][lookahead] use the second index of the 3d wire cost map for target layer --- vpr/src/route/router_lookahead_map.cpp | 45 +++++++++++++------------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/vpr/src/route/router_lookahead_map.cpp b/vpr/src/route/router_lookahead_map.cpp index 9e7061b4dc6..80cac91ee16 100644 --- a/vpr/src/route/router_lookahead_map.cpp +++ b/vpr/src/route/router_lookahead_map.cpp @@ -478,12 +478,13 @@ static util::Cost_Entry get_wire_cost_entry(e_rr_type rr_type, int seg_index, in chan_index = 1; } - VTR_ASSERT_SAFE(from_layer_num < (int)f_wire_cost_map.dim_size(0)); - VTR_ASSERT_SAFE(to_layer_num < (int)f_wire_cost_map.dim_size(3)); - VTR_ASSERT_SAFE(delta_x < (int)f_wire_cost_map.dim_size(4)); - VTR_ASSERT_SAFE(delta_y < (int)f_wire_cost_map.dim_size(5)); + VTR_ASSERT_SAFE(from_layer_num < static_cast(f_wire_cost_map.dim_size(0))); + VTR_ASSERT_SAFE(to_layer_num < static_cast(f_wire_cost_map.dim_size(1))); + VTR_ASSERT_SAFE(seg_index < static_cast(f_wire_cost_map.dim_size(3))); + VTR_ASSERT_SAFE(delta_x < static_cast(f_wire_cost_map.dim_size(4))); + VTR_ASSERT_SAFE(delta_y < static_cast(f_wire_cost_map.dim_size(5))); - return f_wire_cost_map[from_layer_num][chan_index][seg_index][to_layer_num][delta_x][delta_y]; + return f_wire_cost_map[from_layer_num][to_layer_num][chan_index][seg_index][delta_x][delta_y]; } static void compute_router_wire_lookahead(const std::vector& segment_inf_vec) { @@ -494,12 +495,12 @@ static void compute_router_wire_lookahead(const std::vector& segm auto& grid = device_ctx.grid; //Re-allocate - f_wire_cost_map = t_wire_cost_map({static_cast(grid.get_num_layers()), - 2, - segment_inf_vec.size(), - static_cast(grid.get_num_layers()), - device_ctx.grid.width(), - device_ctx.grid.height()}); + f_wire_cost_map = t_wire_cost_map({static_cast(grid.get_num_layers()), + static_cast(grid.get_num_layers()), + 2, + segment_inf_vec.size(), + device_ctx.grid.width(), + device_ctx.grid.height()}); int longest_seg_length = 0; 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_ for (unsigned iy = 0; iy < routing_cost_map.dim_size(2); iy++) { util::Expansion_Cost_Entry& expansion_cost_entry = routing_cost_map[to_layer][ix][iy]; - 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); + 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); } } } @@ -567,7 +568,7 @@ static void fill_in_missing_lookahead_entries(int segment_index, e_rr_type chan_ for (int to_layer_num = 0; to_layer_num < device_ctx.grid.get_num_layers(); ++to_layer_num) { for (unsigned ix = 0; ix < device_ctx.grid.width(); ix++) { for (unsigned iy = 0; iy < device_ctx.grid.height(); iy++) { - util::Cost_Entry cost_entry = f_wire_cost_map[from_layer_num][chan_index][segment_index][to_layer_num][ix][iy]; + util::Cost_Entry cost_entry = f_wire_cost_map[from_layer_num][to_layer_num][chan_index][segment_index][ix][iy]; if (std::isnan(cost_entry.delay) && std::isnan(cost_entry.congestion)) { 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_ to_layer_num, segment_index, chan_index); - f_wire_cost_map[from_layer_num][chan_index][segment_index][to_layer_num][ix][iy] = copied_entry; + f_wire_cost_map[from_layer_num][to_layer_num][chan_index][segment_index][ix][iy] = copied_entry; } } } @@ -612,7 +613,7 @@ static util::Cost_Entry get_nearby_cost_entry(int from_layer_num, int x, int y, copy_y = std::max(copy_y, 0); //Clip to zero copy_x = std::max(copy_x, 0); //Clip to zero - util::Cost_Entry copy_entry = f_wire_cost_map[from_layer_num][chan_index][segment_index][to_layer_num][copy_x][copy_y]; + util::Cost_Entry copy_entry = f_wire_cost_map[from_layer_num][to_layer_num][chan_index][segment_index][copy_x][copy_y]; /* if the entry to be copied is also empty, recurse */ 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 int segment_index, int chan_index) { // Make sure that the given location doesn't have a valid entry - VTR_ASSERT(std::isnan(f_wire_cost_map[from_layer_num][chan_index][segment_index][to_layer_num][missing_dx][missing_dy].delay)); - VTR_ASSERT(std::isnan(f_wire_cost_map[from_layer_num][chan_index][segment_index][to_layer_num][missing_dx][missing_dy].congestion)); + VTR_ASSERT(std::isnan(f_wire_cost_map[from_layer_num][to_layer_num][chan_index][segment_index][missing_dx][missing_dy].delay)); + VTR_ASSERT(std::isnan(f_wire_cost_map[from_layer_num][to_layer_num][chan_index][segment_index][missing_dx][missing_dy].congestion)); int neighbour_num = 0; // Number of neighbours with valid entry 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 if (neighbour_y < 0 || neighbour_y >= (int)f_wire_cost_map.dim_size(5)) { continue; } - util::Cost_Entry copy_entry = f_wire_cost_map[from_layer_num][chan_index][segment_index][to_layer_num][neighbour_x][neighbour_y]; + util::Cost_Entry copy_entry = f_wire_cost_map[from_layer_num][to_layer_num][chan_index][segment_index][neighbour_x][neighbour_y]; if (std::isnan(copy_entry.delay) || std::isnan(copy_entry.congestion)) { continue; } @@ -779,10 +780,10 @@ static void min_chann_global_cost_map(vtr::NdMatrix& distan for (int dx = 0; dx < width; dx++) { for (int dy = 0; dy < height; dy++) { util::Cost_Entry min_cost(std::numeric_limits::max(), std::numeric_limits::max()); - for (int chan_idx = 0; chan_idx < (int)f_wire_cost_map.dim_size(1); chan_idx++) { - for (int seg_idx = 0; seg_idx < (int)f_wire_cost_map.dim_size(2); seg_idx++) { - auto cost = util::Cost_Entry(f_wire_cost_map[from_layer_num][chan_idx][seg_idx][to_layer_num][dx][dy].delay, - f_wire_cost_map[from_layer_num][chan_idx][seg_idx][to_layer_num][dx][dy].congestion); + for (int chan_idx = 0; chan_idx < (int)f_wire_cost_map.dim_size(2); chan_idx++) { + for (int seg_idx = 0; seg_idx < (int)f_wire_cost_map.dim_size(3); seg_idx++) { + auto cost = util::Cost_Entry(f_wire_cost_map[from_layer_num][to_layer_num][chan_idx][seg_idx][dx][dy].delay, + f_wire_cost_map[from_layer_num][to_layer_num][chan_idx][seg_idx][dx][dy].congestion); if (cost.delay < min_cost.delay) { min_cost.delay = cost.delay; min_cost.congestion = cost.congestion; From be3aeed5dab3d240978e9a483d3005d7d56d31f7 Mon Sep 17 00:00:00 2001 From: amin1377 Date: Thu, 12 Sep 2024 18:57:21 -0400 Subject: [PATCH 3/5] [vpr][test] update router lookahead test with the new structre of f_wire_cost_map --- vpr/test/test_map_lookahead_serdes.cpp | 44 +++++++++++++------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/vpr/test/test_map_lookahead_serdes.cpp b/vpr/test/test_map_lookahead_serdes.cpp index a9095377df5..499326e2eb9 100644 --- a/vpr/test/test_map_lookahead_serdes.cpp +++ b/vpr/test/test_map_lookahead_serdes.cpp @@ -11,17 +11,17 @@ static constexpr const char kMapLookaheadBin[] = "test_map_lookahead.bin"; TEST_CASE("round_trip_map_lookahead", "[vpr]") { constexpr size_t num_layers = 1; - constexpr std::array kDim({num_layers, 10, 12, num_layers, 15, 16}); + constexpr std::array kDim({num_layers, num_layers, 10, 12, 15, 16}); f_wire_cost_map.resize(kDim); for (size_t from_layer = 0; from_layer < kDim[0]; from_layer++) { - for (size_t x = 0; x < kDim[1]; ++x) { - for (size_t y = 0; y < kDim[2]; ++y) { - for (size_t to_layer = 0; to_layer < kDim[3]; to_layer++) { - for (size_t z = 0; z < kDim[4]; ++z) { - for (size_t w = 0; w < kDim[5]; ++w) { - f_wire_cost_map[from_layer][x][y][to_layer][z][w].delay = (x + 1) * (y + 1) * (z + 1) * (w + 1); - f_wire_cost_map[from_layer][x][y][to_layer][z][w].congestion = 2 * (x + 1) * (y + 1) * (z + 1) * (w + 1); + for (size_t to_layer = 0; to_layer < kDim[1]; to_layer++) { + for (size_t z = 0; z < kDim[2]; ++z) { + for (size_t w = 0; w < kDim[3]; ++w) { + for (size_t x = 0; x < kDim[4]; ++x) { + for (size_t y = 0; y < kDim[5]; ++y) { + f_wire_cost_map[from_layer][to_layer][z][w][x][y].delay = (x + 1) * (y + 1) * (z + 1) * (w + 1); + f_wire_cost_map[from_layer][to_layer][z][w][x][y].congestion = 2 * (x + 1) * (y + 1) * (z + 1) * (w + 1); } } } @@ -32,13 +32,13 @@ TEST_CASE("round_trip_map_lookahead", "[vpr]") { write_router_lookahead(kMapLookaheadBin); for (size_t from_layer = 0; from_layer < kDim[0]; from_layer++) { - for (size_t x = 0; x < kDim[1]; ++x) { - for (size_t y = 0; y < kDim[2]; ++y) { - for (size_t to_layer = 0; to_layer < kDim[3]; to_layer++) { - for (size_t z = 0; z < kDim[4]; ++z) { - for (size_t w = 0; w < kDim[5]; ++w) { - f_wire_cost_map[from_layer][x][y][to_layer][z][w].delay = 0.f; - f_wire_cost_map[from_layer][x][y][to_layer][z][w].congestion = 0.f; + for (size_t to_layer = 0; to_layer < kDim[1]; to_layer++) { + for (size_t z = 0; z < kDim[2]; ++z) { + for (size_t w = 0; w < kDim[3]; ++w) { + for (size_t x = 0; x < kDim[4]; ++x) { + for (size_t y = 0; y < kDim[5]; ++y) { + f_wire_cost_map[from_layer][to_layer][z][w][x][y].delay = 0.f; + f_wire_cost_map[from_layer][to_layer][z][w][x][y].congestion = 0.f; } } } @@ -55,13 +55,13 @@ TEST_CASE("round_trip_map_lookahead", "[vpr]") { } for (size_t from_layer = 0; from_layer < kDim[0]; from_layer++) { - for (size_t x = 0; x < kDim[1]; ++x) { - for (size_t y = 0; y < kDim[2]; ++y) { - for (size_t to_layer = 0; to_layer < kDim[3]; to_layer++) { - for (size_t z = 0; z < kDim[4]; ++z) { - for (size_t w = 0; w < kDim[5]; ++w) { - REQUIRE(f_wire_cost_map[from_layer][x][y][to_layer][z][w].delay == (x + 1) * (y + 1) * (z + 1) * (w + 1)); - REQUIRE(f_wire_cost_map[from_layer][x][y][to_layer][z][w].congestion == 2 * (x + 1) * (y + 1) * (z + 1) * (w + 1)); + for (size_t to_layer = 0; to_layer < kDim[1]; to_layer++) { + for (size_t z = 0; z < kDim[2]; ++z) { + for (size_t w = 0; w < kDim[3]; ++w) { + for (size_t x = 0; x < kDim[4]; ++x) { + for (size_t y = 0; y < kDim[5]; ++y) { + REQUIRE(f_wire_cost_map[from_layer][to_layer][z][w][x][y].delay == (x + 1) * (y + 1) * (z + 1) * (w + 1)); + REQUIRE(f_wire_cost_map[from_layer][to_layer][z][w][x][y].congestion == 2 * (x + 1) * (y + 1) * (z + 1) * (w + 1)); } } } From 8446d888a28ecfc27f737f6c9bfff62c2ce9b812 Mon Sep 17 00:00:00 2001 From: amin1377 Date: Thu, 12 Sep 2024 19:04:47 -0400 Subject: [PATCH 4/5] [vpr][route][lookahead] fix dump_lookahead --- vpr/src/route/router_lookahead_map_utils.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/vpr/src/route/router_lookahead_map_utils.cpp b/vpr/src/route/router_lookahead_map_utils.cpp index c48ee90e073..00c76c24afc 100644 --- a/vpr/src/route/router_lookahead_map_utils.cpp +++ b/vpr/src/route/router_lookahead_map_utils.cpp @@ -893,30 +893,30 @@ void dump_readable_router_lookahead_map(const std::string& file_name, const std: } VTR_ASSERT(dim_sizes[0] == num_layers); - VTR_ASSERT(dim_sizes[1] == 2); - VTR_ASSERT(dim_sizes[3] == num_layers); + VTR_ASSERT(dim_sizes[1] == num_layers); + VTR_ASSERT(dim_sizes[2] == 2); VTR_ASSERT(dim_sizes.size() == 5 || (dim_sizes.size() == 6 && dim_sizes[4] == grid_width && dim_sizes[5] == grid_height)); ofs << "from_layer," + "to_layer," "chan_type," "seg_type," - "to_layer," "delta_x," "delta_y," "cong_cost," "delay_cost\n"; for (int from_layer_num = 0; from_layer_num < num_layers; from_layer_num++) { - for (e_rr_type chan_type : {CHANX, CHANY}) { - for (int seg_index = 0; seg_index < dim_sizes[2]; seg_index++) { - for (int to_layer_num = 0; to_layer_num < num_layers; to_layer_num++) { + for (int to_layer_num = 0; to_layer_num < num_layers; to_layer_num++) { + for (e_rr_type chan_type : {CHANX, CHANY}) { + for (int seg_index = 0; seg_index < dim_sizes[3]; seg_index++) { for (int dx = 0; dx < grid_width; dx++) { for (int dy = 0; dy < grid_height; dy++) { auto cost = wire_cost_func(chan_type, seg_index, from_layer_num, dx, dy, to_layer_num); ofs << from_layer_num << "," + << to_layer_num << "," << rr_node_typename[chan_type] << "," << seg_index << "," - << to_layer_num << "," << dx << "," << dy << "," << cost.congestion << "," From ce1ce1b6528fdfbf2eba0510024bf8916b06de83 Mon Sep 17 00:00:00 2001 From: amin1377 Date: Wed, 25 Sep 2024 17:28:18 -0400 Subject: [PATCH 5/5] [vpr][route] fix comment --- vpr/src/route/router_lookahead_map.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vpr/src/route/router_lookahead_map.h b/vpr/src/route/router_lookahead_map.h index 34dc851ede0..29293020078 100644 --- a/vpr/src/route/router_lookahead_map.h +++ b/vpr/src/route/router_lookahead_map.h @@ -44,8 +44,8 @@ class MapLookahead : public RouterLookahead { /* provides delay/congestion estimates to travel specified distances * in the x/y direction */ // 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. -// 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) -// 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 +// 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) +// 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 // target "layer_num" mentioned above, the fifth is dx, and the last one is dy. typedef vtr::NdMatrix 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] //[0..1] entry distinguish between CHANX/CHANY start nodes respectively