Skip to content

Commit 6803792

Browse files
use the correct layer for CHANZ nodes when initalizing src_opin_delays
1 parent 21dfd5d commit 6803792

File tree

5 files changed

+41
-51
lines changed

5 files changed

+41
-51
lines changed

vpr/src/base/read_options.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1104,7 +1104,7 @@ struct ParseRouteBBUpdate {
11041104

11051105
struct ParseRouterLookahead {
11061106
ConvertedValue<e_router_lookahead> from_str(std::string str) {
1107-
std::transform(str.begin(), str.end(), str.begin(), ::tolower);
1107+
std::ranges::transform(str, str.begin(), ::tolower);
11081108
ConvertedValue<e_router_lookahead> conv_value;
11091109
if (str == "classic")
11101110
conv_value.set_value(e_router_lookahead::CLASSIC);

vpr/src/place/delay_model/simple_delay_model.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ void SimpleDelayModel::compute(RouterDelayProfiler& route_profiler,
1313
const t_placer_opts& /*placer_opts*/,
1414
const t_router_opts& /*router_opts*/,
1515
int /*longest_length*/) {
16-
const auto& grid = g_vpr_ctx.device().grid;
16+
const DeviceGrid& grid = g_vpr_ctx.device().grid;
1717
const size_t num_physical_tile_types = g_vpr_ctx.device().physical_tile_types.size();
1818
const size_t num_layers = grid.get_num_layers();
1919

@@ -31,10 +31,8 @@ void SimpleDelayModel::compute(RouterDelayProfiler& route_profiler,
3131
for (size_t dx = 0; dx < grid.width(); ++dx) {
3232
for (size_t dy = 0; dy < grid.height(); ++dy) {
3333
float min_delay = route_profiler.get_min_delay(physical_tile_type_idx,
34-
from_layer,
35-
to_layer,
36-
dx,
37-
dy);
34+
from_layer, to_layer,
35+
dx, dy);
3836
delays_[physical_tile_type_idx][from_layer][to_layer][dx][dy] = min_delay;
3937
}
4038
}

vpr/src/route/router_lookahead/router_lookahead.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ class RouterLookahead {
6666
virtual void write_intra_cluster(const std::string& file) const = 0;
6767

6868
/**
69-
* @brief Retrieve the minimum delay to a point on the "to_layer," which is dx and dy away, across all the OPINs on the physical tile identified by "physical_tile_idx."
69+
* @brief Retrieve the minimum delay to a point on the "to_layer," which is dx and dy away,
70+
* across all the OPINs on the physical tile identified by "physical_tile_idx".
7071
* @param physical_tile_idx The index of the physical tile from which the cost is calculated
7172
* @param from_layer The layer that the tile is located on
7273
* @param to_layer The layer on which the destination is located

vpr/src/route/router_lookahead/router_lookahead_map.cpp

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,8 @@ static void store_min_cost_to_sinks(std::unordered_map<int, std::unordered_map<i
118118
static void min_chann_global_cost_map(vtr::NdMatrix<util::Cost_Entry, 4>& distance_min_cost);
119119

120120
/**
121-
* @brief // Given the src/opin map of each physical tile type, iterate over all OPINs/sources of a type and create
121+
* @brief Given the src/opin map of each physical tile type, iterate over all OPINs/sources of a type and create
122122
* the minimum cost map across all of them for each tile type.
123-
* @param src_opin_delays
124-
* @param distance_min_cost
125123
*/
126124
static void min_opin_distance_cost_map(const util::t_src_opin_delays& src_opin_delays, vtr::NdMatrix<util::Cost_Entry, 5>& distance_min_cost);
127125

@@ -390,8 +388,6 @@ std::pair<float, float> MapLookahead::get_expected_delay_and_cong(RRNodeId from_
390388
delta_x,
391389
delta_y,
392390
to_layer_num);
393-
expected_delay_cost = cost_entry.delay;
394-
expected_cong_cost = cost_entry.congestion;
395391

396392
VTR_ASSERT_SAFE_MSG(std::isfinite(expected_delay_cost),
397393
vtr::string_fmt("Lookahead failed to estimate cost from %s: %s",
@@ -835,13 +831,11 @@ static void min_chann_global_cost_map(vtr::NdMatrix<util::Cost_Entry, 4>& distan
835831
}
836832

837833
static void min_opin_distance_cost_map(const util::t_src_opin_delays& src_opin_delays, vtr::NdMatrix<util::Cost_Entry, 5>& distance_min_cost) {
838-
/**
839-
* This function calculates and stores the minimum cost to reach a point on layer `n_sink`, which is `dx` and `dy` further from the current point
840-
* on layer `n_source` and is located on physical tile type `t`. To compute this cost, the function iterates over all output pins of tile `t`,
841-
* and for each pin, iterates over all segment types accessible by it. It then determines and stores the minimum cost to the destination point.
842-
* "src_opin_delays" stores the routing segments accessible by each OPIN of each physical type on each layer. After getting the accessible segment types,
843-
* "get_wire_cost_entry" is called to get the cost from that segment type to the destination point.
844-
*/
834+
// This function calculates and stores the minimum cost to reach a point on layer `n_sink`, which is `dx` and `dy` further from the current point
835+
// on layer `n_source` and is located on physical tile type `t`. To compute this cost, the function iterates over all output pins of tile `t`,
836+
// and for each pin, iterates over all segment types accessible by it. It then determines and stores the minimum cost to the destination point.
837+
// "src_opin_delays" stores the routing segments accessible by each OPIN of each physical type on each layer. After getting the accessible segment types,
838+
// "get_wire_cost_entry" is called to get the cost from that segment type to the destination point.
845839
int num_tile_types = g_vpr_ctx.device().physical_tile_types.size();
846840
int num_layers = g_vpr_ctx.device().grid.get_num_layers();
847841
int width = (int)g_vpr_ctx.device().grid.width();
@@ -874,14 +868,13 @@ static void min_opin_distance_cost_map(const util::t_src_opin_delays& src_opin_d
874868
if (reachable_wire_inf.wire_rr_type == e_rr_type::SINK) {
875869
continue;
876870
}
877-
util::Cost_Entry wire_cost_entry;
878-
879-
wire_cost_entry = get_wire_cost_entry(reachable_wire_inf.wire_rr_type,
880-
reachable_wire_inf.wire_seg_index,
881-
reachable_wire_inf.layer_number,
882-
dx,
883-
dy,
884-
to_layer_num);
871+
872+
util::Cost_Entry wire_cost_entry = get_wire_cost_entry(reachable_wire_inf.wire_rr_type,
873+
reachable_wire_inf.wire_seg_index,
874+
reachable_wire_inf.layer_number,
875+
dx,
876+
dy,
877+
to_layer_num);
885878

886879
float this_delay_cost = reachable_wire_inf.delay + wire_cost_entry.delay;
887880
float this_cong_cost = reachable_wire_inf.congestion + wire_cost_entry.congestion;

vpr/src/route/router_lookahead/router_lookahead_map_utils.cpp

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
* To access the utility functions, the util namespace needs to be used. */
1212

1313
#include <fstream>
14+
#include <ranges>
1415
#include "globals.h"
1516
#include "physical_types_util.h"
1617
#include "vpr_context.h"
@@ -372,8 +373,7 @@ t_src_opin_delays compute_router_src_opin_lookahead(bool is_flat,
372373

373374
int num_layers = device_ctx.grid.get_num_layers();
374375

375-
t_src_opin_delays src_opin_delays;
376-
src_opin_delays.resize(num_layers);
376+
t_src_opin_delays src_opin_delays(num_layers);
377377
std::vector<int> tile_max_ptc(device_ctx.physical_tile_types.size(), UNDEFINED);
378378

379379
// Get the maximum OPIN ptc for each tile type to reserve src_opin_delays
@@ -392,8 +392,8 @@ t_src_opin_delays compute_router_src_opin_lookahead(bool is_flat,
392392
}
393393
}
394394

395-
//We assume that the routing connectivity of each instance of a physical tile is the same,
396-
//and so only measure one instance of each type
395+
// We assume that the routing connectivity of each instance of a physical tile is the same,
396+
// and so only measure one instance of each type
397397
for (int from_layer_num = 0; from_layer_num < num_layers; from_layer_num++) {
398398
for (size_t itile = 0; itile < device_ctx.physical_tile_types.size(); ++itile) {
399399
if (device_ctx.grid.num_instances(&device_ctx.physical_tile_types[itile], from_layer_num) == 0) {
@@ -430,11 +430,9 @@ t_src_opin_delays compute_router_src_opin_lookahead(bool is_flat,
430430

431431
VTR_ASSERT(ptc < int(src_opin_delays[from_layer_num][itile].size()));
432432

433-
//Find the wire types which are reachable from inode and record them and
434-
//the cost to reach them
435-
dijkstra_flood_to_wires(itile,
436-
node_id,
437-
src_opin_delays);
433+
// Find the wire types which are reachable from inode and record them and
434+
// the cost to reach them
435+
dijkstra_flood_to_wires(itile, node_id, src_opin_delays);
438436

439437
bool reachable_wire_found = false;
440438
for (int to_layer_num = 0; to_layer_num < num_layers; to_layer_num++) {
@@ -876,7 +874,7 @@ std::pair<float, float> get_cost_from_src_opin(const std::map<int, util::t_reach
876874
//From the current SOURCE/OPIN we look-up the wiretypes which are reachable
877875
//and then add the estimates from those wire types for the distance of interest.
878876
//If there are multiple options we use the minimum value.
879-
for (const auto& [_, reachable_wire_inf] : src_opin_delay_map) {
877+
for (const util::t_reachable_wire_inf& reachable_wire_inf : src_opin_delay_map | std::views::values) {
880878

881879
util::Cost_Entry wire_cost_entry;
882880
if (reachable_wire_inf.wire_rr_type == e_rr_type::SINK) {
@@ -967,7 +965,7 @@ void dump_readable_router_lookahead_map(const std::string& file_name, const std:
967965
static void dijkstra_flood_to_wires(int itile,
968966
RRNodeId node,
969967
util::t_src_opin_delays& src_opin_delays) {
970-
const auto& device_ctx = g_vpr_ctx.device();
968+
const DeviceContext& device_ctx = g_vpr_ctx.device();
971969
const auto& rr_graph = device_ctx.rr_graph;
972970

973971
struct t_pq_entry {
@@ -1018,23 +1016,27 @@ static void dijkstra_flood_to_wires(int itile,
10181016
e_rr_type curr_rr_type = rr_graph.node_type(curr.node);
10191017
int curr_layer_num = rr_graph.node_layer_low(curr.node);
10201018
if (curr_rr_type == e_rr_type::CHANX || curr_rr_type == e_rr_type::CHANY || curr_rr_type == e_rr_type::CHANZ || curr_rr_type == e_rr_type::SINK) {
1021-
//We stop expansion at any CHANX/CHANY/SINK
1019+
// We stop expansion at any CHANX/CHANY/SINK
10221020
int seg_index;
10231021
if (curr_rr_type != e_rr_type::SINK) {
10241022
//It's a wire, figure out its type
1025-
auto cost_index = rr_graph.node_cost_index(curr.node);
1023+
RRIndexedDataId cost_index = rr_graph.node_cost_index(curr.node);
10261024
seg_index = device_ctx.rr_indexed_data[cost_index].seg_index;
10271025
} else {
1028-
//This is a direct-connect path between an IPIN and OPIN,
1029-
//which terminated at a SINK.
1026+
// This is a direct-connect path between an IPIN and OPIN,
1027+
// which terminated at a SINK.
10301028
//
1031-
//We treat this as a 'special' wire type.
1032-
//When the src_opin_delays data structure is queried and a SINK rr_type
1033-
//is found, the lookahead is not accessed to get the cost entries
1034-
//as this is a special case of direct connections between OPIN and IPIN.
1029+
// We treat this as a 'special' wire type.
1030+
// When the src_opin_delays data structure is queried and a SINK rr_type
1031+
// is found, the lookahead is not accessed to get the cost entries
1032+
// as this is a special case of direct connections between OPIN and IPIN.
10351033
seg_index = DIRECT_CONNECT_SPECIAL_SEG_TYPE;
10361034
}
10371035

1036+
if (curr_rr_type == e_rr_type::CHANZ) {
1037+
curr_layer_num = (root_layer_num + 1) % 2;
1038+
}
1039+
10381040
//Keep costs of the best path to reach each wire type
10391041
if (!src_opin_delays[root_layer_num][itile][ptc][curr_layer_num].count(seg_index)
10401042
|| curr.delay < src_opin_delays[root_layer_num][itile][ptc][curr_layer_num][seg_index].delay) {
@@ -1047,7 +1049,7 @@ static void dijkstra_flood_to_wires(int itile,
10471049

10481050
} else if (curr_rr_type == e_rr_type::SOURCE || curr_rr_type == e_rr_type::OPIN || curr_rr_type == e_rr_type::IPIN || curr_rr_type == e_rr_type::MUX) {
10491051
//We allow expansion through SOURCE/OPIN/IPIN types
1050-
auto cost_index = rr_graph.node_cost_index(curr.node);
1052+
RRIndexedDataId cost_index = rr_graph.node_cost_index(curr.node);
10511053
float incr_cong = device_ctx.rr_indexed_data[cost_index].base_cost; //Current nodes congestion cost
10521054

10531055
for (RREdgeId edge : rr_graph.edge_range(curr.node)) {
@@ -1201,8 +1203,6 @@ static t_physical_tile_loc pick_sample_tile(int layer_num, t_physical_tile_type_
12011203
//Very simple for now, just pick the fist matching tile found
12021204
t_physical_tile_loc loc(UNDEFINED, UNDEFINED, UNDEFINED);
12031205

1204-
//VTR_LOG("Prev: %d,%d\n", prev.x, prev.y);
1205-
12061206
auto& device_ctx = g_vpr_ctx.device();
12071207
auto& grid = device_ctx.grid;
12081208

@@ -1235,8 +1235,6 @@ static t_physical_tile_loc pick_sample_tile(int layer_num, t_physical_tile_type_
12351235
}
12361236
}
12371237

1238-
//VTR_LOG("Next: %d,%d\n", loc.x, loc.y);
1239-
12401238
return loc;
12411239
}
12421240

0 commit comments

Comments
 (0)