run_expr_3.py 3.6 KB

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