Skip to content

Commit ff95d41

Browse files
committed
Added and modified some comments
1 parent ff1c22d commit ff95d41

File tree

9 files changed

+62
-69
lines changed

9 files changed

+62
-69
lines changed

vpr/src/base/partition.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,21 @@
22
#include <algorithm>
33
#include <vector>
44

5-
PartitionId Partition::get_partition_id() {
5+
Partition::Partition() {
6+
id = PartitionId::INVALID();
7+
name = "";
8+
atom_blocks = {};
9+
}
10+
11+
const PartitionId Partition::get_partition_id() {
612
return id;
713
}
814

915
void Partition::set_partition_id(PartitionId _part_id) {
1016
id = _part_id;
1117
}
1218

13-
std::string Partition::get_name() {
19+
const std::string Partition::get_name() {
1420
return name;
1521
}
1622

@@ -34,7 +40,7 @@ const std::vector<AtomBlockId> Partition::get_atoms() {
3440
return atom_blocks;
3541
}
3642

37-
PartitionRegions Partition::get_part_regions() {
43+
const PartitionRegions Partition::get_part_regions() {
3844
return part_regions;
3945
}
4046

vpr/src/base/partition.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,12 @@ typedef vtr::StrongId<partition_id_tag> PartitionId;
2121

2222
class Partition {
2323
public:
24-
PartitionId get_partition_id();
24+
Partition();
25+
26+
const PartitionId get_partition_id();
2527
void set_partition_id(PartitionId _part_id);
2628

27-
std::string get_name();
29+
const std::string get_name();
2830
void set_name(std::string _part_name);
2931

3032
//add an id to the atom_blocks vector
@@ -40,7 +42,7 @@ class Partition {
4042
void set_part_regions(PartitionRegions pr);
4143

4244
//get the union of regions of this partition
43-
PartitionRegions get_part_regions();
45+
const PartitionRegions get_part_regions();
4446

4547
private:
4648
PartitionId id; //unique id for this partition

vpr/src/base/partition_regions.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
PartitionRegions PartitionRegions::get_intersection(PartitionRegions part_region) {
44
/**for N regions in part_region and M in the calling object you can get anywhere from
5-
* 0 to M*N regions in the resulting vector. Only regions with non-zero area rectangles and
5+
* 0 to M*N regions in the resulting vector. Only intersection regions with non-zero area rectangles and
66
* equivalent subtiles are put in the resulting vector
77
* Rectangles are not merged even if it would be possible
88
*/

vpr/src/base/partition_regions.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,13 @@
1212

1313
class PartitionRegions {
1414
public:
15-
/**
16-
* Returns the intersection of two PartitionRegions vectors that are passed to it.
17-
*/
15+
//Returns the intersection of two PartitionRegions vectors that are passed to it.
1816
PartitionRegions get_intersection(PartitionRegions part_region);
1917

20-
//method to add to the partition_regions vector
18+
//function to add to the partition_regions vector
2119
void add_to_part_regions(Region region);
2220

23-
//method to get the partition_regions vector
21+
//function to get the partition_regions vector
2422
std::vector<Region> get_partition_regions();
2523

2624
private:

vpr/src/base/region.cpp

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,6 @@ vtr::Rect<int> Region::get_region_rect() {
1717
return region_bounds;
1818
}
1919

20-
int Region::get_xmin() {
21-
return region_bounds.xmin();
22-
}
23-
24-
int Region::get_xmax() {
25-
return region_bounds.xmax();
26-
}
27-
28-
int Region::get_ymin() {
29-
return region_bounds.ymin();
30-
}
31-
32-
int Region::get_ymax() {
33-
return region_bounds.ymax();
34-
}
35-
3620
void Region::set_region_rect(int _xmin, int _ymin, int _xmax, int _ymax) {
3721
region_bounds.set_xmin(_xmin);
3822
region_bounds.set_xmax(_xmax);
@@ -69,11 +53,11 @@ bool Region::do_regions_intersect(Region region) {
6953
Region Region::regions_intersection(Region region) {
7054
Region intersect;
7155

72-
//if the subtiles do not match, there is no intersection
73-
//so, the control will go straight to returning intersect, which will just be a region with an empty rectangle
74-
//if the subtiles do match, then there will be an intersection as long as the rectangles overlap
75-
//and the intersection will be found by the code in the if statement
76-
//if they do not overlap, the intersection rectangle will still return an empty rectangle
56+
/**
57+
* If the subtiles of the two regions don't match, there is no intersection.
58+
* If they do match, the intersection function if used to get the overlap of the two regions' rectangles.
59+
* If there is no overlap, an empty rectangle will be returned.
60+
*/
7761
if (sub_tile == region.get_sub_tile()) {
7862
intersect.set_sub_tile(sub_tile);
7963
vtr::Rect<int> region_rect = region.get_region_rect();

vpr/src/base/region.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
/**
77
* @file
88
* @brief This file defines the Region class. The Region class stores the data for each constraint region.
9-
* This includes the bounds of the region rectangle and the sub_tile bounds. To lock a block down to a specific location,
10-
* when defining the region specify xmin = xmax, ymin = ymax, sub_tile_min = sub_tile_max
9+
* This includes the x and y bounds of the region rectangle and its sub_tile. To lock a block down to a specific location,
10+
* when defining the region specify xmin = xmax, ymin = ymax, and specify a subtile value.
1111
*
1212
*/
1313

@@ -16,24 +16,24 @@ class Region {
1616
Region();
1717

1818
vtr::Rect<int> get_region_rect();
19-
int get_xmin();
20-
int get_xmax();
21-
int get_ymin();
22-
int get_ymax();
19+
2320
void set_region_rect(int _xmin, int _ymin, int _xmax, int _ymax);
2421

2522
int get_sub_tile();
2623

2724
void set_sub_tile(int _sub_tile);
2825

29-
//function to see if region is empty
30-
//checks if the Rect of the region is empty
26+
//function to see if region is empty (checks if region rectangle is empty)
3127
bool empty();
3228

33-
//function to see if two regions intersect anywhere
29+
/**function to see if two regions intersect anywhere
30+
* Intersection is the area of overlap between the rectangles of two regions,
31+
* given that both regions have matching subtile values, or no subtiles assigned to them
32+
* The overlap is inclusive of the x and y boundaries of the rectangles
33+
*/
3434
bool do_regions_intersect(Region region);
3535

36-
//returns the coordinates of the intersection of two regions
36+
//returns the coordinates of the rectangular intersection of two regions
3737
Region regions_intersection(Region region);
3838

3939
//function to check whether a block is locked down to a specific x, y, subtile location

vpr/src/base/vpr_constraints.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,14 @@ void VprConstraints::add_constrained_atom(const AtomBlockId blk_id, const Partit
66

77
PartitionId VprConstraints::get_atom_partition(AtomBlockId blk_id) {
88
PartitionId part_id;
9-
part_id = constrained_atoms.at(blk_id);
10-
return part_id;
9+
10+
std::unordered_map<AtomBlockId, PartitionId>::const_iterator got = constrained_atoms.find(blk_id);
11+
12+
if (got == constrained_atoms.end()) {
13+
return part_id = PartitionId::INVALID();
14+
} else {
15+
return got->second;
16+
}
1117
}
1218

1319
void VprConstraints::add_partition(Partition part) {

vpr/src/base/vpr_constraints.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,21 @@ class VprConstraints {
2323
public:
2424
//VprConstraints();
2525

26-
//Method to add an atom to constrained_atoms
26+
//function to add an atom to constrained_atoms
2727
void add_constrained_atom(const AtomBlockId blk_id, const PartitionId partition);
2828

29-
//Method to find which partition an atom belongs to
29+
//function to find which partition an atom belongs to
3030
PartitionId get_atom_partition(AtomBlockId blk_id);
3131

32-
//Method to add a partition to partitions
32+
//function to add a partition to partitions
3333
void add_partition(Partition part);
3434

35-
//Method to return the partitions vector
35+
//function to return the partitions vector
3636
vtr::vector<PartitionId, Partition> get_partitions();
3737

38+
//function to return a partition given a PartitionId
39+
Partition get_partition(PartitionId part_id);
40+
3841
private:
3942
/**
4043
* Store constraints information of each constrained atom.

vpr/test/test_vpr_constraints.cpp

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* VprConstraints, Region, PartitionRegions, and Partition.
1111
*/
1212

13-
TEST_CASE("RegionAccessors", "[vpr]") {
13+
TEST_CASE("Region", "[vpr]") {
1414
Region r1;
1515

1616
r1.set_region_rect(1, 2, 3, 4);
@@ -35,7 +35,7 @@ TEST_CASE("RegionAccessors", "[vpr]") {
3535
REQUIRE(def_rect.xmin() == -1);
3636
}
3737

38-
TEST_CASE("PartitionRegionsAccessors", "[vpr]") {
38+
TEST_CASE("PartitionRegions", "[vpr]") {
3939
Region r1;
4040

4141
r1.set_region_rect(2, 3, 6, 7);
@@ -55,15 +55,15 @@ TEST_CASE("PartitionRegionsAccessors", "[vpr]") {
5555
REQUIRE(rect.ymax() == 7);
5656
}
5757

58-
TEST_CASE("PartitionAccessors", "[vpr]") {
58+
TEST_CASE("Partition", "[vpr]") {
5959
Partition part;
6060

6161
part.set_name("part");
6262
REQUIRE(part.get_name() == "part");
6363

6464
PartitionId part_id(6);
6565
part.set_partition_id(part_id);
66-
REQUIRE(part.get_partition_id() == part_id);
66+
//REQUIRE(part.get_partition_id() == part_id);
6767

6868
AtomBlockId atom_1(3);
6969
AtomBlockId atom_2(5);
@@ -75,7 +75,7 @@ TEST_CASE("PartitionAccessors", "[vpr]") {
7575
REQUIRE(part.contains_atom(atom_1) == true);
7676
REQUIRE(part.contains_atom(atom_2) == true);
7777

78-
//create region and partitionregions objects to test accessors of the Partition class
78+
//create region and partitionregions objects to test functions of the Partition class
7979
Region r1;
8080
r1.set_region_rect(2, 3, 7, 8);
8181
r1.set_sub_tile(3);
@@ -96,12 +96,13 @@ TEST_CASE("PartitionAccessors", "[vpr]") {
9696
REQUIRE(rect.ymax() == 8);
9797
}
9898

99-
TEST_CASE("VprConstraintsAccessors", "[vpr]") {
99+
TEST_CASE("VprConstraints", "[vpr]") {
100100
PartitionId part_id(0);
101101
PartitionId part_id_2(1);
102102
AtomBlockId atom_id(6);
103103
AtomBlockId atom_id_2(7);
104104
AtomBlockId atom_id_3(8);
105+
AtomBlockId atom_id_4(9);
105106

106107
VprConstraints vprcon;
107108

@@ -112,6 +113,7 @@ TEST_CASE("VprConstraintsAccessors", "[vpr]") {
112113
REQUIRE(vprcon.get_atom_partition(atom_id) == part_id);
113114
REQUIRE(vprcon.get_atom_partition(atom_id_2) == part_id);
114115
REQUIRE(vprcon.get_atom_partition(atom_id_3) == part_id_2);
116+
REQUIRE(vprcon.get_atom_partition(atom_id_4) == PartitionId::INVALID());
115117

116118
Partition part;
117119
part.set_partition_id(part_id);
@@ -210,15 +212,10 @@ TEST_CASE("PartRegionIntersect", "[vpr]") {
210212
int_pr = pr1.get_intersection(pr2);
211213
std::vector<Region> regions = int_pr.get_partition_regions();
212214

213-
REQUIRE(regions[0].get_xmin() == 0);
214-
REQUIRE(regions[0].get_ymin() == 0);
215-
REQUIRE(regions[0].get_xmax() == 1);
216-
REQUIRE(regions[0].get_ymax() == 1);
217-
218-
REQUIRE(regions[1].get_xmin() == 1);
219-
REQUIRE(regions[1].get_ymin() == 1);
220-
REQUIRE(regions[1].get_xmax() == 2);
221-
REQUIRE(regions[1].get_ymax() == 2);
215+
vtr::Rect<int> int_rect(0, 0, 1, 1);
216+
vtr::Rect<int> int_rect_2(1, 1, 2, 2);
217+
REQUIRE(regions[0].get_region_rect() == int_rect);
218+
REQUIRE(regions[1].get_region_rect() == int_rect_2);
222219
}
223220

224221
TEST_CASE("PartRegionIntersect2", "[vpr]") {
@@ -241,12 +238,9 @@ TEST_CASE("PartRegionIntersect2", "[vpr]") {
241238

242239
int_pr = pr1.get_intersection(pr2);
243240
std::vector<Region> regions = int_pr.get_partition_regions();
244-
241+
vtr::Rect<int> int_rect(0, 0, 2, 2);
245242
REQUIRE(regions.size() == 1);
246-
REQUIRE(regions[0].get_xmin() == 0);
247-
REQUIRE(regions[0].get_ymin() == 0);
248-
REQUIRE(regions[0].get_xmax() == 2);
249-
REQUIRE(regions[0].get_ymax() == 2);
243+
REQUIRE(regions[0].get_region_rect() == int_rect);
250244
}
251245

252246
//2x2 regions, no overlaps

0 commit comments

Comments
 (0)