Skip to content

Commit f924fe4

Browse files
committed
Merge branch 'ipin_base_cost' of https://github.com/verilog-to-routing/vtr-verilog-to-routing into add_crr
2 parents 56796ca + 4dd6a63 commit f924fe4

File tree

2 files changed

+51
-10
lines changed

2 files changed

+51
-10
lines changed

libs/librrgraph/src/utils/alloc_and_load_rr_indexed_data.cpp

Lines changed: 50 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include <algorithm>
44
#include <cmath> /* Needed only for sqrt call (remove if sqrt removed) */
5+
#include <cstddef>
56
#include <fstream>
67
#include <iomanip>
78
#include <numeric>
@@ -28,7 +29,9 @@ static void load_rr_indexed_data_base_costs(const RRGraphView& rr_graph,
2829

2930
static float get_delay_normalization_fac(const vtr::vector<RRIndexedDataId, t_rr_indexed_data>& rr_indexed_data, const bool echo_enabled, const char* echo_file_name);
3031

31-
static void load_rr_indexed_data_T_values(const RRGraphView& rr_graph, vtr::vector<RRIndexedDataId, t_rr_indexed_data>& rr_indexed_data);
32+
static void load_rr_indexed_data_T_values(const RRGraphView& rr_graph,
33+
const RRSwitchId wire_to_ipin_switch,
34+
vtr::vector<RRIndexedDataId, t_rr_indexed_data>& rr_indexed_data);
3235

3336
/**
3437
* @brief Computes average R, Tdel, and Cinternal of fan-in switches for a given node.
@@ -49,7 +52,7 @@ static void calculate_average_switch(const RRGraphView& rr_graph,
4952
int& num_switches,
5053
int& num_shorts,
5154
short& buffered,
52-
vtr::vector<RRNodeId, std::vector<RREdgeId>>& fan_in_list);
55+
const vtr::vector<RRNodeId, std::vector<RREdgeId>>& fan_in_list);
5356

5457
static void fixup_rr_indexed_data_T_values(vtr::vector<RRIndexedDataId, t_rr_indexed_data>& rr_indexed_data, size_t num_segment);
5558

@@ -84,7 +87,7 @@ void alloc_and_load_rr_indexed_data(const RRGraphView& rr_graph,
8487
const std::vector<t_segment_inf>& segment_inf_y,
8588
const std::vector<t_segment_inf>& segment_inf_z,
8689
vtr::vector<RRIndexedDataId, t_rr_indexed_data>& rr_indexed_data,
87-
RRSwitchId wire_to_ipin_switch,
90+
const RRSwitchId wire_to_ipin_switch,
8891
e_base_cost_type base_cost_type,
8992
const bool echo_enabled,
9093
const char* echo_file_name) {
@@ -108,9 +111,6 @@ void alloc_and_load_rr_indexed_data(const RRGraphView& rr_graph,
108111
rr_indexed_data[RRIndexedDataId(i)].C_load = 0.;
109112
}
110113

111-
//TODO: SM: IPIN t_linear assumes wire_to_ipin_switch which corresponds to within die switch connection
112-
rr_indexed_data[RRIndexedDataId(IPIN_COST_INDEX)].T_linear = rr_graph.rr_switch_inf(wire_to_ipin_switch).Tdel;
113-
114114
std::vector<int> ortho_costs = find_ortho_cost_index(rr_graph, segment_inf_x, segment_inf_y, e_parallel_axis::X_AXIS);
115115

116116
/* AA: The code below should replace find_ortho_cost_index call once we deprecate the CLASSIC lookahead as it is the only lookahead
@@ -158,7 +158,9 @@ void alloc_and_load_rr_indexed_data(const RRGraphView& rr_graph,
158158
rr_indexed_data[index].seg_index = seg_ptr->seg_index;
159159
}
160160

161-
load_rr_indexed_data_T_values(rr_graph, rr_indexed_data);
161+
load_rr_indexed_data_T_values(rr_graph,
162+
wire_to_ipin_switch,
163+
rr_indexed_data);
162164

163165
fixup_rr_indexed_data_T_values(rr_indexed_data, total_num_segment);
164166

@@ -513,6 +515,7 @@ static float get_delay_normalization_fac(const vtr::vector<RRIndexedDataId, t_rr
513515
* - Placement Delay Matrix computation
514516
*/
515517
static void load_rr_indexed_data_T_values(const RRGraphView& rr_graph,
518+
const RRSwitchId wire_to_ipin_switch,
516519
vtr::vector<RRIndexedDataId, t_rr_indexed_data>& rr_indexed_data) {
517520
vtr::vector<RRNodeId, std::vector<RREdgeId>> fan_in_list = get_fan_in_list(rr_graph);
518521

@@ -531,12 +534,25 @@ static void load_rr_indexed_data_T_values(const RRGraphView& rr_graph,
531534
vtr::vector<RRIndexedDataId, std::vector<float>> switch_Cinternal_total(rr_indexed_data.size());
532535
vtr::vector<RRIndexedDataId, short> switches_buffered(rr_indexed_data.size(), LIBRRGRAPH_UNDEFINED_VAL);
533536

537+
std::map<short, size_t> ipin_switch_count;
538+
534539
// Walk through the RR graph and collect all R and C values of all the nodes,
535540
// as well as their fan-in switches R, T_del, and Cinternal values.
536541
// The median of R and C values for each cost index is assigned to the indexed data.
537542
for (const RRNodeId rr_id : rr_graph.nodes()) {
538543
e_rr_type rr_type = rr_graph.node_type(rr_id);
539544

545+
if (rr_type == e_rr_type::IPIN) {
546+
for (const RREdgeId edge : fan_in_list[rr_id]) {
547+
short switch_index = rr_graph.rr_nodes().edge_switch(edge);
548+
if (ipin_switch_count.find(switch_index) == ipin_switch_count.end()) {
549+
ipin_switch_count[switch_index] = 1;
550+
} else {
551+
ipin_switch_count[switch_index]++;
552+
}
553+
}
554+
}
555+
540556
if (!is_chanxy(rr_type) && !is_chanz(rr_type)) {
541557
continue;
542558
}
@@ -550,7 +566,15 @@ static void load_rr_indexed_data_T_values(const RRGraphView& rr_graph,
550566
int num_switches = 0;
551567
int num_shorts = 0;
552568
short buffered = LIBRRGRAPH_UNDEFINED_VAL;
553-
calculate_average_switch(rr_graph, rr_id, avg_switch_R, avg_switch_T, avg_switch_Cinternal, num_switches, num_shorts, buffered, fan_in_list);
569+
calculate_average_switch(rr_graph,
570+
rr_id,
571+
avg_switch_R,
572+
avg_switch_T,
573+
avg_switch_Cinternal,
574+
num_switches,
575+
num_shorts,
576+
buffered,
577+
fan_in_list);
554578

555579
if (num_switches == 0) {
556580
if (num_shorts == 0) {
@@ -590,6 +614,23 @@ static void load_rr_indexed_data_T_values(const RRGraphView& rr_graph,
590614
}
591615
}
592616

617+
short most_frequent_ipin_switch = -1;
618+
size_t most_frequent_ipin_switch_count = 0;
619+
for (const auto& [switch_index, count] : ipin_switch_count) {
620+
if (count > most_frequent_ipin_switch_count) {
621+
most_frequent_ipin_switch = switch_index;
622+
most_frequent_ipin_switch_count = count;
623+
}
624+
}
625+
VTR_ASSERT(most_frequent_ipin_switch != -1);
626+
rr_indexed_data[RRIndexedDataId(IPIN_COST_INDEX)].T_linear = rr_graph.rr_switch_inf(RRSwitchId(most_frequent_ipin_switch)).Tdel;
627+
short wire_to_ipin_switch_index = static_cast<short>(size_t(wire_to_ipin_switch));
628+
if (most_frequent_ipin_switch != wire_to_ipin_switch_index) {
629+
VTR_LOG_WARN("Most frequent ipin switch %d is not the same as the wire_to_ipin_switch %d\n",
630+
most_frequent_ipin_switch,
631+
wire_to_ipin_switch_index);
632+
}
633+
593634
unsigned num_occurences_of_no_instances_with_cost_index = 0;
594635
for (size_t cost_index = CHANX_COST_INDEX_START; cost_index < rr_indexed_data.size(); cost_index++) {
595636
if (num_nodes_of_index[RRIndexedDataId(cost_index)] == 0) { // Segments don't exist.
@@ -650,7 +691,7 @@ static void calculate_average_switch(const RRGraphView& rr_graph,
650691
int& num_switches,
651692
int& num_shorts,
652693
short& buffered,
653-
vtr::vector<RRNodeId, std::vector<RREdgeId>>& fan_in_list) {
694+
const vtr::vector<RRNodeId, std::vector<RREdgeId>>& fan_in_list) {
654695

655696
avg_switch_R = 0;
656697
avg_switch_T = 0;

libs/librrgraph/src/utils/alloc_and_load_rr_indexed_data.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ void alloc_and_load_rr_indexed_data(const RRGraphView& rr_graph,
1212
const std::vector<t_segment_inf>& segment_inf_y,
1313
const std::vector<t_segment_inf>& segment_inf_z,
1414
vtr::vector<RRIndexedDataId, t_rr_indexed_data>& rr_indexed_data,
15-
RRSwitchId wire_to_ipin_switch,
15+
const RRSwitchId wire_to_ipin_switch,
1616
e_base_cost_type base_cost_type,
1717
const bool echo_enabled,
1818
const char* echo_file_name);

0 commit comments

Comments
 (0)