Skip to content

Commit 31cf9d6

Browse files
committed
route: added penalty cost to switches
Signed-off-by: Alessandro Comodi <[email protected]>
1 parent 0718586 commit 31cf9d6

13 files changed

+94
-24
lines changed

libs/libarchfpga/src/physical_types.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1457,6 +1457,7 @@ struct t_arch_switch_inf {
14571457
float Cin = 0.;
14581458
float Cout = 0.;
14591459
float Cinternal = 0.;
1460+
float penalty_cost = 0.;
14601461
float mux_trans_size = 1.;
14611462
BufferSize buf_size_type = BufferSize::AUTO;
14621463
float buf_size = 0.;
@@ -1521,6 +1522,7 @@ struct t_rr_switch_inf {
15211522
float Cout = 0.;
15221523
float Cinternal = 0.;
15231524
float Tdel = 0.;
1525+
float penalty_cost = 0.;
15241526
float mux_trans_size = 0.;
15251527
float buf_size = 0.;
15261528
const char* name = nullptr;

libs/libarchfpga/src/read_xml_arch_file.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3978,23 +3978,23 @@ static void ProcessSwitches(pugi::xml_node Parent,
39783978
SwitchType type = SwitchType::MUX;
39793979
if (0 == strcmp(type_name, "mux")) {
39803980
type = SwitchType::MUX;
3981-
expect_only_attributes(Node, {"type", "name", "R", "Cin", "Cout", "Cinternal", "Tdel", "buf_size", "power_buf_size", "mux_trans_size"}, " with type '"s + type_name + "'"s, loc_data);
3981+
expect_only_attributes(Node, {"type", "name", "R", "Cin", "Cout", "Cinternal", "Tdel", "penalty_cost", "buf_size", "power_buf_size", "mux_trans_size"}, " with type '"s + type_name + "'"s, loc_data);
39823982

39833983
} else if (0 == strcmp(type_name, "tristate")) {
39843984
type = SwitchType::TRISTATE;
3985-
expect_only_attributes(Node, {"type", "name", "R", "Cin", "Cout", "Cinternal", "Tdel", "buf_size", "power_buf_size"}, " with type '"s + type_name + "'"s, loc_data);
3985+
expect_only_attributes(Node, {"type", "name", "R", "Cin", "Cout", "Cinternal", "Tdel", "penalty_cost", "buf_size", "power_buf_size"}, " with type '"s + type_name + "'"s, loc_data);
39863986

39873987
} else if (0 == strcmp(type_name, "buffer")) {
39883988
type = SwitchType::BUFFER;
3989-
expect_only_attributes(Node, {"type", "name", "R", "Cin", "Cout", "Tdel", "buf_size", "power_buf_size"}, " with type '"s + type_name + "'"s, loc_data);
3989+
expect_only_attributes(Node, {"type", "name", "R", "Cin", "Cout", "Tdel", "penalty_cost", "buf_size", "power_buf_size"}, " with type '"s + type_name + "'"s, loc_data);
39903990

39913991
} else if (0 == strcmp(type_name, "pass_gate")) {
39923992
type = SwitchType::PASS_GATE;
3993-
expect_only_attributes(Node, {"type", "name", "R", "Cin", "Cout", "Tdel"}, " with type '"s + type_name + "'"s, loc_data);
3993+
expect_only_attributes(Node, {"type", "name", "R", "Cin", "Cout", "Tdel", "penalty_cost"}, " with type '"s + type_name + "'"s, loc_data);
39943994

39953995
} else if (0 == strcmp(type_name, "short")) {
39963996
type = SwitchType::SHORT;
3997-
expect_only_attributes(Node, {"type", "name", "R", "Cin", "Cout", "Tdel"}, " with type "s + type_name + "'"s, loc_data);
3997+
expect_only_attributes(Node, {"type", "name", "R", "Cin", "Cout", "Tdel", "penalty_cost"}, " with type "s + type_name + "'"s, loc_data);
39983998
} else {
39993999
archfpga_throw(loc_data.filename_c_str(), loc_data.line(Node),
40004000
"Invalid switch type '%s'.\n", type_name);
@@ -4017,6 +4017,7 @@ static void ProcessSwitches(pugi::xml_node Parent,
40174017
arch_switch.Cin = get_attribute(Node, "Cin", loc_data, CIN_REQD).as_float(0);
40184018
arch_switch.Cout = get_attribute(Node, "Cout", loc_data, COUT_REQD).as_float(0);
40194019
arch_switch.Cinternal = get_attribute(Node, "Cinternal", loc_data, CINTERNAL_REQD).as_float(0);
4020+
arch_switch.penalty_cost = get_attribute(Node, "penalty_cost", loc_data, ReqOpt::OPTIONAL).as_float(0);
40204021

40214022
if (arch_switch.type() == SwitchType::MUX) {
40224023
//Only muxes have mux transistors

libs/libvtrcapnproto/gen/rr_graph_uxsdcxx.capnp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
# https://github.com/duck2/uxsdcxx
33
# Modify only if your build process doesn't involve regenerating this file.
44
#
5-
# Cmdline: uxsdcxx/uxsdcap.py /home/kmurray/trees/vtr/vpr/src/route/rr_graph.xsd
6-
# Input file: /home/kmurray/trees/vtr/vpr/src/route/rr_graph.xsd
7-
# md5sum of input file: 40e83d2ea6556761d4e29f21324b1871
5+
# Cmdline: uxsdcxx/uxsdcap.py rr_graph.xsd
6+
# Input file: rr_graph.xsd
7+
# md5sum of input file: c4f47394efd27f5819c943829c111204
88

9-
@0xb803100e76d3342d;
9+
@0x9e90feddf132e6a8;
1010
using Cxx = import "/capnp/c++.capnp";
1111
$Cxx.namespace("ucap");
1212

@@ -81,6 +81,7 @@ struct Timing {
8181
cout @2 :Float32;
8282
r @3 :Float32;
8383
tdel @4 :Float32;
84+
penaltyCost @5 :Float32;
8485
}
8586

8687
struct Sizing {

vpr/src/base/SetupVPR.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,7 @@ static void SetupSwitches(const t_arch& Arch,
282282
device_ctx.arch_switch_inf[RoutingArch->delayless_switch].R = 0.;
283283
device_ctx.arch_switch_inf[RoutingArch->delayless_switch].Cin = 0.;
284284
device_ctx.arch_switch_inf[RoutingArch->delayless_switch].Cout = 0.;
285+
device_ctx.arch_switch_inf[RoutingArch->delayless_switch].penalty_cost = 0.;
285286
device_ctx.arch_switch_inf[RoutingArch->delayless_switch].set_Tdel(t_arch_switch_inf::UNDEFINED_FANIN, 0.);
286287
device_ctx.arch_switch_inf[RoutingArch->delayless_switch].power_buffer_type = POWER_BUFFER_TYPE_NONE;
287288
device_ctx.arch_switch_inf[RoutingArch->delayless_switch].mux_trans_size = 0.;

vpr/src/route/gen/rr_graph_uxsdcxx.h

Lines changed: 26 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vpr/src/route/gen/rr_graph_uxsdcxx_capnp.h

Lines changed: 6 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vpr/src/route/gen/rr_graph_uxsdcxx_interface.h

Lines changed: 6 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vpr/src/route/router_lookahead.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,19 @@ float ClassicLookahead::classic_wire_lookahead_cost(int inode, int target_node,
7676
+ ipin_data.base_cost
7777
+ sink_data.base_cost;
7878

79+
float penalty_cost = num_segs_same_dir * same_data.penalty_cost
80+
+ num_segs_ortho_dir * ortho_data.penalty_cost
81+
+ ipin_data.penalty_cost
82+
+ sink_data.penalty_cost;
83+
7984
float Tdel = num_segs_same_dir * same_data.T_linear
8085
+ num_segs_ortho_dir * ortho_data.T_linear
8186
+ num_segs_same_dir * num_segs_same_dir * same_data.T_quadratic
8287
+ num_segs_ortho_dir * num_segs_ortho_dir * ortho_data.T_quadratic
8388
+ R_upstream * (num_segs_same_dir * same_data.C_load + num_segs_ortho_dir * ortho_data.C_load)
8489
+ ipin_data.T_linear;
8590

86-
float expected_cost = criticality * Tdel + (1. - criticality) * cong_cost;
91+
float expected_cost = criticality * penalty_cost + criticality * Tdel + (1. - criticality) * cong_cost;
8792
return (expected_cost);
8893
}
8994

vpr/src/route/rr_graph.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -884,6 +884,7 @@ void load_rr_switch_from_arch_switch(int arch_switch_idx,
884884
device_ctx.rr_switch_inf[rr_switch_idx].Cin = device_ctx.arch_switch_inf[arch_switch_idx].Cin;
885885
device_ctx.rr_switch_inf[rr_switch_idx].Cinternal = device_ctx.arch_switch_inf[arch_switch_idx].Cinternal;
886886
device_ctx.rr_switch_inf[rr_switch_idx].Cout = device_ctx.arch_switch_inf[arch_switch_idx].Cout;
887+
device_ctx.rr_switch_inf[rr_switch_idx].penalty_cost = device_ctx.arch_switch_inf[arch_switch_idx].penalty_cost;
887888
device_ctx.rr_switch_inf[rr_switch_idx].Tdel = rr_switch_Tdel;
888889
device_ctx.rr_switch_inf[rr_switch_idx].mux_trans_size = device_ctx.arch_switch_inf[arch_switch_idx].mux_trans_size;
889890
if (device_ctx.arch_switch_inf[arch_switch_idx].buf_size_type == BufferSize::AUTO) {

vpr/src/route/rr_graph.xsd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@
101101
<xs:attribute name="Cinternal" type="xs:float"/>
102102
<xs:attribute name="Cout" type="xs:float"/>
103103
<xs:attribute name="Tdel" type="xs:float"/>
104+
<xs:attribute name="penalty_cost" type="xs:float"/>
104105
</xs:complexType>
105106

106107
<xs:complexType name="sizing">

vpr/src/route/rr_graph_indexed_data.cpp

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,13 @@ void alloc_and_load_rr_indexed_data(const std::vector<t_segment_inf>& segment_in
7777
device_ctx.rr_indexed_data[i].T_linear = 0.;
7878
device_ctx.rr_indexed_data[i].T_quadratic = 0.;
7979
device_ctx.rr_indexed_data[i].C_load = 0.;
80+
device_ctx.rr_indexed_data[i].penalty_cost = 0.;
8081
}
82+
8183
device_ctx.rr_indexed_data[IPIN_COST_INDEX].T_linear = device_ctx.rr_switch_inf[wire_to_ipin_switch].Tdel;
8284

85+
device_ctx.rr_indexed_data[IPIN_COST_INDEX].penalty_cost = device_ctx.rr_switch_inf[wire_to_ipin_switch].penalty_cost;
86+
8387
/* X-directed segments. */
8488
for (iseg = 0; iseg < num_segment; iseg++) {
8589
index = CHANX_COST_INDEX_START + iseg;
@@ -319,8 +323,8 @@ static void load_rr_indexed_data_T_values(int index_start,
319323
* segment. */
320324

321325
int itrack, cost_index;
322-
float *C_total, *R_total; /* [0..device_ctx.rr_indexed_data.size() - 1] */
323-
double *switch_R_total, *switch_T_total, *switch_Cinternal_total; /* [0..device_ctx.rr_indexed_data.size() - 1] */
326+
float *C_total, *R_total; /* [0..device_ctx.rr_indexed_data.size() - 1] */
327+
double *switch_R_total, *switch_T_total, *switch_Cinternal_total, *switch_penalty_cost_total; /* [0..device_ctx.rr_indexed_data.size() - 1] */
324328
short* switches_buffered;
325329
int* num_nodes_of_index; /* [0..device_ctx.rr_indexed_data.size() - 1] */
326330
float Rnode, Cnode, Rsw, Tsw, Cinternalsw;
@@ -340,6 +344,7 @@ static void load_rr_indexed_data_T_values(int index_start,
340344
switch_R_total = (double*)vtr::calloc(device_ctx.rr_indexed_data.size(), sizeof(double));
341345
switch_T_total = (double*)vtr::calloc(device_ctx.rr_indexed_data.size(), sizeof(double));
342346
switch_Cinternal_total = (double*)vtr::calloc(device_ctx.rr_indexed_data.size(), sizeof(double));
347+
switch_penalty_cost_total = (double*)vtr::calloc(device_ctx.rr_indexed_data.size(), sizeof(double));
343348
switches_buffered = (short*)vtr::calloc(device_ctx.rr_indexed_data.size(), sizeof(short));
344349

345350
/* initialize switches_buffered array */
@@ -364,9 +369,23 @@ static void load_rr_indexed_data_T_values(int index_start,
364369
double avg_switch_R = 0;
365370
double avg_switch_T = 0;
366371
double avg_switch_Cinternal = 0;
372+
double avg_switch_penalty_cost = 0;
373+
int num_edges = device_ctx.rr_nodes[inode].num_edges();
367374
int num_switches = 0;
368375
short buffered = UNDEFINED;
369-
calculate_average_switch(inode, avg_switch_R, avg_switch_T, avg_switch_Cinternal, num_switches, buffered);
376+
for (int iedge = 0; iedge < num_edges; iedge++) {
377+
int to_node_index = device_ctx.rr_nodes[inode].edge_sink_node(iedge);
378+
/* want to get C/R/Tdel/Cinternal of switches that connect this track segment to other track segments */
379+
if (device_ctx.rr_nodes[to_node_index].type() == CHANX || device_ctx.rr_nodes[to_node_index].type() == CHANY) {
380+
int switch_index = device_ctx.rr_nodes[inode].edge_switch(iedge);
381+
avg_switch_R += device_ctx.rr_switch_inf[switch_index].R;
382+
avg_switch_T += device_ctx.rr_switch_inf[switch_index].Tdel;
383+
avg_switch_Cinternal += device_ctx.rr_switch_inf[switch_index].Cinternal;
384+
avg_switch_penalty_cost += device_ctx.rr_switch_inf[switch_index].penalty_cost;
385+
386+
num_switches++;
387+
}
388+
}
370389

371390
if (num_switches == 0) {
372391
VTR_LOG_WARN("Track %d had no out-going switches\n", itrack);
@@ -377,6 +396,7 @@ static void load_rr_indexed_data_T_values(int index_start,
377396
switch_R_total[cost_index] += avg_switch_R;
378397
switch_T_total[cost_index] += avg_switch_T;
379398
switch_Cinternal_total[cost_index] += avg_switch_Cinternal;
399+
switch_penalty_cost_total[cost_index] += avg_switch_penalty_cost;
380400
if (buffered == UNDEFINED) {
381401
/* this segment does not have any outgoing edges to other general routing wires */
382402
continue;
@@ -461,6 +481,8 @@ static void load_rr_indexed_data_T_values(int index_start,
461481
device_ctx.rr_indexed_data[cost_index].T_quadratic = (Rsw + Rnode) * 0.5
462482
* Cnode;
463483
}
484+
485+
device_ctx.rr_indexed_data[cost_index].penalty_cost = (float)switch_penalty_cost_total[cost_index] / num_nodes_of_index[cost_index];
464486
}
465487
}
466488

@@ -470,6 +492,7 @@ static void load_rr_indexed_data_T_values(int index_start,
470492
free(switch_R_total);
471493
free(switch_T_total);
472494
free(switch_Cinternal_total);
495+
free(switch_penalty_cost_total);
473496
free(switches_buffered);
474497
}
475498

vpr/src/route/rr_graph_uxsdcxx_serializer.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,13 @@ class RrGraphSerializer final : public uxsd::RrGraphBase<RrGraphContextTypes> {
355355
return sw->Tdel;
356356
}
357357

358+
inline void set_timing_penalty_cost(float penalty_cost, t_rr_switch_inf*& sw) final {
359+
sw->penalty_cost = penalty_cost;
360+
}
361+
inline float get_timing_penalty_cost(const t_rr_switch_inf*& sw) final {
362+
return sw->penalty_cost;
363+
}
364+
358365
/** Generated for complex type "switch":
359366
* <xs:complexType name="switch">
360367
* <xs:all>

vpr/src/route/rr_node.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ struct t_rr_indexed_data {
185185
float T_linear = std::numeric_limits<float>::quiet_NaN();
186186
float T_quadratic = std::numeric_limits<float>::quiet_NaN();
187187
float C_load = std::numeric_limits<float>::quiet_NaN();
188+
float penalty_cost;
188189
};
189190

190191
#include "rr_node_impl.h"

0 commit comments

Comments
 (0)