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