Skip to content

Minor router lookahed cleanup #2563

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 4 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions libs/libarchfpga/src/physical_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -1558,8 +1558,8 @@ enum e_Fc_type {
* seg_index: The index of the segment as stored in the appropriate Segs list*
* Upon loading the architecture, we use this field to keep track *
* the segment's index in the unified segment_inf vector. This is *
* usefull when building the rr_graph for different Y & X channels*
* interms of track distribution and segment type. *
* useful when building the rr_graph for different Y & X channels *
* in terms of track distribution and segment type. *
* meta: Table storing extra arbitrary metadata attributes. */
struct t_segment_inf {
std::string name;
Expand Down
4 changes: 2 additions & 2 deletions libs/librrgraph/src/base/rr_graph_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ class RRGraphView {
/** @brief Get outgoing edges for a node.
* This API is designed to enable range-based loop to walk through the outgoing edges of a node
* Example:
* RRGraphView rr_graph; // A dummny rr_graph for a short example
* RRGraphView rr_graph; // A dummy rr_graph for a short example
* RRNodeId node; // A dummy node for a short example
* for (RREdgeId edge : rr_graph.edges(node)) {
* // Do something with the edge
Expand Down Expand Up @@ -436,7 +436,7 @@ class RRGraphView {
}

/** @brief Return the switch information that is categorized in the rr_switch_inf with a given id
* rr_switch_inf is created to minimize memory footprint of RRGraph classs
* rr_switch_inf is created to minimize memory footprint of RRGraph class
* While the RRG could contain millions (even much larger) of edges, there are only
* a limited number of types of switches.
* Hence, we use a flyweight pattern to store switch-related information that differs
Expand Down
2 changes: 1 addition & 1 deletion vpr/src/base/read_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2572,7 +2572,7 @@ argparse::ArgumentParser create_arg_parser(const std::string& prog_name, t_optio
" * classic: The classic VPR lookahead (may perform better on un-buffered routing\n"
" architectures)\n"
" * map: An advanced lookahead which accounts for diverse wire type\n"
" * compressed_map: The algorithm is similar to map lookahead with the exception of saprse sampling of the chip"
" * compressed_map: The algorithm is similar to map lookahead with the exception of sparse sampling of the chip"
" to reduce the run-time to build the router lookahead and also its memory footprint\n"
" * extended_map: A more advanced and extended lookahead which accounts for a more\n"
" exhaustive node sampling method\n"
Expand Down
6 changes: 4 additions & 2 deletions vpr/src/base/vpr_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,9 @@ void vpr_create_device_grid(const t_vpr_setup& vpr_setup, const t_arch& Arch) {
float target_device_utilization = vpr_setup.PackerOpts.target_device_utilization;
device_ctx.grid = create_device_grid(vpr_setup.device_layout, Arch.grid_layouts, num_type_instances, target_device_utilization);

VTR_ASSERT_MSG(device_ctx.grid.get_num_layers() <= MAX_NUM_LAYERS, "Number of layers should be less than MAX_NUM_LAYERS. If you need more layers, please increase the value of MAX_NUM_LAYERS in vpr_types.h");
VTR_ASSERT_MSG(device_ctx.grid.get_num_layers() <= MAX_NUM_LAYERS,
"Number of layers should be less than MAX_NUM_LAYERS. "
"If you need more layers, please increase the value of MAX_NUM_LAYERS in vpr_types.h");

/*
*Report on the device
Expand Down Expand Up @@ -1455,7 +1457,7 @@ void vpr_analysis(const Netlist<>& net_list,
generate_setup_timing_stats(/*prefix=*/"", *timing_info,
*analysis_delay_calc, vpr_setup.AnalysisOpts, vpr_setup.RouterOpts.flat_routing);

//Write the post-syntesis netlist
//Write the post-synthesis netlist
if (vpr_setup.AnalysisOpts.gen_post_synthesis_netlist) {
netlist_writer(atom_ctx.nlist.netlist_name().c_str(), analysis_delay_calc,
vpr_setup.AnalysisOpts);
Expand Down
2 changes: 1 addition & 1 deletion vpr/src/base/vpr_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -1681,7 +1681,7 @@ class t_chan_seg_details {

private:
//The only unique information about a channel segment is it's start/end
//and length. All other information is shared accross segment types,
//and length. All other information is shared across segment types,
//so we use a flyweight to the t_seg_details which defines that info.
//
//To preserve the illusion of uniqueness we wrap all t_seg_details members
Expand Down
1 change: 1 addition & 0 deletions vpr/src/place/timing_place_lookup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ std::unique_ptr<PlaceDelayModel> compute_place_delay_model(const t_placer_opts&
router_opts.read_router_lookahead,
segment_inf,
is_flat);

RouterDelayProfiler route_profiler(net_list, router_lookahead, is_flat);

int longest_length = get_longest_segment_length(segment_inf);
Expand Down
2 changes: 1 addition & 1 deletion vpr/src/route/router_delay_profiling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ vtr::vector<RRNodeId, float> calculate_all_path_delays_from_rr_node(RRNodeId src
return path_delays_to;
}

void alloc_routing_structs(t_chan_width chan_width,
void alloc_routing_structs(const t_chan_width& chan_width,
const t_router_opts& router_opts,
t_det_routing_arch* det_routing_arch,
std::vector<t_segment_inf>& segment_inf,
Expand Down
2 changes: 1 addition & 1 deletion vpr/src/route/router_delay_profiling.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ vtr::vector<RRNodeId, float> calculate_all_path_delays_from_rr_node(RRNodeId src
const t_router_opts& router_opts,
bool is_flat);

void alloc_routing_structs(t_chan_width chan_width,
void alloc_routing_structs(const t_chan_width& chan_width,
const t_router_opts& router_opts,
t_det_routing_arch* det_routing_arch,
std::vector<t_segment_inf>& segment_inf,
Expand Down
64 changes: 35 additions & 29 deletions vpr/src/route/router_lookahead.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,16 @@
#include "vpr_error.h"
#include "globals.h"

static int get_expected_segs_to_target(RRNodeId inode, RRNodeId target_node, int* num_segs_ortho_dir_ptr);
/**
* Assuming inode is CHANX or CHANY, this function calculates the number of required wires of the same type as inode
* to arrive at target_noe.
* @param inode The source node from which the cost to the target node is obtained.
* @param target_node The target node to which the cost is obtained.
* @return std::pait<int, int> The first element is the number of required wires in the same direction as inode,
* while the second element determines the number of wires in the direction orthogonal to inode.
*/
static std::pair<int, int> get_expected_segs_to_target(RRNodeId inode, RRNodeId target_node);

static int round_up(float x);

static std::unique_ptr<RouterLookahead> make_router_lookahead_object(const t_det_routing_arch& det_routing_arch,
Expand All @@ -31,8 +40,8 @@ static std::unique_ptr<RouterLookahead> make_router_lookahead_object(const t_det

std::unique_ptr<RouterLookahead> make_router_lookahead(const t_det_routing_arch& det_routing_arch,
e_router_lookahead router_lookahead_type,
std::string write_lookahead,
std::string read_lookahead,
const std::string& write_lookahead,
const std::string& read_lookahead,
const std::vector<t_segment_inf>& segment_inf,
bool is_flat) {
std::unique_ptr<RouterLookahead> router_lookahead = make_router_lookahead_object(det_routing_arch,
Expand All @@ -53,8 +62,7 @@ std::unique_ptr<RouterLookahead> make_router_lookahead(const t_det_routing_arch&
}

float ClassicLookahead::get_expected_cost(RRNodeId current_node, RRNodeId target_node, const t_conn_cost_params& params, float R_upstream) const {
float delay_cost, cong_cost;
std::tie(delay_cost, cong_cost) = get_expected_delay_and_cong(current_node, target_node, params, R_upstream);
auto [delay_cost, cong_cost] = get_expected_delay_and_cong(current_node, target_node, params, R_upstream);

return delay_cost + cong_cost;
}
Expand All @@ -66,8 +74,7 @@ std::pair<float, float> ClassicLookahead::get_expected_delay_and_cong(RRNodeId n
t_rr_type rr_type = rr_graph.node_type(node);

if (rr_type == CHANX || rr_type == CHANY) {
int num_segs_ortho_dir = 0;
int num_segs_same_dir = get_expected_segs_to_target(node, target_node, &num_segs_ortho_dir);
auto [num_segs_same_dir, num_segs_ortho_dir] = get_expected_segs_to_target(node, target_node);

auto cost_index = rr_graph.node_cost_index(node);
int ortho_cost_index = device_ctx.rr_indexed_data[cost_index].ortho_cost_index;
Expand Down Expand Up @@ -112,28 +119,27 @@ static int round_up(float x) {
return std::ceil(x - 0.001);
}

static int get_expected_segs_to_target(RRNodeId inode, RRNodeId target_node, int* num_segs_ortho_dir_ptr) {
static std::pair<int, int> get_expected_segs_to_target(RRNodeId inode, RRNodeId target_node) {
/* Returns the number of segments the same type as inode that will be needed *
* to reach target_node (not including inode) in each direction (the same *
* direction (horizontal or vertical) as inode and the orthogonal direction).*/

auto& device_ctx = g_vpr_ctx.device();
const auto& rr_graph = device_ctx.rr_graph;

t_rr_type rr_type;
int target_x, target_y, num_segs_same_dir, ortho_cost_index;
RRIndexedDataId cost_index;
int num_segs_ortho_dir;
int num_segs_same_dir;

int no_need_to_pass_by_clb;
float inv_length, ortho_inv_length, ylow, yhigh, xlow, xhigh;
float ylow, yhigh, xlow, xhigh;

target_x = rr_graph.node_xlow(target_node);
target_y = rr_graph.node_ylow(target_node);
int target_x = rr_graph.node_xlow(target_node);
int target_y = rr_graph.node_ylow(target_node);

cost_index = rr_graph.node_cost_index(inode);
inv_length = device_ctx.rr_indexed_data[cost_index].inv_length;
ortho_cost_index = device_ctx.rr_indexed_data[cost_index].ortho_cost_index;
ortho_inv_length = device_ctx.rr_indexed_data[RRIndexedDataId(ortho_cost_index)].inv_length;
rr_type = rr_graph.node_type(inode);
RRIndexedDataId cost_index = rr_graph.node_cost_index(inode);
float inv_length = device_ctx.rr_indexed_data[cost_index].inv_length;
int ortho_cost_index = device_ctx.rr_indexed_data[cost_index].ortho_cost_index;
float ortho_inv_length = device_ctx.rr_indexed_data[RRIndexedDataId(ortho_cost_index)].inv_length;
t_rr_type rr_type = rr_graph.node_type(inode);

if (rr_type == CHANX) {
ylow = rr_graph.node_ylow(inode);
Expand All @@ -143,13 +149,13 @@ static int get_expected_segs_to_target(RRNodeId inode, RRNodeId target_node, int
/* Count vertical (orthogonal to inode) segs first. */

if (ylow > target_y) { /* Coming from a row above target? */
*num_segs_ortho_dir_ptr = round_up((ylow - target_y + 1.) * ortho_inv_length);
num_segs_ortho_dir = round_up((ylow - target_y + 1.) * ortho_inv_length);
no_need_to_pass_by_clb = 1;
} else if (ylow < target_y - 1) { /* Below the CLB bottom? */
*num_segs_ortho_dir_ptr = round_up((target_y - ylow) * ortho_inv_length);
num_segs_ortho_dir = round_up((target_y - ylow) * ortho_inv_length);
no_need_to_pass_by_clb = 1;
} else { /* In a row that passes by target CLB */
*num_segs_ortho_dir_ptr = 0;
num_segs_ortho_dir = 0;
no_need_to_pass_by_clb = 0;
}

Expand All @@ -170,13 +176,13 @@ static int get_expected_segs_to_target(RRNodeId inode, RRNodeId target_node, int
/* Count horizontal (orthogonal to inode) segs first. */

if (xlow > target_x) { /* Coming from a column right of target? */
*num_segs_ortho_dir_ptr = round_up((xlow - target_x + 1.) * ortho_inv_length);
num_segs_ortho_dir = round_up((xlow - target_x + 1.) * ortho_inv_length);
no_need_to_pass_by_clb = 1;
} else if (xlow < target_x - 1) { /* Left of and not adjacent to the CLB? */
*num_segs_ortho_dir_ptr = round_up((target_x - xlow) * ortho_inv_length);
num_segs_ortho_dir = round_up((target_x - xlow) * ortho_inv_length);
no_need_to_pass_by_clb = 1;
} else { /* In a column that passes by target CLB */
*num_segs_ortho_dir_ptr = 0;
num_segs_ortho_dir = 0;
no_need_to_pass_by_clb = 0;
}

Expand All @@ -191,7 +197,7 @@ static int get_expected_segs_to_target(RRNodeId inode, RRNodeId target_node, int
}
}

return (num_segs_same_dir);
return {num_segs_same_dir, num_segs_ortho_dir};
}

void invalidate_router_lookahead_cache() {
Expand All @@ -201,8 +207,8 @@ void invalidate_router_lookahead_cache() {

const RouterLookahead* get_cached_router_lookahead(const t_det_routing_arch& det_routing_arch,
e_router_lookahead router_lookahead_type,
std::string write_lookahead,
std::string read_lookahead,
const std::string& write_lookahead,
const std::string& read_lookahead,
const std::vector<t_segment_inf>& segment_inf,
bool is_flat) {
auto& router_ctx = g_vpr_ctx.routing();
Expand Down
8 changes: 4 additions & 4 deletions vpr/src/route/router_lookahead.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ class RouterLookahead {
*/
std::unique_ptr<RouterLookahead> make_router_lookahead(const t_det_routing_arch& det_routing_arch,
e_router_lookahead router_lookahead_type,
std::string write_lookahead,
std::string read_lookahead,
const std::string& write_lookahead,
const std::string& read_lookahead,
const std::vector<t_segment_inf>& segment_inf,
bool is_flat);

Expand All @@ -115,8 +115,8 @@ void invalidate_router_lookahead_cache();
*/
const RouterLookahead* get_cached_router_lookahead(const t_det_routing_arch& det_routing_arch,
e_router_lookahead router_lookahead_type,
std::string write_lookahead,
std::string read_lookahead,
const std::string& write_lookahead,
const std::string& read_lookahead,
const std::vector<t_segment_inf>& segment_inf,
bool is_flat);

Expand Down
3 changes: 1 addition & 2 deletions vpr/src/route/router_lookahead_compressed_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -428,10 +428,9 @@ std::pair<float, float> CompressedMapLookahead::get_expected_delay_and_cong(RRNo
auto& device_ctx = g_vpr_ctx.device();
auto& rr_graph = device_ctx.rr_graph;

int delta_x, delta_y;
int from_layer_num = rr_graph.node_layer(from_node);
int to_layer_num = rr_graph.node_layer(to_node);
util::get_xy_deltas(from_node, to_node, &delta_x, &delta_y);
auto [delta_x, delta_y] = util::get_xy_deltas(from_node, to_node);
delta_x = abs(delta_x);
delta_y = abs(delta_y);

Expand Down
Loading
Loading