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
+ # No Windows support due to the lack of the ‘psutil’ module in the CI infrastructure
34
+ return None
35
+
36
+ def log_memory_usage (logger , start_mem_usage , end_mem_usage , action_name ):
37
+ if start_mem_usage is None or end_mem_usage is None :
38
+ return
39
+
40
+ logger .info (f"Start of { action_name } memory usage: Peak { start_mem_usage } KB" )
41
+ logger .info (f"End of { action_name } memory usage: Peak { end_mem_usage } KB" )
42
+ logger .info (f"Load model ram used { end_mem_usage - start_mem_usage } KB" )
43
+
25
44
def parse_and_check_command_line ():
26
45
def arg_not_empty (arg_value ,empty_value ):
27
46
return not arg_value is None and not arg_value == empty_value
@@ -349,10 +368,15 @@ def set_nthreads_pin(property_name, property_value):
349
368
# --------------------- 7. Loading the model to the device -------------------------------------------------
350
369
next_step ()
351
370
371
+ start_mem_usage = get_peak_memory_usage ()
352
372
start_time = datetime .utcnow ()
373
+
353
374
compiled_model = benchmark .core .compile_model (args .path_to_model , benchmark .device , device_config )
375
+
354
376
duration_ms = f"{ (datetime .utcnow () - start_time ).total_seconds () * 1000 :.2f} "
377
+ end_mem_usage = get_peak_memory_usage ()
355
378
logger .info (f"Compile model took { duration_ms } ms" )
379
+ log_memory_usage (logger , start_mem_usage , end_mem_usage , "compilation" )
356
380
if statistics :
357
381
statistics .add_parameters (StatisticsReport .Category .EXECUTION_RESULTS ,
358
382
[
@@ -411,11 +435,15 @@ def set_nthreads_pin(property_name, property_value):
411
435
412
436
# --------------------- 7. Loading the model to the device -------------------------------------------------
413
437
next_step ()
438
+ start_mem_usage = get_peak_memory_usage ()
414
439
start_time = datetime .utcnow ()
415
- compiled_model = benchmark .core .compile_model (model , benchmark .device , device_config )
416
440
441
+ compiled_model = benchmark .core .compile_model (model , benchmark .device , device_config )
442
+
417
443
duration_ms = f"{ (datetime .utcnow () - start_time ).total_seconds () * 1000 :.2f} "
444
+ end_mem_usage = get_peak_memory_usage ()
418
445
logger .info (f"Compile model took { duration_ms } ms" )
446
+ log_memory_usage (logger , start_mem_usage , end_mem_usage , "compilation" )
419
447
if statistics :
420
448
statistics .add_parameters (StatisticsReport .Category .EXECUTION_RESULTS ,
421
449
[
@@ -435,10 +463,15 @@ def set_nthreads_pin(property_name, property_value):
435
463
# --------------------- 7. Loading the model to the device -------------------------------------------------
436
464
next_step ()
437
465
466
+ start_mem_usage = get_peak_memory_usage ()
438
467
start_time = datetime .utcnow ()
468
+
439
469
compiled_model = benchmark .core .import_model (args .path_to_model , benchmark .device , device_config )
470
+
440
471
duration_ms = f"{ (datetime .utcnow () - start_time ).total_seconds () * 1000 :.2f} "
472
+ end_mem_usage = get_peak_memory_usage ()
441
473
logger .info (f"Import model took { duration_ms } ms" )
474
+ log_memory_usage (logger , start_mem_usage , end_mem_usage , "import" )
442
475
if statistics :
443
476
statistics .add_parameters (StatisticsReport .Category .EXECUTION_RESULTS ,
444
477
[
0 commit comments