88
99sys .path .append (".." ) # noqa
1010from core .global_config import logger # noqa
11+ from core .standard import get_repeats_from_backend # noqa
1112from utils .device import ( # noqa
1213 get_adb_devices ,
1314 get_target_freq_idx ,
1415 get_cpu_max_freqs ,
1516 get_battery_level ,
17+ get_system_version ,
18+ get_imei ,
1619) # noqa
1720from utils .cmd import run_cmds , run_cmd # noqa
1821from utils .misc import pattern_match , get_file_name # noqa
@@ -33,14 +36,20 @@ def set_config(self, key, value):
3336
3437 def prepare_engine (self ):
3538 logger .info ("==== {} ====" .format (self .prepare_engine .__name__ ))
36- branch = run_cmd ("git branch" )[0 ].replace ("* " , "" )
39+ lookup_branch_name_cmd = "cd {}; git branch" .format (
40+ self .config ["framework_name" ]
41+ )
42+ branch = run_cmd (lookup_branch_name_cmd )[0 ].replace ("* " , "" )
3743 self .config ["framework_repo_branch" ] = branch
3844 logger .info (
3945 "framework_repo_branch:{}" .format (
4046 self .config ["framework_repo_branch" ] # noqa
4147 ) # noqa
4248 )
43- commit_id = run_cmd ("git rev-parse --short HEAD" )[0 ]
49+ lookup_commit_id_cmd = "cd {}; git rev-parse --short HEAD" .format (
50+ self .config ["framework_name" ]
51+ )
52+ commit_id = run_cmd (lookup_commit_id_cmd )[0 ]
4453 self .config ["framework_repo_commit_id" ] = commit_id
4554 logger .info (
4655 "framework_repo_commit_id:{}" .format (
@@ -193,6 +202,16 @@ def prepare_devices(self):
193202 device_serial_num
194203 )
195204
205+ # system version
206+ device_dict [device_serial_num ][
207+ "system_version"
208+ ] = get_system_version ( # noqa
209+ device_serial_num
210+ )
211+
212+ # imie
213+ device_dict [device_serial_num ]["imei" ] = get_imei (device_serial_num ) # noqa
214+
196215 # ro.board.platform, ro.board.chiptype, ro.board.hardware
197216 device_soc_cmd = (
198217 "adb -s {} shell getprop |"
@@ -392,7 +411,9 @@ def run_bench(self):
392411 ], # noqa
393412 "model_dir" : model_dir ,
394413 "backend" : backend ,
395- "repeats" : self .config ["repeats" ],
414+ "repeats" : self .config ["repeats" ](
415+ backend
416+ ), # noqa
396417 "warmup" : self .config ["warmup" ],
397418 "thread_num" : cpu_thread_num ,
398419 "bind_cpu_idx" : device_dict [
@@ -403,13 +424,14 @@ def run_bench(self):
403424 }
404425 )
405426 elif self .config ["framework_name" ] == "ncnn" :
406- # TODO(ysh329): add benchmark dict
407427 bench_cmd = bench_cmd_pattern .format (
408428 ** {
409429 "serial_num" : device_serial_num ,
410430 "device_benchmark_bin" : device_benchmark_bin , # noqa
411431 "model_dir" : model_dir ,
412- "repeats" : self .config ["repeats" ],
432+ "repeats" : self .config ["repeats" ](
433+ backend
434+ ), # noqa
413435 "warmup" : self .config ["warmup" ],
414436 "thread_num" : cpu_thread_num ,
415437 "power_mode" : self .config [
@@ -418,7 +440,6 @@ def run_bench(self):
418440 "gpu_device" : backend ,
419441 }
420442 )
421- pass
422443 cmd_handle = run_cmd (
423444 bench_cmd , wait_interval_sec = 3 # noqa
424445 ) # noqa
@@ -432,7 +453,7 @@ def run_bench(self):
432453 "serial_num" : device_serial_num ,
433454 "platform" : platform ,
434455 "model_name" : model_name ,
435- "repeats" : self .config ["repeats" ],
456+ "repeats" : self .config ["repeats" ]( backend ) ,
436457 "warmup" : self .config ["warmup" ],
437458 "avg" : perf_dict ["avg" ],
438459 "max" : perf_dict ["max" ],
@@ -449,7 +470,13 @@ def run_bench(self):
449470 "battery_level" : device_dict [device_serial_num ][ # noqa
450471 "battery_level"
451472 ],
473+ "system_version" : device_dict [
474+ device_serial_num
475+ ][ # noqa
476+ "system_version"
477+ ],
452478 "cmd" : bench_cmd ,
479+ "imei" : device_dict [device_serial_num ]["imei" ],
453480 }
454481 bench_dict [model_name ].append (bench_record )
455482 logger .info (bench_record )
@@ -471,8 +498,10 @@ def generate_benchmark_summary(self, bench_dict, is_print_summary=True):
471498 "max" ,
472499 "min" ,
473500 "battery_level" ,
501+ "system_version" ,
474502 "repeats" ,
475503 "warmup" ,
504+ "imei" ,
476505 ]
477506 summary_header_str = "," .join (summary_header )
478507 summary = [summary_header_str ]
@@ -500,8 +529,10 @@ def generate_benchmark_summary(self, bench_dict, is_print_summary=True):
500529 record_dict ["max" ],
501530 record_dict ["min" ],
502531 record_dict ["battery_level" ],
532+ record_dict ["system_version" ],
503533 record_dict ["repeats" ],
504534 record_dict ["warmup" ],
535+ record_dict ["imei" ],
505536 ]
506537 elif self .config ["framework_name" ] == "ncnn" :
507538 backend_id_to_str_dict = self .config [
@@ -519,8 +550,10 @@ def generate_benchmark_summary(self, bench_dict, is_print_summary=True):
519550 record_dict ["max" ],
520551 record_dict ["min" ],
521552 record_dict ["battery_level" ],
553+ record_dict ["system_version" ],
522554 record_dict ["repeats" ],
523555 record_dict ["warmup" ],
556+ record_dict ["imei" ],
524557 ]
525558 else :
526559 logger .fatal (
@@ -558,19 +591,29 @@ def parse_benchmark(self, cmd_res):
558591 benchmark ["max" ] = pattern_match (line , "max=" , "ms" , False )
559592 benchmark ["avg" ] = pattern_match (line , "avg=" , "ms" , False )
560593 elif self .config ["framework_name" ] == "ncnn" :
561- pass
562- output_lines = filter (lambda line : "min = " in line , output_lines )
563- output_lines = list (output_lines )
564- logger .debug ("output_lines:\n {}" .format (output_lines ))
565- assert len (output_lines ) == 1
566- line = output_lines [0 ]
567- line = line .split ()
568- logger .debug (line )
569- line = "" .join (line ) + "END"
570- benchmark ["min" ] = pattern_match (line , "min=" , "max" , False )
571- benchmark ["max" ] = pattern_match (line , "max=" , "avg" , False )
572- benchmark ["avg" ] = pattern_match (line , "avg=" , "END" , False )
573- logger .info ("benchmark:{}" .format (benchmark ))
594+ is_no_vulkan = list (
595+ filter (lambda line : "no vulkan device" in line , output_lines )
596+ )
597+ is_no_vulkan = len (is_no_vulkan ) > 0
598+ if is_no_vulkan :
599+ benchmark ["min" ] = 0.0
600+ benchmark ["max" ] = 0.0
601+ benchmark ["avg" ] = 0.0
602+ else :
603+ output_lines = filter (
604+ lambda line : "min = " in line , output_lines
605+ ) # noqa
606+ output_lines = list (output_lines )
607+ logger .debug ("output_lines:\n {}" .format (output_lines ))
608+ assert len (output_lines ) == 1
609+ line = output_lines [0 ]
610+ line = line .split ()
611+ logger .debug (line )
612+ line = "" .join (line ) + "END"
613+ benchmark ["min" ] = pattern_match (line , "min=" , "max" , False )
614+ benchmark ["max" ] = pattern_match (line , "max=" , "avg" , False )
615+ benchmark ["avg" ] = pattern_match (line , "avg=" , "END" , False )
616+ logger .info ("benchmark:{}" .format (benchmark ))
574617 assert len (benchmark ) != 0
575618 return benchmark
576619
@@ -629,6 +672,7 @@ def tearDown(self):
629672 ) # noqa
630673 )
631674
675+ """
632676 def test_tnn_engine(self):
633677 from core.global_config import create_config
634678
@@ -659,7 +703,9 @@ def test_tnn_engine(self):
659703 summary_str = "\n ".join(summary_list)
660704 logger.info("summary_str:\n {}".format(summary_str))
661705 return 0
706+ #"""
662707
708+ # """
663709 def test_ncnn_engine (self ):
664710 from core .global_config import create_config
665711
@@ -671,18 +717,18 @@ def test_ncnn_engine(self):
671717 ncnn .set_config (
672718 "benchmark_platform" , ["android-armv8" , "android-armv7" ] # noqa
673719 )
674- ncnn .set_config (
675- "support_backend" , ["0" ]
676- ) # ["-1", "0"]) # -1: cpu, 0: gpu # noqa
720+ ncnn .set_config ("support_backend" , ["0" ]) # -1: cpu, 0: gpu # noqa
677721 ncnn .set_config ("cpu_thread_num" , [1 , 2 , 4 ])
678- ncnn .config ["repeats" ] = 10
722+ ncnn .config ["repeats" ] = (
723+ lambda backend : 100 if backend == "VULKAN" else 1000
724+ ) # noqa
679725 ncnn .config ["warmup" ] = 2
680726 model_dict = ncnn .prepare_models ()
681727
682728 device_dict = ncnn .prepare_devices ()
683729 if len (device_dict ) == 0 :
684730 logger .error ("no device found" )
685- # return 0
731+ return 0
686732 config_dict = ncnn .set_config ("model_dict" , model_dict )
687733 config_dict = ncnn .set_config ("device_dict" , device_dict )
688734
@@ -696,6 +742,48 @@ def test_ncnn_engine(self):
696742 summary_str = "\n " .join (summary_list )
697743 logger .info ("summary_str:\n {}" .format (summary_str ))
698744 return 0
745+ # """
746+
747+ def test_mnn_engine (self ):
748+ pass
749+ """
750+ from core.global_config import create_config
751+
752+ framework_name = "mnn"
753+ config_dict = create_config(framework_name)
754+ config_dict["work_dir"] = os.getcwd() + "/../mnn"
755+
756+ mnn = Engine(config_dict)
757+ mnn.set_config(
758+ "benchmark_platform", ["android-armv8", "android-armv7"] # noqa
759+ )
760+
761+ mnn.set_config(
762+ "support_backend", ["-1", "0"]
763+ ) # ["-1", "0"]) # -1: cpu, 0: gpu # noqa
764+ mnn.set_config("cpu_thread_num", [1, 2, 4])
765+ mnn.config["repeats"] = 10
766+ mnn.config["warmup"] = 2
767+ model_dict = mnn.prepare_models()
768+
769+ device_dict = mnn.prepare_devices()
770+ if len(device_dict) == 0:
771+ logger.error("no device found")
772+ return 0
773+ config_dict = mnn.set_config("model_dict", model_dict)
774+ config_dict = mnn.set_config("device_dict", device_dict)
775+
776+ mnn.prepare_models_for_devices()
777+ mnn.prepare_benchmark_assets_for_devices()
778+
779+ bench_dict = mnn.run_bench()
780+ summary_list = mnn.generate_benchmark_summary(bench_dict)
781+ mnn.write_list_to_file(summary_list)
782+
783+ summary_str = "\n ".join(summary_list)
784+ logger.info("summary_str:\n {}".format(summary_str))
785+ """
786+ return 0
699787
700788
701789if __name__ == "__main__" :
0 commit comments