Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit e03148a

Browse files
committedOct 30, 2024
use RngContainer in cb_metrics.cpp
1 parent c99b45f commit e03148a

File tree

3 files changed

+47
-17
lines changed

3 files changed

+47
-17
lines changed
 

‎vpr/src/place/move_utils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,7 @@ ClusterBlockId propose_block_to_move(const t_placer_opts& placer_opts,
588588
}
589589
} else { //If the block type is specified, choose a random block with blk_type to be swapped with another random block
590590
if (highly_crit_block) {
591-
b_from = pick_from_highly_critical_block(*net_from, *pin_from, logical_blk_type_index, placer_state);
591+
b_from = pick_from_highly_critical_block(*net_from, *pin_from, logical_blk_type_index, placer_state, rng);
592592
} else {
593593
b_from = pick_from_block(logical_blk_type_index, rng);
594594
}

‎vpr/src/place/move_utils.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,8 @@ ClusterBlockId pick_from_highly_critical_block(ClusterNetId& net_from,
236236
ClusterBlockId pick_from_highly_critical_block(ClusterNetId& net_from,
237237
int& pin_from,
238238
int logical_blk_type_index,
239-
const PlacerState& placer_state);
239+
const PlacerState& placer_state,
240+
vtr::RngContainer& rng);
240241

241242
bool find_to_loc_uniform(t_logical_block_type_ptr type,
242243
float rlim,

‎vpr/src/route/cb_metrics.cpp

Lines changed: 44 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -105,14 +105,27 @@ static float get_lemieux_cost_func(const int exponent, const bool both_sides, co
105105

106106
/* this annealer is used to adjust a desired wire or pin metric while keeping the other type of metric
107107
* relatively constant */
108-
static bool annealer(const e_metric metric, const int nodes_per_chan, const t_physical_tile_type_ptr block_type, const e_pin_type pin_type, const int Fc, const int num_pin_type_pins, const float target_metric, const float target_metric_tolerance, int***** pin_to_track_connections, Conn_Block_Metrics* cb_metrics);
108+
static bool annealer(const e_metric metric, const int nodes_per_chan, const t_physical_tile_type_ptr block_type, const e_pin_type pin_type, const int Fc, const int num_pin_type_pins, const float target_metric, const float target_metric_tolerance, int***** pin_to_track_connections, Conn_Block_Metrics* cb_metrics, vtr::RngContainer& rng);
109109
/* updates temperature based on current temperature and the annealer's outer loop iteration */
110110
static double update_temp(const double temp);
111111
/* determines whether to accept or reject a proposed move based on the resulting delta of the cost and current temperature */
112-
static bool accept_move(const double del_cost, const double temp);
112+
static bool accept_move(const double del_cost, const double temp, vtr::RngContainer& rng);
113113
/* this function simply moves a switch from one track to another track (with an empty slot). The switch stays on the
114114
* same pin as before. */
115-
static double try_move(const e_metric metric, const int nodes_per_chan, const float initial_orthogonal_metric, const float orthogonal_metric_tolerance, const t_physical_tile_type_ptr block_type, const e_pin_type pin_type, const int Fc, const int num_pin_type_pins, const double cost, const double temp, const float target_metric, int***** pin_to_track_connections, Conn_Block_Metrics* cb_metrics);
115+
static double try_move(const e_metric metric,
116+
const int nodes_per_chan,
117+
const float initial_orthogonal_metric,
118+
const float orthogonal_metric_tolerance,
119+
const t_physical_tile_type_ptr block_type,
120+
const e_pin_type pin_type,
121+
const int Fc,
122+
const int num_pin_type_pins,
123+
const double cost,
124+
const double temp,
125+
const float target_metric,
126+
int***** pin_to_track_connections,
127+
Conn_Block_Metrics* cb_metrics,
128+
vtr::RngContainer& rng);
116129

117130
static void print_switch_histogram(const int nodes_per_chan, const Conn_Block_Metrics* cb_metrics);
118131

@@ -157,9 +170,11 @@ void adjust_cb_metric(const e_metric metric, const float target, const float tar
157170
get_conn_block_metrics(block_type, pin_to_track_connections, num_segments, segment_inf, pin_type,
158171
Fc_array, chan_width_inf, &cb_metrics);
159172

173+
174+
vtr::RngContainer rng(0);
160175
/* now run the annealer to adjust the desired metric towards the target value */
161176
bool success = annealer(metric, nodes_per_chan, block_type, pin_type, Fc, num_pin_type_pins, target,
162-
target_tolerance, pin_to_track_connections, &cb_metrics);
177+
target_tolerance, pin_to_track_connections, &cb_metrics, rng);
163178
if (!success) {
164179
VTR_LOG("Failed to adjust specified connection block metric\n");
165180
}
@@ -658,15 +673,28 @@ static void find_tracks_unconnected_to_pin(const std::set<int>* pin_tracks, cons
658673

659674
/* this function simply moves a switch from one track to another track (with an empty slot). The switch stays on the
660675
* same pin as before. */
661-
static double try_move(const e_metric metric, const int nodes_per_chan, const float initial_orthogonal_metric, const float orthogonal_metric_tolerance, const t_physical_tile_type_ptr block_type, const e_pin_type pin_type, const int Fc, const int num_pin_type_pins, const double cost, const double temp, const float target_metric, int***** pin_to_track_connections, Conn_Block_Metrics* cb_metrics) {
676+
static double try_move(const e_metric metric,
677+
const int nodes_per_chan,
678+
const float initial_orthogonal_metric,
679+
const float orthogonal_metric_tolerance,
680+
const t_physical_tile_type_ptr block_type,
681+
const e_pin_type pin_type,
682+
const int Fc,
683+
const int num_pin_type_pins,
684+
const double cost,
685+
const double temp,
686+
const float target_metric,
687+
int***** pin_to_track_connections,
688+
Conn_Block_Metrics* cb_metrics,
689+
vtr::RngContainer& rng) {
662690
double new_cost = 0;
663691
float new_orthogonal_metric = 0;
664692
float new_metric = 0;
665693

666694
/* will determine whether we should revert the attempted move at the end of this function */
667695
bool revert = false;
668696
/* indicates whether or not we allow a track to be fully disconnected from all the pins of the connection block
669-
* in the processs of trying a move (to allow this, preserve_tracks is set to false) */
697+
* in the process of trying a move (to allow this, preserve_tracks is set to false) */
670698
const bool preserve_tracks = true;
671699

672700
t_vec_vec_set* pin_to_tracks = &cb_metrics->pin_to_tracks;
@@ -694,8 +722,8 @@ static double try_move(const e_metric metric, const int nodes_per_chan, const fl
694722
set_of_tracks.clear();
695723

696724
/* choose a random side, random pin, and a random switch */
697-
int rand_side = vtr::irand(3);
698-
int rand_pin_index = vtr::irand(cb_metrics->pin_locations.at(rand_side).size() - 1);
725+
int rand_side = rng.irand(3);
726+
int rand_pin_index = rng.irand(cb_metrics->pin_locations.at(rand_side).size() - 1);
699727
int rand_pin = cb_metrics->pin_locations.at(rand_side).at(rand_pin_index);
700728
std::set<int>* tracks_connected_to_pin = &pin_to_tracks->at(rand_side).at(rand_pin_index);
701729

@@ -724,12 +752,12 @@ static double try_move(const e_metric metric, const int nodes_per_chan, const fl
724752
new_cost = cost;
725753
} else {
726754
/* now choose a random track from the returned set of qualifying tracks */
727-
int old_track = vtr::irand(set_of_tracks.size() - 1);
755+
int old_track = rng.irand(set_of_tracks.size() - 1);
728756
old_track = set_of_tracks.at(old_track);
729757

730758
/* next, get a new track connection i.e. one that is not already connected to our randomly chosen pin */
731759
find_tracks_unconnected_to_pin(tracks_connected_to_pin, &track_to_pins->at(rand_side), &set_of_tracks);
732-
int new_track = vtr::irand(set_of_tracks.size() - 1);
760+
int new_track = rng.irand(set_of_tracks.size() - 1);
733761
new_track = set_of_tracks.at(new_track);
734762

735763
/* move the rand_pin's connection from the old track to the new track and see what the new cost is */
@@ -781,7 +809,7 @@ static double try_move(const e_metric metric, const int nodes_per_chan, const fl
781809
}
782810
new_cost = fabs(target_metric - new_metric);
783811
delta_cost = new_cost - cost;
784-
if (!accept_move(delta_cost, temp)) {
812+
if (!accept_move(delta_cost, temp, rng)) {
785813
revert = true;
786814
}
787815
} else {
@@ -843,7 +871,7 @@ static double try_move(const e_metric metric, const int nodes_per_chan, const fl
843871

844872
/* this annealer is used to adjust a desired wire or pin metric while keeping the other type of metric
845873
* relatively constant */
846-
static bool annealer(const e_metric metric, const int nodes_per_chan, const t_physical_tile_type_ptr block_type, const e_pin_type pin_type, const int Fc, const int num_pin_type_pins, const float target_metric, const float target_metric_tolerance, int***** pin_to_track_connections, Conn_Block_Metrics* cb_metrics) {
874+
static bool annealer(const e_metric metric, const int nodes_per_chan, const t_physical_tile_type_ptr block_type, const e_pin_type pin_type, const int Fc, const int num_pin_type_pins, const float target_metric, const float target_metric_tolerance, int***** pin_to_track_connections, Conn_Block_Metrics* cb_metrics, vtr::RngContainer& rng) {
847875
bool success = false;
848876
double temp = INITIAL_TEMP;
849877

@@ -890,7 +918,8 @@ static bool annealer(const e_metric metric, const int nodes_per_chan, const t_ph
890918
for (int i_inner = 0; i_inner < MAX_INNER_ITERATIONS; i_inner++) {
891919
double new_cost = 0;
892920
new_cost = try_move(metric, nodes_per_chan, initial_orthogonal_metric, orthogonal_metric_tolerance,
893-
block_type, pin_type, Fc, num_pin_type_pins, cost, temp, target_metric, pin_to_track_connections, cb_metrics);
921+
block_type, pin_type, Fc, num_pin_type_pins, cost, temp, target_metric,
922+
pin_to_track_connections, cb_metrics, rng);
894923

895924
/* update the cost after trying the move */
896925
if (new_cost != cost) {
@@ -937,7 +966,7 @@ static double update_temp(const double temp) {
937966
}
938967

939968
/* determines whether to accept or reject a proposed move based on the resulting delta of the cost and current temperature */
940-
static bool accept_move(const double del_cost, const double temp) {
969+
static bool accept_move(const double del_cost, const double temp, vtr::RngContainer& rng) {
941970
bool accept = false;
942971

943972
if (del_cost < 0) {
@@ -946,7 +975,7 @@ static bool accept_move(const double del_cost, const double temp) {
946975
} else {
947976
/* determine probabilistically whether or not to accept */
948977
double probability = pow(2.718, -(del_cost / temp));
949-
double rand_value = (double)vtr::frand();
978+
double rand_value = (double)rng.frand();
950979
if (rand_value < probability) {
951980
accept = true;
952981
} else {

0 commit comments

Comments
 (0)
Please sign in to comment.