Skip to content

Commit 083f15a

Browse files
[SQUASH ME] Removed Clustered Netlist from Packer
1 parent df22e4c commit 083f15a

14 files changed

+426
-271
lines changed

vpr/src/base/clustered_netlist.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,12 +171,8 @@ ClusterNetId ClusteredNetlist::create_net(const std::string& name) {
171171

172172
void ClusteredNetlist::remove_block_impl(const ClusterBlockId blk_id) {
173173
//Remove & invalidate pointers
174-
// FIXME: This cannot set the pb to nullptr properly, causing it to double
175-
// free... Need some way to transfer ownership.
176-
/*
177174
free_pb(block_pbs_[blk_id]);
178175
delete block_pbs_[blk_id];
179-
*/
180176
block_pbs_.insert(blk_id, NULL);
181177
block_types_.insert(blk_id, NULL);
182178
block_logical_pins_.insert(blk_id, std::vector<ClusterPinId>());

vpr/src/base/vpr_context.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include "noc_routing.h"
3737
#include "tatum/report/TimingPath.hpp"
3838
#include "blk_loc_registry.h"
39+
#include "vtr_vector_map.h"
3940

4041
#ifndef NO_SERVER
4142

@@ -320,8 +321,17 @@ struct ClusteringHelperContext : public Context {
320321
int max_cluster_size;
321322

322323
// total number of CLBs
324+
// TODO: Rename to num_legalized_clusters.
325+
// - Maybe even remove this if it becomes trivial.
323326
int total_clb_num;
324327

328+
std::vector<LegalizationClusterId> legalized_clusters;
329+
// FIXME: These are overshadowed by the legalizer which can return these!
330+
// - They can just be removed and use the cluster legalizer as the lookup.
331+
// - This also gets invalidated by the compress, making it uber wrong!
332+
vtr::vector_map<LegalizationClusterId, t_pb*> cluster_pb;
333+
vtr::vector_map<LegalizationClusterId, t_logical_block_type_ptr> cluster_type;
334+
325335
// A vector of routing resource nodes within each of logic cluster_ctx.blocks types [0 .. num_logical_block_type-1]
326336
// FIXME: This is only used for a handoff between the vpr_setup and the packer.
327337
// This can be made cleaner.

vpr/src/pack/cluster.cpp

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,7 @@ std::map<t_logical_block_type_ptr, size_t> do_clustering(const t_packer_opts& pa
7575
bool balance_block_type_utilization,
7676
AttractionInfo& attraction_groups,
7777
bool& floorplan_regions_overfull,
78-
t_clustering_data& clustering_data,
79-
size_t num_models) {
78+
t_clustering_data& clustering_data) {
8079
/* Does the actual work of clustering multiple netlist blocks *
8180
* into clusters. */
8281

@@ -120,7 +119,6 @@ std::map<t_logical_block_type_ptr, size_t> do_clustering(const t_packer_opts& pa
120119

121120
auto& atom_ctx = g_vpr_ctx.atom();
122121
auto& device_ctx = g_vpr_ctx.mutable_device();
123-
auto& cluster_ctx = g_vpr_ctx.mutable_clustering();
124122
auto& helper_ctx = g_vpr_ctx.mutable_cl_helper();
125123

126124
std::shared_ptr<PreClusterDelayCalculator> clustering_delay_calc;
@@ -136,12 +134,15 @@ std::map<t_logical_block_type_ptr, size_t> do_clustering(const t_packer_opts& pa
136134
// Index 2 holds the number of LEs that are used for registers only.
137135
std::vector<int> le_count(3, 0);
138136

137+
// helper_ctx.legalized_clusters.clear();
138+
helper_ctx.cluster_pb.clear();
139+
helper_ctx.cluster_type.clear();
139140
helper_ctx.total_clb_num = 0;
140141

141142
/* TODO: This is memory inefficient, fix if causes problems */
142143
/* Store stats on nets used by packed block, useful for determining transitively connected blocks
143144
* (eg. [A1, A2, ..]->[B1, B2, ..]->C implies cluster [A1, A2, ...] and C have a weak link) */
144-
vtr::vector<ClusterBlockId, std::vector<AtomNetId>> clb_inter_blk_nets(atom_ctx.nlist.blocks().size());
145+
vtr::vector<LegalizationClusterId, std::vector<AtomNetId>> clb_inter_blk_nets(atom_ctx.nlist.blocks().size());
145146

146147
istart = nullptr;
147148

@@ -228,24 +229,16 @@ std::map<t_logical_block_type_ptr, size_t> do_clustering(const t_packer_opts& pa
228229
// FIXME: Pass in the cluster legalizer.
229230
helper_ctx.cluster_legalizer.set_legalization_strategy(strategy);
230231

231-
// FIXME: Remove the reference to the clustered netlist. It is not
232-
// even correct.
233-
// - Or maybe we can just leave it for now. This is more of a
234-
// clustering issue and not a legalizer issue.
235-
// Use the total number created clusters so far as the ID for the new cluster
236-
ClusterBlockId clb_index(helper_ctx.total_clb_num);
237232
LegalizationClusterId legalization_cluster_id;
238233

239234
VTR_LOGV(verbosity > 2, "Complex block %d:\n", helper_ctx.total_clb_num);
240235

241236
start_new_cluster(helper_ctx.cluster_legalizer,
242-
clb_index,
243237
legalization_cluster_id,
244238
istart,
245239
num_used_type_instances,
246240
packer_opts.target_device_utilization,
247241
arch, packer_opts.device_layout,
248-
&cluster_ctx.clb_nlist,
249242
primitive_candidate_block_types,
250243
verbosity,
251244
balance_block_type_utilization);
@@ -263,14 +256,14 @@ std::map<t_logical_block_type_ptr, size_t> do_clustering(const t_packer_opts& pa
263256

264257
VTR_LOGV(verbosity > 2,
265258
"Complex block %d: '%s' (%s) ", helper_ctx.total_clb_num,
266-
cluster_ctx.clb_nlist.block_name(clb_index).c_str(),
267-
cluster_ctx.clb_nlist.block_type(clb_index)->name);
259+
helper_ctx.cluster_pb[legalization_cluster_id]->name,
260+
helper_ctx.cluster_type[legalization_cluster_id]->name);
268261
VTR_LOGV(verbosity > 2, ".");
269262
//Progress dot for seed-block
270263
fflush(stdout);
271264

272-
int high_fanout_threshold = helper_ctx.high_fanout_thresholds.get_threshold(cluster_ctx.clb_nlist.block_type(clb_index)->name);
273-
update_cluster_stats(istart, clb_index,
265+
int high_fanout_threshold = helper_ctx.high_fanout_thresholds.get_threshold(helper_ctx.cluster_type[legalization_cluster_id]->name);
266+
update_cluster_stats(istart,
274267
is_clock, //Set of clock nets
275268
is_global, //Set of global nets (currently all clocks)
276269
packer_opts.global_clocks,
@@ -288,9 +281,9 @@ std::map<t_logical_block_type_ptr, size_t> do_clustering(const t_packer_opts& pa
288281
*is only one atom block clustered it would not change anything */
289282
}
290283
// FIXME: This access should be a getter.
291-
cur_cluster_placement_stats_ptr = &(helper_ctx.cluster_legalizer.cluster_placement_stats[cluster_ctx.clb_nlist.block_type(clb_index)->index]);
284+
cur_cluster_placement_stats_ptr = &(helper_ctx.cluster_legalizer.cluster_placement_stats[helper_ctx.cluster_type[legalization_cluster_id]->index]);
292285
cluster_stats.num_unrelated_clustering_attempts = 0;
293-
next_molecule = get_molecule_for_cluster(cluster_ctx.clb_nlist.block_pb(clb_index),
286+
next_molecule = get_molecule_for_cluster(helper_ctx.cluster_pb[legalization_cluster_id],
294287
attraction_groups,
295288
allow_unrelated_clustering,
296289
packer_opts.prioritize_transitive_connectivity,
@@ -299,7 +292,7 @@ std::map<t_logical_block_type_ptr, size_t> do_clustering(const t_packer_opts& pa
299292
&cluster_stats.num_unrelated_clustering_attempts,
300293
cur_cluster_placement_stats_ptr,
301294
clb_inter_blk_nets,
302-
clb_index,
295+
legalization_cluster_id,
303296
verbosity,
304297
clustering_data.unclustered_list_head,
305298
unclustered_list_head_size,
@@ -333,7 +326,6 @@ std::map<t_logical_block_type_ptr, size_t> do_clustering(const t_packer_opts& pa
333326
num_repeated_molecules,
334327
cluster_stats,
335328
helper_ctx.total_clb_num,
336-
clb_index,
337329
legalization_cluster_id,
338330
attraction_groups,
339331
clb_inter_blk_nets,
@@ -361,10 +353,11 @@ std::map<t_logical_block_type_ptr, size_t> do_clustering(const t_packer_opts& pa
361353
}
362354

363355
if (is_cluster_legal) {
356+
// helper_ctx.legalized_clusters.push_back(legalization_cluster_id);
364357
istart = save_cluster_routing_and_pick_new_seed(packer_opts, seed_atoms, num_blocks_hill_added, seed_index, cluster_stats);
365-
store_cluster_info_and_free(packer_opts, clb_index, logic_block_type, le_pb_type, le_count, clb_inter_blk_nets);
358+
store_cluster_info_and_free(packer_opts, legalization_cluster_id, logic_block_type, le_pb_type, le_count, clb_inter_blk_nets);
366359
} else {
367-
free_data_and_requeue_used_mols_if_illegal(clb_index, legalization_cluster_id, saved_seed_index, num_used_type_instances, helper_ctx.total_clb_num, seed_index);
360+
free_data_and_requeue_used_mols_if_illegal(legalization_cluster_id, saved_seed_index, num_used_type_instances, helper_ctx.total_clb_num, seed_index);
368361
}
369362
}
370363
}

vpr/src/pack/cluster.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,7 @@ std::map<t_logical_block_type_ptr, size_t> do_clustering(const t_packer_opts& pa
2222
bool balance_block_type_utilization,
2323
AttractionInfo& attraction_groups,
2424
bool& floorplan_regions_overfull,
25-
t_clustering_data& clustering_data,
26-
size_t num_models);
27-
28-
int get_cluster_of_block(int blkidx);
25+
t_clustering_data& clustering_data);
2926

3027
void print_pb_type_count(const ClusteredNetlist& clb_nlist);
3128
#endif

vpr/src/pack/cluster_legalizer.cpp

Lines changed: 48 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@
1616
#include <tuple>
1717
#include <vector>
1818
#include "atom_lookup.h"
19+
#include "atom_netlist.h"
1920
#include "cluster_placement.h"
2021
#include "cluster_router.h"
2122
#include "globals.h"
2223
#include "logic_types.h"
24+
#include "netlist_utils.h"
2325
#include "noc_data_types.h"
2426
#include "pack_types.h"
2527
#include "partition.h"
@@ -514,15 +516,13 @@ try_place_atom_block_rec(const t_pb_graph_node* pb_graph_node,
514516
// FIXME: UPDATE THIS!
515517
VTR_ASSERT(!atom_ctx.lookup.pb_atom(pb)
516518
&& atom_ctx.lookup.atom_pb(blk_id) == nullptr
517-
&& (!atom_cluster.contains(blk_id) ||
518-
atom_cluster[blk_id] == LegalizationClusterId::INVALID()));
519+
&& atom_cluster[blk_id] == LegalizationClusterId::INVALID());
519520
/* try pack to location */
520521
VTR_ASSERT(pb->name == nullptr);
521522
pb->name = vtr::strdup(atom_ctx.nlist.block_name(blk_id).c_str());
522523

523524
//Update the atom netlist mappings
524-
// FIXME: This needs to be cleaned up!
525-
atom_cluster.insert(blk_id, cluster_id);
525+
atom_cluster[blk_id] = cluster_id;
526526
// NOTE: This pb is different from the pb of the cluster. It is the pb
527527
// of the actual primitive. It may be an upwards battle to try and
528528
// remove it!
@@ -679,10 +679,8 @@ static void compute_and_mark_lookahead_pins_used_for_pin(const t_pb_graph_pin* p
679679
// pb_graph_pin driving net_id in the driver pb block
680680
t_pb_graph_pin* output_pb_graph_pin = nullptr;
681681
// if the driver block is in the same clb as the input primitive block
682-
// FIXME: If atom_cluster was a vector, this can be made much cleaner!
683-
LegalizationClusterId driver_cluster_id = atom_cluster.contains(driver_blk_id) ? atom_cluster[driver_blk_id] : LegalizationClusterId::INVALID();
684-
LegalizationClusterId prim_cluster_id = atom_cluster.contains(prim_blk_id) ? atom_cluster[prim_blk_id] : LegalizationClusterId::INVALID();
685-
// if (atom_ctx.lookup.atom_clb(driver_blk_id) == atom_ctx.lookup.atom_clb(prim_blk_id)) {
682+
LegalizationClusterId driver_cluster_id = atom_cluster[driver_blk_id];
683+
LegalizationClusterId prim_cluster_id = atom_cluster[prim_blk_id];
686684
if (driver_cluster_id == prim_cluster_id) {
687685
// get pb_graph_pin driving the given net
688686
output_pb_graph_pin = get_driver_pb_graph_pin(driver_pb, driver_pin_id);
@@ -753,9 +751,7 @@ static void compute_and_mark_lookahead_pins_used_for_pin(const t_pb_graph_pin* p
753751
LegalizationClusterId driver_cluster = atom_cluster[driver_blk_id];
754752
for (auto pin_id : atom_ctx.nlist.net_sinks(net_id)) {
755753
auto sink_blk_id = atom_ctx.nlist.pin_block(pin_id);
756-
// FIXME: Can be made cleaner if atom_cluster was a vector
757-
if (!atom_cluster.contains(sink_blk_id) ||
758-
atom_cluster[sink_blk_id] != driver_cluster) {
754+
if (atom_cluster[sink_blk_id] != driver_cluster) {
759755
all_sinks_in_cur_cluster = false;
760756
break;
761757
}
@@ -1320,6 +1316,10 @@ e_block_pack_status ClusterLegalizer::try_pack_molecule(t_pack_molecule* molecul
13201316
cur_molecule->valid = false;
13211317

13221318
commit_primitive(cluster_placement_stats_ptr, primitives_list[i]);
1319+
1320+
// FIXME: Does this need to go here? Shouldn't all atoms
1321+
// be labeled?
1322+
atom_cluster[atom_blk_id] = cluster_id;
13231323
}
13241324

13251325
// Update the lookahead pins used.
@@ -1399,13 +1399,14 @@ ClusterLegalizer::start_new_cluster(t_pack_molecule* molecule,
13991399
// TODO: Figure out why this uses FULL_EXTERNAL_PIN_UTIL
14001400
//Constant allowing all cluster pins to be used
14011401
const t_ext_pin_util FULL_EXTERNAL_PIN_UTIL(1., 1.);
1402-
LegalizationClusterId new_cluster_id = LegalizationClusterId(legalization_clusters.size());
1402+
LegalizationClusterId new_cluster_id = LegalizationClusterId(legalization_cluster_ids.size());
14031403
e_block_pack_status pack_status = try_pack_molecule(molecule,
14041404
new_cluster,
14051405
new_cluster_id,
14061406
FULL_EXTERNAL_PIN_UTIL);
14071407

14081408
if (pack_status == e_block_pack_status::BLK_PASSED) {
1409+
legalization_cluster_ids.push_back(new_cluster_id);
14091410
legalization_clusters.push_back(std::move(new_cluster));
14101411
molecule_cluster[molecule] = new_cluster_id;
14111412
} else {
@@ -1467,6 +1468,8 @@ void ClusterLegalizer::destroy_cluster(LegalizationClusterId cluster_id) {
14671468
VTR_ASSERT_SAFE(molecule_cluster.find(mol) != molecule_cluster.end() &&
14681469
molecule_cluster[mol] == cluster_id);
14691470
molecule_cluster[mol] = LegalizationClusterId::INVALID();
1471+
// FIXME: Document this.
1472+
mol->valid = true;
14701473
// Revert the placement of all blocks in the molecule.
14711474
// TODO: remove_atom_from_target can also be used for a move function
14721475
// to remove a single molecule from a cluster. Truly just copy
@@ -1490,6 +1493,35 @@ void ClusterLegalizer::destroy_cluster(LegalizationClusterId cluster_id) {
14901493
free_router_data(cluster.router_data);
14911494
cluster.router_data = nullptr;
14921495
cluster.pr = PartitionRegion();
1496+
1497+
// Mark the cluster as invalid.
1498+
legalization_cluster_ids[cluster_id] = LegalizationClusterId::INVALID();
1499+
}
1500+
1501+
void ClusterLegalizer::compress() {
1502+
// Create a map from the old ids to the new (compressed) one.
1503+
vtr::vector_map<LegalizationClusterId, LegalizationClusterId> cluster_id_map;
1504+
cluster_id_map = compress_ids(legalization_cluster_ids);
1505+
// Update all cluster values.
1506+
legalization_cluster_ids = clean_and_reorder_ids(cluster_id_map);
1507+
legalization_clusters = clean_and_reorder_values(legalization_clusters, cluster_id_map);
1508+
// Update the reverse lookups.
1509+
for (auto& it : molecule_cluster) {
1510+
if (!it.second.is_valid())
1511+
continue;
1512+
molecule_cluster[it.first] = cluster_id_map[it.second];
1513+
}
1514+
for (size_t i = 0; i < atom_cluster.size(); i++) {
1515+
AtomBlockId atom_blk_id = AtomBlockId(i);
1516+
LegalizationClusterId old_cluster_id = atom_cluster[atom_blk_id];
1517+
if (!old_cluster_id.is_valid())
1518+
continue;
1519+
atom_cluster[atom_blk_id] = cluster_id_map[old_cluster_id];
1520+
}
1521+
// Shrink everything to fit
1522+
legalization_cluster_ids.shrink_to_fit();
1523+
legalization_clusters.shrink_to_fit();
1524+
atom_cluster.shrink_to_fit();
14931525
}
14941526

14951527
bool ClusterLegalizer::check_cluster_legality(LegalizationClusterId cluster_id) {
@@ -1498,7 +1530,8 @@ bool ClusterLegalizer::check_cluster_legality(LegalizationClusterId cluster_id)
14981530
return try_intra_lb_route(cluster.router_data, log_verbosity, &mode_status);
14991531
}
15001532

1501-
void ClusterLegalizer::init(const Prepacker& prepacker,
1533+
void ClusterLegalizer::init(const AtomNetlist& atom_netlist,
1534+
const Prepacker& prepacker,
15021535
const std::vector<t_logical_block_type>& logical_block_types,
15031536
std::vector<t_lb_type_rr_node>* t_lb_type_rr_graphs,
15041537
size_t t_num_models,
@@ -1514,6 +1547,8 @@ void ClusterLegalizer::init(const Prepacker& prepacker,
15141547
// Verify that the inputs are valid.
15151548
VTR_ASSERT(t_lb_type_rr_graphs != nullptr);
15161549

1550+
// Resize the atom_cluster lookup to make the accesses much cheaper.
1551+
atom_cluster.resize(atom_netlist.blocks().size(), LegalizationClusterId::INVALID());
15171552
// Allocate the cluster_placement_stats
15181553
cluster_placement_stats = alloc_and_load_cluster_placement_stats();
15191554
// Allocate the primitives_lists

0 commit comments

Comments
 (0)