Skip to content

Commit eb2cc34

Browse files
sfkhalidvaughnbetz
authored andcommitted
Changed type of pad_loc_type back to enum instead of string
1 parent d81d55b commit eb2cc34

File tree

6 files changed

+54
-14
lines changed

6 files changed

+54
-14
lines changed

vpr/src/base/ShowSetup.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -511,12 +511,15 @@ static void ShowPlacerOpts(const t_placer_opts& PlacerOpts,
511511
}
512512

513513
VTR_LOG("PlacerOpts.pad_loc_type: ");
514-
if (PlacerOpts.pad_loc_type == "free") {
515-
VTR_LOG("FREE\n");
516-
} else if (PlacerOpts.pad_loc_type == "random") {
517-
VTR_LOG("RANDOM\n");
518-
} else {
519-
VPR_FATAL_ERROR(VPR_ERROR_UNKNOWN, "Unknown I/O pad location type\n");
514+
switch (PlacerOpts.pad_loc_type) {
515+
case FREE:
516+
VTR_LOG("FREE\n");
517+
break;
518+
case RANDOM:
519+
VTR_LOG("RANDOM\n");
520+
break;
521+
default:
522+
VPR_FATAL_ERROR(VPR_ERROR_UNKNOWN, "Unknown I/O pad location type\n");
520523
}
521524

522525
VTR_LOG("PlacerOpts.constraints_file: ");

vpr/src/base/read_options.cpp

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,37 @@ struct ParsePlaceAlgorithm {
343343
}
344344
};
345345

346+
struct ParseFixPins {
347+
ConvertedValue<e_pad_loc_type> from_str(std::string str) {
348+
ConvertedValue<e_pad_loc_type> conv_value;
349+
if (str == "free")
350+
conv_value.set_value(FREE);
351+
else if (str == "random")
352+
conv_value.set_value(RANDOM);
353+
else {
354+
std::stringstream msg;
355+
msg << "Invalid conversion from '" << str << "' to e_router_algorithm (expected one of: " << argparse::join(default_choices(), ", ") << ")";
356+
conv_value.set_error(msg.str());
357+
}
358+
return conv_value;
359+
}
360+
361+
ConvertedValue<std::string> to_str(e_pad_loc_type val) {
362+
ConvertedValue<std::string> conv_value;
363+
if (val == FREE)
364+
conv_value.set_value("free");
365+
else {
366+
VTR_ASSERT(val == RANDOM);
367+
conv_value.set_value("random");
368+
}
369+
return conv_value;
370+
}
371+
372+
std::vector<std::string> default_choices() {
373+
return {"free", "random"};
374+
}
375+
};
376+
346377
struct ParseClusterSeed {
347378
ConvertedValue<e_cluster_seed> from_str(std::string str) {
348379
ConvertedValue<e_cluster_seed> conv_value;
@@ -1596,12 +1627,13 @@ argparse::ArgumentParser create_arg_parser(std::string prog_name, t_options& arg
15961627
.default_value("0.25")
15971628
.show_in(argparse::ShowIn::HELP_ONLY);
15981629

1599-
place_grp.add_argument(args.pad_loc_type, "--fix_pins")
1630+
place_grp.add_argument<e_pad_loc_type, ParseFixPins>(args.pad_loc_type, "--fix_pins")
16001631
.help(
16011632
"Fixes I/O pad locations randomly during placement. Valid options:\n"
16021633
" * 'free' allows placement to optimize pad locations\n"
16031634
" * 'random' fixes pad locations to arbitrary locations\n.")
16041635
.default_value("free")
1636+
.choices({"free", "random"})
16051637
.show_in(argparse::ShowIn::HELP_ONLY);
16061638

16071639
place_grp.add_argument(args.constraints_file, "--fix_clusters")

vpr/src/base/read_options.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ struct t_options {
104104
argparse::ArgValue<float> PlaceSuccessTarget;
105105
argparse::ArgValue<sched_type> anneal_sched_type;
106106
argparse::ArgValue<e_place_algorithm> PlaceAlgorithm;
107-
argparse::ArgValue<std::string> pad_loc_type;
107+
argparse::ArgValue<e_pad_loc_type> pad_loc_type;
108108
argparse::ArgValue<int> PlaceChanWidth;
109109
argparse::ArgValue<float> place_rlim_escape_fraction;
110110
argparse::ArgValue<std::string> place_move_stats_file;

vpr/src/base/vpr_types.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -837,6 +837,11 @@ enum e_place_algorithm {
837837
PATH_TIMING_DRIVEN_PLACE
838838
};
839839

840+
enum e_pad_loc_type {
841+
FREE,
842+
RANDOM
843+
};
844+
840845
enum e_place_effort_scaling {
841846
CIRCUIT, ///<Effort scales based on circuit size only
842847
DEVICE_CIRCUIT ///<Effort scales based on both circuit and device size
@@ -872,7 +877,7 @@ struct t_placer_opts {
872877
float timing_tradeoff;
873878
float place_cost_exp;
874879
int place_chan_width;
875-
std::string pad_loc_type;
880+
enum e_pad_loc_type pad_loc_type;
876881
std::string constraints_file;
877882
enum pfreq place_freq;
878883
int recompute_crit_iter;

vpr/src/place/initial_placement.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ static int check_macro_can_be_placed(t_pl_macro pl_macro, int itype, t_pl_loc he
2323
static int try_place_macro(int itype, int ipos, int isub_tile, t_pl_macro pl_macro);
2424
static void initial_placement_pl_macros(int macros_max_num_tries, std::vector<std::vector<int>>& free_locations);
2525

26-
static void initial_placement_blocks(std::vector<std::vector<int>>& free_locations, std::string pad_loc_type);
26+
static void initial_placement_blocks(std::vector<std::vector<int>>& free_locations, enum e_pad_loc_type pad_loc_type);
2727

2828
static t_physical_tile_type_ptr pick_placement_type(t_logical_block_type_ptr logical_block,
2929
int num_needed_types,
@@ -296,7 +296,7 @@ static void initial_placement_pl_macros(int macros_max_num_tries, std::vector<st
296296

297297
/* Place blocks that are NOT a part of any macro.
298298
* We'll randomly place each block in the clustered netlist, one by one. */
299-
static void initial_placement_blocks(std::vector<std::vector<int>>& free_locations, std::string pad_loc_type) {
299+
static void initial_placement_blocks(std::vector<std::vector<int>>& free_locations, enum e_pad_loc_type pad_loc_type) {
300300
auto& cluster_ctx = g_vpr_ctx.clustering();
301301
auto& device_ctx = g_vpr_ctx.device();
302302
auto& place_ctx = g_vpr_ctx.mutable_placement();
@@ -368,7 +368,7 @@ static void initial_placement_blocks(std::vector<std::vector<int>>& free_locatio
368368
place_ctx.block_locs[blk_id].loc = to;
369369

370370
//Mark IOs as fixed if specifying a (fixed) random placement
371-
if (is_io_type(pick_best_physical_type(logical_block)) && pad_loc_type == "random") {
371+
if (is_io_type(pick_best_physical_type(logical_block)) && pad_loc_type == RANDOM) {
372372
place_ctx.block_locs[blk_id].is_fixed = true;
373373
}
374374

@@ -396,7 +396,7 @@ static t_physical_tile_type_ptr pick_placement_type(t_logical_block_type_ptr log
396396
return nullptr;
397397
}
398398

399-
void initial_placement(std::string pad_loc_type, const char* constraints_file) {
399+
void initial_placement(enum e_pad_loc_type pad_loc_type, const char* constraints_file) {
400400
vtr::ScopedStartFinishTimer timer("Initial Placement");
401401

402402
/* Randomly places the blocks to create an initial placement. We rely on

vpr/src/place/initial_placement.h

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

44
#include "vpr_types.h"
55

6-
void initial_placement(std::string pad_loc_type, const char* constraints_file);
6+
void initial_placement(enum e_pad_loc_type pad_loc_type, const char* constraints_file);
77

88
#endif

0 commit comments

Comments
 (0)