17
17
18
18
#include < fstream>
19
19
#include " vpr_constraints_writer.h"
20
+ #include " region.h"
20
21
21
- void write_vpr_floorplan_constraints (const char * file_name, int expand, bool subtile) {
22
- // Fill in the constraints object to be printed out.
22
+ void write_vpr_floorplan_constraints (const char * file_name, int expand, bool subtile, int horizontal_partitions, int vertical_partitions) {
23
23
VprConstraints constraints;
24
24
25
- setup_vpr_floorplan_constraints (constraints, expand, subtile);
25
+ if (horizontal_partitions != 0 && vertical_partitions != 0 ) {
26
+ setup_vpr_floorplan_constraints_cutpoints (constraints, horizontal_partitions, vertical_partitions);
27
+ } else {
28
+ setup_vpr_floorplan_constraints_one_loc (constraints, expand, subtile);
29
+ }
26
30
27
31
VprConstraintsSerializer writer (constraints);
28
32
@@ -39,7 +43,7 @@ void write_vpr_floorplan_constraints(const char* file_name, int expand, bool sub
39
43
}
40
44
}
41
45
42
- void setup_vpr_floorplan_constraints (VprConstraints& constraints, int expand, bool subtile) {
46
+ void setup_vpr_floorplan_constraints_one_loc (VprConstraints& constraints, int expand, bool subtile) {
43
47
auto & cluster_ctx = g_vpr_ctx.clustering ();
44
48
auto & place_ctx = g_vpr_ctx.placement ();
45
49
ClusterAtomsLookup atoms_lookup;
@@ -83,3 +87,134 @@ void setup_vpr_floorplan_constraints(VprConstraints& constraints, int expand, bo
83
87
part_id++;
84
88
}
85
89
}
90
+
91
+ void setup_vpr_floorplan_constraints_cutpoints (VprConstraints& constraints, int horizontal_cutpoints, int vertical_cutpoints) {
92
+ auto & cluster_ctx = g_vpr_ctx.clustering ();
93
+ auto & place_ctx = g_vpr_ctx.placement ();
94
+ auto & device_ctx = g_vpr_ctx.device ();
95
+ ClusterAtomsLookup atoms_lookup;
96
+
97
+ // calculate the cutpoint values according to the grid size
98
+ // load two arrays - one for horizontal cutpoints and one for vertical
99
+
100
+ std::vector<int > horizontal_cuts;
101
+
102
+ std::vector<int > vertical_cuts;
103
+
104
+ int horizontal_interval = device_ctx.grid .width () / horizontal_cutpoints;
105
+ VTR_LOG (" Device grid width is %d, horizontal interval is %d\n " , device_ctx.grid .width (), horizontal_interval);
106
+
107
+ unsigned int horizontal_point = horizontal_interval;
108
+ horizontal_cuts.push_back (0 );
109
+ int num_horizontal_cuts = 0 ;
110
+ while (num_horizontal_cuts < horizontal_cutpoints - 1 ) {
111
+ horizontal_cuts.push_back (horizontal_point);
112
+ horizontal_point = horizontal_point + horizontal_interval;
113
+ num_horizontal_cuts++;
114
+ }
115
+ // Add in the last point after your exit the while loop
116
+ horizontal_cuts.push_back (device_ctx.grid .width ());
117
+
118
+ int vertical_interval = device_ctx.grid .height () / vertical_cutpoints;
119
+ VTR_LOG (" Device grid height is %d, vertical interval is %d\n " , device_ctx.grid .height (), vertical_interval);
120
+
121
+ unsigned int vertical_point = vertical_interval;
122
+ vertical_cuts.push_back (0 );
123
+ int num_vertical_cuts = 0 ;
124
+ while (num_vertical_cuts < vertical_cutpoints - 1 ) {
125
+ vertical_cuts.push_back (vertical_point);
126
+ vertical_point = vertical_point + vertical_interval;
127
+ num_vertical_cuts++;
128
+ }
129
+ // Add in the last point after your exit the while loop
130
+ vertical_cuts.push_back (device_ctx.grid .height ());
131
+
132
+ // Create floorplan regions based on the cutpoints
133
+ std::unordered_map<Region, std::vector<AtomBlockId>> region_atoms;
134
+
135
+ for (unsigned int i = 0 ; i < horizontal_cuts.size () - 1 ; i++) {
136
+ int xmin = horizontal_cuts[i];
137
+ int xmax = horizontal_cuts[i + 1 ] - 1 ;
138
+
139
+ for (unsigned int j = 0 ; j < vertical_cuts.size () - 1 ; j++) {
140
+ int ymin = vertical_cuts[j];
141
+ int ymax = vertical_cuts[j + 1 ] - 1 ;
142
+
143
+ Region reg;
144
+ reg.set_region_rect (xmin, ymin, xmax, ymax);
145
+ std::vector<AtomBlockId> atoms;
146
+
147
+ region_atoms.insert ({reg, atoms});
148
+ }
149
+ }
150
+
151
+ /*
152
+ * For each cluster block, see which region it belongs to, and add its atoms to the
153
+ * appropriate region accordingly
154
+ */
155
+ for (auto blk_id : cluster_ctx.clb_nlist .blocks ()) {
156
+ std::vector<AtomBlockId> atoms = atoms_lookup.atoms_in_cluster (blk_id);
157
+ int num_atoms = atoms.size ();
158
+ int x = place_ctx.block_locs [blk_id].loc .x ;
159
+ int y = place_ctx.block_locs [blk_id].loc .y ;
160
+ int width = device_ctx.grid .width ();
161
+ int height = device_ctx.grid .height ();
162
+ VTR_ASSERT (x >= 0 && x < width);
163
+ VTR_ASSERT (y >= 0 && y < height);
164
+ int xminimum = 0 , yminimum = 0 , xmaximum = 0 , ymaximum = 0 ;
165
+
166
+ for (unsigned int h = 1 ; h < horizontal_cuts.size (); h++) {
167
+ if (x < horizontal_cuts[h]) {
168
+ xmaximum = horizontal_cuts[h] - 1 ;
169
+ xminimum = horizontal_cuts[h - 1 ];
170
+ break ;
171
+ }
172
+ }
173
+
174
+ for (unsigned int v = 1 ; v < vertical_cuts.size (); v++) {
175
+ if (y < vertical_cuts[v]) {
176
+ ymaximum = vertical_cuts[v] - 1 ;
177
+ yminimum = vertical_cuts[v - 1 ];
178
+ break ;
179
+ }
180
+ }
181
+
182
+ Region current_reg;
183
+ current_reg.set_region_rect (xminimum, yminimum, xmaximum, ymaximum);
184
+
185
+ auto got = region_atoms.find (current_reg);
186
+
187
+ VTR_ASSERT (got != region_atoms.end ());
188
+
189
+ for (int at = 0 ; at < num_atoms; at++) {
190
+ got->second .push_back (atoms[at]);
191
+ }
192
+ }
193
+
194
+ int num_partitions = 0 ;
195
+ for (auto region : region_atoms) {
196
+ Partition part;
197
+ PartitionId partid (num_partitions);
198
+ std::string part_name = " Part" + std::to_string (num_partitions);
199
+ vtr::Rect <int > rect = region.first .get_region_rect ();
200
+ create_partition (part, part_name, rect.xmin (), rect.ymin (), rect.xmax (), rect.ymax ());
201
+ constraints.add_partition (part);
202
+
203
+ for (unsigned int k = 0 ; k < region.second .size (); k++) {
204
+ constraints.add_constrained_atom (region.second [k], partid);
205
+ }
206
+
207
+ num_partitions++;
208
+ }
209
+ }
210
+
211
+ void create_partition (Partition& part, std::string part_name, int xmin, int ymin, int xmax, int ymax) {
212
+ part.set_name (part_name);
213
+ PartitionRegion part_pr;
214
+ Region part_region;
215
+ part_region.set_region_rect (xmin, ymin, xmax, ymax);
216
+ std::vector<Region> part_regions;
217
+ part_regions.push_back (part_region);
218
+ part_pr.set_partition_region (part_regions);
219
+ part.set_part_region (part_pr);
220
+ }
0 commit comments