Skip to content

Commit 87715a7

Browse files
vpr: use vtr::safe_ratio to avoid potential divide by zero
1 parent b88108c commit 87715a7

File tree

1 file changed

+2
-10
lines changed

1 file changed

+2
-10
lines changed

vpr/src/pack/cluster.cpp

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1963,16 +1963,8 @@ static void start_new_cluster(t_cluster_placement_stats* cluster_placement_stats
19631963
//support the same primitive(s).
19641964
std::stable_sort(candidate_types.begin(), candidate_types.end(),
19651965
[&](t_type_ptr lhs, t_type_ptr rhs) {
1966-
float lhs_util = 0.;
1967-
if (device_ctx.grid.num_instances(lhs) != 0) {
1968-
lhs_util = float(num_used_type_instances[lhs]) / device_ctx.grid.num_instances(lhs);
1969-
}
1970-
1971-
float rhs_util = 0;
1972-
if (device_ctx.grid.num_instances(rhs) != 0) {
1973-
rhs_util = float(num_used_type_instances[rhs]) / device_ctx.grid.num_instances(rhs);
1974-
}
1975-
1966+
float lhs_util = vtr::safe_ratio(num_used_type_instances[lhs], device_ctx.grid.num_instances(lhs));
1967+
float rhs_util = vtr::safe_ratio(num_used_type_instances[rhs], device_ctx.grid.num_instances(rhs));
19761968
//Lower util first
19771969
return lhs_util < rhs_util;
19781970
});

0 commit comments

Comments
 (0)