Skip to content

Commit c9551f6

Browse files
[WIP] Iterative Re-Packing
1 parent 37709a0 commit c9551f6

File tree

5 files changed

+85
-5
lines changed

5 files changed

+85
-5
lines changed

vpr/src/base/vpr_types.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,10 @@ class t_ext_pin_util_targets {
188188
*/
189189
void set_block_pin_util(const std::string& block_type_name, t_ext_pin_util target);
190190

191+
inline void reset_all_block_pin_utils() {
192+
overrides_.clear();
193+
}
194+
191195
/**
192196
* @brief Sets the default pin util
193197
* @return Returns true if a default was previously set

vpr/src/pack/appack_context.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ struct t_appack_options {
8282
// search within the cluster's tile. Setting this to a higher number would
8383
// allow APPack to search farther away; but may bring in molecules which
8484
// do not "want" to be in the cluster.
85-
static constexpr float max_unrelated_tile_distance = 5.0f;
85+
// static constexpr float max_unrelated_tile_distance = 5.0f;
86+
std::vector<float> max_unrelated_tile_distance;
8687

8788
// Unrelated clustering occurs after all other candidate selection methods
8889
// have failed. This parameter sets how many time we will attempt unrelated
@@ -93,7 +94,8 @@ struct t_appack_options {
9394
// NOTE: A similar option exists in the candidate selector class. This was
9495
// duplicated since it is very likely that APPack would need a
9596
// different value for this option than the non-APPack flow.
96-
static constexpr int max_unrelated_clustering_attempts = 10;
97+
// static constexpr int max_unrelated_clustering_attempts = 10;
98+
std::vector<int> max_unrelated_clustering_attempts;
9799

98100
// TODO: Investigate adding flat placement info to seed selection.
99101
};
@@ -122,6 +124,9 @@ struct APPackContext : public Context {
122124
logical_block_types,
123125
device_grid);
124126
}
127+
128+
appack_options.max_unrelated_tile_distance.resize(logical_block_types.size(), 1.0);
129+
appack_options.max_unrelated_clustering_attempts.resize(logical_block_types.size(), 10);
125130
}
126131

127132
/**

vpr/src/pack/appack_max_dist_th_manager.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ class APPackMaxDistThManager {
9191
return logical_block_dist_thresholds_[logical_block_ty.index];
9292
}
9393

94+
inline void set_max_dist_threshold(const t_logical_block_type& logical_block_ty,
95+
float new_threshold) {
96+
logical_block_dist_thresholds_[logical_block_ty.index] = new_threshold;
97+
}
98+
9499
private:
95100
/**
96101
* @brief Helper method that initializes the thresholds of all logical

vpr/src/pack/greedy_candidate_selector.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -755,7 +755,8 @@ PackMoleculeId GreedyCandidateSelector::get_next_candidate_for_cluster(
755755
if (allow_unrelated_clustering_ && best_molecule == PackMoleculeId::INVALID()) {
756756
const t_appack_options& appack_options = appack_ctx_.appack_options;
757757
if (appack_options.use_appack) {
758-
if (num_unrelated_clustering_attempts_ < appack_options.max_unrelated_clustering_attempts) {
758+
t_logical_block_type_ptr cluster_type = cluster_legalizer.get_cluster_type(cluster_id);
759+
if (num_unrelated_clustering_attempts_ < appack_options.max_unrelated_clustering_attempts[cluster_type->index]) {
759760
best_molecule = get_unrelated_candidate_for_cluster_appack(cluster_gain_stats,
760761
cluster_id,
761762
cluster_legalizer);
@@ -1252,14 +1253,17 @@ PackMoleculeId GreedyCandidateSelector::get_unrelated_candidate_for_cluster_appa
12521253
// Push the position of the cluster to the queue.
12531254
search_queue.push(cluster_gain_stats.flat_cluster_position);
12541255

1256+
t_logical_block_type_ptr cluster_type = cluster_legalizer.get_cluster_type(cluster_id);
1257+
float max_dist = appack_ctx_.appack_options.max_unrelated_tile_distance[cluster_type->index];
1258+
12551259
while (!search_queue.empty()) {
12561260
// Pop a position to search from the queue.
12571261
const t_flat_pl_loc& node_loc = search_queue.front();
12581262
VTR_ASSERT_SAFE(node_loc.layer == 0);
12591263

12601264
// If this position is too far from the source, skip it.
12611265
float dist = get_manhattan_distance(node_loc, cluster_gain_stats.flat_cluster_position);
1262-
if (dist > 1) {
1266+
if (dist > max_dist) {
12631267
search_queue.pop();
12641268
continue;
12651269
}

vpr/src/pack/pack.cpp

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,8 @@ bool try_pack(const t_packer_opts& packer_opts,
170170
/// @brief Region constraints: Turns on more attraction groups for all regions
171171
/// and increases the target density of clb blocks.
172172
ATTRACTION_GROUPS_ALL_REGIONS_AND_INCREASED_TARGET_DENSITY,
173+
INCREASE_TARGET_DENSITY,
174+
AP_INCREASE_MAX_DISPLACEMENT,
173175
/// @brief The failure state.
174176
FAILURE
175177
};
@@ -192,6 +194,21 @@ bool try_pack(const t_packer_opts& packer_opts,
192194
//Try to size/find a device
193195
bool fits_on_device = try_size_device_grid(arch, num_used_type_instances, packer_opts.target_device_utilization, packer_opts.device_layout);
194196

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+
195212
/* We use this bool to determine the cause for the clustering not being dense enough. If the clustering
196213
* is not dense enough and there are floorplan constraints, it is presumed that the constraints are the cause
197214
* 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,
209226
// not overfilled, the next state is success.
210227
next_packer_state = e_packer_state::SUCCESS;
211228
} 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) {
213248
// If there are overfilled region constraints.
214249
/*
215250
* 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,
270305
VTR_ASSERT(balance_block_type_util == false);
271306
balance_block_type_util = true;
272307
}
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+
}
273318
VTR_LOG("Packing failed to fit on device. Re-packing with: unrelated_logic_clustering=%s balance_block_type_util=%s\n",
274319
(allow_unrelated_clustering ? "true" : "false"),
275320
(balance_block_type_util ? "true" : "false"));
@@ -308,6 +353,23 @@ bool try_pack(const t_packer_opts& packer_opts,
308353
cluster_legalizer.get_target_external_pin_util().set_block_pin_util("clb", pin_util);
309354
break;
310355
}
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+
}
311373
case e_packer_state::DEFAULT:
312374
case e_packer_state::SUCCESS:
313375
case e_packer_state::FAILURE:

0 commit comments

Comments
 (0)