Skip to content

Commit ea77b2d

Browse files
[SQUASH ME] Fixed Bug with partition region legalization
1 parent ad35684 commit ea77b2d

9 files changed

+48
-66
lines changed

vpr/src/base/read_netlist.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,11 @@
1010
#include <cstring>
1111
#include <ctime>
1212
#include <map>
13-
#include <unordered_set>
1413

1514
#include "pugixml.hpp"
1615
#include "pugixml_loc.hpp"
1716
#include "pugixml_util.hpp"
1817

19-
#include "vpr_context.h"
2018
#include "vtr_assert.h"
2119
#include "vtr_util.h"
2220
#include "vtr_log.h"

vpr/src/base/vpr_api.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -614,12 +614,13 @@ bool vpr_pack_flow(t_vpr_setup& vpr_setup, const t_arch& arch) {
614614
//Load a previous packing from the .net file
615615
vpr_load_packing(vpr_setup, arch);
616616

617-
//Load cluster_constraints data structure here since loading pack file
618-
load_cluster_constraints();
619617
}
620618

621619
}
622620

621+
// Load cluster_constraints data structure here since loading pack file
622+
load_cluster_constraints();
623+
623624
/* Sanity check the resulting netlist */
624625
check_netlist(packer_opts.pack_verbosity);
625626

vpr/src/base/vpr_constraints_writer.cpp

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,9 @@ static Partition create_partition(const std::string& part_name, const Region& re
2929
void write_vpr_floorplan_constraints(const char* file_name, int expand, bool subtile, int horizontal_partitions, int vertical_partitions) {
3030
VprConstraints constraints;
3131
if (horizontal_partitions != 0 && vertical_partitions != 0) {
32-
setup_vpr_floorplan_constraints_cutpoints(constraints,
33-
horizontal_partitions,
34-
vertical_partitions);
32+
setup_vpr_floorplan_constraints_cutpoints(constraints, horizontal_partitions, vertical_partitions);
3533
} else {
36-
setup_vpr_floorplan_constraints_one_loc(constraints,
37-
expand,
38-
subtile);
34+
setup_vpr_floorplan_constraints_one_loc(constraints, expand, subtile);
3935
}
4036

4137
VprConstraintsSerializer writer(constraints);
@@ -53,9 +49,7 @@ void write_vpr_floorplan_constraints(const char* file_name, int expand, bool sub
5349
}
5450
}
5551

56-
void setup_vpr_floorplan_constraints_one_loc(VprConstraints& constraints,
57-
int expand,
58-
bool subtile) {
52+
void setup_vpr_floorplan_constraints_one_loc(VprConstraints& constraints, int expand, bool subtile) {
5953
auto& cluster_ctx = g_vpr_ctx.clustering();
6054
auto& block_locs = g_vpr_ctx.placement().block_locs();
6155

vpr/src/base/vpr_constraints_writer.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,7 @@ void write_vpr_floorplan_constraints(const char* file_name, int expand, bool sub
5252
* @param subtile Specifies whether to write out the constraint regions with or without
5353
* subtile values.
5454
*/
55-
void setup_vpr_floorplan_constraints_one_loc(VprConstraints& constraints,
56-
int expand,
57-
bool subtile);
55+
void setup_vpr_floorplan_constraints_one_loc(VprConstraints& constraints, int expand, bool subtile);
5856

5957
/**
6058
* @brief Populates VprConstraints by dividing the grid into multiple partitions.
@@ -66,8 +64,6 @@ void setup_vpr_floorplan_constraints_one_loc(VprConstraints& constraints,
6664
* @param horizontal_cutpoints The number of horizontal cut-lines.
6765
* @param vertical_cutpoints The number of vertical cut_lines.
6866
*/
69-
void setup_vpr_floorplan_constraints_cutpoints(VprConstraints& constraints,
70-
int horizontal_cutpoints,
71-
int vertical_cutpoints);
67+
void setup_vpr_floorplan_constraints_cutpoints(VprConstraints& constraints, int horizontal_cutpoints, int vertical_cutpoints);
7268

7369
#endif /* VPR_SRC_BASE_VPR_CONSTRAINTS_WRITER_H_ */

vpr/src/pack/cluster.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ std::map<t_logical_block_type_ptr, size_t> do_clustering(const t_packer_opts& pa
367367
}
368368

369369
//check_floorplan_regions(floorplan_regions_overfull);
370-
floorplan_regions_overfull = floorplan_constraints_regions_overfull();
370+
floorplan_regions_overfull = floorplan_constraints_regions_overfull(cluster_legalizer);
371371

372372
// Ensure that we have kept track of the number of clusters correctly.
373373
// TODO: The total_clb_num variable could probably just be replaced by

vpr/src/pack/cluster_legalizer.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ static bool check_cluster_floorplanning(AtomBlockId atom_blk_id,
195195

196196
// Get the Atom and Cluster Partition Regions
197197
const PartitionRegion& atom_pr = constraints.get_partition_pr(part_id);
198-
198+
199199
// If the Cluster's PartitionRegion is empty, then this atom's PR becomes
200200
// the Cluster's new PartitionRegion.
201201
if (cluster_pr.empty()) {
@@ -539,7 +539,7 @@ try_place_atom_block_rec(const t_pb_graph_node* pb_graph_node,
539539
}
540540
pb_type = pb_graph_node->pb_type;
541541

542-
/* Any pb_type under an mode, which is disabled for packing, should not be considerd for mapping
542+
/* Any pb_type under an mode, which is disabled for packing, should not be considerd for mapping
543543
* Early exit to flag failure
544544
*/
545545
if (true == pb_type->parent_mode->disable_packing) {
@@ -1048,7 +1048,7 @@ static void commit_lookahead_pins_used(t_pb* cur_pb) {
10481048
*
10491049
* The cleaning itself includes deleting all child pbs, resetting mode of the
10501050
* pb and also freeing its name. This prepares the pb for another round of
1051-
* molecule packing tryout.
1051+
* molecule packing tryout.
10521052
*/
10531053
static bool cleanup_pb(t_pb* pb) {
10541054
bool can_free = true;
@@ -1201,7 +1201,7 @@ e_block_pack_status ClusterLegalizer::try_pack_molecule(t_pack_molecule* molecul
12011201
VTR_LOGV(log_verbosity > 3, "\t\tFAILED No candidate primitives available\n");
12021202
block_pack_status = e_block_pack_status::BLK_FAILED_FEASIBLE;
12031203
break; /* no more candidate primitives available, this molecule will not pack, return fail */
1204-
}
1204+
}
12051205

12061206
block_pack_status = e_block_pack_status::BLK_PASSED;
12071207
int failed_location = 0;

vpr/src/pack/cluster_util.cpp

Lines changed: 25 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ void calc_init_packing_timing(const t_packer_opts& packer_opts,
7979
std::shared_ptr<PreClusterDelayCalculator>& clustering_delay_calc,
8080
std::shared_ptr<SetupTimingInfo>& timing_info,
8181
vtr::vector<AtomBlockId, float>& atom_criticality) {
82-
auto& atom_ctx = g_vpr_ctx.atom();
82+
const AtomContext& atom_ctx = g_vpr_ctx.atom();
8383

8484
/*
8585
* Initialize the timing analyzer
@@ -228,7 +228,7 @@ void rebuild_attraction_groups(AttractionInfo& attraction_groups,
228228

229229
/* Determine if atom block is in pb */
230230
bool is_atom_blk_in_pb(const AtomBlockId blk_id, const t_pb* pb) {
231-
auto& atom_ctx = g_vpr_ctx.atom();
231+
const AtomContext& atom_ctx = g_vpr_ctx.atom();
232232

233233
const t_pb* cur_pb = atom_ctx.lookup.atom_pb(blk_id);
234234
while (cur_pb) {
@@ -514,7 +514,7 @@ void update_connection_gain_values(const AtomNetId net_id,
514514
enum e_net_relation_to_clustered_block net_relation_to_clustered_block) {
515515
/*This function is called when the connectiongain values on the net net_id*
516516
*require updating. */
517-
auto& atom_ctx = g_vpr_ctx.atom();
517+
const AtomContext& atom_ctx = g_vpr_ctx.atom();
518518

519519
int num_internal_connections, num_open_connections, num_stuck_connections;
520520

@@ -597,8 +597,8 @@ void try_fill_cluster(ClusterLegalizer& cluster_legalizer,
597597
const int& unclustered_list_head_size,
598598
std::unordered_map<AtomNetId, int>& net_output_feeds_driving_block_input,
599599
std::map<const t_model*, std::vector<t_logical_block_type_ptr>>& primitive_candidate_block_types) {
600-
auto& atom_ctx = g_vpr_ctx.atom();
601-
auto& device_ctx = g_vpr_ctx.mutable_device();
600+
const AtomContext& atom_ctx = g_vpr_ctx.atom();
601+
const DeviceContext& device_ctx = g_vpr_ctx.device();
602602

603603
block_pack_status = cluster_legalizer.add_mol_to_cluster(next_molecule,
604604
legalization_cluster_id);
@@ -714,7 +714,7 @@ void store_cluster_info_and_free(const t_packer_opts& packer_opts,
714714
std::vector<int>& le_count,
715715
const ClusterLegalizer& cluster_legalizer,
716716
vtr::vector<LegalizationClusterId, std::vector<AtomNetId>>& clb_inter_blk_nets) {
717-
auto& atom_ctx = g_vpr_ctx.atom();
717+
const AtomContext& atom_ctx = g_vpr_ctx.atom();
718718

719719
/* store info that will be used later in packing from pb_stats and free the rest */
720720
t_pb* cur_pb = cluster_legalizer.get_cluster_pb(legalization_cluster_id);
@@ -746,7 +746,7 @@ void update_timing_gain_values(const AtomNetId net_id,
746746
*net_id requires updating. */
747747
float timinggain;
748748

749-
auto& atom_ctx = g_vpr_ctx.atom();
749+
const AtomContext& atom_ctx = g_vpr_ctx.atom();
750750

751751
/* Check if this atom net lists its driving atom block twice. If so, avoid *
752752
* double counting this atom block by skipping the first (driving) pin. */
@@ -811,7 +811,7 @@ void mark_and_update_partial_gain(const AtomNetId net_id,
811811
* cluster. The timinggain is the criticality of the most critical*
812812
* atom net between this atom block and an atom block in the cluster. */
813813

814-
auto& atom_ctx = g_vpr_ctx.atom();
814+
const AtomContext& atom_ctx = g_vpr_ctx.atom();
815815
t_pb* cur_pb = atom_ctx.lookup.atom_pb(clustered_blk_id)->parent_pb;
816816
cur_pb = get_top_level_pb(cur_pb);
817817

@@ -889,7 +889,7 @@ void update_total_gain(float alpha, float beta, bool timing_driven, bool connect
889889
/*Updates the total gain array to reflect the desired tradeoff between*
890890
*input sharing (sharinggain) and path_length minimization (timinggain)
891891
*input each time a new molecule is added to the cluster.*/
892-
auto& atom_ctx = g_vpr_ctx.atom();
892+
const AtomContext& atom_ctx = g_vpr_ctx.atom();
893893
t_pb* cur_pb = pb;
894894

895895
cur_pb = get_top_level_pb(cur_pb);
@@ -966,7 +966,7 @@ void update_cluster_stats(const t_pack_molecule* molecule,
966966
int iblock;
967967
t_pb *cur_pb, *cb;
968968

969-
auto& atom_ctx = g_vpr_ctx.mutable_atom();
969+
const AtomContext& atom_ctx = g_vpr_ctx.atom();
970970
molecule_size = get_array_size_of_molecule(molecule);
971971
cb = nullptr;
972972

@@ -1079,13 +1079,9 @@ void start_new_cluster(ClusterLegalizer& cluster_legalizer,
10791079
* It expands the FPGA if it cannot find a legal cluster for the atom block
10801080
*/
10811081

1082-
auto& atom_ctx = g_vpr_ctx.atom();
1083-
auto& device_ctx = g_vpr_ctx.mutable_device();
1084-
auto& floorplanning_ctx = g_vpr_ctx.mutable_floorplanning();
1085-
1086-
/*Cluster's PartitionRegion is empty initially, meaning it has no floorplanning constraints*/
1087-
PartitionRegion empty_pr;
1088-
floorplanning_ctx.cluster_constraints.push_back(empty_pr);
1082+
const AtomContext& atom_ctx = g_vpr_ctx.atom();
1083+
DeviceContext& mutable_device_ctx = g_vpr_ctx.mutable_device();
1084+
const DeviceContext& device_ctx = g_vpr_ctx.mutable_device();
10891085

10901086
/* Allocate a dummy initial cluster and load a atom block as a seed and check if it is legal */
10911087
AtomBlockId root_atom = molecule->atom_block_ids[molecule->root];
@@ -1177,7 +1173,7 @@ void start_new_cluster(ClusterLegalizer& cluster_legalizer,
11771173
}
11781174

11791175
if (num_used_type_instances[block_type] > num_instances) {
1180-
device_ctx.grid = create_device_grid(device_layout_name, arch->grid_layouts, num_used_type_instances, target_device_utilization);
1176+
mutable_device_ctx.grid = create_device_grid(device_layout_name, arch->grid_layouts, num_used_type_instances, target_device_utilization);
11811177
}
11821178
}
11831179

@@ -1294,7 +1290,7 @@ void add_cluster_molecule_candidates_by_connectivity_and_timing(t_pb* cur_pb,
12941290
AttractionInfo& attraction_groups) {
12951291
VTR_ASSERT(cur_pb->pb_stats->num_feasible_blocks == NOT_VALID);
12961292

1297-
auto& atom_ctx = g_vpr_ctx.atom();
1293+
const AtomContext& atom_ctx = g_vpr_ctx.atom();
12981294

12991295
cur_pb->pb_stats->num_feasible_blocks = 0;
13001296
cur_pb->pb_stats->explore_transitive_fanout = true; /* If no legal molecules found, enable exploration of molecules two hops away */
@@ -1322,12 +1318,12 @@ void add_cluster_molecule_candidates_by_highfanout_connectivity(t_pb* cur_pb,
13221318
/* Because the packer ignores high fanout nets when marking what blocks
13231319
* to consider, use one of the ignored high fanout net to fill up lightly
13241320
* related blocks */
1321+
const AtomContext& atom_ctx = g_vpr_ctx.atom();
1322+
13251323
reset_tried_but_unused_cluster_placements(cluster_placement_stats_ptr);
13261324

13271325
AtomNetId net_id = cur_pb->pb_stats->tie_break_high_fanout_net;
13281326

1329-
auto& atom_ctx = g_vpr_ctx.atom();
1330-
13311327
int count = 0;
13321328
for (auto pin_id : atom_ctx.nlist.net_pins(net_id)) {
13331329
if (count >= AAPACK_MAX_HIGH_FANOUT_EXPLORE) {
@@ -1366,7 +1362,7 @@ void add_cluster_molecule_candidates_by_attraction_group(t_pb* cur_pb,
13661362
const int feasible_block_array_size,
13671363
LegalizationClusterId legalization_cluster_id,
13681364
std::map<const t_model*, std::vector<t_logical_block_type_ptr>>& primitive_candidate_block_types) {
1369-
auto& atom_ctx = g_vpr_ctx.atom();
1365+
const AtomContext& atom_ctx = g_vpr_ctx.atom();
13701366

13711367
auto cluster_type = cluster_legalizer.get_cluster_type(legalization_cluster_id);
13721368

@@ -1774,7 +1770,7 @@ std::vector<AtomBlockId> initialize_seed_atoms(const e_cluster_seed seed_type,
17741770
t_pack_molecule* get_highest_gain_seed_molecule(int& seed_index,
17751771
const std::vector<AtomBlockId>& seed_atoms,
17761772
const ClusterLegalizer& cluster_legalizer) {
1777-
auto& atom_ctx = g_vpr_ctx.atom();
1773+
const AtomContext& atom_ctx = g_vpr_ctx.atom();
17781774

17791775
while (seed_index < static_cast<int>(seed_atoms.size())) {
17801776
AtomBlockId blk_id = seed_atoms[seed_index++];
@@ -1808,7 +1804,7 @@ float get_molecule_gain(t_pack_molecule* molecule, std::map<AtomBlockId, float>&
18081804
float gain;
18091805
int i;
18101806
int num_introduced_inputs_of_indirectly_related_block;
1811-
auto& atom_ctx = g_vpr_ctx.atom();
1807+
const AtomContext& atom_ctx = g_vpr_ctx.atom();
18121808

18131809
gain = 0;
18141810
float attraction_group_penalty = 0.1;
@@ -1873,7 +1869,7 @@ void load_transitive_fanout_candidates(LegalizationClusterId legalization_cluste
18731869
const ClusterLegalizer& cluster_legalizer,
18741870
vtr::vector<LegalizationClusterId, std::vector<AtomNetId>>& clb_inter_blk_nets,
18751871
int transitive_fanout_threshold) {
1876-
auto& atom_ctx = g_vpr_ctx.atom();
1872+
const AtomContext& atom_ctx = g_vpr_ctx.atom();
18771873

18781874
// iterate over all the nets that have pins in this cluster
18791875
for (const auto net_id : pb_stats->marked_nets) {
@@ -1915,9 +1911,8 @@ void load_transitive_fanout_candidates(LegalizationClusterId legalization_cluste
19151911

19161912
std::map<const t_model*, std::vector<t_logical_block_type_ptr>> identify_primitive_candidate_block_types() {
19171913
std::map<const t_model*, std::vector<t_logical_block_type_ptr>> model_candidates;
1918-
auto& atom_ctx = g_vpr_ctx.atom();
1919-
auto& atom_nlist = atom_ctx.nlist;
1920-
auto& device_ctx = g_vpr_ctx.device();
1914+
const AtomNetlist& atom_nlist = g_vpr_ctx.atom().nlist;
1915+
const DeviceContext& device_ctx = g_vpr_ctx.device();
19211916

19221917
std::set<const t_model*> unique_models;
19231918
// Find all logic models used in the netlist
@@ -1945,7 +1940,7 @@ std::map<const t_model*, std::vector<t_logical_block_type_ptr>> identify_primiti
19451940
void print_seed_gains(const char* fname, const std::vector<AtomBlockId>& seed_atoms, const vtr::vector<AtomBlockId, float>& atom_gain, const vtr::vector<AtomBlockId, float>& atom_criticality) {
19461941
FILE* fp = vtr::fopen(fname, "w");
19471942

1948-
auto& atom_ctx = g_vpr_ctx.atom();
1943+
const AtomContext& atom_ctx = g_vpr_ctx.atom();
19491944

19501945
//For prett formatting determine the maximum name length
19511946
int max_name_len = strlen("atom_block_name");
@@ -2170,7 +2165,7 @@ t_pb* get_top_level_pb(t_pb* pb) {
21702165
}
21712166

21722167
void init_clb_atoms_lookup(vtr::vector<ClusterBlockId, std::unordered_set<AtomBlockId>>& atoms_lookup) {
2173-
auto& atom_ctx = g_vpr_ctx.atom();
2168+
const AtomContext& atom_ctx = g_vpr_ctx.atom();
21742169
auto& cluster_ctx = g_vpr_ctx.clustering();
21752170

21762171
atoms_lookup.resize(cluster_ctx.clb_nlist.blocks().size());

vpr/src/pack/constraints_report.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
#include "constraints_report.h"
2+
#include "cluster_legalizer.h"
3+
#include "globals.h"
4+
#include "grid_tile_lookup.h"
25

3-
bool floorplan_constraints_regions_overfull() {
6+
bool floorplan_constraints_regions_overfull(const ClusterLegalizer& cluster_legalizer) {
47
GridTileLookup grid_tiles;
58

6-
auto& cluster_ctx = g_vpr_ctx.clustering();
79
auto& floorplanning_ctx = g_vpr_ctx.mutable_floorplanning();
810
auto& device_ctx = g_vpr_ctx.device();
911

@@ -12,15 +14,13 @@ bool floorplan_constraints_regions_overfull() {
1214
// keep record of how many blocks of each type are assigned to each PartitionRegion
1315
std::unordered_map<PartitionRegion, std::vector<int>> pr_count_info;
1416

15-
for (const ClusterBlockId blk_id : cluster_ctx.clb_nlist.blocks()) {
16-
if (!is_cluster_constrained(blk_id)) {
17+
for (LegalizationClusterId cluster_id : cluster_legalizer.clusters()) {
18+
const PartitionRegion& pr = cluster_legalizer.get_cluster_pr(cluster_id);
19+
if (pr.empty())
1720
continue;
18-
}
19-
t_logical_block_type_ptr bt = cluster_ctx.clb_nlist.block_type(blk_id);
2021

21-
const PartitionRegion& pr = floorplanning_ctx.cluster_constraints[blk_id];
22+
t_logical_block_type_ptr bt = cluster_legalizer.get_cluster_type(cluster_id);
2223
auto got = pr_count_info.find(pr);
23-
2424
if (got == pr_count_info.end()) {
2525
std::vector<int> block_type_counts(block_types.size(), 0);
2626
block_type_counts[bt->index]++;

vpr/src/pack/constraints_report.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
#ifndef VPR_SRC_PACK_CONSTRAINTS_REPORT_H_
66
#define VPR_SRC_PACK_CONSTRAINTS_REPORT_H_
77

8-
#include "globals.h"
9-
#include "grid_tile_lookup.h"
10-
#include "place_constraints.h"
8+
class ClusterLegalizer;
119

1210
/**
1311
* @brief Check if any constraint partition regions are overfull,
@@ -27,6 +25,6 @@
2725
*
2826
* @return True if there is at least one overfull partition.
2927
*/
30-
bool floorplan_constraints_regions_overfull();
28+
bool floorplan_constraints_regions_overfull(const ClusterLegalizer& cluster_legalizer);
3129

3230
#endif /* VPR_SRC_PACK_CONSTRAINTS_REPORT_H_ */

0 commit comments

Comments
 (0)