Skip to content

Commit ddae365

Browse files
Merge pull request #2871 from verilog-to-routing/making_packer_rng_deterministic
Changed the random number generator in packer to deterministic vtr::irand
2 parents ca53359 + 313753c commit ddae365

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

vpr/src/pack/greedy_candidate_selector.cpp

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ GreedyCandidateSelector::GreedyCandidateSelector(
7777
is_clock_(is_clock),
7878
is_global_(is_global),
7979
net_output_feeds_driving_block_input_(net_output_feeds_driving_block_input),
80-
timing_info_(timing_info) {
80+
timing_info_(timing_info),
81+
rng_(0) {
8182
// Initialize the list of molecules to pack, the clustering data, and the
8283
// net info.
8384

@@ -779,17 +780,9 @@ void GreedyCandidateSelector::add_cluster_molecule_candidates_by_attraction_grou
779780
return;
780781
}
781782

782-
int min = 0;
783-
int max = num_available_atoms - 1;
784-
785783
for (int j = 0; j < attraction_group_num_atoms_threshold_; j++) {
786-
// FIXME: This is a non-deterministic random number generator and it is
787-
// overkill to what this needs to be. Should use vtr::irand which
788-
// would be faster.
789-
std::random_device rd;
790-
std::mt19937 gen(rd());
791-
std::uniform_int_distribution<> distr(min, max);
792-
int selected_atom = distr(gen);
784+
//Get a random atom between 0 and the number of available atoms - 1
785+
int selected_atom = rng_.irand(num_available_atoms - 1);
793786

794787
AtomBlockId blk_id = available_atoms[selected_atom];
795788

vpr/src/pack/greedy_candidate_selector.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "cluster_legalizer.h"
1717
#include "physical_types.h"
1818
#include "vtr_vector.h"
19+
#include "vtr_random.h"
1920

2021
// Forward declarations
2122
class AtomNetlist;
@@ -516,5 +517,10 @@ class GreedyCandidateSelector {
516517
/// @brief A count on the number of unrelated clustering attempts which
517518
/// have been performed.
518519
int num_unrelated_clustering_attempts_ = 0;
520+
521+
/// @brief Random number generator used by the clusterer. Currently this
522+
/// is used only when selecting atoms from attraction groups, but
523+
/// could be used for other purposes in the future.
524+
vtr::RngContainer rng_;
519525
};
520526

0 commit comments

Comments
 (0)