run_expr_3.py 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. import tempfile
  2. import time
  3. import pickle
  4. import pandas as pd
  5. from imc_utils.pps_e36311a import PPS_E36311A
  6. from imc_utils.smu_b2902a import SMU_B2902A
  7. from imc_utils.build_config.cortex_m33 import BuildConfigM33
  8. from imc_utils.build_config.test_env import TestEnv
  9. from imc_utils.serial_watch import SerialWatcher
  10. WORKSPACE_ROOT = "/home/ybkim/workspace/imc/imc_freertos_app_m33"
  11. NVM_RESET_BIN = f"{WORKSPACE_ROOT}/imc/utils/nvm_reset.elf"
  12. OPENOCD_SCRIPT = f"{WORKSPACE_ROOT}/imc_freertos_app_m33.cfg"
  13. use_smu = False
  14. def get_build_config(benchmark, config_name):
  15. config = get_default_build_config()
  16. config.bench_name = benchmark
  17. bench_repeat_count = config.bench_repeat_count_small[benchmark]
  18. config.bench_repeat_count = bench_repeat_count
  19. if config_name == "pass_count":
  20. config.use_checkpoint_pass_counter = True
  21. # config.checkpoint_pass_count = config.pass_count_10ms[benchmark]
  22. # config.checkpoint_pass_count = config.pass_count_400ms[benchmark]
  23. # config.checkpoint_pass_count = config.pass_count_167ms[benchmark]
  24. config.checkpoint_pass_count = config.pass_count_154ms[benchmark]
  25. if config_name == "adaptive":
  26. config.use_checkpoint_voltage_check = True
  27. config.split_loop = True
  28. config.enable_adaptive_loop_pass_count = True
  29. config.max_loop_ids = 15
  30. config.loop_opt_debug = False
  31. if config_name == "unroll":
  32. config.use_checkpoint_voltage_check = True
  33. config.custom_unroll = True
  34. return config
  35. def main():
  36. pps = PPS_E36311A()
  37. if use_smu:
  38. volt = 3.3
  39. smu = SMU_B2902A(voltage=3.3)
  40. config = get_default_build_config()
  41. benchmarks = [
  42. "vBasicMath",
  43. "vCrc",
  44. "vFFT",
  45. "vSha",
  46. "vStringSearch",
  47. "vMatMul",
  48. "vConv2d",
  49. "vAes",
  50. ]
  51. benchmarks = [
  52. # "vCrc",
  53. # "vSha",
  54. "vBasicMath",
  55. # "vMatMul"
  56. ]
  57. configs = ["pass_count", "adaptive", "unroll"]
  58. # configs = ["adaptive"]
  59. total_iterations = 20
  60. target_current_limit = 0.015
  61. for benchmark in benchmarks:
  62. for config_name in configs:
  63. all_records = []
  64. config = get_build_config(benchmark, config_name)
  65. if use_smu:
  66. smu.set_current_limit(0.1)
  67. smu.power_on()
  68. else:
  69. pps.set_voltage(3.3, 1)
  70. pps.set_current(0.1, 1)
  71. pps.output_on(1)
  72. env = TestEnv(WORKSPACE_ROOT, NVM_RESET_BIN, OPENOCD_SCRIPT)
  73. with tempfile.TemporaryDirectory() as build_dir:
  74. binary = env.build_binary(config, build_dir)
  75. env.clear_nvm_and_load_binary(binary, resume=False)
  76. if use_smu:
  77. smu.set_current_limit(target_current_limit)
  78. else:
  79. pps.set_current(target_current_limit, 1)
  80. time.sleep(1)
  81. env.resume_board(terminate=True)
  82. watcher = SerialWatcher(benchmark, total_iterations)
  83. records = watcher.run()
  84. for record in records:
  85. record.update(
  86. {
  87. # "loop_pass_count": loop_pass_count,
  88. }
  89. )
  90. all_records.append(record)
  91. df = pd.DataFrame(all_records)
  92. columns = ["bench_name", "time_taken", "recovery", "stats", "is_correct"]
  93. print(df[columns])
  94. save_records(benchmark, config_name, df)
  95. if use_smu:
  96. smu.power_off()
  97. else:
  98. pps.output_off(1)
  99. def get_default_build_config():
  100. config = BuildConfigM33()
  101. config.insert_compiler_checkpoints = True
  102. config.enable_extension = True
  103. config.use_checkpoint_pass_counter = False
  104. config.use_checkpoint_voltage_check = False
  105. config.bench_infinite_loop = True
  106. config.print_recovery_message = True
  107. config.split_loop = False
  108. config.enable_static_loop_pass_count = False
  109. config.enable_adaptive_loop_pass_count = False
  110. config.print_stats = True
  111. config.custom_unroll = False
  112. config.loop_opt_debug = False
  113. return config
  114. def save_records(bench_name, config_name, df):
  115. with open(f"output/{config_name}/{bench_name}.pickle", "wb") as f:
  116. pickle.dump(df, f)
  117. if __name__ == "__main__":
  118. main()