def test_run_benchmark_sensitivity_analysis(): env = "llvm-v0" reward = "IrInstructionCountO3" benchmarks = ["cbench-v1/crc32"] FLAGS.unparse_flags() FLAGS(["argv0", f"--env={env}"]) with tempfile.TemporaryDirectory() as tmp: tmp = Path(tmp) run_benchmark_sensitivity_analysis( benchmarks=benchmarks, rewards_path=tmp / "rewards.txt", runtimes_path=tmp / "runtimes.txt", reward=reward, num_trials=2, min_steps=3, max_steps=5, nproc=1, ) assert (tmp / "rewards.txt").is_file() assert (tmp / "runtimes.txt").is_file() run_sensitivity_analysis_eval( rewards_path=tmp / "rewards.txt", runtimes_path=tmp / "runtimes.txt", )
def test_run_action_sensitivity_analysis(): actions = [0, 1] env = "llvm-v0" reward = "IrInstructionCountO3" benchmark = "cbench-v1/crc32" FLAGS.unparse_flags() FLAGS(["argv0", f"--env={env}", f"--benchmark={benchmark}"]) with tempfile.TemporaryDirectory() as tmp: tmp = Path(tmp) run_action_sensitivity_analysis( actions=actions, rewards_path=tmp / "rewards.txt", runtimes_path=tmp / "runtimes.txt", reward_space=reward, num_trials=2, max_warmup_steps=5, nproc=1, ) assert (tmp / "rewards.txt").is_file() assert (tmp / "runtimes.txt").is_file() run_sensitivity_analysis_eval( rewards_path=tmp / "rewards.txt", runtimes_path=tmp / "runtimes.txt", )
def test_run_random_walk_smoke_test(): FLAGS.unparse_flags() FLAGS(["argv0"]) with capture_output() as out: with compiler_gym.make("llvm-autophase-ic-v0") as env: env.benchmark = "cbench-v1/crc32" run_random_walk(env=env, step_count=5) print(out.stdout) # Note the ".*" before and after the step count to ignore the shell # formatting. assert re.search(r"Completed .*5.* steps in ", out.stdout)
def test_tune_smoke_test(search: str, gcc_bin: str, capsys, tmpdir: Path): tmpdir = Path(tmpdir) flags = [ "argv0", "--seed=0", f"--output_dir={tmpdir}", f"--gcc_bin={gcc_bin}", "--gcc_benchmark=benchmark://chstone-v0/aes", f"--search={search}", "--pop_size=3", "--gcc_search_budget=6", ] sys.argv = flags FLAGS.unparse_flags() FLAGS(flags) tune.main([]) out, _ = capsys.readouterr() assert "benchmark://chstone-v0/aes" in out assert (tmpdir / "results.csv").is_file()