place_sa: Adding seed option

Signed-off-by: David Shah <davey1576@gmail.com>
This commit is contained in:
David Shah 2018-06-17 15:04:53 +02:00
parent 681c9654d7
commit 748171dae2
4 changed files with 23 additions and 13 deletions

View File

@ -74,9 +74,10 @@ static void place_initial(Design *design, CellInfo *cell, rnd_state &rnd)
{
bool all_placed = false;
int iters = 25;
while(!all_placed) {
while (!all_placed) {
BelId best_bel = BelId();
float best_score = std::numeric_limits<float>::infinity(), best_ripup_score = std::numeric_limits<float>::infinity();
float best_score = std::numeric_limits<float>::infinity(),
best_ripup_score = std::numeric_limits<float>::infinity();
Chip &chip = design->chip;
CellInfo *ripup_target = nullptr;
BelId ripup_bel = BelId();
@ -86,7 +87,8 @@ static void place_initial(Design *design, CellInfo *cell, rnd_state &rnd)
}
BelType targetType = belTypeFromId(cell->type);
for (auto bel : chip.getBels()) {
if (chip.getBelType(bel) == targetType && isValidBelForCell(design, cell, bel)) {
if (chip.getBelType(bel) == targetType &&
isValidBelForCell(design, cell, bel)) {
if (chip.checkBelAvail(bel)) {
float score = random_float_upto(rnd, 1.0);
if (score <= best_score) {
@ -97,12 +99,11 @@ static void place_initial(Design *design, CellInfo *cell, rnd_state &rnd)
float score = random_float_upto(rnd, 1.0);
if (score <= best_ripup_score) {
best_ripup_score = score;
ripup_target = design->cells.at(chip.getBelCell(bel, true));
ripup_target =
design->cells.at(chip.getBelCell(bel, true));
ripup_bel = bel;
}
}
}
}
if (best_bel == BelId()) {
@ -123,7 +124,6 @@ static void place_initial(Design *design, CellInfo *cell, rnd_state &rnd)
cell->attrs["BEL"] = chip.getBelName(cell->bel).str();
cell = ripup_target;
}
}
// Stores the state of the SA placer
@ -293,7 +293,7 @@ BelId random_bel_for_cell(Design *design, CellInfo *cell, SAState &state,
}
}
void place_design_sa(Design *design)
void place_design_sa(Design *design, int seed)
{
SAState state;
@ -329,7 +329,7 @@ void place_design_sa(Design *design)
}
log_info("place_constraints placed %d\n", int(placed_cells));
rnd_state rnd;
rnd.state = 1;
rnd.state = seed;
std::vector<CellInfo *> autoplaced;
// Sort to-place cells for deterministic initial placement
for (auto cell : design->cells) {

View File

@ -23,7 +23,7 @@
NEXTPNR_NAMESPACE_BEGIN
extern void place_design_sa(Design *design);
extern void place_design_sa(Design *design, int seed);
NEXTPNR_NAMESPACE_END

View File

@ -82,6 +82,8 @@ int main(int argc, char *argv[])
"PCF constraints file to ingest");
options.add_options()("asc", po::value<std::string>(),
"asc bitstream file to write");
options.add_options()("seed", po::value<int>(),
"seed value for random number generator");
options.add_options()("version,V", "show version");
options.add_options()("lp384", "set device type to iCE40LP384");
options.add_options()("lp1k", "set device type to iCE40LP1K");
@ -223,8 +225,16 @@ int main(int argc, char *argv[])
pack_design(&design);
print_utilisation(&design);
int seed = 1;
if (vm.count("seed")) {
seed = vm["seed"].as<int>();
if (seed == 0)
log_error("seed must be non-zero value");
}
if (!vm.count("pack-only")) {
place_design_sa(&design);
place_design_sa(&design, seed);
route_design(&design, verbose);
}
}