Skip to content

Commit 22e69b1

Browse files
authored
Merge pull request #1433 from verilog-to-routing/adding_fix_clusters_option
vpr: Add fix_clusters option to allow users to lock down any block to…
2 parents e28aafe + 9f0515f commit 22e69b1

File tree

20 files changed

+643
-97
lines changed

20 files changed

+643
-97
lines changed

libs/EXTERNAL/libargparse/argparse_test.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ struct Args {
5151
ArgValue<float> exit_t;
5252
ArgValue<float> alpha_t;
5353
ArgValue<std::string> fix_pins;
54+
ArgValue<std::string> fix_clusters;
5455
ArgValue<std::string> place_algorithm;
5556
ArgValue<size_t> place_chan_width;
5657

@@ -302,6 +303,13 @@ int main(
302303
" or a file specifying the pad locations.")
303304
.default_value("off")
304305
.show_in(argparse::ShowIn::HELP_ONLY);
306+
place_grp.add_argument(args.fix_clusters, "--fix_clusters")
307+
.help("Fixes block locations during placement."
308+
" Can be 'random' for a random initial assignment,"
309+
" 'off' to allow the place to optimize block locations,"
310+
" or a file specifying the block locations.")
311+
.default_value("off")
312+
.show_in(argparse::ShowIn::HELP_ONLY);
305313
place_grp.add_argument(args.place_algorithm, "--place_algorithm")
306314
.help("Controls which placement algorithm is used")
307315
.default_value("path_timing_driven")

vpr/src/base/CheckSetup.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ void CheckSetup(const t_packer_opts& PackerOpts,
3838
"Timing analysis must be enabled for timing-driven placement.\n");
3939
}
4040

41-
if (!PlacerOpts.doPlacement && (USER == PlacerOpts.pad_loc_type)) {
41+
if (!PlacerOpts.doPlacement && (LOCKED == PlacerOpts.block_loc_type)) {
4242
VPR_FATAL_ERROR(VPR_ERROR_OTHER,
43-
"A pad location file requires that placement is enabled.\n");
43+
"A block location file requires that placement is enabled.\n");
4444
}
4545

4646
if (RouterOpts.doRouting) {

vpr/src/base/SetupVPR.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,8 +528,10 @@ static void SetupPlacerOpts(const t_options& Options, t_placer_opts* PlacerOpts)
528528

529529
PlacerOpts->place_algorithm = Options.PlaceAlgorithm;
530530

531+
PlacerOpts->constraints_file = Options.constraints_file;
531532
PlacerOpts->pad_loc_file = Options.pad_loc_file;
532533
PlacerOpts->pad_loc_type = Options.pad_loc_type;
534+
PlacerOpts->block_loc_type = Options.block_loc_type;
533535

534536
PlacerOpts->place_chan_width = Options.PlaceChanWidth;
535537

vpr/src/base/ShowSetup.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -518,13 +518,22 @@ static void ShowPlacerOpts(const t_placer_opts& PlacerOpts,
518518
case RANDOM:
519519
VTR_LOG("RANDOM\n");
520520
break;
521-
case USER:
522-
VTR_LOG("USER '%s'\n", PlacerOpts.pad_loc_file.c_str());
523-
break;
524521
default:
525522
VPR_FATAL_ERROR(VPR_ERROR_UNKNOWN, "Unknown I/O pad location type\n");
526523
}
527524

525+
VTR_LOG("PlacerOpts.block_loc_type: ");
526+
switch (PlacerOpts.block_loc_type) {
527+
case NOT_LOCKED:
528+
VTR_LOG("NOT_LOCKED\n");
529+
break;
530+
case LOCKED:
531+
VTR_LOG("LOCKED '%s'\n", PlacerOpts.constraints_file.c_str());
532+
break;
533+
default:
534+
VPR_FATAL_ERROR(VPR_ERROR_UNKNOWN, "Unknown block location type\n");
535+
}
536+
528537
VTR_LOG("PlacerOpts.place_cost_exp: %f\n", PlacerOpts.place_cost_exp);
529538

530539
VTR_LOG("PlacerOpts.place_chan_width: %d\n", PlacerOpts.place_chan_width);

vpr/src/base/read_options.cpp

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1598,13 +1598,19 @@ argparse::ArgumentParser create_arg_parser(std::string prog_name, t_options& arg
15981598

15991599
place_grp.add_argument(args.pad_loc_file, "--fix_pins")
16001600
.help(
1601-
"Fixes I/O pad locations during placement. Valid options:\n"
1601+
"Fixes I/O pad locations randomly during placement. Valid options:\n"
16021602
" * 'free' allows placement to optimize pad locations\n"
1603-
" * 'random' fixes pad locations to arbitraray locations\n"
1604-
" * path to a file specifying pad locations (.place format with only pads specified).")
1603+
" * 'random' fixes pad locations to arbitrary locations\n.")
16051604
.default_value("free")
16061605
.show_in(argparse::ShowIn::HELP_ONLY);
16071606

1607+
place_grp.add_argument(args.constraints_file, "--fix_clusters")
1608+
.help(
1609+
"Fixes block locations during placement. Valid options:\n"
1610+
" * path to a file specifying block locations (.place format with block locations specified).")
1611+
.default_value("not_locked")
1612+
.show_in(argparse::ShowIn::HELP_ONLY);
1613+
16081614
place_grp.add_argument<e_place_algorithm, ParsePlaceAlgorithm>(args.PlaceAlgorithm, "--place_algorithm")
16091615
.help("Controls which placement algorithm is used")
16101616
.default_value("path_timing_driven")
@@ -2237,7 +2243,7 @@ void set_conditional_defaults(t_options& args) {
22372243
args.anneal_sched_type.set(AUTO_SCHED, Provenance::INFERRED); // Otherwise use the automatic schedule
22382244
}
22392245

2240-
//Are the pad locations specified?
2246+
//Are the pads free to be moved during placement or randomly locked to certain locations?
22412247
if (std::string(args.pad_loc_file) == "free") {
22422248
args.pad_loc_type.set(FREE, Provenance::INFERRED);
22432249

@@ -2247,8 +2253,15 @@ void set_conditional_defaults(t_options& args) {
22472253

22482254
args.pad_loc_file.set("", Provenance::SPECIFIED);
22492255
} else {
2250-
args.pad_loc_type.set(USER, Provenance::INFERRED);
2251-
VTR_ASSERT(!args.pad_loc_file.value().empty());
2256+
VPR_FATAL_ERROR(VPR_ERROR_UNKNOWN, "Unknown I/O pad location type\n");
2257+
}
2258+
2259+
//Are the blocks locked to locations given by a constraints file?
2260+
if (std::string(args.constraints_file) == "not_locked") {
2261+
args.block_loc_type.set(NOT_LOCKED, Provenance::INFERRED);
2262+
} else {
2263+
args.block_loc_type.set(LOCKED, Provenance::INFERRED);
2264+
VTR_ASSERT(!args.constraints_file.value().empty());
22522265
}
22532266

22542267
/*

vpr/src/base/read_options.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ struct t_options {
2323
argparse::ArgValue<e_circuit_format> circuit_format;
2424

2525
argparse::ArgValue<std::string> out_file_prefix;
26+
argparse::ArgValue<std::string> constraints_file;
2627
argparse::ArgValue<std::string> pad_loc_file;
2728
argparse::ArgValue<std::string> write_rr_graph_file;
2829
argparse::ArgValue<std::string> read_rr_graph_file;
@@ -105,6 +106,7 @@ struct t_options {
105106
argparse::ArgValue<sched_type> anneal_sched_type;
106107
argparse::ArgValue<e_place_algorithm> PlaceAlgorithm;
107108
argparse::ArgValue<e_pad_loc_type> pad_loc_type;
109+
argparse::ArgValue<e_block_loc_type> block_loc_type;
108110
argparse::ArgValue<int> PlaceChanWidth;
109111
argparse::ArgValue<float> place_rlim_escape_fraction;
110112
argparse::ArgValue<std::string> place_move_stats_file;

vpr/src/base/read_place.cpp

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,8 @@ void read_place(const char* net_file,
139139
place_ctx.placement_id = vtr::secure_digest_file(place_file);
140140
}
141141

142-
///@brief Reads in the locations of the IO pads from a file.
143-
void read_user_pad_loc(const char* pad_loc_file) {
142+
void read_user_block_loc(const char* constraints_file) {
143+
/* Reads in the locations of the blocks from a file. */
144144
t_hash **hash_table, *h_ptr;
145145
int xtmp, ytmp;
146146
FILE* fp;
@@ -152,11 +152,11 @@ void read_user_pad_loc(const char* pad_loc_file) {
152152
auto& place_ctx = g_vpr_ctx.mutable_placement();
153153

154154
VTR_LOG("\n");
155-
VTR_LOG("Reading locations of IO pads from '%s'.\n", pad_loc_file);
156-
fp = fopen(pad_loc_file, "r");
155+
VTR_LOG("Reading locations of blocks from '%s'.\n", constraints_file);
156+
fp = fopen(constraints_file, "r");
157157
if (!fp) VPR_FATAL_ERROR(VPR_ERROR_PLACE_F,
158-
"'%s' - Cannot find IO pads location file.\n",
159-
pad_loc_file);
158+
"'%s' - Cannot find block locations file.\n",
159+
constraints_file);
160160

161161
hash_table = alloc_hash_table();
162162
for (auto blk_id : cluster_ctx.clb_nlist.blocks()) {
@@ -189,41 +189,41 @@ void read_user_pad_loc(const char* pad_loc_file) {
189189
if (strlen(ptr) + 1 < vtr::bufsize) {
190190
strcpy(bname, ptr);
191191
} else {
192-
vpr_throw(VPR_ERROR_PLACE_F, pad_loc_file, vtr::get_file_line_number_of_last_opened_file(),
192+
vpr_throw(VPR_ERROR_PLACE_F, constraints_file, vtr::get_file_line_number_of_last_opened_file(),
193193
"Block name exceeded buffer size of %zu characters", vtr::bufsize);
194194
}
195195

196196
ptr = vtr::strtok(nullptr, TOKENS, fp, buf);
197197
if (ptr == nullptr) {
198-
vpr_throw(VPR_ERROR_PLACE_F, pad_loc_file, vtr::get_file_line_number_of_last_opened_file(),
198+
vpr_throw(VPR_ERROR_PLACE_F, constraints_file, vtr::get_file_line_number_of_last_opened_file(),
199199
"Incomplete.\n");
200200
}
201201
sscanf(ptr, "%d", &xtmp);
202202

203203
ptr = vtr::strtok(nullptr, TOKENS, fp, buf);
204204
if (ptr == nullptr) {
205-
vpr_throw(VPR_ERROR_PLACE_F, pad_loc_file, vtr::get_file_line_number_of_last_opened_file(),
205+
vpr_throw(VPR_ERROR_PLACE_F, constraints_file, vtr::get_file_line_number_of_last_opened_file(),
206206
"Incomplete.\n");
207207
}
208208
sscanf(ptr, "%d", &ytmp);
209209

210210
ptr = vtr::strtok(nullptr, TOKENS, fp, buf);
211211
if (ptr == nullptr) {
212-
vpr_throw(VPR_ERROR_PLACE_F, pad_loc_file, vtr::get_file_line_number_of_last_opened_file(),
212+
vpr_throw(VPR_ERROR_PLACE_F, constraints_file, vtr::get_file_line_number_of_last_opened_file(),
213213
"Incomplete.\n");
214214
}
215215
int k;
216216
sscanf(ptr, "%d", &k);
217217

218218
ptr = vtr::strtok(nullptr, TOKENS, fp, buf);
219219
if (ptr != nullptr) {
220-
vpr_throw(VPR_ERROR_PLACE_F, pad_loc_file, vtr::get_file_line_number_of_last_opened_file(),
220+
vpr_throw(VPR_ERROR_PLACE_F, constraints_file, vtr::get_file_line_number_of_last_opened_file(),
221221
"Extra characters at end of line.\n");
222222
}
223223

224224
h_ptr = get_hash_entry(hash_table, bname);
225225
if (h_ptr == nullptr) {
226-
VTR_LOG_WARN("[Line %d] Block %s invalid, no such IO pad.\n",
226+
VTR_LOG_WARN("[Line %d] Block %s invalid, no such block.\n",
227227
vtr::get_file_line_number_of_last_opened_file(), bname);
228228
ptr = vtr::fgets(buf, vtr::bufsize, fp);
229229
continue;
@@ -233,12 +233,12 @@ void read_user_pad_loc(const char* pad_loc_file) {
233233
int j = ytmp;
234234

235235
if (place_ctx.block_locs[bnum].loc.x != OPEN) {
236-
VPR_THROW(VPR_ERROR_PLACE_F, pad_loc_file, vtr::get_file_line_number_of_last_opened_file(),
237-
"Block %s is listed twice in pad file.\n", bname);
236+
VPR_THROW(VPR_ERROR_PLACE_F, constraints_file, vtr::get_file_line_number_of_last_opened_file(),
237+
"Block %s is listed twice in constraints file.\n", bname);
238238
}
239239

240240
if (i < 0 || i > int(device_ctx.grid.width() - 1) || j < 0 || j > int(device_ctx.grid.height() - 1)) {
241-
VPR_THROW(VPR_ERROR_PLACE_F, pad_loc_file, 0,
241+
VPR_THROW(VPR_ERROR_PLACE_F, constraints_file, 0,
242242
"Block #%zu (%s) location, (%d,%d) is out of range.\n", size_t(bnum), bname, i, j);
243243
}
244244

@@ -250,13 +250,13 @@ void read_user_pad_loc(const char* pad_loc_file) {
250250
auto physical_tile = device_ctx.grid[i][j].type;
251251
auto logical_block = cluster_ctx.clb_nlist.block_type(bnum);
252252
if (!is_sub_tile_compatible(physical_tile, logical_block, place_ctx.block_locs[bnum].loc.sub_tile)) {
253-
VPR_THROW(VPR_ERROR_PLACE_F, pad_loc_file, 0,
253+
VPR_THROW(VPR_ERROR_PLACE_F, constraints_file, 0,
254254
"Attempt to place block %s at illegal location (%d, %d).\n", bname, i, j);
255255
}
256256

257257
if (k >= physical_tile->capacity || k < 0) {
258-
VPR_THROW(VPR_ERROR_PLACE_F, pad_loc_file, vtr::get_file_line_number_of_last_opened_file(),
259-
"Block %s subblock number (%d) is out of range.\n", bname, k);
258+
VPR_THROW(VPR_ERROR_PLACE_F, constraints_file, vtr::get_file_line_number_of_last_opened_file(),
259+
"Block %s subtile number (%d) is out of range.\n", bname, k);
260260
}
261261
place_ctx.grid_blocks[i][j].blocks[k] = bnum;
262262
place_ctx.grid_blocks[i][j].usage++;
@@ -273,14 +273,14 @@ void read_user_pad_loc(const char* pad_loc_file) {
273273
}
274274

275275
if (place_ctx.block_locs[blk_id].loc.x == OPEN) {
276-
VPR_THROW(VPR_ERROR_PLACE_F, pad_loc_file, 0,
277-
"IO block %s location was not specified in the pad file.\n", cluster_ctx.clb_nlist.block_name(blk_id).c_str());
276+
VPR_THROW(VPR_ERROR_PLACE_F, constraints_file, 0,
277+
"Block %s location was not specified in the constraints file.\n", cluster_ctx.clb_nlist.block_name(blk_id).c_str());
278278
}
279279
}
280280

281281
fclose(fp);
282282
free_hash_table(hash_table);
283-
VTR_LOG("Successfully read %s.\n", pad_loc_file);
283+
VTR_LOG("Successfully read %s.\n", constraints_file);
284284
VTR_LOG("\n");
285285
}
286286

vpr/src/base/read_place.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ void print_place(const char* net_file,
1111
const char* net_id,
1212
const char* place_file);
1313

14-
void read_user_pad_loc(const char* pad_loc_file);
14+
void read_user_block_loc(const char* constraints_file);
1515

1616
#endif

vpr/src/base/vpr_types.h

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -505,16 +505,21 @@ enum pfreq {
505505
};
506506

507507
/**
508-
* @brief Are the pads free to be moved, locked in a random configuration, or
509-
* locked in user-specified positions?
508+
* @brief Are the pads free to be moved or locked in a random configuration?
510509
*/
511510
enum e_pad_loc_type {
512511
FREE,
513-
RANDOM,
514-
USER
512+
RANDOM
513+
};
514+
515+
/*Are the blocks not locked (free to be moved) or locked in user-specified positions?*/
516+
enum e_block_loc_type {
517+
NOT_LOCKED,
518+
LOCKED
515519
};
516520

517521
///@brief Power data for t_netlist structure
522+
518523
struct t_net_power {
519524
///@brief Signal probability - long term probability that signal is logic-high
520525
float probability;
@@ -829,8 +834,10 @@ struct t_annealing_sched {
829834
* place_chan_width: The channel width assumed if only one placement is *
830835
* performed. *
831836
* pad_loc_type: Are pins FREE, fixed randomly, or fixed from a file. *
832-
* pad_loc_file: File to read pin locations form if pad_loc_type *
833-
* is USER. *
837+
* block_loc_type: Are blocks fixed from a file. *
838+
* constraints_file: File to read block locations from if block_loc_type *
839+
* is LOCKED. *
840+
* pad_loc_file: File to read pad locations from if pad_loc_type is USER. *
834841
* place_freq: Should the placement be skipped, done once, or done for each *
835842
* channel width in the binary search. *
836843
* recompute_crit_iter: how many temperature stages pass before we recompute *
@@ -883,6 +890,8 @@ struct t_placer_opts {
883890
float place_cost_exp;
884891
int place_chan_width;
885892
enum e_pad_loc_type pad_loc_type;
893+
enum e_block_loc_type block_loc_type;
894+
std::string constraints_file;
886895
std::string pad_loc_file;
887896
enum pfreq place_freq;
888897
int recompute_crit_iter;

vpr/src/place/initial_placement.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -392,9 +392,9 @@ static t_physical_tile_type_ptr pick_placement_type(t_logical_block_type_ptr log
392392
return nullptr;
393393
}
394394

395-
void initial_placement(enum e_pad_loc_type pad_loc_type,
396-
const char* pad_loc_file) {
395+
void initial_placement(enum e_pad_loc_type pad_loc_type, enum e_block_loc_type block_loc_type, const char* constraints_file) {
397396
vtr::ScopedStartFinishTimer timer("Initial Placement");
397+
398398
/* Randomly places the blocks to create an initial placement. We rely on
399399
* the legal_pos array already being loaded. That legal_pos[itype] is an
400400
* array that gives every legal value of (x,y,z) that can accommodate a block.
@@ -445,8 +445,9 @@ void initial_placement(enum e_pad_loc_type pad_loc_type,
445445
place_ctx.block_locs[blk_id].loc = t_pl_loc();
446446
}
447447

448-
if (pad_loc_type == USER) {
449-
read_user_pad_loc(pad_loc_file);
448+
/*If the user specified block locations using a constraints file, read those locations in here*/
449+
if (block_loc_type == LOCKED) {
450+
read_user_block_loc(constraints_file);
450451
}
451452

452453
initial_placement_pl_macros(MAX_NUM_TRIES_TO_PLACE_MACROS_RANDOMLY, free_locations);

vpr/src/place/initial_placement.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
#include "vpr_types.h"
55

6-
void initial_placement(enum e_pad_loc_type pad_loc_type,
7-
const char* pad_loc_file);
6+
void initial_placement(enum e_pad_loc_type pad_loc_type, enum e_block_loc_type block_loc_type, const char* constraints_file);
87

98
#endif

vpr/src/place/place.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,7 @@ void try_place(const t_placer_opts& placer_opts,
569569
alloc_and_load_placement_structs(placer_opts.place_cost_exp, placer_opts,
570570
directs, num_directs);
571571

572-
initial_placement(placer_opts.pad_loc_type, placer_opts.pad_loc_file.c_str());
572+
initial_placement(placer_opts.pad_loc_type, placer_opts.block_loc_type, placer_opts.constraints_file.c_str());
573573

574574
// Update physical pin values
575575
for (auto block_id : cluster_ctx.clb_nlist.blocks()) {
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
###################################################
2+
# Architecture Files
3+
###################################################
4+
5+
This directory contains architecture files that are used in regression testing.
6+
7+

0 commit comments

Comments
 (0)