Skip to content

Commit 5c3070c

Browse files
committed
Added cleaning of a pb after unsuccessful molecule packing
Signed-off-by: Maciej Kurc <[email protected]>
1 parent 53780c0 commit 5c3070c

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

vpr/src/pack/cluster.cpp

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1179,6 +1179,64 @@ static void alloc_and_load_pb_stats(t_pb* pb, const int feasible_block_array_siz
11791179
}
11801180
/*****************************************/
11811181

1182+
/**
1183+
* Cleans up a pb after unsuccessful molecule packing
1184+
*/
1185+
static bool cleanup_pb(t_pb* pb) {
1186+
bool can_free = true;
1187+
1188+
/* Recursively check if there are any children with already assigned atoms */
1189+
if (pb->child_pbs != nullptr) {
1190+
const t_mode* mode = &pb->pb_graph_node->pb_type->modes[pb->mode];
1191+
VTR_ASSERT(mode != nullptr);
1192+
1193+
/* Check each mode */
1194+
for (int i = 0; i < mode->num_pb_type_children; ++i) {
1195+
/* Check each child */
1196+
if (pb->child_pbs[i] != nullptr) {
1197+
for (int j = 0; j < mode->pb_type_children[i].num_pb; ++j) {
1198+
t_pb* pb_child = &pb->child_pbs[i][j];
1199+
t_pb_type* pb_type = pb_child->pb_graph_node->pb_type;
1200+
1201+
/* Primitive, check occupancy */
1202+
if (pb_type->num_modes == 0) {
1203+
if (pb_child->name != nullptr) {
1204+
can_free = false;
1205+
}
1206+
}
1207+
1208+
/* Non-primitive, recurse */
1209+
else {
1210+
if (!cleanup_pb(pb_child)) {
1211+
can_free = false;
1212+
}
1213+
}
1214+
}
1215+
}
1216+
}
1217+
1218+
/* Free if can */
1219+
if (can_free) {
1220+
for (int i = 0; i < mode->num_pb_type_children; ++i) {
1221+
if (pb->child_pbs[i] != nullptr) {
1222+
delete[] pb->child_pbs[i];
1223+
}
1224+
}
1225+
1226+
delete[] pb->child_pbs;
1227+
pb->child_pbs = nullptr;
1228+
pb->mode = 0;
1229+
1230+
if (pb->name) {
1231+
free(pb->name);
1232+
pb->name = nullptr;
1233+
}
1234+
}
1235+
}
1236+
1237+
return can_free;
1238+
}
1239+
11821240
/**
11831241
* Try pack molecule into current cluster
11841242
*/
@@ -1358,6 +1416,10 @@ static enum e_block_pack_status try_pack_molecule(t_cluster_placement_stats* clu
13581416
revert_place_atom_block(molecule->atom_block_ids[i], router_data, atom_molecules);
13591417
}
13601418
}
1419+
1420+
/* Placement failed, clean the pb */
1421+
cleanup_pb(pb);
1422+
13611423
} else {
13621424
VTR_LOGV(verbosity > 3, "\t\tPASSED pack molecule\n");
13631425
}

0 commit comments

Comments
 (0)