Skip to content

Commit fac21ca

Browse files
[Pack] Removed Global Overfilled Partition Regions
After each pack, the partition regions are checked to see if any of the partition regions are overfilled. During this process, the overfilled partition regions were stored in the Floorplanning context (likely for legacy reasons). This was then read from a few lines later in another function. Turned this into a local variable instead of a global variable.
1 parent d52240a commit fac21ca

11 files changed

+45
-43
lines changed

vpr/src/base/vpr_context.h

+2-8
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,17 @@
66
#include <mutex>
77

88
#include "FlatPlacementInfo.h"
9+
#include "user_place_constraints.h"
10+
#include "user_route_constraints.h"
911
#include "vpr_types.h"
10-
#include "vtr_ndmatrix.h"
1112
#include "vtr_optional.h"
1213
#include "vtr_vector.h"
1314
#include "vtr_vector_map.h"
1415
#include "atom_netlist.h"
1516
#include "clustered_netlist.h"
1617
#include "rr_graph_view.h"
17-
#include "rr_graph_storage.h"
1818
#include "rr_graph_builder.h"
1919
#include "rr_node.h"
20-
#include "rr_rc_data.h"
2120
#include "tatum/TimingGraph.hpp"
2221
#include "tatum/TimingConstraints.hpp"
2322
#include "power.h"
@@ -27,10 +26,7 @@
2726
#include "clock_connection_builders.h"
2827
#include "route_tree.h"
2928
#include "router_lookahead.h"
30-
#include "place_macro.h"
3129
#include "compressed_grid.h"
32-
#include "metadata_storage.h"
33-
#include "vpr_constraints.h"
3430
#include "noc_storage.h"
3531
#include "noc_traffic_flows.h"
3632
#include "noc_routing.h"
@@ -513,8 +509,6 @@ struct FloorplanningContext : public Context {
513509
*
514510
*/
515511
std::vector<vtr::vector<ClusterBlockId, PartitionRegion>> compressed_cluster_constraints;
516-
517-
std::vector<PartitionRegion> overfull_partition_regions;
518512
};
519513

520514
/**

vpr/src/pack/attraction_groups.cpp

+3-4
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ AttractionInfo::AttractionInfo(bool attraction_groups_on) {
3333
}
3434
}
3535

36-
void AttractionInfo::create_att_groups_for_overfull_regions() {
36+
void AttractionInfo::create_att_groups_for_overfull_regions(
37+
const std::vector<PartitionRegion>& overfull_partition_regions) {
3738
const auto& floorplanning_ctx = g_vpr_ctx.floorplanning();
3839
auto& atom_ctx = g_vpr_ctx.atom();
3940
int num_parts = floorplanning_ctx.constraints.get_num_partitions();
@@ -48,8 +49,6 @@ void AttractionInfo::create_att_groups_for_overfull_regions() {
4849
atom_attraction_group.resize(num_atoms);
4950
fill(atom_attraction_group.begin(), atom_attraction_group.end(), AttractGroupId::INVALID());
5051

51-
const std::vector<PartitionRegion>& overfull_prs = floorplanning_ctx.overfull_partition_regions;
52-
5352
/*
5453
* Create an attraction group for each partition that overlaps with at least one overfull partition
5554
*/
@@ -58,7 +57,7 @@ void AttractionInfo::create_att_groups_for_overfull_regions() {
5857

5958
const Partition& part = floorplanning_ctx.constraints.get_partition(partid);
6059

61-
for (const PartitionRegion& overfull_pr : overfull_prs) {
60+
for (const PartitionRegion& overfull_pr : overfull_partition_regions) {
6261
PartitionRegion intersect_pr = intersection(part.get_part_region(), overfull_pr);
6362
if (!intersect_pr.empty()) {
6463
AttractionGroup group_info;

vpr/src/pack/attraction_groups.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
#include "vtr_vector.h"
1313
#include "atom_netlist_fwd.h"
1414

15+
// Forward declarations
16+
class PartitionRegion;
17+
1518
/**
1619
* @file
1720
* @brief This file defines the AttractionInfo class, which is used to store atoms in attraction groups, which are
@@ -53,7 +56,7 @@ class AttractionInfo {
5356
* Create attraction groups for the partitions that contain overfull regions (i.e.
5457
* The region has more blocks of a certain type assigned to than are actually available).
5558
*/
56-
void create_att_groups_for_overfull_regions();
59+
void create_att_groups_for_overfull_regions(const std::vector<PartitionRegion>& overfull_partition_regions);
5760

5861
/*
5962
* Create attraction groups for all partitions.

vpr/src/pack/constraints_report.cpp

+8-10
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
#include "constraints_report.h"
22
#include "cluster_legalizer.h"
3-
#include "globals.h"
43
#include "grid_tile_lookup.h"
54

6-
bool floorplan_constraints_regions_overfull(const ClusterLegalizer& cluster_legalizer) {
5+
bool floorplan_constraints_regions_overfull(
6+
std::vector<PartitionRegion>& overfull_partition_regions,
7+
const ClusterLegalizer& cluster_legalizer,
8+
const std::vector<t_logical_block_type>& logical_block_types) {
79
GridTileLookup grid_tiles;
810

9-
auto& floorplanning_ctx = g_vpr_ctx.mutable_floorplanning();
10-
auto& device_ctx = g_vpr_ctx.device();
11-
12-
const std::vector<t_logical_block_type>& block_types = device_ctx.logical_block_types;
13-
1411
// keep record of how many blocks of each type are assigned to each PartitionRegion
1512
std::unordered_map<PartitionRegion, std::vector<int>> pr_count_info;
1613

@@ -22,7 +19,7 @@ bool floorplan_constraints_regions_overfull(const ClusterLegalizer& cluster_lega
2219
t_logical_block_type_ptr bt = cluster_legalizer.get_cluster_type(cluster_id);
2320
auto got = pr_count_info.find(pr);
2421
if (got == pr_count_info.end()) {
25-
std::vector<int> block_type_counts(block_types.size(), 0);
22+
std::vector<int> block_type_counts(logical_block_types.size(), 0);
2623
block_type_counts[bt->index]++;
2724
pr_count_info.insert({pr, block_type_counts});
2825
} else {
@@ -35,15 +32,15 @@ bool floorplan_constraints_regions_overfull(const ClusterLegalizer& cluster_lega
3532
for (const auto& [pr, block_type_counts] : pr_count_info) {
3633
const std::vector<Region>& regions = pr.get_regions();
3734

38-
for (const t_logical_block_type& block_type : block_types) {
35+
for (const t_logical_block_type& block_type : logical_block_types) {
3936
int num_assigned_blocks = block_type_counts[block_type.index];
4037
int num_tiles = std::accumulate(regions.begin(), regions.end(), 0, [&grid_tiles, &block_type](int acc, const Region& reg) -> int {
4138
return acc + grid_tiles.region_tile_count(reg, &block_type);
4239
});
4340

4441
if (num_assigned_blocks > num_tiles) {
4542
floorplan_regions_overfull = true;
46-
floorplanning_ctx.overfull_partition_regions.push_back(pr);
43+
overfull_partition_regions.push_back(pr);
4744
VTR_LOG("\n\nA partition including the following regions has been assigned %d blocks of type %s, "
4845
"but only has %d tiles of that type\n",
4946
num_assigned_blocks, block_type.name.c_str(), num_tiles);
@@ -62,3 +59,4 @@ bool floorplan_constraints_regions_overfull(const ClusterLegalizer& cluster_lega
6259

6360
return floorplan_regions_overfull;
6461
}
62+

vpr/src/pack/constraints_report.h

+11-4
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@
22
* floorplan regions have been packed with too many clusters.
33
*/
44

5-
#ifndef VPR_SRC_PACK_CONSTRAINTS_REPORT_H_
6-
#define VPR_SRC_PACK_CONSTRAINTS_REPORT_H_
5+
#pragma once
6+
7+
#include <vector>
78

89
class ClusterLegalizer;
10+
class PartitionRegion;
11+
struct t_logical_block_type;
912

1013
/**
1114
* @brief Check if any constraint partition regions are overfull,
@@ -23,8 +26,12 @@ class ClusterLegalizer;
2326
* VPR can still work if these assumptions do not hold true, but for tight overlapping
2427
* partitions, the placement engine may fail to find a legal placement.
2528
*
29+
* Adds the overfilled partition regions to the overfull_partition_regions vector.
30+
*
2631
* @return True if there is at least one overfull partition.
2732
*/
28-
bool floorplan_constraints_regions_overfull(const ClusterLegalizer& cluster_legalizer);
33+
bool floorplan_constraints_regions_overfull(
34+
std::vector<PartitionRegion> &overfull_partition_regions,
35+
const ClusterLegalizer& cluster_legalizer,
36+
const std::vector<t_logical_block_type>& logical_block_types);
2937

30-
#endif /* VPR_SRC_PACK_CONSTRAINTS_REPORT_H_ */

vpr/src/pack/greedy_clusterer.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
#include "attraction_groups.h"
4848
#include "cluster_legalizer.h"
4949
#include "cluster_util.h"
50-
#include "constraints_report.h"
5150
#include "greedy_candidate_selector.h"
5251
#include "greedy_seed_selector.h"
5352
#include "physical_types.h"

vpr/src/pack/pack.cpp

+13-3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "constraints_report.h"
1111
#include "globals.h"
1212
#include "greedy_clusterer.h"
13+
#include "partition_region.h"
1314
#include "physical_types_util.h"
1415
#include "prepack.h"
1516
#include "verify_flat_placement.h"
@@ -99,6 +100,12 @@ bool try_pack(t_packer_opts* packer_opts,
99100
VTR_LOG("%d attraction groups were created during prepacking.\n", attraction_groups.num_attraction_groups());
100101
VTR_LOG("Finish prepacking.\n");
101102

103+
// We keep track of the overfilled partition regions from all pack iterations in
104+
// this vector. This is so that if the first iteration fails due to overfilled
105+
// partition regions, and it fails again, we can carry over the previous failed
106+
// partition regions to the current iteration.
107+
std::vector<PartitionRegion> overfull_partition_regions;
108+
102109
// Verify that the Flat Placement is valid for packing.
103110
if (flat_placement_info.valid) {
104111
unsigned num_errors = verify_flat_placement_for_packing(flat_placement_info,
@@ -196,7 +203,10 @@ bool try_pack(t_packer_opts* packer_opts,
196203
* is not dense enough and there are floorplan constraints, it is presumed that the constraints are the cause
197204
* of the floorplan not fitting, so attraction groups are turned on for later iterations.
198205
*/
199-
bool floorplan_regions_overfull = floorplan_constraints_regions_overfull(cluster_legalizer);
206+
bool floorplan_regions_overfull = floorplan_constraints_regions_overfull(overfull_partition_regions,
207+
cluster_legalizer,
208+
device_ctx.logical_block_types);
209+
200210
bool floorplan_not_fitting = (floorplan_regions_overfull || g_vpr_ctx.floorplanning().constraints.get_num_partitions() > 0);
201211

202212
if (fits_on_device && !floorplan_regions_overfull) {
@@ -228,13 +238,13 @@ bool try_pack(t_packer_opts* packer_opts,
228238
*/
229239
} else if (pack_iteration == 1 && floorplan_not_fitting) {
230240
VTR_LOG("Floorplan regions are overfull: trying to pack again using cluster attraction groups. \n");
231-
attraction_groups.create_att_groups_for_overfull_regions();
241+
attraction_groups.create_att_groups_for_overfull_regions(overfull_partition_regions);
232242
attraction_groups.set_att_group_pulls(1);
233243

234244
} else if (pack_iteration >= 2 && pack_iteration < 5 && floorplan_not_fitting) {
235245
if (pack_iteration == 2) {
236246
VTR_LOG("Floorplan regions are overfull: trying to pack again with more attraction groups exploration. \n");
237-
attraction_groups.create_att_groups_for_overfull_regions();
247+
attraction_groups.create_att_groups_for_overfull_regions(overfull_partition_regions);
238248
VTR_LOG("Pack iteration is %d\n", pack_iteration);
239249
} else if (pack_iteration == 3) {
240250
attraction_groups.create_att_groups_for_all_regions();

vpr/src/route/clock_connection_builders.cpp

+1-5
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,7 @@
22

33
#include "globals.h"
44
#include "arch_util.h"
5-
#include "rr_graph2.h"
6-
7-
#include "vtr_assert.h"
8-
#include "vtr_log.h"
9-
#include "vtr_error.h"
5+
#include "rr_rc_data.h"
106

117
#include <random>
128
#include <math.h>

vpr/src/route/clock_network_builders.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
#include "globals.h"
44

5+
#include "rr_rc_data.h"
56
#include "vtr_assert.h"
67
#include "vtr_log.h"
7-
#include "vtr_error.h"
88

99
void static populate_segment_values(int seg_index,
1010
std::string name,

vpr/src/route/rr_graph.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <vector>
88
#include "alloc_and_load_rr_indexed_data.h"
99
#include "physical_types_util.h"
10+
#include "rr_rc_data.h"
1011
#include "vtr_assert.h"
1112

1213
#include "vtr_util.h"

vpr/src/route/rr_graph_timing_params.cpp

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
#include <cstdio>
22

3-
#include "vtr_memory.h"
4-
5-
#include "vpr_types.h"
6-
#include "vpr_error.h"
7-
83
#include "globals.h"
94
#include "rr_graph.h"
105
#include "rr_graph_utils.h"
11-
#include "rr_graph2.h"
6+
#include "rr_rc_data.h"
127
#include "rr_graph_timing_params.h"
138

149
/****************** Subroutine definitions *********************************/

0 commit comments

Comments
 (0)