Skip to content

Commit 2d8cbdf

Browse files
authored
Merge pull request #2884 from verilog-to-routing/feature-prepacker-cleanup
[Prepack] Pack Molecule Data Structure Cleanup
2 parents d75c699 + 1f8afd8 commit 2d8cbdf

File tree

78 files changed

+1021
-944
lines changed

Some content is hidden

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

78 files changed

+1021
-944
lines changed

vpr/src/analytical_place/analytical_placement_flow.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,7 @@ void run_analytical_placement_flow(t_vpr_setup& vpr_setup) {
6868
const UserPlaceConstraints& constraints = g_vpr_ctx.floorplanning().constraints;
6969

7070
// Run the prepacker
71-
Prepacker prepacker;
72-
prepacker.init(atom_nlist, device_ctx.logical_block_types);
71+
const Prepacker prepacker(atom_nlist, device_ctx.logical_block_types);
7372

7473
// Create the ap netlist from the atom netlist using the result from the
7574
// prepacker.
@@ -80,7 +79,8 @@ void run_analytical_placement_flow(t_vpr_setup& vpr_setup) {
8079

8180
// Run the Global Placer
8281
std::unique_ptr<GlobalPlacer> global_placer = make_global_placer(e_global_placer::SimPL,
83-
ap_netlist);
82+
ap_netlist,
83+
prepacker);
8484
PartialPlacement p_placement = global_placer->place();
8585

8686
// Verify that the partial placement is valid before running the full

vpr/src/analytical_place/ap_netlist.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99
#include <string>
1010
#include "netlist_fwd.h"
1111
#include "netlist_utils.h"
12-
#include "vpr_types.h"
12+
#include "prepack.h"
1313
#include "vtr_assert.h"
1414

1515
/*
1616
* Blocks
1717
*/
18-
const t_pack_molecule* APNetlist::block_molecule(const APBlockId id) const {
18+
PackMoleculeId APNetlist::block_molecule(const APBlockId id) const {
1919
VTR_ASSERT_SAFE(valid_block_id(id));
2020

2121
return block_molecules_[id];
@@ -37,19 +37,19 @@ const APFixedBlockLoc& APNetlist::block_loc(const APBlockId id) const {
3737
/*
3838
* Mutators
3939
*/
40-
APBlockId APNetlist::create_block(const std::string& name, const t_pack_molecule* mol) {
40+
APBlockId APNetlist::create_block(const std::string& name, PackMoleculeId molecule_id) {
4141
APBlockId blk_id = Netlist::create_block(name);
4242

4343
// Initialize the data
44-
block_molecules_.insert(blk_id, mol);
44+
block_molecules_.insert(blk_id, molecule_id);
4545
block_mobilities_.insert(blk_id, APBlockMobility::MOVEABLE);
4646
block_locs_.insert(blk_id, APFixedBlockLoc());
4747

4848
// Check post-conditions: size
4949
VTR_ASSERT(validate_block_sizes());
5050

5151
// Check post-conditions: values
52-
VTR_ASSERT(block_molecule(blk_id) == mol);
52+
VTR_ASSERT(block_molecule(blk_id) == molecule_id);
5353
VTR_ASSERT(block_mobility(blk_id) == APBlockMobility::MOVEABLE);
5454

5555
return blk_id;

vpr/src/analytical_place/ap_netlist.h

+4-6
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@
2323
#include <string>
2424
#include "netlist.h"
2525
#include "ap_netlist_fwd.h"
26-
27-
// Forward declarations
28-
class t_pack_molecule;
26+
#include "prepack.h"
2927

3028
/**
3129
* @brief Struct to store fixed block location information
@@ -83,7 +81,7 @@ class APNetlist : public Netlist<APBlockId, APPortId, APPinId, APNetId> {
8381
*/
8482

8583
/// @brief Returns the molecule that this block represents.
86-
const t_pack_molecule* block_molecule(const APBlockId id) const;
84+
PackMoleculeId block_molecule(const APBlockId id) const;
8785

8886
/// @brief Returns the mobility of this block.
8987
APBlockMobility block_mobility(const APBlockId id) const;
@@ -104,7 +102,7 @@ class APNetlist : public Netlist<APBlockId, APPortId, APPinId, APNetId> {
104102
* @param name The unique name of the block
105103
* @param mol The molecule the block represents
106104
*/
107-
APBlockId create_block(const std::string& name, const t_pack_molecule* mol);
105+
APBlockId create_block(const std::string& name, PackMoleculeId molecule_id);
108106

109107
/**
110108
* @brief Fixes a block at the given location
@@ -182,7 +180,7 @@ class APNetlist : public Netlist<APBlockId, APPortId, APPinId, APNetId> {
182180

183181
private: // Private Data
184182
/// @brief Molecule of each block
185-
vtr::vector_map<APBlockId, const t_pack_molecule*> block_molecules_;
183+
vtr::vector_map<APBlockId, PackMoleculeId> block_molecules_;
186184
/// @brief Type of each block
187185
vtr::vector_map<APBlockId, APBlockMobility> block_mobilities_;
188186
/// @brief Location of each block (if fixed).

vpr/src/analytical_place/full_legalizer.cpp

+17-16
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "place_and_route.h"
2929
#include "place_constraints.h"
3030
#include "place_macro.h"
31+
#include "prepack.h"
3132
#include "verify_clustering.h"
3233
#include "verify_placement.h"
3334
#include "vpr_api.h"
@@ -202,7 +203,8 @@ class APClusterPlacer {
202203
* @param primitive_candidate_block_types A list of candidate block types for
203204
* the given molecule.
204205
*/
205-
static LegalizationClusterId create_new_cluster(t_pack_molecule* seed_molecule,
206+
static LegalizationClusterId create_new_cluster(PackMoleculeId seed_molecule_id,
207+
const Prepacker& prepacker,
206208
ClusterLegalizer& cluster_legalizer,
207209
const std::map<const t_model*, std::vector<t_logical_block_type_ptr>>& primitive_candidate_block_types) {
208210
const AtomContext& atom_ctx = g_vpr_ctx.atom();
@@ -212,7 +214,9 @@ static LegalizationClusterId create_new_cluster(t_pack_molecule* seed_molecule,
212214
// placed into.
213215
// TODO: The original implementation sorted based on balance. Perhaps this
214216
// should do the same.
215-
AtomBlockId root_atom = seed_molecule->atom_block_ids[seed_molecule->root];
217+
VTR_ASSERT(seed_molecule_id.is_valid());
218+
const t_pack_molecule& seed_molecule = prepacker.get_molecule(seed_molecule_id);
219+
AtomBlockId root_atom = seed_molecule.atom_block_ids[seed_molecule.root];
216220
const t_model* root_model = atom_ctx.nlist.block_model(root_atom);
217221

218222
auto itr = primitive_candidate_block_types.find(root_model);
@@ -224,7 +228,7 @@ static LegalizationClusterId create_new_cluster(t_pack_molecule* seed_molecule,
224228
for (int mode = 0; mode < num_modes; mode++) {
225229
e_block_pack_status pack_status = e_block_pack_status::BLK_STATUS_UNDEFINED;
226230
LegalizationClusterId new_cluster_id;
227-
std::tie(pack_status, new_cluster_id) = cluster_legalizer.start_new_cluster(seed_molecule, type, mode);
231+
std::tie(pack_status, new_cluster_id) = cluster_legalizer.start_new_cluster(seed_molecule_id, type, mode);
228232
if (pack_status == e_block_pack_status::BLK_PASSED)
229233
return new_cluster_id;
230234
}
@@ -290,33 +294,29 @@ void FullLegalizer::create_clusters(const PartialPlacement& p_placement) {
290294
for (size_t tile_id_idx = 0; tile_id_idx < num_device_tiles; tile_id_idx++) {
291295
DeviceTileId tile_id = DeviceTileId(tile_id_idx);
292296
// Create the molecule list
293-
std::list<t_pack_molecule*> mol_list;
297+
std::list<PackMoleculeId> mol_list;
294298
for (APBlockId ap_blk_id : blocks_in_tiles[tile_id]) {
295-
// FIXME: The netlist stores a const pointer to mol; but the cluster
296-
// legalizer does not accept this. Need to fix one or the other.
297-
// For now, using const_cast.
298-
t_pack_molecule* mol = const_cast<t_pack_molecule*>(ap_netlist_.block_molecule(ap_blk_id));
299-
mol_list.push_back(mol);
299+
mol_list.push_back(ap_netlist_.block_molecule(ap_blk_id));
300300
}
301301
// Clustering algorithm: Create clusters one at a time.
302302
while (!mol_list.empty()) {
303303
// Arbitrarily choose the first molecule as a seed molecule.
304-
t_pack_molecule* seed_mol = mol_list.front();
304+
PackMoleculeId seed_mol_id = mol_list.front();
305305
mol_list.pop_front();
306306
// Use the seed molecule to create a cluster for this tile.
307-
LegalizationClusterId new_cluster_id = create_new_cluster(seed_mol, cluster_legalizer, primitive_candidate_block_types);
307+
LegalizationClusterId new_cluster_id = create_new_cluster(seed_mol_id, prepacker_, cluster_legalizer, primitive_candidate_block_types);
308308
// Insert all molecules that you can into the cluster.
309309
// NOTE: If the mol_list was somehow sorted, we can just stop at
310310
// first failure!
311311
auto it = mol_list.begin();
312312
while (it != mol_list.end()) {
313-
t_pack_molecule* mol = *it;
314-
if (!cluster_legalizer.is_molecule_compatible(mol, new_cluster_id)) {
313+
PackMoleculeId mol_id = *it;
314+
if (!cluster_legalizer.is_molecule_compatible(mol_id, new_cluster_id)) {
315315
++it;
316316
continue;
317317
}
318318
// Try to insert it. If successful, remove from list.
319-
e_block_pack_status pack_status = cluster_legalizer.add_mol_to_cluster(mol, new_cluster_id);
319+
e_block_pack_status pack_status = cluster_legalizer.add_mol_to_cluster(mol_id, new_cluster_id);
320320
if (pack_status == e_block_pack_status::BLK_PASSED) {
321321
it = mol_list.erase(it);
322322
} else {
@@ -352,8 +352,9 @@ void FullLegalizer::place_clusters(const ClusteredNetlist& clb_nlist,
352352
// Create a lookup from the AtomBlockId to the APBlockId
353353
vtr::vector<AtomBlockId, APBlockId> atom_to_ap_block(atom_netlist_.blocks().size());
354354
for (APBlockId ap_blk_id : ap_netlist_.blocks()) {
355-
const t_pack_molecule* blk_mol = ap_netlist_.block_molecule(ap_blk_id);
356-
for (AtomBlockId atom_blk_id : blk_mol->atom_block_ids) {
355+
PackMoleculeId blk_mol_id = ap_netlist_.block_molecule(ap_blk_id);
356+
const t_pack_molecule& blk_mol = prepacker_.get_molecule(blk_mol_id);
357+
for (AtomBlockId atom_blk_id : blk_mol.atom_block_ids) {
357358
// See issue #2791, some of the atom_block_ids may be invalid. They
358359
// can safely be ignored.
359360
if (!atom_blk_id.is_valid())

vpr/src/analytical_place/gen_ap_netlist_from_atoms.cpp

+7-6
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#include "prepack.h"
1717
#include "region.h"
1818
#include "user_place_constraints.h"
19-
#include "vpr_types.h"
2019
#include "vtr_assert.h"
2120
#include "vtr_geometry.h"
2221
#include "vtr_time.h"
@@ -40,10 +39,11 @@ APNetlist gen_ap_netlist_from_atoms(const AtomNetlist& atom_netlist,
4039
// Each net has the exact same name as in the atom netlist
4140
for (AtomBlockId atom_blk_id : atom_netlist.blocks()) {
4241
// Get the molecule of this block
43-
t_pack_molecule* mol = prepacker.get_atom_molecule(atom_blk_id);
42+
PackMoleculeId molecule_id = prepacker.get_atom_molecule(atom_blk_id);
43+
const t_pack_molecule& mol = prepacker.get_molecule(molecule_id);
4444
// Create the AP block (if not already done)
45-
const std::string& first_blk_name = atom_netlist.block_name(mol->atom_block_ids[0]);
46-
APBlockId ap_blk_id = ap_netlist.create_block(first_blk_name, mol);
45+
const std::string& first_blk_name = atom_netlist.block_name(mol.atom_block_ids[0]);
46+
APBlockId ap_blk_id = ap_netlist.create_block(first_blk_name, molecule_id);
4747
// Add the ports and pins of this block to the supernode
4848
for (AtomPortId atom_port_id : atom_netlist.block_ports(atom_blk_id)) {
4949
BitIndex port_width = atom_netlist.port_width(atom_port_id);
@@ -68,8 +68,9 @@ APNetlist gen_ap_netlist_from_atoms(const AtomNetlist& atom_netlist,
6868

6969
// Fix the block locations given by the VPR constraints
7070
for (APBlockId ap_blk_id : ap_netlist.blocks()) {
71-
const t_pack_molecule* mol = ap_netlist.block_molecule(ap_blk_id);
72-
for (AtomBlockId mol_atom_blk_id : mol->atom_block_ids) {
71+
PackMoleculeId molecule_id = ap_netlist.block_molecule(ap_blk_id);
72+
const t_pack_molecule& mol = prepacker.get_molecule(molecule_id);
73+
for (AtomBlockId mol_atom_blk_id : mol.atom_block_ids) {
7374
PartitionId part_id = constraints.get_atom_partition(mol_atom_blk_id);
7475
if (!part_id.is_valid())
7576
continue;

vpr/src/analytical_place/global_placer.cpp

+8-4
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,22 @@
1818
#include "vtr_time.h"
1919

2020
std::unique_ptr<GlobalPlacer> make_global_placer(e_global_placer placer_type,
21-
const APNetlist& netlist) {
21+
const APNetlist& netlist,
22+
const Prepacker& prepacker) {
2223
// Based on the placer type passed in, build the global placer.
2324
switch (placer_type) {
2425
case e_global_placer::SimPL:
25-
return std::make_unique<SimPLGlobalPlacer>(netlist);
26+
return std::make_unique<SimPLGlobalPlacer>(netlist, prepacker);
2627
default:
2728
VPR_FATAL_ERROR(VPR_ERROR_AP,
2829
"Unrecognized global placer type");
2930

3031
}
3132
}
3233

33-
SimPLGlobalPlacer::SimPLGlobalPlacer(const APNetlist& netlist) : GlobalPlacer(netlist) {
34+
SimPLGlobalPlacer::SimPLGlobalPlacer(const APNetlist& netlist,
35+
const Prepacker& prepacker)
36+
: GlobalPlacer(netlist) {
3437
// This can be a long method. Good to time this to see how long it takes to
3538
// construct the global placer.
3639
vtr::ScopedStartFinishTimer global_placer_building_timer("Constructing Global Placer");
@@ -39,7 +42,8 @@ SimPLGlobalPlacer::SimPLGlobalPlacer(const APNetlist& netlist) : GlobalPlacer(ne
3942
netlist);
4043
// Build the partial legalizer
4144
partial_legalizer_ = make_partial_legalizer(e_partial_legalizer::FLOW_BASED,
42-
netlist);
45+
netlist,
46+
prepacker);
4347
}
4448

4549
/**

vpr/src/analytical_place/global_placer.h

+5-3
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@
1919
// Forward declarations
2020
class APNetlist;
2121
class AnalyticalSolver;
22-
class PartialPlacement;
2322
class PartialLegalizer;
23+
class PartialPlacement;
24+
class Prepacker;
2425

2526
/**
2627
* @brief Enumeration of all of the global placers currently implemented in VPR.
@@ -77,7 +78,8 @@ class GlobalPlacer {
7778
* @brief A factory method which creates a Global Placer of the given type.
7879
*/
7980
std::unique_ptr<GlobalPlacer> make_global_placer(e_global_placer placer_type,
80-
const APNetlist& netlist);
81+
const APNetlist& netlist,
82+
const Prepacker& prepacker);
8183

8284
/**
8385
* @brief A Global Placer based on the SimPL work for analytical ASIC placement.
@@ -130,7 +132,7 @@ class SimPLGlobalPlacer : public GlobalPlacer {
130132
*
131133
* Constructs the solver and partial legalizer.
132134
*/
133-
SimPLGlobalPlacer(const APNetlist& netlist);
135+
SimPLGlobalPlacer(const APNetlist& netlist, const Prepacker& prepacker);
134136

135137
/**
136138
* @brief Run a SimPL-like global placement algorithm

vpr/src/analytical_place/partial_legalizer.cpp

+12-9
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@
2323
#include "globals.h"
2424
#include "partial_placement.h"
2525
#include "physical_types.h"
26+
#include "prepack.h"
2627
#include "primitive_vector.h"
2728
#include "vpr_context.h"
2829
#include "vpr_error.h"
29-
#include "vpr_types.h"
3030
#include "vtr_assert.h"
3131
#include "vtr_geometry.h"
3232
#include "vtr_log.h"
@@ -36,11 +36,12 @@
3636
#include "vtr_vector_map.h"
3737

3838
std::unique_ptr<PartialLegalizer> make_partial_legalizer(e_partial_legalizer legalizer_type,
39-
const APNetlist& netlist) {
39+
const APNetlist& netlist,
40+
const Prepacker& prepacker) {
4041
// Based on the partial legalizer type passed in, build the partial legalizer.
4142
switch (legalizer_type) {
4243
case e_partial_legalizer::FLOW_BASED:
43-
return std::make_unique<FlowBasedLegalizer>(netlist);
44+
return std::make_unique<FlowBasedLegalizer>(netlist, prepacker);
4445
default:
4546
VPR_FATAL_ERROR(VPR_ERROR_AP,
4647
"Unrecognized partial legalizer type");
@@ -72,10 +73,12 @@ static inline float get_model_mass(const t_model* model) {
7273
* (primitive types) in the architecture.
7374
*/
7475
static inline PrimitiveVector get_primitive_mass(APBlockId blk_id,
75-
const APNetlist& netlist) {
76+
const APNetlist& netlist,
77+
const Prepacker& prepacker) {
7678
PrimitiveVector mass;
77-
const t_pack_molecule* mol = netlist.block_molecule(blk_id);
78-
for (AtomBlockId atom_blk_id : mol->atom_block_ids) {
79+
PackMoleculeId mol_id = netlist.block_molecule(blk_id);
80+
const t_pack_molecule& mol = prepacker.get_molecule(mol_id);
81+
for (AtomBlockId atom_blk_id : mol.atom_block_ids) {
7982
// See issue #2791, some of the atom_block_ids may be invalid. They can
8083
// safely be ignored.
8184
if (!atom_blk_id.is_valid())
@@ -459,8 +462,8 @@ void FlowBasedLegalizer::compute_neighbors_of_bin(LegalizerBinId src_bin_id, siz
459462
bins_[src_bin_id].neighbors.assign(neighbors.begin(), neighbors.end());
460463
}
461464

462-
FlowBasedLegalizer::FlowBasedLegalizer(const APNetlist& netlist)
463-
: PartialLegalizer(netlist),
465+
FlowBasedLegalizer::FlowBasedLegalizer(const APNetlist& netlist, const Prepacker& prepacker)
466+
: PartialLegalizer(netlist, prepacker),
464467
// TODO: Pass the device grid in.
465468
tile_bin_({g_vpr_ctx.device().grid.width(), g_vpr_ctx.device().grid.height()}) {
466469
const DeviceGrid& grid = g_vpr_ctx.device().grid;
@@ -542,7 +545,7 @@ FlowBasedLegalizer::FlowBasedLegalizer(const APNetlist& netlist)
542545
// Pre-compute the masses of the APBlocks
543546
VTR_LOGV(log_verbosity_ >= 10, "Pre-computing the block masses...\n");
544547
for (APBlockId blk_id : netlist.blocks()) {
545-
block_masses_.insert(blk_id, get_primitive_mass(blk_id, netlist));
548+
block_masses_.insert(blk_id, get_primitive_mass(blk_id, netlist, prepacker));
546549
}
547550
VTR_LOGV(log_verbosity_ >= 10, "Finished pre-computing the block masses.\n");
548551

0 commit comments

Comments
 (0)