From b4249745057a0f71f2710013e7f263e46a496f53 Mon Sep 17 00:00:00 2001 From: Michael McGeagh Date: Thu, 30 Jul 2020 14:36:40 +0100 Subject: vela: Protect against divide by zero If the total cycle count is zero (for whatever reason), then a divide by zero can occur when calculating the midpoint_fps. This change protects against that by detecting when that is the case and instead setting the midpoint_fps to nan. Further calculations using that variable is safe and results in nan throughout. Change-Id: I2d29545d331a6eb5b27b6d9c931587c15f877e74 Signed-off-by: Michael McGeagh --- ethosu/vela/stats_writer.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'ethosu/vela') diff --git a/ethosu/vela/stats_writer.py b/ethosu/vela/stats_writer.py index c90d9876..af7b6997 100644 --- a/ethosu/vela/stats_writer.py +++ b/ethosu/vela/stats_writer.py @@ -85,7 +85,10 @@ def write_summary_metrics_csv(nng, summary_filename, arch): ) midpoint_inference_time = nng.cycles[PassCycles.Total] / arch.npu_clock - midpoint_fps = 1 / midpoint_inference_time + if midpoint_inference_time > 0: + midpoint_fps = 1 / midpoint_inference_time + else: + midpoint_fps = np.nan n_passes = sum(len(sg.passes) for sg in nng.subgraphs) n_cascaded_passes = sum(len(sg.cascaded_passes) for sg in nng.subgraphs) @@ -231,7 +234,10 @@ def print_performance_metrics_for_strat( orig_mem_areas_labels = [(v, v.display_name()) for v in MemArea.all()] midpoint_inference_time = cycles[PassCycles.Total] / arch.npu_clock - midpoint_fps = 1 / midpoint_inference_time + if midpoint_inference_time > 0: + midpoint_fps = 1 / midpoint_inference_time + else: + midpoint_fps = np.nan mem_area_labels = [ (mem_area, label) for mem_area, label in orig_mem_areas_labels if np.sum(bandwidths[mem_area]) > 0 -- cgit v1.2.1