@@ -170,6 +170,8 @@ bool try_pack(const t_packer_opts& packer_opts,
170
170
// / @brief Region constraints: Turns on more attraction groups for all regions
171
171
// / and increases the target density of clb blocks.
172
172
ATTRACTION_GROUPS_ALL_REGIONS_AND_INCREASED_TARGET_DENSITY,
173
+ INCREASE_TARGET_DENSITY,
174
+ AP_INCREASE_MAX_DISPLACEMENT,
173
175
// / @brief The failure state.
174
176
FAILURE
175
177
};
@@ -192,6 +194,21 @@ bool try_pack(const t_packer_opts& packer_opts,
192
194
// Try to size/find a device
193
195
bool fits_on_device = try_size_device_grid (arch, num_used_type_instances, packer_opts.target_device_utilization , packer_opts.device_layout );
194
196
197
+ std::vector<t_logical_block_type_ptr> overused_type_instances;
198
+ overused_type_instances.reserve (num_used_type_instances.size ());
199
+ for (const auto & p : num_used_type_instances) {
200
+ unsigned num_used_instances = p.second ;
201
+
202
+ unsigned num_available_instances = 0 ;
203
+ for (auto type : p.first ->equivalent_tiles )
204
+ num_available_instances += device_ctx.grid .num_instances (type, -1 );
205
+
206
+ if (num_used_instances > num_available_instances) {
207
+ overused_type_instances.push_back (p.first );
208
+ }
209
+ }
210
+
211
+
195
212
/* We use this bool to determine the cause for the clustering not being dense enough. If the clustering
196
213
* is not dense enough and there are floorplan constraints, it is presumed that the constraints are the cause
197
214
* of the floorplan not fitting, so attraction groups are turned on for later iterations.
@@ -209,7 +226,25 @@ bool try_pack(const t_packer_opts& packer_opts,
209
226
// not overfilled, the next state is success.
210
227
next_packer_state = e_packer_state::SUCCESS;
211
228
} else {
212
- if (floorplan_not_fitting) {
229
+ if (appack_ctx.appack_options .use_appack ) {
230
+ switch (current_packer_state) {
231
+ case e_packer_state::DEFAULT:
232
+ next_packer_state = e_packer_state::UNRELATED_AND_BALANCED;
233
+ break ;
234
+ case e_packer_state::UNRELATED_AND_BALANCED:
235
+ // FIXME: Check if the overfilled block type has a non-1 target density. If not this has no point.
236
+ next_packer_state = e_packer_state::INCREASE_TARGET_DENSITY;
237
+ break ;
238
+ case e_packer_state::INCREASE_TARGET_DENSITY:
239
+ // FIXME: Check if the max displacement of the issue block type is not already huge.
240
+ next_packer_state = e_packer_state::AP_INCREASE_MAX_DISPLACEMENT;
241
+ break ;
242
+ case e_packer_state::AP_INCREASE_MAX_DISPLACEMENT:
243
+ default :
244
+ next_packer_state = e_packer_state::FAILURE;
245
+ break ;
246
+ }
247
+ } else if (floorplan_not_fitting) {
213
248
// If there are overfilled region constraints.
214
249
/*
215
250
* When running with tight floorplan constraints, some regions may become overfull with clusters (i.e.
@@ -270,6 +305,16 @@ bool try_pack(const t_packer_opts& packer_opts,
270
305
VTR_ASSERT (balance_block_type_util == false );
271
306
balance_block_type_util = true ;
272
307
}
308
+ if (appack_ctx.appack_options .use_appack ) {
309
+ // Only do unrelated clustering on the overused type instances.
310
+ // FIXME: Make this cleaner so we do not have the magic number 10.
311
+ std::fill (appack_ctx.appack_options .max_unrelated_clustering_attempts .begin (),
312
+ appack_ctx.appack_options .max_unrelated_clustering_attempts .end (),
313
+ 0 );
314
+ for (t_logical_block_type_ptr block_type : overused_type_instances) {
315
+ appack_ctx.appack_options .max_unrelated_clustering_attempts [block_type->index ] = 10 ;
316
+ }
317
+ }
273
318
VTR_LOG (" Packing failed to fit on device. Re-packing with: unrelated_logic_clustering=%s balance_block_type_util=%s\n " ,
274
319
(allow_unrelated_clustering ? " true" : " false" ),
275
320
(balance_block_type_util ? " true" : " false" ));
@@ -308,6 +353,23 @@ bool try_pack(const t_packer_opts& packer_opts,
308
353
cluster_legalizer.get_target_external_pin_util ().set_block_pin_util (" clb" , pin_util);
309
354
break ;
310
355
}
356
+ case e_packer_state::INCREASE_TARGET_DENSITY: {
357
+ t_ext_pin_util pin_util (1.0 , 1.0 );
358
+ for (t_logical_block_type_ptr type : overused_type_instances) {
359
+ cluster_legalizer.get_target_external_pin_util ().set_block_pin_util (type->name , pin_util);
360
+ }
361
+ VTR_LOG (" Increasing target density.\n " );
362
+ break ;
363
+ }
364
+ case e_packer_state::AP_INCREASE_MAX_DISPLACEMENT: {
365
+ VTR_ASSERT (appack_ctx.appack_options .use_appack );
366
+ for (t_logical_block_type_ptr logical_block_ty : overused_type_instances) {
367
+ float max_distance = device_ctx.grid .width () + device_ctx.grid .height ();
368
+ appack_ctx.max_distance_threshold_manager .set_max_dist_threshold (*logical_block_ty, max_distance);
369
+ }
370
+ VTR_LOG (" APPACK: Increasing max displacement.\n " );
371
+ break ;
372
+ }
311
373
case e_packer_state::DEFAULT:
312
374
case e_packer_state::SUCCESS:
313
375
case e_packer_state::FAILURE:
0 commit comments