MCPcopy Create free account
hub / github.com/CVCUDA/CV-CUDA / calc_mean_ranges

Function calc_mean_ranges

bench/python/benchmark.py:351–392  ·  view source on GitHub ↗

Calculates the mean of all NVTX ranges present in the all_range_info. Since NVTX ranges can be reported per process, per thread, we need to have a way to average those numbers. The mean here is computed by taking the average of all the numbers per process per thread.

(all_range_info)

Source from the content-addressed store, hash-verified

349
350
351def calc_mean_ranges(all_range_info):
352 """
353 Calculates the mean of all NVTX ranges present in the all_range_info. Since NVTX ranges
354 can be reported per process, per thread, we need to have a way to average those numbers.
355 The mean here is computed by taking the average of all the numbers per process per thread.
356 """
357 mean_range_info = {}
358
359 # Aggregate all the values in a list keyed by the range names.
360 for process_id in all_range_info:
361 for thread_id in all_range_info[process_id]:
362 for range_name in all_range_info[process_id][thread_id]:
363 if range_name not in mean_range_info:
364 mean_range_info[range_name] = (
365 [],
366 [],
367 ) # Mean lists for CPU and GPU time info
368
369 cpu_time = all_range_info[process_id][thread_id][
370 range_name
371 ].cpu_time_info.duration_ms
372 gpu_time = all_range_info[process_id][thread_id][
373 range_name
374 ].gpu_time_info.duration_ms
375
376 mean_range_info[range_name][0].append(cpu_time)
377 mean_range_info[range_name][1].append(gpu_time)
378
379 # Replace the list with the mean value.
380 for range_name in mean_range_info:
381 if len(mean_range_info[range_name]):
382 cpu_ranges_list = mean_range_info[range_name][0]
383 gpu_ranges_list = mean_range_info[range_name][1]
384
385 avg_cpu_time = round(sum(cpu_ranges_list) / len(cpu_ranges_list), 4)
386 avg_gpu_time = round(sum(gpu_ranges_list) / len(gpu_ranges_list), 4)
387
388 mean_range_info[range_name] = (avg_cpu_time, avg_gpu_time)
389 else:
390 mean_range_info[range_name] = (0, 0)
391
392 return mean_range_info
393
394
395class NumpyValuesEncoder(json.JSONEncoder):

Callers 1

benchmark_scriptFunction · 0.85

Calls 1

roundFunction · 0.85

Tested by

no test coverage detected