Skip to content

Commit 369f5d1

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

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed

vpr/src/pack/cluster.cpp

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1179,6 +1179,70 @@ 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+
1187+
bool can_free = true;
1188+
1189+
/* Recursively check if there are any children with already assigned atoms */
1190+
if (pb->child_pbs != nullptr) {
1191+
1192+
const t_mode* mode = &pb->pb_graph_node->pb_type->modes[pb->mode];
1193+
VTR_ASSERT(mode != nullptr);
1194+
1195+
/* Check each mode */
1196+
for (int i=0; i<mode->num_pb_type_children; ++i) {
1197+
1198+
/* Check each child */
1199+
if (pb->child_pbs[i] != nullptr) {
1200+
for (int j=0; j<mode->pb_type_children[i].num_pb; ++j) {
1201+
1202+
t_pb* pb_child = &pb->child_pbs[i][j];
1203+
t_pb_type* pb_type = pb_child->pb_graph_node->pb_type;
1204+
1205+
/* Primitive, check occupancy */
1206+
if (pb_type->num_modes == 0) {
1207+
if (pb_child->name != nullptr) {
1208+
can_free = false;
1209+
}
1210+
}
1211+
1212+
/* Non-primitive, recurse */
1213+
else {
1214+
if (!cleanup_pb(pb_child)) {
1215+
can_free = false;
1216+
}
1217+
}
1218+
1219+
}
1220+
}
1221+
}
1222+
1223+
/* Free if can */
1224+
if (can_free) {
1225+
1226+
for (int i=0; i<mode->num_pb_type_children; ++i) {
1227+
if (pb->child_pbs[i] != nullptr) {
1228+
delete[] pb->child_pbs[i];
1229+
}
1230+
}
1231+
1232+
delete[] pb->child_pbs;
1233+
pb->child_pbs = nullptr;
1234+
pb->mode = 0;
1235+
1236+
if (pb->name) {
1237+
free(pb->name);
1238+
pb->name = nullptr;
1239+
}
1240+
}
1241+
}
1242+
1243+
return can_free;
1244+
}
1245+
11821246
/**
11831247
* Try pack molecule into current cluster
11841248
*/
@@ -1358,6 +1422,10 @@ static enum e_block_pack_status try_pack_molecule(t_cluster_placement_stats* clu
13581422
revert_place_atom_block(molecule->atom_block_ids[i], router_data, atom_molecules);
13591423
}
13601424
}
1425+
1426+
/* Placement failed, clean the pb */
1427+
cleanup_pb(pb);
1428+
13611429
} else {
13621430
VTR_LOGV(verbosity > 3, "\t\tPASSED pack molecule\n");
13631431
}

0 commit comments

Comments
 (0)