Skip to content

Commit 4acad0f

Browse files
authored
Merge pull request #1641 from verilog-to-routing/clusterer_feasibility_changes
Clusterer feasibility changes
2 parents 21ec433 + b807f83 commit 4acad0f

20 files changed

+499
-102
lines changed

libs/libvtrutil/src/vtr_geometry.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,16 @@ Rect<T> bounding_box(const Rect<T>& lhs, const Rect<T>& rhs);
208208
template<class T>
209209
Rect<T> intersection(const Rect<T>& lhs, const Rect<T>& rhs);
210210

211+
//Prints a rectangle
212+
template<class T>
213+
static void print_rect(FILE* fp, const Rect<T> rect);
214+
215+
//Sample on a uniformly spaced grid within a rectangle
216+
// sample(vtr::Rect(l, h), 0, 0, M) == l
217+
// sample(vtr::Rect(l, h), M, M, M) == h
218+
//To avoid the edges, use `sample(r, x+1, y+1, N+1) for x, y, in 0..N-1
219+
//Only defined for integral types
220+
211221
/**
212222
* @brief Sample on a uniformly spaced grid within a rectangle
213223
*
@@ -216,6 +226,7 @@ Rect<T> intersection(const Rect<T>& lhs, const Rect<T>& rhs);
216226
* To avoid the edges, use `sample(r, x+1, y+1, N+1) for x, y, in 0..N-1
217227
* Only defined for integral types
218228
*/
229+
219230
template<typename T, typename std::enable_if<std::is_integral<T>::value>::type...>
220231
Point<T> sample(const vtr::Rect<T>& r, T x, T y, T d);
221232

libs/libvtrutil/src/vtr_geometry.tpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,13 @@ Rect<T> intersection(const Rect<T>& lhs, const Rect<T>& rhs) {
189189
std::min(lhs.xmax(), rhs.xmax()),
190190
std::min(lhs.ymax(), rhs.ymax()));
191191
}
192+
template<class T>
193+
static void print_rect(FILE* fp, const Rect<T> rect) {
194+
fprintf(fp, "\txmin: %d\n", rect.xmin());
195+
fprintf(fp, "\tymin: %d\n", rect.ymin());
196+
fprintf(fp, "\txmax: %d\n", rect.xmax());
197+
fprintf(fp, "\tymax: %d\n", rect.ymax());
198+
}
192199
//Only defined for integral types
193200
template<typename T, typename std::enable_if<std::is_integral<T>::value>::type...>
194201
Point<T> sample(const vtr::Rect<T>& r, T x, T y, T d) {

vpr/src/base/SetupGrid.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,7 @@ static DeviceGrid auto_size_device_grid(const std::vector<t_grid_def>& grid_layo
191191
//Check if it satisfies the block counts
192192
if (grid_satisfies_instance_counts(grid, minimum_instance_counts, maximum_device_utilization)) {
193193
//Re-build the grid at the final size with out-of-range
194-
//warnings turned on (so users are aware of out-of-range issues
195-
//at the final device sizes)
196-
grid = build_device_grid(grid_def, width, height, true, limiting_resources);
194+
grid = build_device_grid(grid_def, width, height, false, limiting_resources);
197195
return grid;
198196
}
199197

vpr/src/base/constraints_load.cpp

Lines changed: 2 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,82 +1,14 @@
11
#include "constraints_load.h"
22

3-
static void print_region(FILE* fp, Region region);
4-
static void print_partition(FILE* fp, Partition part);
5-
static void print_partition_region(FILE* fp, PartitionRegion pr);
6-
static void print_constraints(FILE* fp, VprConstraints constraints, int num_parts);
7-
8-
void print_region(FILE* fp, Region region) {
9-
vtr::Rect<int> rect = region.get_region_rect();
10-
int xmin = rect.xmin();
11-
int xmax = rect.xmax();
12-
int ymin = rect.ymin();
13-
int ymax = rect.ymax();
14-
int subtile = region.get_sub_tile();
15-
16-
fprintf(fp, "\tRegion: \n");
17-
fprintf(fp, "\txmin: %d\n", xmin);
18-
fprintf(fp, "\txmax: %d\n", xmax);
19-
fprintf(fp, "\tymin: %d\n", ymin);
20-
fprintf(fp, "\tymax: %d\n", ymax);
21-
fprintf(fp, "\tsubtile: %d\n\n", subtile);
22-
}
23-
24-
void print_partition(FILE* fp, Partition part) {
25-
std::string name = part.get_name();
26-
fprintf(fp, "partition_name: %s\n", name.c_str());
27-
28-
PartitionRegion pr = part.get_part_region();
29-
30-
print_partition_region(fp, pr);
31-
}
32-
33-
void print_partition_region(FILE* fp, PartitionRegion pr) {
34-
std::vector<Region> part_region = pr.get_partition_region();
35-
36-
int pr_size = part_region.size();
37-
38-
fprintf(fp, "\tNumber of regions in partition is: %d\n", pr_size);
39-
40-
for (unsigned int i = 0; i < part_region.size(); i++) {
41-
print_region(fp, part_region[i]);
42-
}
43-
}
44-
45-
void print_constraints(FILE* fp, VprConstraints constraints, int num_parts) {
46-
Partition temp_part;
47-
std::vector<AtomBlockId> atoms;
48-
49-
for (int i = 0; i < num_parts; i++) {
50-
PartitionId part_id(i);
51-
52-
temp_part = constraints.get_partition(part_id);
53-
54-
fprintf(fp, "\npartition_id: %zu\n", size_t(part_id));
55-
print_partition(fp, temp_part);
56-
57-
atoms = constraints.get_part_atoms(part_id);
58-
59-
int atoms_size = atoms.size();
60-
61-
fprintf(fp, "\tAtom vector size is %d\n", atoms_size);
62-
fprintf(fp, "\tIds of atoms in partition: \n");
63-
for (unsigned int j = 0; j < atoms.size(); j++) {
64-
AtomBlockId atom_id = atoms[j];
65-
fprintf(fp, "\t#%zu\n", size_t(atom_id));
66-
}
67-
}
68-
}
69-
70-
void echo_constraints(char* filename, VprConstraints constraints, int num_parts) {
3+
void echo_constraints(char* filename, VprConstraints constraints) {
714
FILE* fp;
725
fp = vtr::fopen(filename, "w");
736

747
fprintf(fp, "--------------------------------------------------------------\n");
758
fprintf(fp, "Constraints\n");
769
fprintf(fp, "--------------------------------------------------------------\n");
7710
fprintf(fp, "\n");
78-
fprintf(fp, "\n Number of partitions is %d \n", num_parts);
79-
print_constraints(fp, constraints, num_parts);
11+
print_constraints(fp, constraints);
8012

8113
fclose(fp);
8214
}

vpr/src/base/constraints_load.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "vpr_constraints.h"
88
#include "vtr_vector.h"
99

10-
void echo_constraints(char* filename, VprConstraints constraints, int num_parts);
10+
///@brief Used to print vpr's floorplanning constraints to an echo file "vpr_constraints.echo"
11+
void echo_constraints(char* filename, VprConstraints constraints);
1112

1213
#endif

vpr/src/base/echo_files.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ void alloc_and_load_echo_file_info() {
7474
//Vpr constraints
7575
setEchoFileName(E_ECHO_VPR_CONSTRAINTS, "vpr_constraints.echo");
7676

77+
//Packing
78+
setEchoFileName(E_ECHO_CLUSTERS, "clusters.echo");
79+
7780
//Intra-block routing
7881
setEchoFileName(E_ECHO_INTRA_LB_FAILED_ROUTE, "intra_lb_failed_route.echo");
7982

vpr/src/base/echo_files.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ enum e_echo_files {
1212
E_ECHO_PRE_PACKING_MOLECULES_AND_PATTERNS,
1313
E_ECHO_VPR_CONSTRAINTS,
1414

15+
//Packing
16+
E_ECHO_CLUSTERS,
17+
1518
// Intra-block routing
1619
E_ECHO_INTRA_LB_FAILED_ROUTE,
1720

vpr/src/base/partition.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "partition.h"
2+
#include "partition_region.h"
23
#include <algorithm>
34
#include <vector>
45

@@ -17,3 +18,12 @@ const PartitionRegion Partition::get_part_region() {
1718
void Partition::set_part_region(PartitionRegion pr) {
1819
part_region = pr;
1920
}
21+
22+
void print_partition(FILE* fp, Partition part) {
23+
std::string name = part.get_name();
24+
fprintf(fp, "partition_name: %s\n", name.c_str());
25+
26+
PartitionRegion pr = part.get_part_region();
27+
28+
print_partition_region(fp, pr);
29+
}

vpr/src/base/partition.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,7 @@ class Partition {
5353
PartitionRegion part_region; ///< the union of regions that the partition can be placed in
5454
};
5555

56+
///@brief used to print data from a Partition
57+
void print_partition(FILE* fp, Partition part);
58+
5659
#endif /* PARTITION_H */

vpr/src/base/partition_region.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "partition_region.h"
2+
#include "region.h"
23

34
void PartitionRegion::add_to_part_region(Region region) {
45
partition_region.push_back(region);
@@ -8,6 +9,10 @@ std::vector<Region> PartitionRegion::get_partition_region() {
89
return partition_region;
910
}
1011

12+
bool PartitionRegion::empty() {
13+
return partition_region.size() == 0;
14+
}
15+
1116
PartitionRegion intersection(PartitionRegion& pr1, PartitionRegion& pr2) {
1217
/**for N regions in part_region and M in the calling object you can get anywhere from
1318
* 0 to M*N regions in the resulting vector. Only intersection regions with non-zero area rectangles and
@@ -29,3 +34,15 @@ PartitionRegion intersection(PartitionRegion& pr1, PartitionRegion& pr2) {
2934

3035
return pr;
3136
}
37+
38+
void print_partition_region(FILE* fp, PartitionRegion pr) {
39+
std::vector<Region> part_region = pr.get_partition_region();
40+
41+
int pr_size = part_region.size();
42+
43+
fprintf(fp, "\tNumber of regions in partition is: %d\n", pr_size);
44+
45+
for (unsigned int i = 0; i < part_region.size(); i++) {
46+
print_region(fp, part_region[i]);
47+
}
48+
}

vpr/src/base/partition_region.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
/**
88
* @file
9-
* @brief This file defines the PartitionRegions class. The PartitionRegions class is used to store the union
9+
* @brief This file defines the PartitionRegion class. The PartitionRegion class is used to store the union
1010
* of regions that a partition can be placed in.
1111
*/
1212

@@ -24,6 +24,11 @@ class PartitionRegion {
2424
*/
2525
std::vector<Region> get_partition_region();
2626

27+
/**
28+
* @brief Check if the PartitionRegion is empty (meaning there is no constraint on the object the PartitionRegion belongs to)
29+
*/
30+
bool empty();
31+
2732
/**
2833
* @brief Global friend function that returns the intersection of two PartitionRegions
2934
*
@@ -36,4 +41,7 @@ class PartitionRegion {
3641
std::vector<Region> partition_region; ///< union of rectangular regions that a partition can be placed in
3742
};
3843

44+
///@brief used to print data from a PartitionRegion
45+
void print_partition_region(FILE* fp, PartitionRegion pr);
46+
3947
#endif /* PARTITION_REGIONS_H */

vpr/src/base/region.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,9 @@ Region intersection(Region r1, Region r2) {
8282

8383
return intersect;
8484
}
85+
86+
void print_region(FILE* fp, Region region) {
87+
fprintf(fp, "\tRegion: \n");
88+
print_rect(fp, region.get_region_rect());
89+
fprintf(fp, "\tsubtile: %d\n\n", region.get_sub_tile());
90+
}

vpr/src/base/region.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,7 @@ bool do_regions_intersect(Region r1, Region r2);
7676
*/
7777
Region intersection(Region r1, Region r2);
7878

79+
///@brief Used to print data from a Region
80+
void print_region(FILE* fp, Region region);
81+
7982
#endif /* REGION_H */

vpr/src/base/vpr_constraints.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "vpr_constraints.h"
2+
#include "partition.h"
23

34
void VprConstraints::add_constrained_atom(const AtomBlockId blk_id, const PartitionId part_id) {
45
constrained_atoms.insert({blk_id, part_id});
@@ -47,3 +48,42 @@ std::vector<AtomBlockId> VprConstraints::get_part_atoms(PartitionId part_id) {
4748

4849
return part_atoms;
4950
}
51+
52+
int VprConstraints::get_num_partitions() {
53+
return partitions.size();
54+
}
55+
56+
PartitionRegion VprConstraints::get_partition_pr(PartitionId part_id) {
57+
PartitionRegion pr;
58+
pr = partitions[part_id].get_part_region();
59+
return pr;
60+
}
61+
62+
void print_constraints(FILE* fp, VprConstraints constraints) {
63+
Partition temp_part;
64+
std::vector<AtomBlockId> atoms;
65+
66+
int num_parts = constraints.get_num_partitions();
67+
68+
fprintf(fp, "\n Number of partitions is %d \n", num_parts);
69+
70+
for (int i = 0; i < num_parts; i++) {
71+
PartitionId part_id(i);
72+
73+
temp_part = constraints.get_partition(part_id);
74+
75+
fprintf(fp, "\npartition_id: %zu\n", size_t(part_id));
76+
print_partition(fp, temp_part);
77+
78+
atoms = constraints.get_part_atoms(part_id);
79+
80+
int atoms_size = atoms.size();
81+
82+
fprintf(fp, "\tAtom vector size is %d\n", atoms_size);
83+
fprintf(fp, "\tIds of atoms in partition: \n");
84+
for (unsigned int j = 0; j < atoms.size(); j++) {
85+
AtomBlockId atom_id = atoms[j];
86+
fprintf(fp, "\t#%zu\n", size_t(atom_id));
87+
}
88+
}
89+
}

vpr/src/base/vpr_constraints.h

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,21 @@
1818
* It also specifies which regions the partitions should be placed in. Atoms cannot be placed in more than one partition.
1919
* If an atom is assigned to more than one partition, the last partition is was assigned to will be the partition it is placed in.
2020
*
21+
* Related Classes
22+
* ===============
23+
* The following definitions are useful to understanding this class:
24+
*
25+
* Partition: a grouping of atoms that are constrained to a portion of an FPGA
26+
* See vpr/base/partition.h for more detail
27+
*
28+
* Region: the x and y bounds of a rectangular region, optionally including a subtile value,
29+
* that atoms in a partition are constrained to
30+
* See vpr/base/region.h for more detail
31+
*
32+
* PartitionRegion: the union of regions that a partition can be placed in
33+
* See vpr/base/partition_region.h for more detail
34+
*
35+
*
2136
*/
2237

2338
class VprConstraints {
@@ -33,7 +48,7 @@ class VprConstraints {
3348
/**
3449
* @brief Return id of the partition the atom belongs to
3550
*
36-
* If an atom is not in a partition (unconstrained), PartitionId::Invalid() is returned.
51+
* If an atom is not in a partition (unconstrained), PartitionId::INVALID() is returned.
3752
*
3853
* @param blk_id The atom for which the partition id is needed
3954
*/
@@ -60,6 +75,18 @@ class VprConstraints {
6075
*/
6176
std::vector<AtomBlockId> get_part_atoms(PartitionId part_id);
6277

78+
/**
79+
* @brief Returns the number of partitions in the object
80+
*/
81+
int get_num_partitions();
82+
83+
/**
84+
* @brief Returns the PartitionRegion belonging to the specified Partition
85+
*
86+
* @param part_id The id of the partition whose PartitionRegion is needed
87+
*/
88+
PartitionRegion get_partition_pr(PartitionId part_id);
89+
6390
private:
6491
/**
6592
* Store all constrained atoms
@@ -72,4 +99,7 @@ class VprConstraints {
7299
vtr::vector<PartitionId, Partition> partitions;
73100
};
74101

102+
///@brief used to print floorplanning constraints data from a VprConstraints object
103+
void print_constraints(FILE* fp, VprConstraints constraints);
104+
75105
#endif /* VPR_CONSTRAINTS_H */

vpr/src/base/vpr_constraints_reader.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,13 @@ void load_vpr_constraints_file(const char* read_vpr_constraints_name) {
3131
read_vpr_constraints_name);
3232
}
3333

34-
VprConstraints constraints = reader.constraints_;
35-
int num_parts = reader.num_partitions_;
34+
//Update the floorplanning constraints in the floorplanning constraints context
35+
auto& floorplanning_ctx = g_vpr_ctx.mutable_floorplanning();
36+
floorplanning_ctx.constraints = reader.constraints_;
37+
38+
VprConstraints ctx_constraints = floorplanning_ctx.constraints;
3639

3740
if (getEchoEnabled() && isEchoFileEnabled(E_ECHO_VPR_CONSTRAINTS)) {
38-
echo_constraints(getEchoFileName(E_ECHO_VPR_CONSTRAINTS), constraints, num_parts);
41+
echo_constraints(getEchoFileName(E_ECHO_VPR_CONSTRAINTS), ctx_constraints);
3942
}
4043
}

0 commit comments

Comments
 (0)