Skip to content

Commit 5358bea

Browse files
Merge pull request #3227 from verilog-to-routing/rr_graph_various_cleanups
[RRGraph] Small code clean up according to coding style
2 parents db86bbf + accb27d commit 5358bea

File tree

2 files changed

+39
-56
lines changed

2 files changed

+39
-56
lines changed

libs/librrgraph/src/base/rr_graph_type.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ struct t_chan_width {
1111
int y_min = 0;
1212
std::vector<int> x_list;
1313
std::vector<int> y_list;
14+
15+
bool operator==(const t_chan_width&) const = default;
1416
};
1517

1618
/// @brief Specifies whether global routing or combined global and detailed routing is performed.

vpr/src/route/rr_graph_generation/rr_graph.cpp

Lines changed: 37 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66
#include "alloc_and_load_rr_indexed_data.h"
77
#include "get_parallel_segs.h"
88
#include "physical_types_util.h"
9+
#include "rr_graph_view.h"
910
#include "rr_rc_data.h"
11+
#include "switchblock_types.h"
12+
#include "vpr_context.h"
1013
#include "vtr_assert.h"
1114

1215
#include "vtr_util.h"
@@ -63,9 +66,6 @@ std::set<int> get_layers_pin_is_connected_to(const t_physical_tile_type_ptr type
6366
///@brief given a specific layer number and type, it returns layers which have same pin_index connected to the given layer
6467
std::set<int> get_layers_connected_to_pin(const t_physical_tile_type_ptr type, int to_layer, int pin_index);
6568

66-
///@brief checks whether the channel width has been changed or not
67-
bool channel_widths_unchanged(const t_chan_width& current, const t_chan_width& proposed);
68-
6969
/**
7070
* @brief This routine calculates pin connections to tracks for either all input or all output pins based on the Fc value defined in the architecture file.
7171
* For the requested pin type (input or output), it will loop through all segments and calculate how many connections should be made,
@@ -668,14 +668,14 @@ void create_rr_graph(e_graph_type graph_type,
668668
const std::vector<t_direct_inf>& directs,
669669
int* Warnings,
670670
bool is_flat) {
671-
const auto& device_ctx = g_vpr_ctx.device();
672-
auto& mutable_device_ctx = g_vpr_ctx.mutable_device();
671+
const DeviceContext& device_ctx = g_vpr_ctx.device();
672+
DeviceContext& mutable_device_ctx = g_vpr_ctx.mutable_device();
673673
bool echo_enabled = getEchoEnabled() && isEchoFileEnabled(E_ECHO_RR_GRAPH_INDEXED_DATA);
674674
const char* echo_file_name = getEchoFileName(E_ECHO_RR_GRAPH_INDEXED_DATA);
675675
bool load_rr_graph = !det_routing_arch.read_rr_graph_filename.empty();
676676

677-
if (channel_widths_unchanged(device_ctx.chan_width, nodes_per_chan) && !device_ctx.rr_graph.empty()) {
678-
//No change in channel width, so skip re-building RR graph
677+
if (device_ctx.chan_width == nodes_per_chan && !device_ctx.rr_graph.empty()) {
678+
// No change in channel width, so skip re-building RR graph
679679
if (is_flat && !device_ctx.rr_graph_is_flat) {
680680
VTR_LOG("RR graph channel widths unchanged, intra-cluster resources should be added...\n");
681681
} else {
@@ -965,20 +965,6 @@ std::set<int> get_layers_connected_to_pin(const t_physical_tile_type_ptr type, i
965965
return layers_connected_to_pin;
966966
}
967967

968-
bool channel_widths_unchanged(const t_chan_width& current, const t_chan_width& proposed) {
969-
if (current.max != proposed.max
970-
|| current.x_max != proposed.x_max
971-
|| current.y_max != proposed.y_max
972-
|| current.x_min != proposed.x_min
973-
|| current.y_min != proposed.y_min
974-
|| current.x_list != proposed.x_list
975-
|| current.y_list != proposed.y_list) {
976-
return false; //Different max/min or channel widths
977-
}
978-
979-
return true; //Identical
980-
}
981-
982968
static void build_rr_graph(e_graph_type graph_type,
983969
const std::vector<t_physical_tile_type>& types,
984970
const DeviceGrid& grid,
@@ -1022,8 +1008,8 @@ static void build_rr_graph(e_graph_type graph_type,
10221008

10231009
VTR_ASSERT(max_chan_width_x > 0 && max_chan_width_y > 0);
10241010

1025-
auto& device_ctx = g_vpr_ctx.mutable_device();
1026-
const auto& rr_graph = device_ctx.rr_graph;
1011+
DeviceContext& device_ctx = g_vpr_ctx.mutable_device();
1012+
const RRGraphView& rr_graph = device_ctx.rr_graph;
10271013

10281014
std::vector<t_clb_to_clb_directs> clb_to_clb_directs = alloc_and_load_clb_to_clb_directs(directs, delayless_switch);
10291015

@@ -1232,43 +1218,38 @@ static void build_rr_graph(e_graph_type graph_type,
12321218

12331219
if (is_global_graph) {
12341220
switch_block_conn = alloc_and_load_switch_block_conn(&nodes_per_chan, SUBSET, 3);
1235-
} else if (BI_DIRECTIONAL == directionality) {
1236-
if (sb_type == CUSTOM) {
1237-
sb_conn_map = alloc_and_load_switchblock_permutations(chan_details_x, chan_details_y,
1238-
grid, inter_cluster_prog_rr,
1239-
switchblocks, nodes_per_chan, directionality,
1240-
switchpoint_rng);
1241-
} else {
1242-
switch_block_conn = alloc_and_load_switch_block_conn(&nodes_per_chan, sb_type, Fs);
1243-
}
12441221
} else {
1245-
VTR_ASSERT(UNI_DIRECTIONAL == directionality);
1246-
12471222
if (sb_type == CUSTOM) {
12481223
sb_conn_map = alloc_and_load_switchblock_permutations(chan_details_x, chan_details_y,
1249-
grid,
1250-
inter_cluster_prog_rr,
1251-
switchblocks, nodes_per_chan, directionality,
1252-
switchpoint_rng);
1224+
grid, inter_cluster_prog_rr,
1225+
switchblocks, nodes_per_chan, directionality,
1226+
switchpoint_rng);
12531227
} else {
1254-
// it looks like we get unbalanced muxing from this switch block code with Fs > 3
1255-
VTR_ASSERT(Fs == 3);
1256-
1257-
unidir_sb_pattern = alloc_sblock_pattern_lookup(grid, nodes_per_chan);
1258-
for (size_t i = 0; i < grid.width() - 1; i++) {
1259-
for (size_t j = 0; j < grid.height() - 1; j++) {
1260-
load_sblock_pattern_lookup(i, j, grid, nodes_per_chan,
1261-
chan_details_x, chan_details_y,
1262-
Fs, sb_type, unidir_sb_pattern);
1228+
if (directionality == BI_DIRECTIONAL) {
1229+
switch_block_conn = alloc_and_load_switch_block_conn(&nodes_per_chan, sb_type, Fs);
1230+
} else {
1231+
// it looks like we get unbalanced muxing from this switch block code with Fs > 3
1232+
VTR_ASSERT(Fs == 3);
1233+
// Since directionality is a C enum it could technically be any value. This assertion makes sure it's either BI_DIRECTIONAL or UNI_DIRECTIONAL
1234+
VTR_ASSERT(directionality == UNI_DIRECTIONAL);
1235+
1236+
unidir_sb_pattern = alloc_sblock_pattern_lookup(grid, nodes_per_chan);
1237+
for (size_t i = 0; i < grid.width() - 1; i++) {
1238+
for (size_t j = 0; j < grid.height() - 1; j++) {
1239+
load_sblock_pattern_lookup(i, j, grid, nodes_per_chan,
1240+
chan_details_x, chan_details_y,
1241+
Fs, sb_type, unidir_sb_pattern);
1242+
}
12631243
}
1264-
}
12651244

1266-
if (getEchoEnabled() && isEchoFileEnabled(E_ECHO_SBLOCK_PATTERN)) {
1267-
dump_sblock_pattern(unidir_sb_pattern, max_chan_width, grid,
1268-
getEchoFileName(E_ECHO_SBLOCK_PATTERN));
1245+
if (getEchoEnabled() && isEchoFileEnabled(E_ECHO_SBLOCK_PATTERN)) {
1246+
dump_sblock_pattern(unidir_sb_pattern, max_chan_width, grid,
1247+
getEchoFileName(E_ECHO_SBLOCK_PATTERN));
1248+
}
12691249
}
12701250
}
12711251
}
1252+
12721253
// END SB LOOKUP
12731254

12741255
// Check whether RR graph need to allocate new nodes for 3D custom switch blocks.
@@ -1291,7 +1272,7 @@ static void build_rr_graph(e_graph_type graph_type,
12911272
t_track_to_pin_lookup track_to_pin_lookup_x(types.size());
12921273
t_track_to_pin_lookup track_to_pin_lookup_y(types.size());
12931274

1294-
for (unsigned int itype = 0; itype < types.size(); ++itype) {
1275+
for (size_t itype = 0; itype < types.size(); ++itype) {
12951276
std::set<int> type_layer = get_layers_of_physical_types(&types[itype]);
12961277

12971278
ipin_to_track_map_x[itype] = alloc_and_load_pin_to_track_map(RECEIVER,
@@ -1333,9 +1314,9 @@ static void build_rr_graph(e_graph_type graph_type,
13331314
// Create opin map lookups
13341315
t_pin_to_track_lookup opin_to_track_map(types.size()); // [0..device_ctx.physical_tile_types.size()-1][0..num_pins-1][0..width][0..height][0..3][0..Fc-1]
13351316
if (BI_DIRECTIONAL == directionality) {
1336-
for (unsigned int itype = 0; itype < types.size(); ++itype) {
1337-
auto type_layer = get_layers_of_physical_types(&types[itype]);
1338-
auto perturb_opins = alloc_and_load_perturb_opins(&types[itype], Fc_out[itype],
1317+
for (size_t itype = 0; itype < types.size(); ++itype) {
1318+
std::set<int> type_layer = get_layers_of_physical_types(&types[itype]);
1319+
std::vector<bool> perturb_opins = alloc_and_load_perturb_opins(&types[itype], Fc_out[itype],
13391320
max_chan_width, segment_inf);
13401321
opin_to_track_map[itype] = alloc_and_load_pin_to_track_map(DRIVER,
13411322
Fc_out[itype], &types[itype], type_layer, perturb_opins, directionality,
@@ -2658,7 +2639,7 @@ void free_rr_graph() {
26582639
// a routing graph exists and can be freed. Hence, you can call this routine even if you're not sure of whether a rr_graph exists or not.
26592640

26602641
// Before adding any more free calls here, be sure the data is NOT chunk allocated, as ALL the chunk allocated data is already free!
2661-
auto& device_ctx = g_vpr_ctx.mutable_device();
2642+
DeviceContext& device_ctx = g_vpr_ctx.mutable_device();
26622643

26632644
device_ctx.loaded_rr_graph_filename.clear();
26642645
device_ctx.loaded_rr_edge_override_filename.clear();

0 commit comments

Comments
 (0)