Skip to content

Commit 9618414

Browse files
[ClusterLegalizer] Cluster Legalizer API
Isolated the cluster legalization logic out of the packer's clustering algorithm in such a way that it can be used externally to the clusterer with no issue. Once the ClusterLegalizer API is constructed, it will allocate all of the memory that it needs for legalization; it can then be used to legalize clusters; and when it is destroyed it will remove all state created for clustering. The cluster legalizer API maintains the legalized clusters internally as opposed to using the ClusterBlockId as an ID to the clusters. This allowed me to separate the ClusteredNetlist from the packing algorithm entirely. This importantly helper separate out all legalization logic from directly modifying the ClusteredNetlist generation code. I did my best to remove as much global state as I could from the API to make it as self-contained as possible. This change greatly cleaned up the packer code and removed many of its global variables (including the ClusterLegalizer itself, which is now a local variable!) This change also removed the re_clustering API since it would need to be heavily modified to include this change; and since this feature was not being tested, it would be challenging to upgrade to use this new cluster legalization API.
1 parent c7b9ce0 commit 9618414

31 files changed

+3005
-3604
lines changed

vpr/src/base/SetupGrid.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
#include <vector>
1313
#include "physical_types.h"
1414

15+
class DeviceGrid;
16+
1517
///@brief Find the device satisfying the specified minimum resources
1618
/// minimum_instance_counts and target_device_utilization are not required when specifying a fixed layout
1719
DeviceGrid create_device_grid(const std::string& layout_name,

vpr/src/base/vpr_api.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <cstring>
1616
#include <cmath>
1717

18+
#include "vpr_context.h"
1819
#include "vtr_assert.h"
1920
#include "vtr_math.h"
2021
#include "vtr_log.h"
@@ -359,9 +360,7 @@ void vpr_init_with_options(const t_options* options, t_vpr_setup* vpr_setup, t_a
359360

360361
fflush(stdout);
361362

362-
auto& helper_ctx = g_vpr_ctx.mutable_cl_helper();
363363
auto& device_ctx = g_vpr_ctx.mutable_device();
364-
helper_ctx.lb_type_rr_graphs = vpr_setup->PackerRRGraph;
365364
device_ctx.pad_loc_type = vpr_setup->PlacerOpts.pad_loc_type;
366365
}
367366

@@ -613,12 +612,13 @@ bool vpr_pack_flow(t_vpr_setup& vpr_setup, const t_arch& arch) {
613612
//Load a previous packing from the .net file
614613
vpr_load_packing(vpr_setup, arch);
615614

616-
//Load cluster_constraints data structure here since loading pack file
617-
load_cluster_constraints();
618615
}
619616

620617
}
621618

619+
// Load cluster_constraints data structure here since loading pack file
620+
load_cluster_constraints();
621+
622622
/* Sanity check the resulting netlist */
623623
check_netlist(packer_opts.pack_verbosity);
624624

@@ -696,6 +696,7 @@ void vpr_load_packing(t_vpr_setup& vpr_setup, const t_arch& arch) {
696696
"Must have valid .net filename to load packing");
697697

698698
auto& cluster_ctx = g_vpr_ctx.mutable_clustering();
699+
const AtomContext& atom_ctx = g_vpr_ctx.atom();
699700

700701
/* Ensure we have a clean start with void net remapping information */
701702
cluster_ctx.post_routing_clb_pin_nets.clear();
@@ -706,8 +707,15 @@ void vpr_load_packing(t_vpr_setup& vpr_setup, const t_arch& arch) {
706707
vpr_setup.FileNameOpts.verify_file_digests,
707708
vpr_setup.PackerOpts.pack_verbosity);
708709

710+
/* Load the mapping between clusters and their atoms */
711+
cluster_ctx.atoms_lookup.resize(cluster_ctx.clb_nlist.blocks().size());
712+
for (AtomBlockId atom_blk_id : atom_ctx.nlist.blocks()) {
713+
ClusterBlockId atom_cluster_blk_id = atom_ctx.lookup.atom_clb(atom_blk_id);
714+
cluster_ctx.atoms_lookup[atom_cluster_blk_id].insert(atom_blk_id);
715+
}
716+
709717
process_constant_nets(g_vpr_ctx.mutable_atom().nlist,
710-
g_vpr_ctx.atom().lookup,
718+
atom_ctx.lookup,
711719
cluster_ctx.clb_nlist,
712720
vpr_setup.constant_net_method,
713721
vpr_setup.PackerOpts.pack_verbosity);

vpr/src/base/vpr_constraints_writer.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,15 @@
77
#include "vpr_constraints_serializer.h"
88
#include "vpr_constraints_uxsdcxx.h"
99

10-
#include "vtr_time.h"
10+
#include "vpr_context.h"
1111

1212
#include "globals.h"
1313
#include "pugixml.hpp"
14-
#include "pugixml_util.hpp"
15-
#include "clustered_netlist_utils.h"
1614

1715
#include <fstream>
16+
#include <unordered_set>
1817
#include "vpr_constraints_writer.h"
1918
#include "region.h"
20-
#include "re_cluster_util.h"
2119

2220
/**
2321
* @brief Create a partition with the given name and a single region.
@@ -30,7 +28,6 @@ static Partition create_partition(const std::string& part_name, const Region& re
3028

3129
void write_vpr_floorplan_constraints(const char* file_name, int expand, bool subtile, int horizontal_partitions, int vertical_partitions) {
3230
VprConstraints constraints;
33-
3431
if (horizontal_partitions != 0 && vertical_partitions != 0) {
3532
setup_vpr_floorplan_constraints_cutpoints(constraints, horizontal_partitions, vertical_partitions);
3633
} else {
@@ -83,16 +80,17 @@ void setup_vpr_floorplan_constraints_one_loc(VprConstraints& constraints, int ex
8380
part.set_part_region(pr);
8481
constraints.mutable_place_constraints().add_partition(part);
8582

86-
const std::unordered_set<AtomBlockId>& atoms = cluster_to_atoms(blk_id);
87-
83+
const std::unordered_set<AtomBlockId>& atoms = cluster_ctx.atoms_lookup[blk_id];
8884
for (AtomBlockId atom_id : atoms) {
8985
constraints.mutable_place_constraints().add_constrained_atom(atom_id, partid);
9086
}
9187
part_id++;
9288
}
9389
}
9490

95-
void setup_vpr_floorplan_constraints_cutpoints(VprConstraints& constraints, int horizontal_cutpoints, int vertical_cutpoints) {
91+
void setup_vpr_floorplan_constraints_cutpoints(VprConstraints& constraints,
92+
int horizontal_cutpoints,
93+
int vertical_cutpoints) {
9694
auto& cluster_ctx = g_vpr_ctx.clustering();
9795
auto& block_locs = g_vpr_ctx.placement().block_locs();
9896
auto& device_ctx = g_vpr_ctx.device();
@@ -158,7 +156,7 @@ void setup_vpr_floorplan_constraints_cutpoints(VprConstraints& constraints, int
158156
* appropriate region accordingly
159157
*/
160158
for (ClusterBlockId blk_id : cluster_ctx.clb_nlist.blocks()) {
161-
const std::unordered_set<AtomBlockId>& atoms = cluster_to_atoms(blk_id);
159+
const std::unordered_set<AtomBlockId>& atoms = cluster_ctx.atoms_lookup[blk_id];
162160
int x = block_locs[blk_id].loc.x;
163161
int y = block_locs[blk_id].loc.y;
164162
int width = device_ctx.grid.width();

vpr/src/base/vpr_constraints_writer.h

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
#ifndef VPR_SRC_BASE_VPR_CONSTRAINTS_WRITER_H_
2626
#define VPR_SRC_BASE_VPR_CONSTRAINTS_WRITER_H_
2727

28+
class VprConstraints;
29+
2830
/**
2931
* @brief Write out floorplan constraints to an XML file based on current placement
3032
*
@@ -35,7 +37,11 @@
3537
* @param subtile Specifies whether to write out the constraint regions with or without
3638
* subtile values.
3739
*/
38-
void write_vpr_floorplan_constraints(const char* file_name, int expand, bool subtile, int horizontal_partitions, int vertical_partitions);
40+
void write_vpr_floorplan_constraints(const char* file_name,
41+
int expand,
42+
bool subtile,
43+
int horizontal_partitions,
44+
int vertical_partitions);
3945

4046
/**
4147
* @brief Populates VprConstraints by creating a partition for each clustered block.
@@ -50,7 +56,9 @@ void write_vpr_floorplan_constraints(const char* file_name, int expand, bool sub
5056
* @param subtile Specifies whether to write out the constraint regions with or without
5157
* subtile values.
5258
*/
53-
void setup_vpr_floorplan_constraints_one_loc(VprConstraints& constraints, int expand, bool subtile);
59+
void setup_vpr_floorplan_constraints_one_loc(VprConstraints& constraints,
60+
int expand,
61+
bool subtile);
5462

5563
/**
5664
* @brief Populates VprConstraints by dividing the grid into multiple partitions.
@@ -62,6 +70,8 @@ void setup_vpr_floorplan_constraints_one_loc(VprConstraints& constraints, int ex
6270
* @param horizontal_cutpoints The number of horizontal cut-lines.
6371
* @param vertical_cutpoints The number of vertical cut_lines.
6472
*/
65-
void setup_vpr_floorplan_constraints_cutpoints(VprConstraints& constraints, int horizontal_cutpoints, int vertical_cutpoints);
73+
void setup_vpr_floorplan_constraints_cutpoints(VprConstraints& constraints,
74+
int horizontal_cutpoints,
75+
int vertical_cutpoints);
6676

6777
#endif /* VPR_SRC_BASE_VPR_CONSTRAINTS_WRITER_H_ */

vpr/src/base/vpr_context.h

Lines changed: 12 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "vtr_ndmatrix.h"
1111
#include "vtr_optional.h"
1212
#include "vtr_vector.h"
13+
#include "vtr_vector_map.h"
1314
#include "atom_netlist.h"
1415
#include "clustered_netlist.h"
1516
#include "rr_graph_view.h"
@@ -78,12 +79,6 @@ struct AtomContext : public Context {
7879

7980
/// @brief Mappings to/from the Atom Netlist to physically described .blif models
8081
AtomLookup lookup;
81-
82-
/// @brief Prepacker object which performs prepacking and stores the pack
83-
/// molecules. Has a method to get the pack molecule of an AtomBlock.
84-
/// TODO: This is mainly only used in the clusterer. It can probably be
85-
/// removed from the AtomContext entirely.
86-
Prepacker prepacker;
8782
};
8883

8984
/**
@@ -286,69 +281,23 @@ struct ClusteringContext : public Context {
286281
* CLB Netlist
287282
********************************************************************/
288283

289-
///@brief New netlist class derived from Netlist
284+
/// @brief New netlist class derived from Netlist
290285
ClusteredNetlist clb_nlist;
291286

292-
/* Database for nets of each clb block pin after routing stage
293-
* - post_routing_clb_pin_nets:
294-
* mapping of pb_type pins to clustered net ids
295-
* - pre_routing_net_pin_mapping:
296-
* a copy of mapping for current pb_route index to previous pb_route index
297-
* Record the previous pin mapping for finding the correct pin index during timing analysis
298-
*/
287+
/// @brief Database for nets of each clb block pin after routing stage.
288+
/// - post_routing_clb_pin_nets:
289+
/// mapping of pb_type pins to clustered net ids.
290+
/// - pre_routing_net_pin_mapping:
291+
/// a copy of mapping for current pb_route index to previous pb_route index
292+
/// Record the previous pin mapping for finding the correct pin index during
293+
/// timing analysis.
299294
std::map<ClusterBlockId, std::map<int, ClusterNetId>> post_routing_clb_pin_nets;
300295
std::map<ClusterBlockId, std::map<int, int>> pre_routing_net_pin_mapping;
301-
};
302-
303-
/**
304-
* @brief State relating to helper data structure using in the clustering stage
305-
*
306-
* This should contain helper data structures that are useful in the clustering/packing stage.
307-
* They are encapsulated here as they are useful in clustering and reclustering algorithms that may be used
308-
* in packing or placement stages.
309-
*/
310-
struct ClusteringHelperContext : public Context {
311-
// A map used to save the number of used instances from each logical block type.
312-
std::map<t_logical_block_type_ptr, size_t> num_used_type_instances;
313-
314-
// Stats keeper for placement information during packing/clustering
315-
t_cluster_placement_stats* cluster_placement_stats;
316-
317-
// total number of models in the architecture
318-
int num_models;
319-
320-
int max_cluster_size;
321-
t_pb_graph_node** primitives_list;
322296

323-
bool enable_pin_feasibility_filter;
324-
int feasible_block_array_size;
325-
326-
// total number of CLBs
327-
int total_clb_num;
328-
329-
// A vector of routing resource nodes within each of logic cluster_ctx.blocks types [0 .. num_logical_block_type-1]
330-
std::vector<t_lb_type_rr_node>* lb_type_rr_graphs;
331-
332-
// the utilization of external input/output pins during packing (between 0 and 1)
333-
t_ext_pin_util_targets target_external_pin_util;
334-
335-
// During clustering, a block is related to un-clustered primitives with nets.
336-
// This relation has three types: low fanout, high fanout, and transitive
337-
// high_fanout_thresholds stores the threshold for nets to a block type to be considered high fanout
338-
t_pack_high_fanout_thresholds high_fanout_thresholds;
339-
340-
// A vector of unordered_sets of AtomBlockIds that are inside each clustered block [0 .. num_clustered_blocks-1]
341-
// unordered_set for faster insertion/deletion during the iterative improvement process of packing
297+
/// @brief A vector of unordered_sets of AtomBlockIds that are inside each
298+
/// clustered block [0 .. num_clustered_blocks-1]
299+
/// This is populated when the packing is loaded.
342300
vtr::vector<ClusterBlockId, std::unordered_set<AtomBlockId>> atoms_lookup;
343-
344-
/** Stores the NoC group ID of each atom block. Atom blocks that belong
345-
* to different NoC groups can't be clustered with each other into the
346-
* same clustered block.*/
347-
vtr::vector<AtomBlockId, NocGroupId> atom_noc_grp_id;
348-
349-
~ClusteringHelperContext() {
350-
delete[] primitives_list;
351-
}
352301
};
353302

354303
/**
@@ -728,9 +677,6 @@ class VprContext : public Context {
728677
const ClusteringContext& clustering() const { return clustering_; }
729678
ClusteringContext& mutable_clustering() { return clustering_; }
730679

731-
const ClusteringHelperContext& cl_helper() const { return helper_; }
732-
ClusteringHelperContext& mutable_cl_helper() { return helper_; }
733-
734680
const PlacementContext& placement() const { return placement_; }
735681
PlacementContext& mutable_placement() { return placement_; }
736682

@@ -760,8 +706,6 @@ class VprContext : public Context {
760706
PowerContext power_;
761707

762708
ClusteringContext clustering_;
763-
ClusteringHelperContext helper_;
764-
765709
PlacementContext placement_;
766710
RoutingContext routing_;
767711
FloorplanningContext constraints_;

vpr/src/base/vpr_types.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -168,15 +168,6 @@ enum class e_cluster_seed {
168168
BLEND2
169169
};
170170

171-
enum class e_block_pack_status {
172-
BLK_PASSED,
173-
BLK_FAILED_FEASIBLE,
174-
BLK_FAILED_ROUTE,
175-
BLK_FAILED_FLOORPLANNING,
176-
BLK_FAILED_NOC_GROUP,
177-
BLK_STATUS_UNDEFINED
178-
};
179-
180171
struct t_ext_pin_util {
181172
t_ext_pin_util() = default;
182173
t_ext_pin_util(float in, float out)

0 commit comments

Comments
 (0)