Skip to content

Commit 11920a1

Browse files
committed
[AP][FullLegalizer] Basic Min. Disturbance FL
Added read flat placement to AP flow and and command line option for Basic Min. Disturbance FL.
1 parent ef945a7 commit 11920a1

File tree

7 files changed

+84
-12
lines changed

7 files changed

+84
-12
lines changed

vpr/src/analytical_place/analytical_placement_flow.cpp

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,24 @@ static void print_ap_netlist_stats(const APNetlist& netlist) {
5858
VTR_LOG("\n");
5959
}
6060

61+
void convert_flat_to_partial_placement(const FlatPlacementInfo& flat_placement_info, const APNetlist& ap_netlist, PartialPlacement& p_placement){
62+
for (APBlockId ap_blk_id : ap_netlist.blocks()) {
63+
std::string ap_block_name = ap_netlist.block_name(ap_blk_id);
64+
65+
// Find the AtomBlockId of a given AP block name
66+
AtomBlockId atom_blk = g_vpr_ctx.atom().netlist().find_block(ap_block_name);
67+
if (!atom_blk.is_valid()) {
68+
continue;
69+
}
70+
71+
// Pass the placement information
72+
p_placement.block_x_locs[ap_blk_id] = flat_placement_info.blk_x_pos[atom_blk];
73+
p_placement.block_y_locs[ap_blk_id] = flat_placement_info.blk_y_pos[atom_blk];
74+
p_placement.block_layer_nums[ap_blk_id] = flat_placement_info.blk_layer[atom_blk];
75+
p_placement.block_sub_tiles[ap_blk_id] = flat_placement_info.blk_sub_tile[atom_blk];
76+
}
77+
}
78+
6179
void run_analytical_placement_flow(t_vpr_setup& vpr_setup) {
6280
// Start an overall timer for the Analytical Placement flow.
6381
vtr::ScopedStartFinishTimer timer("Analytical Placement");
@@ -77,15 +95,25 @@ void run_analytical_placement_flow(t_vpr_setup& vpr_setup) {
7795
constraints);
7896
print_ap_netlist_stats(ap_netlist);
7997

80-
// Run the Global Placer
81-
std::unique_ptr<GlobalPlacer> global_placer = make_global_placer(e_global_placer::SimPL,
82-
ap_netlist,
83-
prepacker,
84-
atom_nlist,
85-
device_ctx.grid,
86-
device_ctx.logical_block_types,
87-
device_ctx.physical_tile_types);
88-
PartialPlacement p_placement = global_placer->place();
98+
// If a flat placement is provided, skip the Global Placer and conver it
99+
// to a partial placement. Otherwise, run the Global Placer.
100+
PartialPlacement p_placement(ap_netlist);
101+
if (g_vpr_ctx.atom().flat_placement_info().valid) {
102+
VTR_LOG("Flat Placement is provided in the AP flow, skipping the Global Placement.\n");
103+
convert_flat_to_partial_placement(g_vpr_ctx.atom().flat_placement_info(),
104+
ap_netlist,
105+
p_placement);
106+
} else {
107+
// Run the Global Placer
108+
std::unique_ptr<GlobalPlacer> global_placer = make_global_placer(e_global_placer::SimPL,
109+
ap_netlist,
110+
prepacker,
111+
atom_nlist,
112+
device_ctx.grid,
113+
device_ctx.logical_block_types,
114+
device_ctx.physical_tile_types);
115+
p_placement = global_placer->place();
116+
}
89117

90118
// Verify that the partial placement is valid before running the full
91119
// legalizer.

vpr/src/analytical_place/analytical_placement_flow.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,19 @@
99

1010
// Forward declarations
1111
struct t_vpr_setup;
12+
struct PartialPlacement;
13+
class FlatPlacementInfo;
14+
class APNetlist;
15+
16+
/**
17+
* @brief Passes the flat placement information to a provided partial placement.
18+
*
19+
* @param flat_placement_info The flat placement information to be read.
20+
* @param ap_netlist The APNetlist that used to iterate over its blocks.
21+
* @param p_placement The partial placement to be updated which is assumend
22+
* to be generated on ap_netlist or have same blocks.
23+
*/
24+
void convert_flat_to_partial_placement(const FlatPlacementInfo& flat_placement_info, const APNetlist& ap_netlist, PartialPlacement& p_placement);
1225

1326
/**
1427
* @brief Run the Analaytical Placement flow.

vpr/src/analytical_place/ap_flow_enums.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
enum class e_ap_full_legalizer {
1717
Naive, ///< The Naive Full Legalizer, which clusters atoms placed in the same tile and tries to place them in that tile according to the flat placement.
18-
APPack ///< The APPack Full Legalizer, which uses the flat placement to improve the Packer and Placer.
18+
APPack, ///< The APPack Full Legalizer, which uses the flat placement to improve the Packer and Placer.
19+
Basic_Min_Disturbance ///< The Basic Min. Disturbance Full Legalizer, which uses flat placement and tries to reconstruct clusters identically. The method for handling orphan clusters has not yet been determined.
1920
};
2021

vpr/src/analytical_place/full_legalizer.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ std::unique_ptr<FullLegalizer> make_full_legalizer(e_ap_full_legalizer full_lega
7070
vpr_setup,
7171
arch,
7272
device_grid);
73+
case e_ap_full_legalizer::Basic_Min_Disturbance:
74+
VTR_LOG("Basic Minimum Disturbance Full Legalizer selected!\n");
75+
VPR_FATAL_ERROR(VPR_ERROR_AP,
76+
"Basic Min. Disturbance Full Legalizer has not been implemented yet.");
77+
7378
default:
7479
VPR_FATAL_ERROR(VPR_ERROR_AP,
7580
"Unrecognized full legalizer type");

vpr/src/base/ShowSetup.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,9 @@ static void ShowAnalyticalPlacerOpts(const t_ap_opts& APOpts) {
603603
case e_ap_full_legalizer::APPack:
604604
VTR_LOG("appack\n");
605605
break;
606+
case e_ap_full_legalizer::Basic_Min_Disturbance:
607+
VTR_LOG("basic_min_disturbance\n");
608+
break;
606609
default:
607610
VPR_FATAL_ERROR(VPR_ERROR_UNKNOWN, "Unknown full_legalizer_type\n");
608611
}

vpr/src/base/read_options.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ struct ParseAPFullLegalizer {
141141
conv_value.set_value(e_ap_full_legalizer::Naive);
142142
else if (str == "appack")
143143
conv_value.set_value(e_ap_full_legalizer::APPack);
144+
else if (str == "basic_min_disturbance")
145+
conv_value.set_value(e_ap_full_legalizer::Basic_Min_Disturbance);
144146
else {
145147
std::stringstream msg;
146148
msg << "Invalid conversion from '" << str << "' to e_ap_full_legalizer (expected one of: " << argparse::join(default_choices(), ", ") << ")";
@@ -158,14 +160,16 @@ struct ParseAPFullLegalizer {
158160
case e_ap_full_legalizer::APPack:
159161
conv_value.set_value("appack");
160162
break;
163+
case e_ap_full_legalizer::Basic_Min_Disturbance:
164+
conv_value.set_value("basic_min_disturbance");
161165
default:
162166
VTR_ASSERT(false);
163167
}
164168
return conv_value;
165169
}
166170

167171
std::vector<std::string> default_choices() {
168-
return {"naive", "appack"};
172+
return {"naive", "appack", "basic_min_disturbance"};
169173
}
170174
};
171175

@@ -1787,7 +1791,8 @@ argparse::ArgumentParser create_arg_parser(const std::string& prog_name, t_optio
17871791
.help(
17881792
"Controls which Full Legalizer to use in the AP Flow.\n"
17891793
" * naive: Use a Naive Full Legalizer which will try to create clusters exactly where their atoms are placed.\n"
1790-
" * appack: Use APPack, which takes the Packer in VPR and uses the flat atom placement to create better clusters.")
1794+
" * appack: Use APPack, which takes the Packer in VPR and uses the flat atom placement to create better clusters.\n"
1795+
" * basic_min_disturbance: Use The Basic Min. Disturbance Full Legalizer which uses flat placement to reconstruct clusters identically, but the orphan cluster handling method is yet to be determined.")
17911796
.default_value("appack")
17921797
.show_in(argparse::ShowIn::HELP_ONLY);
17931798

vpr/src/base/vpr_api.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,8 +404,25 @@ bool vpr_flow(t_vpr_setup& vpr_setup, t_arch& arch) {
404404

405405
{ // Analytical Place
406406
if (vpr_setup.APOpts.doAP == STAGE_DO) {
407+
// Passing flat placement input if provided and not loaded yet.
408+
if (!vpr_setup.FileNameOpts.read_flat_place_file.empty() &&
409+
!g_vpr_ctx.atom().flat_placement_info().valid) {
410+
g_vpr_ctx.mutable_atom().mutable_flat_placement_info() = read_flat_placement(
411+
vpr_setup.FileNameOpts.read_flat_place_file,
412+
g_vpr_ctx.atom().netlist());
413+
}
414+
407415
// TODO: Make this return a bool if the placement was successful or not.
408416
run_analytical_placement_flow(vpr_setup);
417+
418+
// Write out a flat placement file at the end of Analytical Placement
419+
// flow if the option is specified.
420+
if (!vpr_setup.FileNameOpts.write_flat_place_file.empty()) {
421+
write_flat_placement(vpr_setup.FileNameOpts.write_flat_place_file.c_str(),
422+
g_vpr_ctx.clustering().clb_nlist,
423+
g_vpr_ctx.placement().block_locs(),
424+
g_vpr_ctx.clustering().atoms_lookup);
425+
}
409426
}
410427
// Print the placement generated by AP to a .place file.
411428
auto& filename_opts = vpr_setup.FileNameOpts;

0 commit comments

Comments
 (0)