22
22
from openvino .tools .benchmark .utils .statistics_report import StatisticsReport , JsonStatisticsReport , CsvStatisticsReport , \
23
23
averageCntReport , detailedCntReport
24
24
25
+ def get_peak_memory_usage ():
26
+ if os .name == "posix" :
27
+ with open ("/proc/self/status" , "r" ) as f :
28
+ for line in f :
29
+ if line .startswith ("VmPeak:" ):
30
+ return int (line .split ()[1 ]) # The value in KB
31
+ raise RuntimeError ("VmPeak attribute not found. Unable to determine peak memory usage." )
32
+
33
+ return None
34
+
35
+ def log_memory_usage (logger , start_mem_usage , end_mem_usage , action_name ):
36
+ if start_mem_usage is None or end_mem_usage is None :
37
+ return
38
+
39
+ logger .info (f"Start of { action_name } memory usage: Peak { start_mem_usage } KB" )
40
+ logger .info (f"End of { action_name } memory usage: Peak { end_mem_usage } KB" )
41
+ logger .info (f"Load model ram used { end_mem_usage - start_mem_usage } KB" )
42
+
25
43
def parse_and_check_command_line ():
26
44
def arg_not_empty (arg_value ,empty_value ):
27
45
return not arg_value is None and not arg_value == empty_value
@@ -346,10 +364,15 @@ def set_nthreads_pin(property_name, property_value):
346
364
# --------------------- 7. Loading the model to the device -------------------------------------------------
347
365
next_step ()
348
366
367
+ start_mem_usage = get_peak_memory_usage ()
349
368
start_time = datetime .utcnow ()
369
+
350
370
compiled_model = benchmark .core .compile_model (args .path_to_model , benchmark .device , device_config )
371
+
351
372
duration_ms = f"{ (datetime .utcnow () - start_time ).total_seconds () * 1000 :.2f} "
373
+ end_mem_usage = get_peak_memory_usage ()
352
374
logger .info (f"Compile model took { duration_ms } ms" )
375
+ log_memory_usage (logger , start_mem_usage , end_mem_usage , "compilation" )
353
376
if statistics :
354
377
statistics .add_parameters (StatisticsReport .Category .EXECUTION_RESULTS ,
355
378
[
@@ -408,11 +431,15 @@ def set_nthreads_pin(property_name, property_value):
408
431
409
432
# --------------------- 7. Loading the model to the device -------------------------------------------------
410
433
next_step ()
434
+ start_mem_usage = get_peak_memory_usage ()
411
435
start_time = datetime .utcnow ()
412
- compiled_model = benchmark .core .compile_model (model , benchmark .device , device_config )
413
436
437
+ compiled_model = benchmark .core .compile_model (model , benchmark .device , device_config )
438
+
414
439
duration_ms = f"{ (datetime .utcnow () - start_time ).total_seconds () * 1000 :.2f} "
440
+ end_mem_usage = get_peak_memory_usage ()
415
441
logger .info (f"Compile model took { duration_ms } ms" )
442
+ log_memory_usage (logger , start_mem_usage , end_mem_usage , "compilation" )
416
443
if statistics :
417
444
statistics .add_parameters (StatisticsReport .Category .EXECUTION_RESULTS ,
418
445
[
@@ -432,10 +459,15 @@ def set_nthreads_pin(property_name, property_value):
432
459
# --------------------- 7. Loading the model to the device -------------------------------------------------
433
460
next_step ()
434
461
462
+ start_mem_usage = get_peak_memory_usage ()
435
463
start_time = datetime .utcnow ()
464
+
436
465
compiled_model = benchmark .core .import_model (args .path_to_model , benchmark .device , device_config )
466
+
437
467
duration_ms = f"{ (datetime .utcnow () - start_time ).total_seconds () * 1000 :.2f} "
468
+ end_mem_usage = get_peak_memory_usage ()
438
469
logger .info (f"Import model took { duration_ms } ms" )
470
+ log_memory_usage (logger , start_mem_usage , end_mem_usage , "import" )
439
471
if statistics :
440
472
statistics .add_parameters (StatisticsReport .Category .EXECUTION_RESULTS ,
441
473
[
0 commit comments