Skip to content

Commit 3610503

Browse files
some cleanups in rr_graph files
1 parent 72e130c commit 3610503

File tree

3 files changed

+58
-74
lines changed

3 files changed

+58
-74
lines changed

vpr/src/route/rr_graph_generation/rr_graph.cpp

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -963,8 +963,7 @@ static void build_rr_graph(e_graph_type graph_type,
963963
// alloc_and_load_rr_switch_inf()
964964
device_ctx.rr_graph_builder.reserve_switches(device_ctx.all_sw_inf.size());
965965
// Create the switches
966-
for (const auto& sw_pair : device_ctx.all_sw_inf) {
967-
const t_arch_switch_inf& arch_sw = sw_pair.second;
966+
for (const t_arch_switch_inf& arch_sw : device_ctx.all_sw_inf | std::views::values) {
968967
t_rr_switch_inf rr_switch = create_rr_switch_from_arch_switch(arch_sw,
969968
R_minW_nmos,
970969
R_minW_pmos);
@@ -1278,7 +1277,7 @@ std::vector<vtr::Matrix<int>> alloc_and_load_actual_fc(const std::vector<t_physi
12781277
for (const t_fc_specification& fc_spec : type.fc_specs) {
12791278
if (fc_type != fc_spec.fc_type) continue;
12801279

1281-
VTR_ASSERT(fc_spec.pins.size() > 0);
1280+
VTR_ASSERT(!fc_spec.pins.empty());
12821281

12831282
int iseg = fc_spec.seg_index;
12841283

@@ -2941,7 +2940,7 @@ static int get_opin_direct_connections(RRGraphBuilder& rr_graph_builder,
29412940
inodes = rr_graph_builder.node_lookup().find_nodes_at_all_sides(layer, final_ipin_x, final_ipin_y, e_rr_type::IPIN, ipin);
29422941
}
29432942

2944-
if (inodes.size() > 0) {
2943+
if (!inodes.empty()) {
29452944
// There may be multiple physical pins corresponding to the logical
29462945
// target ipin. We only need to connect to one of them (since the physical pins
29472946
// are logically equivalent). This also ensures the graphics look reasonable and map
@@ -2963,16 +2962,13 @@ static std::vector<bool> alloc_and_load_perturb_opins(const t_physical_tile_type
29632962
const vtr::Matrix<int>& Fc_out,
29642963
const int max_chan_width,
29652964
const std::vector<t_segment_inf>& segment_inf) {
2966-
int i, Fc_max, iclass, num_wire_types;
2967-
int num, max_primes, factor, num_factors;
2968-
int* prime_factors;
2965+
int num_wire_types;
29692966
float step_size = 0;
29702967
float n = 0;
29712968
float threshold = 0.07;
29722969

29732970
std::vector<bool> perturb_opins(segment_inf.size(), false);
29742971

2975-
i = Fc_max = iclass = 0;
29762972
if (segment_inf.size() > 1) {
29772973
/* Segments of one length are grouped together in the channel. *
29782974
* In the future we can determine if any of these segments will *
@@ -2987,8 +2983,9 @@ static std::vector<bool> alloc_and_load_perturb_opins(const t_physical_tile_type
29872983
num_wire_types = segment_inf[0].length;
29882984
}
29892985

2990-
/* get Fc_max */
2991-
for (i = 0; i < type->num_pins; ++i) {
2986+
// get Fc_max
2987+
int Fc_max = 0;
2988+
for (int i = 0; i < type->num_pins; ++i) {
29922989
auto pin_type = get_pin_type_from_pin_physical_num(type, i);
29932990
if (Fc_out[i][0] > Fc_max && pin_type == e_pin_type::DRIVER) {
29942991
Fc_max = Fc_out[i][0];
@@ -3005,19 +3002,19 @@ static std::vector<bool> alloc_and_load_perturb_opins(const t_physical_tile_type
30053002
* will always skip some wires. Thus, we perturb pins if we detect this *
30063003
* case. */
30073004

3008-
/* get an upper bound on the number of prime factors of num_wire_types */
3009-
max_primes = (int)floor(log((float)num_wire_types) / log(2.0));
3005+
// get an upper bound on the number of prime factors of num_wire_types
3006+
int max_primes = (int)floor(log((float)num_wire_types) / log(2.0));
30103007
max_primes = std::max(max_primes, 1); //Minimum of 1 to ensure we allocate space for at least one prime_factor
30113008

3012-
prime_factors = new int[max_primes];
3013-
for (i = 0; i < max_primes; i++) {
3009+
int* prime_factors = new int[max_primes];
3010+
for (int i = 0; i < max_primes; i++) {
30143011
prime_factors[i] = 0;
30153012
}
30163013

3017-
/* Find the prime factors of num_wire_types */
3018-
num = num_wire_types;
3019-
factor = 2;
3020-
num_factors = 0;
3014+
// Find the prime factors of num_wire_types
3015+
int num = num_wire_types;
3016+
int factor = 2;
3017+
int num_factors = 0;
30213018
while (pow((float)factor, 2) <= num) {
30223019
if (num % factor == 0) {
30233020
num /= factor;
@@ -3036,7 +3033,7 @@ static std::vector<bool> alloc_and_load_perturb_opins(const t_physical_tile_type
30363033
/* Now see if step size is an approximate multiple of one of the factors. A *
30373034
* threshold is used because step size may not be an integer. */
30383035
step_size = (float)max_chan_width / Fc_max;
3039-
for (i = 0; i < num_factors; i++) {
3036+
for (int i = 0; i < num_factors; i++) {
30403037
if (vtr::nint(step_size) < prime_factors[i]) {
30413038
perturb_opins[0] = false;
30423039
break;

vpr/src/route/rr_graph_generation/rr_graph2.cpp

Lines changed: 39 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ static int vpr_to_phy_track(const int itrack,
128128
const int chan_num,
129129
const int seg_num,
130130
const t_chan_seg_details* seg_details,
131-
const enum e_directionality directionality);
131+
const e_directionality directionality);
132132

133133
/**
134134
* @brief Identifies and labels all mux endpoints at a given channel segment coordinate.
@@ -189,9 +189,9 @@ std::vector<int> get_seg_track_counts(int num_sets,
189189
// Scale factor so we can divide by any length and still use integers
190190
double scale = 1;
191191
int freq_sum = 0;
192-
for (size_t i = 0; i < segment_inf.size(); ++i) {
193-
scale *= segment_inf[i].length;
194-
freq_sum += segment_inf[i].frequency;
192+
for (const t_segment_inf& seg_inf : segment_inf) {
193+
scale *= seg_inf.length;
194+
freq_sum += seg_inf.frequency;
195195
}
196196
const double reduce = scale * freq_sum;
197197

@@ -1082,10 +1082,10 @@ int get_track_to_tracks(RRGraphBuilder& rr_graph_builder,
10821082
const t_sb_connection_map* sb_conn_map) {
10831083
int to_chan, to_sb;
10841084
std::vector<int> conn_tracks;
1085-
bool from_is_sblock, is_behind, Fs_clipped;
1085+
bool Fs_clipped;
10861086
e_side to_side;
10871087

1088-
/* check whether a custom switch block will be used */
1088+
// check whether a custom switch block will be used
10891089
bool custom_switch_block = false;
10901090
if (sb_conn_map != nullptr) {
10911091
custom_switch_block = true;
@@ -1134,9 +1134,9 @@ int get_track_to_tracks(RRGraphBuilder& rr_graph_builder,
11341134
continue;
11351135
}
11361136

1137-
/* Figure out if we are at a sblock */
1138-
from_is_sblock = is_sblock(from_chan, from_seg, sb_seg, from_track,
1139-
from_seg_details, directionality);
1137+
// Figure out if we are at a sblock
1138+
bool from_is_sblock = is_sblock(from_chan, from_seg, sb_seg, from_track,
1139+
from_seg_details, directionality);
11401140
if (sb_seg == end_sb_seg || sb_seg == start_sb_seg) {
11411141
/* end of wire must be an sblock */
11421142
from_is_sblock = true;
@@ -1173,9 +1173,9 @@ int get_track_to_tracks(RRGraphBuilder& rr_graph_builder,
11731173
if (to_seg_details[0].length() == 0)
11741174
continue;
11751175

1176-
/* Figure out whether the switch block at the current sb_seg coordinate is *behind*
1177-
* the target channel segment (with respect to VPR coordinate system) */
1178-
is_behind = false;
1176+
// Figure out whether the switch block at the current sb_seg coordinate is *behind*
1177+
// the target channel segment (with respect to VPR coordinate system)
1178+
bool is_behind = false;
11791179
if (to_type == from_type) {
11801180
if (sb_seg == start) {
11811181
is_behind = true;
@@ -1296,12 +1296,10 @@ static int get_bidir_track_to_chan_seg(RRGraphBuilder& rr_graph_builder,
12961296
const enum e_directionality directionality,
12971297
RRNodeId from_rr_node,
12981298
t_rr_edge_info_set& rr_edges_to_create) {
1299-
unsigned iconn;
1300-
int to_track, to_switch, num_conn, to_x, to_y, i;
1301-
bool to_is_sblock;
1299+
int to_x, to_y;
13021300
short switch_types[2];
13031301

1304-
/* x, y coords for get_rr_node lookups */
1302+
// x, y coords for get_rr_node lookups
13051303
if (e_rr_type::CHANX == to_type) {
13061304
to_x = to_seg;
13071305
to_y = to_chan;
@@ -1311,27 +1309,25 @@ static int get_bidir_track_to_chan_seg(RRGraphBuilder& rr_graph_builder,
13111309
to_y = to_seg;
13121310
}
13131311

1314-
/* Go through the list of tracks we can connect to */
1315-
num_conn = 0;
1316-
for (iconn = 0; iconn < conn_tracks.size(); ++iconn) {
1317-
to_track = conn_tracks[iconn];
1312+
// Go through the list of tracks we can connect to
1313+
int num_conn = 0;
1314+
for (int to_track : conn_tracks) {
13181315
RRNodeId to_node = rr_graph_builder.node_lookup().find_node(layer, to_x, to_y, to_type, to_track);
13191316

13201317
if (!to_node) {
13211318
continue;
13221319
}
13231320

13241321
/* Get the switches for any edges between the two tracks */
1325-
to_switch = seg_details[to_track].arch_wire_switch();
1322+
int to_switch = seg_details[to_track].arch_wire_switch();
13261323

1327-
to_is_sblock = is_sblock(to_chan, to_seg, to_sb, to_track, seg_details,
1328-
directionality);
1324+
bool to_is_sblock = is_sblock(to_chan, to_seg, to_sb, to_track, seg_details, directionality);
13291325
get_switch_type(from_is_sblock, to_is_sblock, from_switch, to_switch,
13301326
switch_override,
13311327
switch_types);
13321328

1333-
/* There are up to two switch edges allowed from track to track */
1334-
for (i = 0; i < 2; ++i) {
1329+
// There are up to two switch edges allowed from track to track
1330+
for (int i = 0; i < 2; ++i) {
13351331
/* If the switch_type entry is empty, skip it */
13361332
if (UNDEFINED == switch_types[i]) {
13371333
continue;
@@ -1365,7 +1361,7 @@ static void get_switchblocks_edges(RRGraphBuilder& rr_graph_builder,
13651361

13661362
// Coordinate to index into the SB map
13671363
SwitchblockLookupKey sb_coord(tile_x, tile_y, layer, from_side, to_side);
1368-
if (sb_conn_map.count(sb_coord) > 0) {
1364+
if (sb_conn_map.contains(sb_coord)) {
13691365
// Reference to the connections vector which lists all destination wires for a given source wire
13701366
// at a specific coordinate sb_coord
13711367
const std::vector<t_switchblock_edge>& sb_edges = sb_conn_map.at(sb_coord);
@@ -1549,24 +1545,22 @@ static int get_unidir_track_to_chan_seg(RRGraphBuilder& rr_graph_builder,
15491545
}
15501546

15511547
bool is_sblock(const int chan, int wire_seg, const int sb_seg, const int track, const t_chan_seg_details* seg_details, const enum e_directionality directionality) {
1552-
int length, ofs, fac;
1553-
1554-
fac = 1;
1548+
int fac = 1;
15551549
if (UNI_DIRECTIONAL == directionality) {
15561550
fac = 2;
15571551
}
15581552

1559-
length = seg_details[track].length();
1553+
int length = seg_details[track].length();
15601554

1561-
/* Make sure they gave us correct start */
1555+
// Make sure they gave us correct start
15621556
wire_seg = get_seg_start(seg_details, track, chan, wire_seg);
15631557

1564-
ofs = sb_seg - wire_seg + 1; /* Offset 0 is behind us, so add 1 */
1558+
int ofs = sb_seg - wire_seg + 1; // Offset 0 is behind us, so add 1
15651559

15661560
VTR_ASSERT(ofs >= 0);
15671561
VTR_ASSERT(ofs < (length + 1));
15681562

1569-
/* If unidir segment that is going backwards, we need to flip the ofs */
1563+
// If unidir segment that is going backwards, we need to flip the ofs
15701564
if ((ofs % fac) > 0) {
15711565
ofs = length - ofs;
15721566
}
@@ -1661,28 +1655,21 @@ static int vpr_to_phy_track(const int itrack,
16611655
const int chan_num,
16621656
const int seg_num,
16631657
const t_chan_seg_details* seg_details,
1664-
const enum e_directionality directionality) {
1665-
int group_start, group_size;
1666-
int vpr_offset_for_first_phy_track;
1667-
int vpr_offset, phy_offset;
1668-
int phy_track;
1669-
int fac;
1658+
const e_directionality directionality) {
16701659

1671-
/* Assign in pairs if unidir. */
1672-
fac = 1;
1660+
// Assign in pairs if unidir.
1661+
int fac = 1;
16731662
if (UNI_DIRECTIONAL == directionality) {
16741663
fac = 2;
16751664
}
16761665

1677-
group_start = seg_details[itrack].group_start();
1678-
group_size = seg_details[itrack].group_size();
1666+
int group_start = seg_details[itrack].group_start();
1667+
int group_size = seg_details[itrack].group_size();
16791668

1680-
vpr_offset_for_first_phy_track = (chan_num + seg_num - 1)
1681-
% (group_size / fac);
1682-
vpr_offset = (itrack - group_start) / fac;
1683-
phy_offset = (vpr_offset_for_first_phy_track + vpr_offset)
1684-
% (group_size / fac);
1685-
phy_track = group_start + (fac * phy_offset) + (itrack - group_start) % fac;
1669+
int vpr_offset_for_first_phy_track = (chan_num + seg_num - 1) % (group_size / fac);
1670+
int vpr_offset = (itrack - group_start) / fac;
1671+
int phy_offset = (vpr_offset_for_first_phy_track + vpr_offset) % (group_size / fac);
1672+
int phy_track = group_start + (fac * phy_offset) + (itrack - group_start) % fac;
16861673

16871674
return phy_track;
16881675
}
@@ -2047,7 +2034,7 @@ static void label_incoming_wires(const int chan_num,
20472034

20482035
/* Alloc the list of labels for the tracks */
20492036
labels.resize(max_chan_width);
2050-
std::fill(labels.begin(), labels.end(), UN_SET);
2037+
std::ranges::fill(labels, UN_SET);
20512038

20522039
int num_ending = 0;
20532040
int num_passing = 0;
@@ -2134,12 +2121,12 @@ static int should_create_switchblock(const DeviceGrid& grid, int layer_num, int
21342121
x_coord = from_chan_coord;
21352122
}
21362123

2137-
auto blk_type = grid.get_physical_type({x_coord, y_coord, layer_num});
2124+
t_physical_tile_type_ptr blk_type = grid.get_physical_type({x_coord, y_coord, layer_num});
21382125
int width_offset = grid.get_width_offset({x_coord, y_coord, layer_num});
21392126
int height_offset = grid.get_height_offset({x_coord, y_coord, layer_num});
21402127

21412128
e_sb_type sb_type = blk_type->switchblock_locations[width_offset][height_offset];
2142-
auto switch_override = blk_type->switchblock_switch_overrides[width_offset][height_offset];
2129+
int switch_override = blk_type->switchblock_switch_overrides[width_offset][height_offset];
21432130

21442131
if (sb_type == e_sb_type::FULL) {
21452132
return switch_override;

vpr/src/route/rr_graph_generation/rr_graph_sg.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ void add_edges_opin_chanz_per_side(const RRGraphView& rr_graph,
167167
const t_bottleneck_link& bottleneck_link = interdie_3d_links[sb_loc0.x][sb_loc0.y][track_num];
168168
if (bottleneck_link.parallel_segment_index == seg_index && bottleneck_link.gather_loc.layer_num == layer) {
169169
RRNodeId node_id = node_lookup.find_node(sb_loc0.layer_num, sb_loc0.x, sb_loc0.y, e_rr_type::CHANZ, track_num);
170-
selected_chanz_nodes0.push_back({node_id, bottleneck_link.arch_wire_switch});
170+
selected_chanz_nodes0.emplace_back(node_id, bottleneck_link.arch_wire_switch);
171171
}
172172
}
173173

@@ -176,7 +176,7 @@ void add_edges_opin_chanz_per_side(const RRGraphView& rr_graph,
176176
const t_bottleneck_link& bottleneck_link = interdie_3d_links[sb_loc1.x][sb_loc1.y][track_num];
177177
if (bottleneck_link.parallel_segment_index == seg_index && bottleneck_link.gather_loc.layer_num == layer) {
178178
RRNodeId node_id = node_lookup.find_node(sb_loc1.layer_num, sb_loc1.x, sb_loc1.y, e_rr_type::CHANZ, track_num);
179-
selected_chanz_nodes1.push_back({node_id, bottleneck_link.arch_wire_switch});
179+
selected_chanz_nodes1.emplace_back(node_id, bottleneck_link.arch_wire_switch);
180180
}
181181
}
182182

@@ -239,7 +239,7 @@ void add_edges_opin_chanz_per_block(const RRGraphView& rr_graph,
239239
const t_bottleneck_link& bottleneck_link = interdie_3d_links[track_num];
240240
if (bottleneck_link.parallel_segment_index == seg_index && bottleneck_link.gather_loc.layer_num == layer) {
241241
RRNodeId node_id = node_lookup.find_node(layer, x, y, e_rr_type::CHANZ, track_num);
242-
selected_chanz_nodes.push_back({node_id, bottleneck_link.arch_wire_switch});
242+
selected_chanz_nodes.emplace_back(node_id, bottleneck_link.arch_wire_switch);
243243
}
244244
}
245245

0 commit comments

Comments
 (0)