Skip to content

Update Wire Cost Map #2721

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 23 additions & 22 deletions vpr/src/route/router_lookahead_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>(f_wire_cost_map.dim_size(0)));
VTR_ASSERT_SAFE(to_layer_num < static_cast<int>(f_wire_cost_map.dim_size(1)));
VTR_ASSERT_SAFE(seg_index < static_cast<int>(f_wire_cost_map.dim_size(3)));
VTR_ASSERT_SAFE(delta_x < static_cast<int>(f_wire_cost_map.dim_size(4)));
VTR_ASSERT_SAFE(delta_y < static_cast<int>(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<t_segment_inf>& segment_inf_vec) {
Expand All @@ -494,12 +495,12 @@ static void compute_router_wire_lookahead(const std::vector<t_segment_inf>& segm
auto& grid = device_ctx.grid;

//Re-allocate
f_wire_cost_map = t_wire_cost_map({static_cast<unsigned long>(grid.get_num_layers()),
2,
segment_inf_vec.size(),
static_cast<unsigned long>(grid.get_num_layers()),
device_ctx.grid.width(),
device_ctx.grid.height()});
f_wire_cost_map = t_wire_cost_map({static_cast<unsigned long>(grid.get_num_layers()),
static_cast<unsigned long>(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) {
Expand Down Expand Up @@ -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);
}
}
}
Expand All @@ -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,
Expand All @@ -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;
}
}
}
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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
Expand All @@ -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;
}
Expand Down Expand Up @@ -779,10 +780,10 @@ static void min_chann_global_cost_map(vtr::NdMatrix<util::Cost_Entry, 4>& distan
for (int dx = 0; dx < width; dx++) {
for (int dy = 0; dy < height; dy++) {
util::Cost_Entry min_cost(std::numeric_limits<float>::max(), std::numeric_limits<float>::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;
Expand Down
4 changes: 2 additions & 2 deletions vpr/src/route/router_lookahead_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<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]
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]
//[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);
Expand Down
14 changes: 7 additions & 7 deletions vpr/src/route/router_lookahead_map_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 << ","
Expand Down
44 changes: 22 additions & 22 deletions vpr/test/test_map_lookahead_serdes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<size_t, 6> kDim({num_layers, 10, 12, num_layers, 15, 16});
constexpr std::array<size_t, 6> 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);
}
}
}
Expand All @@ -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;
}
}
}
Expand All @@ -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));
}
}
}
Expand Down
Loading