test_3_new.py 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. import tempfile
  2. import time
  3. import pandas as pd
  4. import pickle
  5. import subprocess
  6. from imc_utils.pps_e36311a import PPS_E36311A
  7. from imc_utils.smu_b2902a import SMU_B2902A
  8. from imc_utils.build_config.cortex_m33 import BuildConfigM33
  9. from imc_utils.build_config.test_env import TestEnv
  10. from imc_utils.serial_watch import SerialWatcher
  11. WORKSPACE_ROOT = "/home/ybkim/workspace/imc/imc_freertos_app_m33"
  12. NVM_RESET_BIN = f"{WORKSPACE_ROOT}/imc/utils/nvm_reset.elf"
  13. OPENOCD_SCRIPT = f"{WORKSPACE_ROOT}/imc_freertos_app_m33.cfg"
  14. def measure_original(benchmark, pps, smu):
  15. config = get_default_build_config(benchmark)
  16. print("\n===== A. measure original program =====\n")
  17. target_current = 0.1
  18. currs = measure(config, pps, smu, target_current, repeat=2)
  19. with open(f"output/test_1_{benchmark}_original.pickle", "wb") as f:
  20. pickle.dump(currs, f)
  21. def measure_ckpt(benchmark, pps, smu: SMU_B2902A):
  22. config = get_default_build_config(benchmark)
  23. config.insert_compiler_checkpoints = False
  24. config.use_checkpoint_pass_counter = False
  25. config.split_loop = False
  26. config.enable_adaptive_loop_pass_count = False
  27. config.use_checkpoint_voltage_check = False
  28. config.max_loop_ids = 15
  29. config.enable_dynamic_checkpoint = True
  30. config.print_init_time = True
  31. # print("\n===== B. measure checkpoint-instrumented program =====\n")
  32. target_current = 0.02
  33. wait_s = 3
  34. repeat = 1
  35. records = measure(config, pps, smu, target_current, repeat=repeat, wait_before_start_s=wait_s)
  36. records = pd.DataFrame(records)
  37. with open(f"output/test_3_{benchmark}_ckpt.pickle", "wb") as f:
  38. pickle.dump(records, f)
  39. def measure(config, pps: PPS_E36311A, smu: SMU_B2902A, target_current, repeat=1, wait_before_start_s=0):
  40. env = program_with_config(config, pps, smu)
  41. benchmark = config.bench_name
  42. pps.set_voltage(3.3, 1)
  43. pps.set_current(target_current, 1)
  44. watcher = SerialWatcher(benchmark, 1)
  45. wait_time = 5
  46. print(" > start board execution")
  47. env.resume_board(terminate=True, verbose=False)
  48. print(f" > wait for {wait_before_start_s} secs")
  49. time.sleep(wait_before_start_s)
  50. print(" > power off")
  51. pps.output_off(1)
  52. print(f" > wait for {wait_time} secs")
  53. time.sleep(wait_time)
  54. print(" > power on\n")
  55. pps.output_on(1)
  56. records = watcher.run()
  57. print("\n > measure finished")
  58. return records
  59. def main():
  60. pps = PPS_E36311A()
  61. smu = SMU_B2902A(voltage=0, use_external_power=True)
  62. smu.setup_sense()
  63. smu.set_current_limit(0.1)
  64. benchmarks = ["vFFT", "vCrc", "vAes", "vSha"]
  65. # benchmarks = ["vFFT"]
  66. total = len(benchmarks)
  67. for i, benchmark in enumerate(benchmarks):
  68. print(f"\n+++ ({i+1}/{total}) {benchmark} +++")
  69. # measure_original(benchmark, pps, smu)
  70. measure_ckpt(benchmark, pps, smu)
  71. def program_with_config(config, pps, smu):
  72. env = TestEnv(WORKSPACE_ROOT, NVM_RESET_BIN, OPENOCD_SCRIPT)
  73. smu.power_on()
  74. pps.set_voltage(3.3, 1)
  75. pps.set_current(0.1, 1)
  76. pps.output_on(1)
  77. time.sleep(1)
  78. print(" > build and program binary")
  79. with tempfile.TemporaryDirectory() as build_dir:
  80. binary = env.build_binary(config, build_dir, redirect_file=subprocess.DEVNULL)
  81. env.clear_nvm_and_load_binary(binary, resume=False, verbose=False)
  82. print(" > program finished")
  83. return env
  84. def get_bench_repeat_count(benchmark):
  85. d = {
  86. "vFFT": 10,
  87. "vConv2d": 15000,
  88. "vCrc": 1000,
  89. "vBasicMath": 1,
  90. "vSha": 40,
  91. "vStringSearch": 3000,
  92. "vAes": 1300,
  93. "vMatMul": 20000,
  94. }
  95. return d[benchmark]
  96. def get_default_build_config(benchmark):
  97. config = BuildConfigM33()
  98. config.bench_name = benchmark
  99. config.insert_compiler_checkpoints = False
  100. config.enable_extension = True
  101. config.use_checkpoint_pass_counter = False
  102. config.use_checkpoint_voltage_check = False
  103. config.bench_infinite_loop = True
  104. config.print_recovery_message = True
  105. config.split_loop = False
  106. config.enable_static_loop_pass_count = False
  107. config.enable_adaptive_loop_pass_count = False
  108. config.print_stats = False
  109. config.custom_unroll = False
  110. config.enable_dynamic_checkpoint = False
  111. config.bench_repeat_count = get_bench_repeat_count(benchmark)
  112. return config
  113. if __name__ == "__main__":
  114. main()