Skip to content

Commit 4eec9fe

Browse files
authored
Merge pull request #3193 from verilog-to-routing/reconstruction_grids_with_LegalizationClusterId
FlatRecon: Flat Placement Reconstruction Full Legalizer
2 parents 98065e9 + 11b4e66 commit 4eec9fe

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+13804
-89
lines changed

.github/workflows/nightly_test_manual.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ jobs:
5151
./dev/upgrade_vtr_archs.sh
5252
make get_symbiflow_benchmarks
5353
make get_zeroasic_rr_graphs
54+
make get_flat_placements
5455
5556
# Build VTR using the default build options.
5657
- name: 'Build VTR'

CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,14 @@ add_custom_target(get_zeroasic_rr_graphs
368368
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
369369
COMMENT "Downloading (~2MB) and extracting Zero ASIC RR graphs (~0.1GB) into VTR source tree.")
370370

371+
#
372+
# Flat Placement Files
373+
#
374+
add_custom_target(get_flat_placements
375+
COMMAND ./vtr_flow/scripts/get_flat_placement_files.py --vtr_flow_dir ./vtr_flow
376+
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
377+
COMMENT "Downloading (~5MB) and extracting Flat Placement Files (~0.1GB) into VTR source tree.")
378+
371379
#
372380
# Unit Testing
373381
#

doc/src/vpr/command_line_usage.rst

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -444,22 +444,22 @@ Use the options below to override this default naming behaviour.
444444
Reads a file containing the locations of each atom on the FPGA.
445445
This is used by the packer to better cluster atoms together.
446446

447-
The flat placement file (which often ends in ``.fplace``) is a text file
447+
The flat placement file (which often ends in :ref:`.fplace <vpr_flat_place_file>`) is a text file
448448
where each line describes the location of an atom. Each line in the flat
449449
placement file should have the following syntax:
450450

451451
.. code-block:: none
452452
453-
<atom_name : str> <x : float> <y : float> <layer : float> <atom_sub_tile : int> <atom_site_idx? : int>
453+
<atom_name : str> <x : float> <y : float> <layer : float> <atom_sub_tile : int>
454454
455455
For example:
456456

457457
.. code-block:: none
458458
459-
n523 6 8 0 0 3
460-
n522 6 8 0 0 5
461-
n520 6 8 0 0 2
462-
n518 6 8 0 0 16
459+
n523 6 8 0 0
460+
n522 6 8 0 0
461+
n520 6 8 0 0
462+
n518 6 8 0 0
463463
464464
The position of the atom on the FPGA is given by 3 floating point values
465465
(``x``, ``y``, ``layer``). We allow for the positions of atom to be not
@@ -475,25 +475,29 @@ Use the options below to override this default naming behaviour.
475475
the sub-tile of an atom is unkown (allowing the packing algorithm to choose
476476
any sub-tile at the given (x, y, layer) location).
477477

478-
The ``site_idx`` is an optional index into a linearized list of primitive
479-
locations within a cluster-level block which may be used as a hint to
480-
reconstruct clusters.
481-
482478
.. warning::
483479

484480
This interface is currently experimental and under active development.
485481

486482
.. option:: --write_flat_place <file>
487483

488-
Writes the post-placement locations of each atom into a flat placement file.
484+
Writes the post-placement locations of each atom into a flat placement file
485+
(see :ref:`flat placement file format <vpr_flat_place_file>`).
486+
487+
For each atom in the netlist, the following information is stored into the
488+
flat placement file:
489+
490+
* The x, y, and sub_tile location of the cluster that contains this atom.
491+
492+
.. option:: --write_legalized_flat_place <file>
493+
494+
Writes the post-legalization locations of each atom into a flat placement file
495+
(see :ref:`flat placement file format <vpr_flat_place_file>`).
489496

490497
For each atom in the netlist, the following information is stored into the
491498
flat placement file:
492499

493500
* The x, y, and sub_tile location of the cluster that contains this atom.
494-
* The flat site index of this atom in its cluster. The flat site index is a
495-
linearized ID of primitive locations in a cluster. This may be used as a
496-
hint to reconstruct clusters.
497501

498502
.. _netlist_options:
499503

@@ -1287,14 +1291,20 @@ Analytical Placement is generally split into three stages:
12871291

12881292
**Default:** ``bipartitioning``
12891293

1290-
.. option:: --ap_full_legalizer {naive | appack}
1294+
.. option:: --ap_full_legalizer {naive | appack | flat-recon}
12911295

12921296
Controls which Full Legalizer to use in the AP Flow.
12931297

12941298
* ``naive`` Use a Naive Full Legalizer which will try to create clusters exactly where their atoms are placed.
12951299

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

1302+
* ``flat-recon`` Use the Flat Placement Reconstruction Full Legalizer which tries to reconstruct a clustered placement that is
1303+
as close to the incoming flat placement as possible. It can be used to read a flat placement from a :ref:`.fplace <vpr_flat_place_file>` file
1304+
or on the (in memory) output of VTR's integrated Global Placement algorithm. In both cases, it expects the given solution to be close to legal.
1305+
If used with a :ref:`.fplace <vpr_flat_place_file>` file, each atom in a molecule should have compatible location information. It is legal to
1306+
leave some molecules unconstrained; the reconstruction phase will choose where to place them but does not attempt to optimize these locations.
1307+
12981308
**Default:** ``appack``
12991309

13001310
.. option:: --ap_detailed_placer {none | annealer}

doc/src/vpr/file_formats.rst

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,42 @@ Placement File Format Example
696696
xor5 1 2 0 0 #6
697697
[1] 1 1 0 1 #7
698698
699+
.. _vpr_flat_place_file:
700+
701+
Flat Placement File Format (.fplace)
702+
------------------------------------
703+
The flat placement file is a text file where each line describes the location of
704+
an atom. Each line in the flat placement file should have the following syntax:
705+
706+
.. code-block:: none
707+
708+
<atom_name : str> <x : float> <y : float> <layer : float> <atom_sub_tile : int>
709+
710+
For example:
711+
712+
.. code-block:: none
713+
714+
n523 6 8 0 0
715+
n522 6 8 0 0
716+
n520 6 9 0 0
717+
n518 6 9 0 0
718+
719+
The position of the atom on the FPGA is given by 3 floating point values
720+
(``x``, ``y``, ``layer``). We allow x and y locations to be off-grid since
721+
this flat placement will be fed into the packer and placer, which will snap
722+
the positions to grid locations. For 2D FPGA architectures, the ``layer`` should be 0.
723+
724+
The ``sub_tile`` is a clustered placement construct: which cluster-level
725+
location at a given (x, y, layer) should these atoms go at (relevant when
726+
multiple clusters can be stacked there). A sub-tile of -1 may be used when
727+
the sub-tile of an atom is unkown (allowing the packing algorithm to choose
728+
any sub-tile at the given (x, y, layer) location).
729+
730+
When used with ``flat-recon`` full legalizer (see :option:`vpr --ap_full_legalizer`),
731+
each atom in a molecule should have compatible location information. It is legal to
732+
leave some molecules unconstrained; the reconstruction phase will choose where
733+
to place them but does not attempt to optimize these locations.
734+
699735
.. _vpr_route_file:
700736

701737
Routing File Format (.route)

libs/libarchfpga/src/physical_types.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -890,7 +890,40 @@ struct t_physical_tile_loc {
890890
operator bool() const {
891891
return !(x == ARCH_FPGA_UNDEFINED_VAL || y == ARCH_FPGA_UNDEFINED_VAL || layer_num == ARCH_FPGA_UNDEFINED_VAL);
892892
}
893+
894+
/**
895+
* @brief Comparison operator for t_physical_tile_loc
896+
*
897+
* Tiles are ordered first by layer number, then by x, and finally by y.
898+
*/
899+
friend bool operator<(const t_physical_tile_loc& lhs, const t_physical_tile_loc& rhs) {
900+
if (lhs.layer_num != rhs.layer_num)
901+
return lhs.layer_num < rhs.layer_num;
902+
if (lhs.x != rhs.x)
903+
return lhs.x < rhs.x;
904+
return lhs.y < rhs.y;
905+
}
906+
907+
friend bool operator==(const t_physical_tile_loc& a, const t_physical_tile_loc& b) {
908+
return a.x == b.x && a.y == b.y && a.layer_num == b.layer_num;
909+
}
910+
911+
friend bool operator!=(const t_physical_tile_loc& a, const t_physical_tile_loc& b) {
912+
return !(a == b);
913+
}
914+
};
915+
916+
namespace std {
917+
template<>
918+
struct hash<t_physical_tile_loc> {
919+
std::size_t operator()(const t_physical_tile_loc& v) const noexcept {
920+
std::size_t seed = std::hash<int>{}(v.x);
921+
vtr::hash_combine(seed, v.y);
922+
vtr::hash_combine(seed, v.layer_num);
923+
return seed;
924+
}
893925
};
926+
} // namespace std
894927

895928
/** Describes I/O and clock ports of a physical tile type
896929
*

vpr/src/analytical_place/analytical_placement_flow.cpp

Lines changed: 57 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "gen_ap_netlist_from_atoms.h"
1919
#include "global_placer.h"
2020
#include "globals.h"
21+
#include "load_flat_place.h"
2122
#include "netlist_fwd.h"
2223
#include "partial_legalizer.h"
2324
#include "partial_placement.h"
@@ -80,6 +81,7 @@ static void print_ap_netlist_stats(const APNetlist& netlist) {
8081
* to be generated on ap_netlist or have the same blocks.
8182
*/
8283
static void convert_flat_to_partial_placement(const FlatPlacementInfo& flat_placement_info, const APNetlist& ap_netlist, const Prepacker& prepacker, PartialPlacement& p_placement) {
84+
size_t num_mols_assigned_to_center = 0;
8385
for (APBlockId ap_blk_id : ap_netlist.blocks()) {
8486
// Get the molecule that AP block represents
8587
PackMoleculeId mol_id = ap_netlist.block_molecule(ap_blk_id);
@@ -97,6 +99,8 @@ static void convert_flat_to_partial_placement(const FlatPlacementInfo& flat_plac
9799
float current_loc_layer = flat_placement_info.blk_layer[atom_blk_id];
98100
int current_loc_sub_tile = flat_placement_info.blk_sub_tile[atom_blk_id];
99101
if (found_valid_atom) {
102+
if (current_loc_x == -1 || current_loc_y == -1)
103+
continue;
100104
if (current_loc_x != atom_loc_x || current_loc_y != atom_loc_y || current_loc_layer != atom_loc_layer || current_loc_sub_tile != atom_loc_sub_tile)
101105
VPR_FATAL_ERROR(VPR_ERROR_AP,
102106
"Molecule of ID %zu contains atom %s (ID: %zu) with a location (%g, %g, layer: %g, subtile: %d) "
@@ -105,21 +109,53 @@ static void convert_flat_to_partial_placement(const FlatPlacementInfo& flat_plac
105109
current_loc_x, current_loc_y, current_loc_layer, current_loc_sub_tile,
106110
atom_loc_x, atom_loc_y, atom_loc_layer, atom_loc_sub_tile);
107111
} else {
108-
atom_loc_x = current_loc_x;
109-
atom_loc_y = current_loc_y;
110-
atom_loc_layer = current_loc_layer;
111-
atom_loc_sub_tile = current_loc_sub_tile;
112-
found_valid_atom = true;
112+
if (current_loc_x != -1 && current_loc_y != -1) {
113+
atom_loc_x = std::clamp(current_loc_x, 0.0f,
114+
static_cast<float>(g_vpr_ctx.device().grid.width() -1));
115+
atom_loc_y = std::clamp(current_loc_y, 0.0f,
116+
static_cast<float>(g_vpr_ctx.device().grid.height() -1));
117+
// If current_loc_layer or current_loc_sub_tile are unset (-1), default to layer 0 and sub_tile 0.
118+
if (current_loc_layer == -1)
119+
current_loc_layer = 0;
120+
if (current_loc_sub_tile == -1)
121+
current_loc_sub_tile = 0;
122+
atom_loc_layer = current_loc_layer;
123+
atom_loc_sub_tile = current_loc_sub_tile;
124+
found_valid_atom = true;
125+
}
113126
}
114127
}
115-
// Ensure that there is a valid atom in the molecule to pass its location.
116-
VTR_ASSERT_MSG(found_valid_atom, "Each molecule must contain at least one valid atom");
117-
// Pass the placement information
118-
p_placement.block_x_locs[ap_blk_id] = atom_loc_x;
119-
p_placement.block_y_locs[ap_blk_id] = atom_loc_y;
120-
p_placement.block_layer_nums[ap_blk_id] = atom_loc_layer;
121-
p_placement.block_sub_tiles[ap_blk_id] = atom_loc_sub_tile;
128+
// If any atom in the molecule has a location assigned, use that location
129+
// for the entire AP block. Otherwise, assign the AP block to the center
130+
// of the device grid and update the flat placement info for all its atoms accordingly.
131+
if (!found_valid_atom) {
132+
num_mols_assigned_to_center++;
133+
VTR_LOG_WARN("No atoms of molecule ID %zu provided in the flat placement. Assigning it to the device center.\n", mol_id);
134+
p_placement.block_x_locs[ap_blk_id] = g_vpr_ctx.device().grid.width() / 2.0f;
135+
p_placement.block_y_locs[ap_blk_id] = g_vpr_ctx.device().grid.height() / 2.0f;
136+
p_placement.block_layer_nums[ap_blk_id] = 0;
137+
p_placement.block_sub_tiles[ap_blk_id] = 0;
138+
// Update flat placement for atoms of that molecule accordingly.
139+
// Needed for flat placement reconstruction statistics reporting.
140+
for (AtomBlockId atom_blk_id : mol.atom_block_ids) {
141+
g_vpr_ctx.mutable_atom().mutable_flat_placement_info().blk_x_pos[atom_blk_id] = g_vpr_ctx.device().grid.width() / 2.0f;
142+
g_vpr_ctx.mutable_atom().mutable_flat_placement_info().blk_y_pos[atom_blk_id] = g_vpr_ctx.device().grid.height() / 2.0f;
143+
g_vpr_ctx.mutable_atom().mutable_flat_placement_info().blk_layer[atom_blk_id] = 0;
144+
g_vpr_ctx.mutable_atom().mutable_flat_placement_info().blk_sub_tile[atom_blk_id] = 0;
145+
}
146+
// TODO: If an atom's location is specified in the placement constraints,
147+
// verify it matches the assigned flat placement. If not, override the
148+
// flat placement with the constraint location and warn the user.
149+
} else {
150+
// Pass the placement information
151+
p_placement.block_x_locs[ap_blk_id] = atom_loc_x;
152+
p_placement.block_y_locs[ap_blk_id] = atom_loc_y;
153+
p_placement.block_layer_nums[ap_blk_id] = atom_loc_layer;
154+
p_placement.block_sub_tiles[ap_blk_id] = atom_loc_sub_tile;
155+
}
122156
}
157+
VTR_LOG("%zu of %zu molecules placed at device center (no atoms of these molecules found in flat placement).\n",
158+
num_mols_assigned_to_center, ap_netlist.blocks().size());
123159
}
124160

125161
/**
@@ -245,6 +281,15 @@ void run_analytical_placement_flow(t_vpr_setup& vpr_setup) {
245281
// Print the device utilization
246282
print_device_utilization(target_device_utilization);
247283

284+
// Write out a flat placement file at the end of Full Legalization if the
285+
// option is specified.
286+
if (!vpr_setup.FileNameOpts.write_legalized_flat_place_file.empty()) {
287+
write_flat_placement(vpr_setup.FileNameOpts.write_legalized_flat_place_file.c_str(),
288+
g_vpr_ctx.clustering().clb_nlist,
289+
g_vpr_ctx.placement().block_locs(),
290+
g_vpr_ctx.clustering().atoms_lookup);
291+
}
292+
248293
// Run the Detailed Placer.
249294
std::unique_ptr<DetailedPlacer> detailed_placer = make_detailed_placer(ap_opts.detailed_placer_type,
250295
g_vpr_ctx.placement().blk_loc_registry(),

vpr/src/analytical_place/ap_flow_enums.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ enum class e_ap_partial_legalizer {
3939
* enum can select between these different Full Legalizers.
4040
*/
4141
enum class e_ap_full_legalizer {
42-
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.
43-
APPack, ///< The APPack Full Legalizer, which uses the flat placement to improve the Packer and Placer.
44-
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.
42+
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.
43+
APPack, ///< The APPack Full Legalizer, which uses the flat placement to improve the Packer and Placer.
44+
FlatRecon ///< The Flat Placement Reconstruction Full Legalizer, which tries to reconstruct a clustered placement (or the in-memory global placement) that is as close to the incoming flat placement as it can.
4545
};
4646

4747
/**

0 commit comments

Comments
 (0)