Skip to content

Commit c3ace92

Browse files
committed
Added member functions to VprConstraints and added unit tests to test these and changed a class name to PartitionRegion
1 parent ff95d41 commit c3ace92

File tree

7 files changed

+81
-114
lines changed

7 files changed

+81
-114
lines changed

vpr/src/base/partition.cpp

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,6 @@
22
#include <algorithm>
33
#include <vector>
44

5-
Partition::Partition() {
6-
id = PartitionId::INVALID();
7-
name = "";
8-
atom_blocks = {};
9-
}
10-
11-
const PartitionId Partition::get_partition_id() {
12-
return id;
13-
}
14-
15-
void Partition::set_partition_id(PartitionId _part_id) {
16-
id = _part_id;
17-
}
18-
195
const std::string Partition::get_name() {
206
return name;
217
}
@@ -24,26 +10,10 @@ void Partition::set_name(std::string _part_name) {
2410
name = _part_name;
2511
}
2612

27-
void Partition::add_to_atoms(AtomBlockId atom_id) {
28-
atom_blocks.push_back(atom_id);
29-
}
30-
31-
bool Partition::contains_atom(AtomBlockId atom_id) {
32-
bool contains_atom = false;
33-
if (std::find(atom_blocks.begin(), atom_blocks.end(), atom_id) != atom_blocks.end()) {
34-
contains_atom = true;
35-
}
36-
return contains_atom;
37-
}
38-
39-
const std::vector<AtomBlockId> Partition::get_atoms() {
40-
return atom_blocks;
41-
}
42-
43-
const PartitionRegions Partition::get_part_regions() {
13+
const PartitionRegion Partition::get_part_regions() {
4414
return part_regions;
4515
}
4616

47-
void Partition::set_part_regions(PartitionRegions pr) {
17+
void Partition::set_part_regions(PartitionRegion pr) {
4818
part_regions = pr;
4919
}

vpr/src/base/partition.h

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33

44
#include "vtr_strong_id.h"
55
#include "region.h"
6-
#include "partition_regions.h"
76
#include "atom_netlist_fwd.h"
7+
#include "partition_region.h"
88
/**
99
* @file
1010
* @brief This file defines the data for a partition: a grouping of atoms that are constrained to a portion of an FPGA. A partition defines
@@ -21,34 +21,18 @@ typedef vtr::StrongId<partition_id_tag> PartitionId;
2121

2222
class Partition {
2323
public:
24-
Partition();
25-
26-
const PartitionId get_partition_id();
27-
void set_partition_id(PartitionId _part_id);
28-
2924
const std::string get_name();
3025
void set_name(std::string _part_name);
3126

32-
//add an id to the atom_blocks vector
33-
void add_to_atoms(AtomBlockId atom_id);
34-
35-
//check if a given atom is in the partition
36-
bool contains_atom(AtomBlockId atom_id);
37-
38-
//get the atom_blocks vector
39-
const std::vector<AtomBlockId> get_atoms();
40-
4127
//set the union of regions for this partition;
42-
void set_part_regions(PartitionRegions pr);
28+
void set_part_regions(PartitionRegion pr);
4329

4430
//get the union of regions of this partition
45-
const PartitionRegions get_part_regions();
31+
const PartitionRegion get_part_regions();
4632

4733
private:
48-
PartitionId id; //unique id for this partition
49-
std::string name; //name of the partition, name will be unique across partitions
50-
std::vector<AtomBlockId> atom_blocks; //atoms that belong to this partition, each atom should only belong to one partition
51-
PartitionRegions part_regions; //the union of regions that the partition can be placed in
34+
std::string name; //name of the partition, name will be unique across partitions
35+
PartitionRegion part_regions; //the union of regions that the partition can be placed in
5236
};
5337

5438
#endif /* PARTITION_H */

vpr/src/base/partition_regions.cpp renamed to vpr/src/base/partition_region.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
#include "partition_regions.h"
1+
#include "partition_region.h"
22

3-
PartitionRegions PartitionRegions::get_intersection(PartitionRegions part_region) {
3+
PartitionRegion PartitionRegion::get_intersection(PartitionRegion part_region) {
44
/**for N regions in part_region and M in the calling object you can get anywhere from
55
* 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
*/
9-
PartitionRegions pr;
9+
PartitionRegion pr;
1010
Region intersect_region;
1111
bool regions_intersect;
1212
for (unsigned int i = 0; i < partition_regions.size(); i++) {
@@ -22,10 +22,10 @@ PartitionRegions PartitionRegions::get_intersection(PartitionRegions part_region
2222
return pr;
2323
}
2424

25-
void PartitionRegions::add_to_part_regions(Region region) {
25+
void PartitionRegion::add_to_part_regions(Region region) {
2626
partition_regions.push_back(region);
2727
}
2828

29-
std::vector<Region> PartitionRegions::get_partition_regions() {
29+
std::vector<Region> PartitionRegion::get_partition_regions() {
3030
return partition_regions;
3131
}

vpr/src/base/partition_regions.h renamed to vpr/src/base/partition_region.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
* of regions that a partition can be placed in.
1111
*/
1212

13-
class PartitionRegions {
13+
class PartitionRegion {
1414
public:
1515
//Returns the intersection of two PartitionRegions vectors that are passed to it.
16-
PartitionRegions get_intersection(PartitionRegions part_region);
16+
PartitionRegion get_intersection(PartitionRegion part_region);
1717

1818
//function to add to the partition_regions vector
1919
void add_to_part_regions(Region region);

vpr/src/base/vpr_constraints.cpp

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,23 @@
11
#include "vpr_constraints.h"
22

3-
void VprConstraints::add_constrained_atom(const AtomBlockId blk_id, const PartitionId partition) {
4-
constrained_atoms.insert({blk_id, partition});
3+
void VprConstraints::add_constrained_atom(const AtomBlockId blk_id, const PartitionId part_id) {
4+
constrained_atoms.insert({blk_id, part_id});
5+
6+
//std::unordered_map<AtomBlockId, PartitionId>::const_iterator got = constrained_atoms.find(blk_id);
7+
auto got = constrained_atoms.find(blk_id);
8+
9+
if (got == constrained_atoms.end()) {
10+
constrained_atoms.insert({blk_id, part_id});
11+
} else {
12+
got->second = part_id;
13+
}
514
}
615

716
PartitionId VprConstraints::get_atom_partition(AtomBlockId blk_id) {
817
PartitionId part_id;
918

10-
std::unordered_map<AtomBlockId, PartitionId>::const_iterator got = constrained_atoms.find(blk_id);
19+
//std::unordered_map<AtomBlockId, PartitionId>::const_iterator got = constrained_atoms.find(blk_id);
20+
auto got = constrained_atoms.find(blk_id);
1121

1222
if (got == constrained_atoms.end()) {
1323
return part_id = PartitionId::INVALID();
@@ -20,6 +30,18 @@ void VprConstraints::add_partition(Partition part) {
2030
partitions.push_back(part);
2131
}
2232

23-
vtr::vector<PartitionId, Partition> VprConstraints::get_partitions() {
24-
return partitions;
33+
Partition VprConstraints::get_partition(PartitionId part_id) {
34+
return partitions[part_id];
35+
}
36+
37+
std::vector<AtomBlockId> VprConstraints::get_part_atoms(PartitionId part_id) {
38+
std::vector<AtomBlockId> part_atoms;
39+
40+
for (auto& it : constrained_atoms) {
41+
if (it.second == part_id) {
42+
part_atoms.push_back(it.first);
43+
}
44+
}
45+
46+
return part_atoms;
2547
}

vpr/src/base/vpr_constraints.h

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#include "vtr_vector.h"
55
#include "vpr_utils.h"
66
#include "partition.h"
7-
#include "partition_regions.h"
7+
#include "partition_region.h"
88

99
/**
1010
* @file
@@ -21,23 +21,21 @@
2121

2222
class VprConstraints {
2323
public:
24-
//VprConstraints();
25-
2624
//function to add an atom to constrained_atoms
27-
void add_constrained_atom(const AtomBlockId blk_id, const PartitionId partition);
25+
void add_constrained_atom(const AtomBlockId blk_id, const PartitionId part_id);
2826

2927
//function to find which partition an atom belongs to
3028
PartitionId get_atom_partition(AtomBlockId blk_id);
3129

3230
//function to add a partition to partitions
3331
void add_partition(Partition part);
3432

35-
//function to return the partitions vector
36-
vtr::vector<PartitionId, Partition> get_partitions();
37-
3833
//function to return a partition given a PartitionId
3934
Partition get_partition(PartitionId part_id);
4035

36+
//function to return the atoms belonging to a partition
37+
std::vector<AtomBlockId> get_part_atoms(PartitionId part_id);
38+
4139
private:
4240
/**
4341
* Store constraints information of each constrained atom.

0 commit comments

Comments
 (0)