Skip to content

FlatRecon: Flat Placement Reconstruction Full Legalizer #3193

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 82 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
c27bacc
pass 1st, 2nd, 3rd with a rough implementation of grids
haydar-c Mar 28, 2025
1535d9a
tile compability with destroying incompatible ones
haydar-c Mar 29, 2025
ef8c354
tile compability with checking before creating cluster
haydar-c Mar 31, 2025
3d26bfb
instepting speed with simple pass
haydar-c Apr 6, 2025
cdff896
simplified first pass and search grids in manhattan
haydar-c Apr 13, 2025
c67da89
sorting before processing
haydar-c Apr 13, 2025
db36eff
added placement step
haydar-c Apr 14, 2025
e737efa
reporting total clusters
haydar-c Apr 15, 2025
2c04563
corrected reporting
haydar-c Apr 15, 2025
41229b5
added neigbour search for cluster creation as well
haydar-c Apr 22, 2025
924073f
added neighbour search for orphan clusters as well
haydar-c Apr 25, 2025
5dfc554
[Faster Reconstruction]
haydar-c Apr 26, 2025
8cbcc2c
[Converting to full strategy after first neighbour pass]
haydar-c Apr 28, 2025
72760c0
just added parsin max_rss for FL and whole run
haydar-c Apr 29, 2025
240eb24
[Reducing memory usage]
haydar-c May 1, 2025
37a42fa
Merged master into this branch, solved conflict in qor parsin for ap
haydar-c May 1, 2025
5761983
Makes my changes compilable after master merge
haydar-c May 2, 2025
b77e6c2
[AP] Illegal Cluster Handling and Partial Placement Verification
haydar-c May 2, 2025
4edcbb2
[AP] Calling initial_placement after my packing
haydar-c May 4, 2025
01ee52a
[AP] Reconstruction Stat Reporting Fix
haydar-c May 5, 2025
c02d48c
Merge branch 'master' into reconstruction_grids_with_LegalizationClus…
haydar-c May 5, 2025
2ab31c2
[AP] Flat Placement Reconstruction: Convert to Full strategy mid
haydar-c May 6, 2025
942274a
Merge branch 'master' into reconstruction_grids_with_LegalizationClus…
haydar-c May 6, 2025
d7a95b9
[AP][FL] Added Stats for debugging block num increase
haydar-c May 16, 2025
a2efbe3
Stat reporting for reconstruction
haydar-c May 17, 2025
1183393
[AP][FL] Corrected displacement tile and atom reporting
haydar-c May 20, 2025
28b5836
Debugging the discrepancy between initial_placement and first pass
haydar-c May 20, 2025
3590016
[AP] Reconstruction Full Legalizer
haydar-c May 22, 2025
5ba4a95
Merge branch 'master' into reconstruction_grids_with_LegalizationClus…
haydar-c May 22, 2025
5ad9f8d
[AP] Reconstruction Legalizer
haydar-c May 25, 2025
0cf1c0b
Merge branch 'master' into reconstruction_grids_with_LegalizationClus…
haydar-c May 27, 2025
c1c1aa2
Reconstruction FL
haydar-c May 29, 2025
df4a7b5
Reconstruction FL
haydar-c May 30, 2025
b6de778
Reconstruction FL
haydar-c May 30, 2025
7ddbe24
Reconstruction FL
haydar-c May 30, 2025
7e74147
Reconstruction FL
haydar-c May 31, 2025
928a8c7
Reconstruction FL
haydar-c May 31, 2025
a876dbc
Reconstruction FL
haydar-c May 31, 2025
b0bd933
Reconstruction FL
haydar-c Jun 1, 2025
e18740f
Reconstruction FL
haydar-c Jun 2, 2025
4b7dfc8
Reconstruction FL
haydar-c Jun 3, 2025
60dec3d
Reconstruction FL
haydar-c Jun 3, 2025
f27a326
Reconstruction FL
haydar-c Jun 5, 2025
33e49f0
Reconstruction FL
haydar-c Jun 8, 2025
2562453
Reconstruction FL
haydar-c Jun 8, 2025
cbdf2ae
Merge branch 'master' into reconstruction_grids_with_LegalizationClus…
haydar-c Jun 8, 2025
de7118b
Reconstruction FL
haydar-c Jun 10, 2025
4d7ed37
Merge master into reconstruction
haydar-c Jun 14, 2025
4063332
Reconstruction FL: parser update
haydar-c Jun 15, 2025
3ea0a28
Merge branch 'master' into reconstruction_grids_with_LegalizationClus…
haydar-c Jun 16, 2025
45866e8
Try version: Fallback to Greedy for orphan molecules
haydar-c Jun 17, 2025
5dc57c6
Try version fix (not passing -r value): Fallback to Greedy for orphan…
haydar-c Jun 18, 2025
ae6d86a
Try version: Fallback to Greedy for orphan clusters with being able t…
haydar-c Jun 19, 2025
6d483c6
Re-apply the neigbor search before trying greedy clustering
haydar-c Jun 20, 2025
94fa495
Reconstruction Legalizer: Set radius to 8, add handling flat
haydar-c Jun 21, 2025
99d7f16
Merge branch 'master' into reconstruction_grids_with_LegalizationClus…
haydar-c Jun 21, 2025
66afc7a
Flat Placement to Partial Placement passing update: Warning about mis…
haydar-c Jun 22, 2025
11f95dd
Change writing to flat placement stage from after DP to after FL
haydar-c Jun 25, 2025
8a60996
Merge branch 'master' into reconstruction_grids_with_LegalizationClus…
haydar-c Jun 25, 2025
06a72ec
Merge branch 'master' into reconstruction_grids_with_LegalizationClus…
haydar-c Jun 26, 2025
b954164
Merge branch 'master' into reconstruction_grids_with_LegalizationClus…
haydar-c Jul 3, 2025
0e4e928
Merge branch 'master' into reconstruction_grids_with_LegalizationClus…
haydar-c Jul 5, 2025
419aaf7
Reconstruction Legalizer: Clean physical_types.h
haydar-c Jul 6, 2025
de6285a
Reconstruction Legalizer: Clean analytical_placement_flow flat placement
haydar-c Jul 6, 2025
21555fd
Reconstruction Legalizer: Clean includes and args in full legalizer
haydar-c Jul 6, 2025
0285f59
Reconstruction Legalizer: document get_molecule_logical_block_type
haydar-c Jul 6, 2025
11fcc17
Reconstruction Legalizer: Class structure
haydar-c Jul 7, 2025
f1d1f97
Reconstruction Legalizer: Clean full legalizer spaces
haydar-c Jul 7, 2025
95b8974
Reconstruction Legalizer: full legalizer header spaces
haydar-c Jul 7, 2025
40b7786
Reconstruction Legalizer: fix forward declarations in FL header
haydar-c Jul 7, 2025
41beb52
Reconstruction Legalizer: Big Picture comment
haydar-c Jul 7, 2025
70d9e92
Reconstruction Legalizer: Class data types clean&document
haydar-c Jul 7, 2025
0471d36
Reconstruction Legalizer: FL header commenting finished
haydar-c Jul 7, 2025
b708d33
Reconstruction Legalizer: clean partial_placement update
haydar-c Jul 7, 2025
8936f3d
Reconstruction Legalizer: clean load flat place
haydar-c Jul 7, 2025
ebb73b4
Reconstruction Legalizer: Add vtr_reg_strong/strong_ap/flatrecon_full…
haydar-c Jul 8, 2025
1994250
Reconstruction Legalizer: Added vtr_reg_nightly_test7/ap_reconstruction
haydar-c Jul 8, 2025
fdbb13c
Reconstruction Legalizer: Conver BasicMinDisturbance to FlatRecon and…
haydar-c Jul 8, 2025
876e6b2
Merge branch 'master' into reconstruction_grids_with_LegalizationClus…
haydar-c Jul 8, 2025
2e2299f
make format
haydar-c Jul 8, 2025
c94043a
Revert librtlnumber internal_bits.hpp make format change
haydar-c Jul 8, 2025
d414ab6
Update std:sort and results with better ones
haydar-c Jul 8, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions doc/src/vpr/command_line_usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1286,6 +1286,12 @@ Analytical Placement is generally split into three stages:

* ``appack`` Use APPack, which takes the Packer in VPR and uses the flat atom placement to create better clusters.

* ``flat-recon`` Use the Flat Placement Reconstruction Full Legalizer which tries to reconstruct a clustered placement
that is as close to the incoming flat placement as possible. It can be used to read flat placement from an '.fplace' file
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

read flat -> read a flat
from an '.fplace' -> from a '.fplace'

or with Global Placement output. In both cases, it expects the given solution to be close to legal. If used with
an '.fplace' file, each atom of a molecule should share same location information. If none of the atoms in a molecule
have a specified location in the file, the molecule will be assigned to the center of the device.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have to explain what this means. You won't really leave it in the center of the device. I suggest just saying it is legal to leave some molecules unconstrained; the reconstruction phase will choose where to place them but does not attempt to optimize those locations.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need a link to the file format (which has to be described somewhere).


**Default:** ``appack``

.. option:: --ap_detailed_placer {none | annealer}
Expand Down
11 changes: 11 additions & 0 deletions libs/libarchfpga/src/physical_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -881,6 +881,17 @@ struct t_physical_tile_loc {
operator bool() const {
return !(x == OPEN || y == OPEN || layer_num == OPEN);
}

/**
* @brief Comparison operator for t_physical_tile_loc
*
* Tiles are ordered first by layer number, then by x, and finally by y.
*/
friend bool operator<(const t_physical_tile_loc& lhs, const t_physical_tile_loc& rhs) {
if (lhs.layer_num != rhs.layer_num) return lhs.layer_num < rhs.layer_num;
if (lhs.x != rhs.x) return lhs.x < rhs.x;
return lhs.y < rhs.y;
}
};

/** Describes I/O and clock ports of a physical tile type
Expand Down
52 changes: 40 additions & 12 deletions vpr/src/analytical_place/analytical_placement_flow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "gen_ap_netlist_from_atoms.h"
#include "global_placer.h"
#include "globals.h"
#include "load_flat_place.h"
#include "netlist_fwd.h"
#include "partial_legalizer.h"
#include "partial_placement.h"
Expand Down Expand Up @@ -105,20 +106,38 @@ static void convert_flat_to_partial_placement(const FlatPlacementInfo& flat_plac
current_loc_x, current_loc_y, current_loc_layer, current_loc_sub_tile,
atom_loc_x, atom_loc_y, atom_loc_layer, atom_loc_sub_tile);
} else {
atom_loc_x = current_loc_x;
atom_loc_y = current_loc_y;
atom_loc_layer = current_loc_layer;
atom_loc_sub_tile = current_loc_sub_tile;
found_valid_atom = true;
if (current_loc_x != -1 && current_loc_y != -1 && current_loc_layer != -1 && current_loc_sub_tile != -1) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line concerns me a little. Here, -1 means that the user has left that part of the location unspecified.

For example, it is common for people to leave the layer or sub_tile unspecified instead of forcing it to 0. I think that there should be special handling for that. If not, this code will put a lot of blocks in the center of the device!

atom_loc_x = current_loc_x;
atom_loc_y = current_loc_y;
atom_loc_layer = current_loc_layer;
atom_loc_sub_tile = current_loc_sub_tile;
found_valid_atom = true;
}
}
}
// Ensure that there is a valid atom in the molecule to pass its location.
VTR_ASSERT_MSG(found_valid_atom, "Each molecule must contain at least one valid atom");
// Pass the placement information
p_placement.block_x_locs[ap_blk_id] = atom_loc_x;
p_placement.block_y_locs[ap_blk_id] = atom_loc_y;
p_placement.block_layer_nums[ap_blk_id] = atom_loc_layer;
p_placement.block_sub_tiles[ap_blk_id] = atom_loc_sub_tile;
// If any atom in the molecule has a location assigned, use that location
// for the entire AP block. Otherwise, assign the AP block to the center
// of the device grid and update the flat placement info for all its atoms accordingly.
if (!found_valid_atom) {
VTR_LOG_WARN("No atoms of molecule ID %zu provided in the flat placement. Assigning it to the device center.\n", mol_id);
p_placement.block_x_locs[ap_blk_id] = g_vpr_ctx.device().grid.width() / 2.0f;
p_placement.block_y_locs[ap_blk_id] = g_vpr_ctx.device().grid.height() / 2.0f;
p_placement.block_layer_nums[ap_blk_id] = 0;
p_placement.block_sub_tiles[ap_blk_id] = 0;
// Update flat placement for atoms of that molecule accordingly
for (AtomBlockId atom_blk_id : mol.atom_block_ids) {
g_vpr_ctx.mutable_atom().mutable_flat_placement_info().blk_x_pos[atom_blk_id] = g_vpr_ctx.device().grid.width() / 2.0f;
g_vpr_ctx.mutable_atom().mutable_flat_placement_info().blk_y_pos[atom_blk_id] = g_vpr_ctx.device().grid.height() / 2.0f;
g_vpr_ctx.mutable_atom().mutable_flat_placement_info().blk_layer[atom_blk_id] = 0;
g_vpr_ctx.mutable_atom().mutable_flat_placement_info().blk_sub_tile[atom_blk_id] = 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mutating the global flat placement info here is odd to me. Why does it need to be updated? Can we not modify the flat placement object coming in? Or even better leave the flat placement object as it is and only use the partial placement object?

}
} else {
// Pass the placement information
p_placement.block_x_locs[ap_blk_id] = atom_loc_x;
p_placement.block_y_locs[ap_blk_id] = atom_loc_y;
p_placement.block_layer_nums[ap_blk_id] = atom_loc_layer;
p_placement.block_sub_tiles[ap_blk_id] = atom_loc_sub_tile;
}
}
}

Expand Down Expand Up @@ -245,6 +264,15 @@ void run_analytical_placement_flow(t_vpr_setup& vpr_setup) {
// Print the device utilization
print_device_utilization(target_device_utilization);

// Write out a flat placement file at the end of Full Legalization if the
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By moving this to here, you have changed the meaning of the write_flat_place option:
Screen Shot 2025-07-08 at 5 01 46 PM

I am ok with this change; in the future, if we want the post-placement flat placement, we can create another option. You should update the documentation for this option accordingly.

Since this has become AP-specific though, you should probably change this option to something like "--ap_write_post_fl_flat_place" or something to make this more clear.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems strange to not be able to write out the final placement; maybe we need another command line option to specify this.

// option is specified.
if (!vpr_setup.FileNameOpts.write_flat_place_file.empty()) {
write_flat_placement(vpr_setup.FileNameOpts.write_flat_place_file.c_str(),
g_vpr_ctx.clustering().clb_nlist,
g_vpr_ctx.placement().block_locs(),
g_vpr_ctx.clustering().atoms_lookup);
}

// Run the Detailed Placer.
std::unique_ptr<DetailedPlacer> detailed_placer = make_detailed_placer(ap_opts.detailed_placer_type,
g_vpr_ctx.placement().blk_loc_registry(),
Expand Down
6 changes: 3 additions & 3 deletions vpr/src/analytical_place/ap_flow_enums.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ enum class e_ap_partial_legalizer {
* enum can select between these different Full Legalizers.
*/
enum class e_ap_full_legalizer {
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.
APPack, ///< The APPack Full Legalizer, which uses the flat placement to improve the Packer and Placer.
Basic_Min_Disturbance ///< The Basic Min. Disturbance Full Legalizer, which tries to reconstruct a clustered placement that is as close to the incoming flat placement as it can.
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.
APPack, ///< The APPack Full Legalizer, which uses the flat placement to improve the Packer and Placer.
FlatRecon ///< The Flat Placement Reconstruction Full Legalizer, which tries to reconstruct a clustered placement that is as close to the incoming flat placement as it can.
};

/**
Expand Down
Loading