Skip to content

Clusterer feasibility changes #1641

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 35 commits into from
Feb 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
918219f
Added a vpr floorplanning constraints context
sfkhalid Dec 16, 2020
1fdf881
Wrote code to set the PartitionRegion of the new cluster in start_new…
sfkhalid Jan 18, 2021
ca7b577
Added code to check for an empty PartitionRegion and code to check in…
sfkhalid Jan 21, 2021
ed6e7a8
Modified function for intersecting atom and cluster PartitionRegions
sfkhalid Jan 21, 2021
532a143
Fixed bug where cluster PartitionRegion was not updated soon enough i…
sfkhalid Jan 25, 2021
511a994
Ran make format
sfkhalid Jan 26, 2021
8008b2e
Added function to echo cluster contents
sfkhalid Jan 27, 2021
54f4995
Merge branch 'master' into clusterer_feasibility_changes
sfkhalid Jan 27, 2021
5845338
Added routine print_pack_status to print some cluster stats increment…
sfkhalid Jan 27, 2021
7b465fe
Printed end of clustering stats in table format
sfkhalid Jan 28, 2021
6fb45ff
Shortened and clarified some comments
sfkhalid Jan 28, 2021
3a606e8
Made formatting changes to cluster echo file
sfkhalid Jan 28, 2021
4fceb1e
Changed frequency of cluster progress messages
sfkhalid Feb 1, 2021
f00d55d
Need to merge changes to be able to push to remote branch. Merge bran…
sfkhalid Feb 1, 2021
f34a1d6
Changed data structure for holding cluster constraints from unordered…
sfkhalid Feb 3, 2021
e4b8257
Changed place where cluster's PartitionRegion is updated so that it d…
sfkhalid Feb 3, 2021
6e59e42
Added comments and removed unnecessary variables
sfkhalid Feb 4, 2021
ffa49a1
Merge branch 'master' into clusterer_feasibility_changes
sfkhalid Feb 4, 2021
83cfe2b
Made packing progress print every 4%
sfkhalid Feb 8, 2021
ed0cd07
Need to update local branchMerge branch 'clusterer_feasibility_change…
sfkhalid Feb 8, 2021
7e8f9d5
Print clustering progress in a table
sfkhalid Feb 8, 2021
c8b58b8
Added function level comments and table headers
sfkhalid Feb 8, 2021
f11da67
Modified build_device_grid function call in SetupGrid.cpp to get rid …
sfkhalid Feb 10, 2021
899a3da
Create the temporary cluster PartitionRegion earlier in the flow when…
sfkhalid Feb 10, 2021
afcb926
Merge branch 'master' into clusterer_feasibility_changes
sfkhalid Feb 11, 2021
ee4bf86
Moved print functions to be within their respective class. ex - print…
sfkhalid Feb 12, 2021
37ef5a7
Merge origin with local to be able to push changes to local 'clustere…
sfkhalid Feb 12, 2021
cfb812f
Comment update for print_constraints function
sfkhalid Feb 12, 2021
e2a7bfc
Updated comment for echo_constraints function
sfkhalid Feb 12, 2021
680cbdc
Merge branch 'master' into clusterer_feasibility_changes
sfkhalid Feb 15, 2021
40e9534
Merge branch 'master' into clusterer_feasibility_changes
sfkhalid Feb 26, 2021
d2d6fcb
Updated PartitionRegion class comment
sfkhalid Feb 26, 2021
bd217bf
Need to run make format on changes that were merged remotely 'cluster…
sfkhalid Feb 26, 2021
8c5bc25
Ran make format to fix formatting in vtr geometry file
sfkhalid Feb 26, 2021
b807f83
Merge branch 'master' into clusterer_feasibility_changes
sfkhalid Feb 26, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions libs/libvtrutil/src/vtr_geometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,16 @@ Rect<T> bounding_box(const Rect<T>& lhs, const Rect<T>& rhs);
template<class T>
Rect<T> intersection(const Rect<T>& lhs, const Rect<T>& rhs);

//Prints a rectangle
template<class T>
static void print_rect(FILE* fp, const Rect<T> rect);

//Sample on a uniformly spaced grid within a rectangle
// sample(vtr::Rect(l, h), 0, 0, M) == l
// sample(vtr::Rect(l, h), M, M, M) == h
//To avoid the edges, use `sample(r, x+1, y+1, N+1) for x, y, in 0..N-1
//Only defined for integral types

/**
* @brief Sample on a uniformly spaced grid within a rectangle
*
Expand All @@ -216,6 +226,7 @@ Rect<T> intersection(const Rect<T>& lhs, const Rect<T>& rhs);
* To avoid the edges, use `sample(r, x+1, y+1, N+1) for x, y, in 0..N-1
* Only defined for integral types
*/

template<typename T, typename std::enable_if<std::is_integral<T>::value>::type...>
Point<T> sample(const vtr::Rect<T>& r, T x, T y, T d);

Expand Down
7 changes: 7 additions & 0 deletions libs/libvtrutil/src/vtr_geometry.tpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,13 @@ Rect<T> intersection(const Rect<T>& lhs, const Rect<T>& rhs) {
std::min(lhs.xmax(), rhs.xmax()),
std::min(lhs.ymax(), rhs.ymax()));
}
template<class T>
static void print_rect(FILE* fp, const Rect<T> rect) {
fprintf(fp, "\txmin: %d\n", rect.xmin());
fprintf(fp, "\tymin: %d\n", rect.ymin());
fprintf(fp, "\txmax: %d\n", rect.xmax());
fprintf(fp, "\tymax: %d\n", rect.ymax());
}
//Only defined for integral types
template<typename T, typename std::enable_if<std::is_integral<T>::value>::type...>
Point<T> sample(const vtr::Rect<T>& r, T x, T y, T d) {
Expand Down
4 changes: 1 addition & 3 deletions vpr/src/base/SetupGrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,7 @@ static DeviceGrid auto_size_device_grid(const std::vector<t_grid_def>& grid_layo
//Check if it satisfies the block counts
if (grid_satisfies_instance_counts(grid, minimum_instance_counts, maximum_device_utilization)) {
//Re-build the grid at the final size with out-of-range
//warnings turned on (so users are aware of out-of-range issues
//at the final device sizes)
grid = build_device_grid(grid_def, width, height, true, limiting_resources);
grid = build_device_grid(grid_def, width, height, false, limiting_resources);
return grid;
}

Expand Down
72 changes: 2 additions & 70 deletions vpr/src/base/constraints_load.cpp
Original file line number Diff line number Diff line change
@@ -1,82 +1,14 @@
#include "constraints_load.h"

static void print_region(FILE* fp, Region region);
static void print_partition(FILE* fp, Partition part);
static void print_partition_region(FILE* fp, PartitionRegion pr);
static void print_constraints(FILE* fp, VprConstraints constraints, int num_parts);

void print_region(FILE* fp, Region region) {
vtr::Rect<int> rect = region.get_region_rect();
int xmin = rect.xmin();
int xmax = rect.xmax();
int ymin = rect.ymin();
int ymax = rect.ymax();
int subtile = region.get_sub_tile();

fprintf(fp, "\tRegion: \n");
fprintf(fp, "\txmin: %d\n", xmin);
fprintf(fp, "\txmax: %d\n", xmax);
fprintf(fp, "\tymin: %d\n", ymin);
fprintf(fp, "\tymax: %d\n", ymax);
fprintf(fp, "\tsubtile: %d\n\n", subtile);
}

void print_partition(FILE* fp, Partition part) {
std::string name = part.get_name();
fprintf(fp, "partition_name: %s\n", name.c_str());

PartitionRegion pr = part.get_part_region();

print_partition_region(fp, pr);
}

void print_partition_region(FILE* fp, PartitionRegion pr) {
std::vector<Region> part_region = pr.get_partition_region();

int pr_size = part_region.size();

fprintf(fp, "\tNumber of regions in partition is: %d\n", pr_size);

for (unsigned int i = 0; i < part_region.size(); i++) {
print_region(fp, part_region[i]);
}
}

void print_constraints(FILE* fp, VprConstraints constraints, int num_parts) {
Partition temp_part;
std::vector<AtomBlockId> atoms;

for (int i = 0; i < num_parts; i++) {
PartitionId part_id(i);

temp_part = constraints.get_partition(part_id);

fprintf(fp, "\npartition_id: %zu\n", size_t(part_id));
print_partition(fp, temp_part);

atoms = constraints.get_part_atoms(part_id);

int atoms_size = atoms.size();

fprintf(fp, "\tAtom vector size is %d\n", atoms_size);
fprintf(fp, "\tIds of atoms in partition: \n");
for (unsigned int j = 0; j < atoms.size(); j++) {
AtomBlockId atom_id = atoms[j];
fprintf(fp, "\t#%zu\n", size_t(atom_id));
}
}
}

void echo_constraints(char* filename, VprConstraints constraints, int num_parts) {
void echo_constraints(char* filename, VprConstraints constraints) {
FILE* fp;
fp = vtr::fopen(filename, "w");

fprintf(fp, "--------------------------------------------------------------\n");
fprintf(fp, "Constraints\n");
fprintf(fp, "--------------------------------------------------------------\n");
fprintf(fp, "\n");
fprintf(fp, "\n Number of partitions is %d \n", num_parts);
print_constraints(fp, constraints, num_parts);
print_constraints(fp, constraints);

fclose(fp);
}
3 changes: 2 additions & 1 deletion vpr/src/base/constraints_load.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "vpr_constraints.h"
#include "vtr_vector.h"

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

#endif
3 changes: 3 additions & 0 deletions vpr/src/base/echo_files.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ void alloc_and_load_echo_file_info() {
//Vpr constraints
setEchoFileName(E_ECHO_VPR_CONSTRAINTS, "vpr_constraints.echo");

//Packing
setEchoFileName(E_ECHO_CLUSTERS, "clusters.echo");

//Intra-block routing
setEchoFileName(E_ECHO_INTRA_LB_FAILED_ROUTE, "intra_lb_failed_route.echo");

Expand Down
3 changes: 3 additions & 0 deletions vpr/src/base/echo_files.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ enum e_echo_files {
E_ECHO_PRE_PACKING_MOLECULES_AND_PATTERNS,
E_ECHO_VPR_CONSTRAINTS,

//Packing
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At top, file controls echo files, we have an enum to each one, search for in code to see what each one prints

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

say what echo files are, what they are used for - dumps that intended to be written and read by a developer, typically direct reps of data structures to make debugging easier

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

enum e_output_files - line 66 - see what these are in code and leave a brief comment, or make an issue saying this may just be same as other enum and we should just put them both together

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

set an issue to clean up these two enums (either just need to comment, or merge the two diff enums)
whole thing could be wrapped in a class

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

echo file name can maybe also take a default name (person can choose to pass it in - if not, default set to null), the set_output_filename would work fore everything

investigate - is there some other reason to have the second output enum? - look at the call sites for that

in the cpp file -> instead of the mallocs, recode using c++ strings and wrap it all in a class

-> all the members of the class could be static members (don't have to turn into class, see if it's worth it) (make a member object of the echo class in something like the vpr_options file)

  • might be better to not have class, either way clean up the code by getting rid of mallocs and use c++ strings

E_ECHO_CLUSTERS,

// Intra-block routing
E_ECHO_INTRA_LB_FAILED_ROUTE,

Expand Down
10 changes: 10 additions & 0 deletions vpr/src/base/partition.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "partition.h"
#include "partition_region.h"
#include <algorithm>
#include <vector>

Expand All @@ -17,3 +18,12 @@ const PartitionRegion Partition::get_part_region() {
void Partition::set_part_region(PartitionRegion pr) {
part_region = pr;
}

void print_partition(FILE* fp, Partition part) {
std::string name = part.get_name();
fprintf(fp, "partition_name: %s\n", name.c_str());

PartitionRegion pr = part.get_part_region();

print_partition_region(fp, pr);
}
3 changes: 3 additions & 0 deletions vpr/src/base/partition.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,7 @@ class Partition {
PartitionRegion part_region; ///< the union of regions that the partition can be placed in
};

///@brief used to print data from a Partition
void print_partition(FILE* fp, Partition part);

#endif /* PARTITION_H */
17 changes: 17 additions & 0 deletions vpr/src/base/partition_region.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "partition_region.h"
#include "region.h"

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

bool PartitionRegion::empty() {
return partition_region.size() == 0;
}

PartitionRegion intersection(PartitionRegion& pr1, PartitionRegion& pr2) {
/**for N regions in part_region and M in the calling object you can get anywhere from
* 0 to M*N regions in the resulting vector. Only intersection regions with non-zero area rectangles and
Expand All @@ -29,3 +34,15 @@ PartitionRegion intersection(PartitionRegion& pr1, PartitionRegion& pr2) {

return pr;
}

void print_partition_region(FILE* fp, PartitionRegion pr) {
std::vector<Region> part_region = pr.get_partition_region();

int pr_size = part_region.size();

fprintf(fp, "\tNumber of regions in partition is: %d\n", pr_size);

for (unsigned int i = 0; i < part_region.size(); i++) {
print_region(fp, part_region[i]);
}
}
10 changes: 9 additions & 1 deletion vpr/src/base/partition_region.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

/**
* @file
* @brief This file defines the PartitionRegions class. The PartitionRegions class is used to store the union
* @brief This file defines the PartitionRegion class. The PartitionRegion class is used to store the union
* of regions that a partition can be placed in.
*/

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

/**
* @brief Check if the PartitionRegion is empty (meaning there is no constraint on the object the PartitionRegion belongs to)
*/
bool empty();

/**
* @brief Global friend function that returns the intersection of two PartitionRegions
*
Expand All @@ -36,4 +41,7 @@ class PartitionRegion {
std::vector<Region> partition_region; ///< union of rectangular regions that a partition can be placed in
};

///@brief used to print data from a PartitionRegion
void print_partition_region(FILE* fp, PartitionRegion pr);

#endif /* PARTITION_REGIONS_H */
6 changes: 6 additions & 0 deletions vpr/src/base/region.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,9 @@ Region intersection(Region r1, Region r2) {

return intersect;
}

void print_region(FILE* fp, Region region) {
fprintf(fp, "\tRegion: \n");
print_rect(fp, region.get_region_rect());
fprintf(fp, "\tsubtile: %d\n\n", region.get_sub_tile());
}
3 changes: 3 additions & 0 deletions vpr/src/base/region.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,7 @@ bool do_regions_intersect(Region r1, Region r2);
*/
Region intersection(Region r1, Region r2);

///@brief Used to print data from a Region
void print_region(FILE* fp, Region region);

#endif /* REGION_H */
40 changes: 40 additions & 0 deletions vpr/src/base/vpr_constraints.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "vpr_constraints.h"
#include "partition.h"

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

return part_atoms;
}

int VprConstraints::get_num_partitions() {
return partitions.size();
}

PartitionRegion VprConstraints::get_partition_pr(PartitionId part_id) {
PartitionRegion pr;
pr = partitions[part_id].get_part_region();
return pr;
}

void print_constraints(FILE* fp, VprConstraints constraints) {
Partition temp_part;
std::vector<AtomBlockId> atoms;

int num_parts = constraints.get_num_partitions();

fprintf(fp, "\n Number of partitions is %d \n", num_parts);

for (int i = 0; i < num_parts; i++) {
PartitionId part_id(i);

temp_part = constraints.get_partition(part_id);

fprintf(fp, "\npartition_id: %zu\n", size_t(part_id));
print_partition(fp, temp_part);

atoms = constraints.get_part_atoms(part_id);

int atoms_size = atoms.size();

fprintf(fp, "\tAtom vector size is %d\n", atoms_size);
fprintf(fp, "\tIds of atoms in partition: \n");
for (unsigned int j = 0; j < atoms.size(); j++) {
AtomBlockId atom_id = atoms[j];
fprintf(fp, "\t#%zu\n", size_t(atom_id));
}
}
}
32 changes: 31 additions & 1 deletion vpr/src/base/vpr_constraints.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,21 @@
* It also specifies which regions the partitions should be placed in. Atoms cannot be placed in more than one partition.
* 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.
*
* Related Classes
* ===============
* The following definitions are useful to understanding this class:
*
* Partition: a grouping of atoms that are constrained to a portion of an FPGA
* See vpr/base/partition.h for more detail
*
* Region: the x and y bounds of a rectangular region, optionally including a subtile value,
* that atoms in a partition are constrained to
* See vpr/base/region.h for more detail
*
* PartitionRegion: the union of regions that a partition can be placed in
* See vpr/base/partition_region.h for more detail
*
*
*/

class VprConstraints {
Expand All @@ -33,7 +48,7 @@ class VprConstraints {
/**
* @brief Return id of the partition the atom belongs to
*
* If an atom is not in a partition (unconstrained), PartitionId::Invalid() is returned.
* If an atom is not in a partition (unconstrained), PartitionId::INVALID() is returned.
*
* @param blk_id The atom for which the partition id is needed
*/
Expand All @@ -60,6 +75,18 @@ class VprConstraints {
*/
std::vector<AtomBlockId> get_part_atoms(PartitionId part_id);

/**
* @brief Returns the number of partitions in the object
*/
int get_num_partitions();

/**
* @brief Returns the PartitionRegion belonging to the specified Partition
*
* @param part_id The id of the partition whose PartitionRegion is needed
*/
PartitionRegion get_partition_pr(PartitionId part_id);

private:
/**
* Store all constrained atoms
Expand All @@ -72,4 +99,7 @@ class VprConstraints {
vtr::vector<PartitionId, Partition> partitions;
};

///@brief used to print floorplanning constraints data from a VprConstraints object
void print_constraints(FILE* fp, VprConstraints constraints);

#endif /* VPR_CONSTRAINTS_H */
9 changes: 6 additions & 3 deletions vpr/src/base/vpr_constraints_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,13 @@ void load_vpr_constraints_file(const char* read_vpr_constraints_name) {
read_vpr_constraints_name);
}

VprConstraints constraints = reader.constraints_;
int num_parts = reader.num_partitions_;
//Update the floorplanning constraints in the floorplanning constraints context
auto& floorplanning_ctx = g_vpr_ctx.mutable_floorplanning();
floorplanning_ctx.constraints = reader.constraints_;

VprConstraints ctx_constraints = floorplanning_ctx.constraints;

if (getEchoEnabled() && isEchoFileEnabled(E_ECHO_VPR_CONSTRAINTS)) {
echo_constraints(getEchoFileName(E_ECHO_VPR_CONSTRAINTS), constraints, num_parts);
echo_constraints(getEchoFileName(E_ECHO_VPR_CONSTRAINTS), ctx_constraints);
}
}
Loading