Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed the random number generator in packer to deterministic vtr::irand #2871

Merged
merged 4 commits into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 4 additions & 11 deletions vpr/src/pack/greedy_candidate_selector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ GreedyCandidateSelector::GreedyCandidateSelector(
is_clock_(is_clock),
is_global_(is_global),
net_output_feeds_driving_block_input_(net_output_feeds_driving_block_input),
timing_info_(timing_info) {
timing_info_(timing_info),
rng_(0) {
// Initialize the list of molecules to pack, the clustering data, and the
// net info.

Expand Down Expand Up @@ -779,17 +780,9 @@ void GreedyCandidateSelector::add_cluster_molecule_candidates_by_attraction_grou
return;
}

int min = 0;
int max = num_available_atoms - 1;

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

AtomBlockId blk_id = available_atoms[selected_atom];

Expand Down
5 changes: 5 additions & 0 deletions vpr/src/pack/greedy_candidate_selector.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "cluster_legalizer.h"
#include "physical_types.h"
#include "vtr_vector.h"
#include "vtr_random.h"
AlexandreSinger marked this conversation as resolved.
Show resolved Hide resolved

// Forward declarations
class AtomNetlist;
Expand Down Expand Up @@ -516,5 +517,9 @@ class GreedyCandidateSelector {
/// @brief A count on the number of unrelated clustering attempts which
/// have been performed.
int num_unrelated_clustering_attempts_ = 0;

/// @brief Random number generator to get a random atom between 0 and
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd make this slightly more general to start.
I'd change this to:
@brief Random number generator used by the clusterer. Currently this is used only when selecting atoms from
attraction groups, but could be used for other purposes in the future.

/// number of available atoms -1 for attraction group.
vtr::RngContainer rng_;
};

Loading