Skip to content

Commit b4f3453

Browse files
committed
[AP][FullLegalizer] Basic Min. Disturbance FL
Changes based on review.
1 parent 11920a1 commit b4f3453

File tree

4 files changed

+70
-46
lines changed

4 files changed

+70
-46
lines changed

vpr/src/analytical_place/analytical_placement_flow.cpp

Lines changed: 68 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -58,21 +58,72 @@ 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){
61+
/**
62+
* @brief Passes the flat placement information to a provided partial placement.
63+
*
64+
* @param flat_placement_info The flat placement information to be read.
65+
* @param ap_netlist The APNetlist that used to iterate over its blocks.
66+
* @param prepacker The Prepacker to get molecule of blocks in the ap_netlist.
67+
* @param p_placement The partial placement to be updated which is assumend
68+
* to be generated on ap_netlist or have same blocks.
69+
*/
70+
static void convert_flat_to_partial_placement(const FlatPlacementInfo& flat_placement_info, const APNetlist& ap_netlist, const Prepacker& prepacker, PartialPlacement& p_placement){
6271
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;
72+
// Get the molecule that AP block represents
73+
PackMoleculeId mol_id = ap_netlist.block_molecule(ap_blk_id);
74+
const t_pack_molecule& mol = prepacker.get_molecule(mol_id);
75+
// Get location of a valid atom in the molecule and verify that
76+
// all atoms of the molecule share same placement information.
77+
t_pl_loc atom_loc;
78+
bool found_valid_atom = false;
79+
for (AtomBlockId atom_blk_id: mol.atom_block_ids) {
80+
if (!atom_blk_id.is_valid())
81+
continue;
82+
const t_pl_loc current_loc(flat_placement_info.blk_x_pos[atom_blk_id],
83+
flat_placement_info.blk_y_pos[atom_blk_id],
84+
flat_placement_info.blk_sub_tile[atom_blk_id],
85+
flat_placement_info.blk_layer[atom_blk_id]);
86+
if (found_valid_atom) {
87+
VTR_ASSERT_MSG(current_loc == atom_loc, "Verify all atoms of a molecule provided in the flat placement share same location.\n");
88+
} else {
89+
atom_loc = current_loc;
90+
found_valid_atom = true;
91+
}
6992
}
70-
93+
// Skip if no valid atom found
94+
if (!found_valid_atom)
95+
continue;
7196
// 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];
97+
p_placement.block_x_locs[ap_blk_id] = atom_loc.x;
98+
p_placement.block_y_locs[ap_blk_id] = atom_loc.y;
99+
p_placement.block_layer_nums[ap_blk_id] = atom_loc.layer;
100+
p_placement.block_sub_tiles[ap_blk_id] = atom_loc.sub_tile;
101+
}
102+
}
103+
104+
/**
105+
* @brief If a flat placement is provided, skips the Global Placer and
106+
* converts it to a partial placement. Otherwise, runs the Global Placer.
107+
*/
108+
static PartialPlacement run_global_placer(const AtomNetlist& atom_nlist, const APNetlist& ap_netlist, const Prepacker& prepacker, const DeviceContext& device_ctx) {
109+
if (g_vpr_ctx.atom().flat_placement_info().valid) {
110+
VTR_LOG("Flat Placement is provided in the AP flow, skipping the Global Placement.\n");
111+
PartialPlacement p_placement(ap_netlist);
112+
convert_flat_to_partial_placement(g_vpr_ctx.atom().flat_placement_info(),
113+
ap_netlist,
114+
prepacker,
115+
p_placement);
116+
return p_placement;
117+
} else {
118+
// Run the Global Placer
119+
std::unique_ptr<GlobalPlacer> global_placer = make_global_placer(e_global_placer::SimPL,
120+
ap_netlist,
121+
prepacker,
122+
atom_nlist,
123+
device_ctx.grid,
124+
device_ctx.logical_block_types,
125+
device_ctx.physical_tile_types);
126+
return global_placer->place();
76127
}
77128
}
78129

@@ -95,25 +146,11 @@ void run_analytical_placement_flow(t_vpr_setup& vpr_setup) {
95146
constraints);
96147
print_ap_netlist_stats(ap_netlist);
97148

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-
}
149+
// Run the Global Placer.
150+
PartialPlacement p_placement = run_global_placer(atom_nlist,
151+
ap_netlist,
152+
prepacker,
153+
device_ctx);
117154

118155
// Verify that the partial placement is valid before running the full
119156
// legalizer.

vpr/src/analytical_place/analytical_placement_flow.h

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,6 @@
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);
2512

2613
/**
2714
* @brief Run the Analaytical Placement flow.

vpr/src/analytical_place/ap_flow_enums.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@
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.
1818
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.
19+
Basic_Min_Disturbance ///< The Basic Min. Disturbance Full Legalizer, which tries to reconstruct a clustered placement as close to the incoming flat placement as it can.
2020
};
2121

vpr/src/base/read_options.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1792,7 +1792,7 @@ argparse::ArgumentParser create_arg_parser(const std::string& prog_name, t_optio
17921792
"Controls which Full Legalizer to use in the AP Flow.\n"
17931793
" * naive: Use a Naive Full Legalizer which will try to create clusters exactly where their atoms are placed.\n"
17941794
" * 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.")
1795+
" * basic-min-disturbance: Use the Basic Min. Disturbance Full Legalizer which tries to reconstruct a clustered placement as close to the incoming flat placement as it can.\n")
17961796
.default_value("appack")
17971797
.show_in(argparse::ShowIn::HELP_ONLY);
17981798

0 commit comments

Comments
 (0)