From 71596a9d88ff561d5ea6bc0aa37e3ddd4017e853 Mon Sep 17 00:00:00 2001 From: Bram Wasti Date: Mon, 11 Oct 2021 08:03:27 -0700 Subject: [PATCH 1/3] check in code used to generate plots for loop_tool in paper --- examples/run_loop_tool_sweep.py | 46 +++++++++++++++++++++++++++++++++ examples/run_loop_tool_sweep.sh | 30 +++++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 examples/run_loop_tool_sweep.py create mode 100755 examples/run_loop_tool_sweep.sh diff --git a/examples/run_loop_tool_sweep.py b/examples/run_loop_tool_sweep.py new file mode 100644 index 000000000..022510268 --- /dev/null +++ b/examples/run_loop_tool_sweep.py @@ -0,0 +1,46 @@ +import sys + +import compiler_gym + +names = ["toggle_mode", "up", "down", "toggle_thread"] +actions = [3, 0, 1, 3, 0] +base = 1024 * 512 +K = int(sys.argv[1]) * base + +vectorize = int(sys.argv[2]) +run_log = int(sys.argv[3]) +env = compiler_gym.make("loop_tool-v0") +env.reset( + benchmark=env.datasets.benchmark(uri="benchmark://loop_tool-v0/{}".format(K)), + action_space="simple", +) +if vectorize - 1: + vs = [1] * (vectorize - 1) + actions += vs + [0, 1, 0] + vs + [0, 2, 0] +for a in actions: + o = env.step(a) + +if run_log: + env.observation_space = "action_state" + inner = 1 + step = 512 + for i in range(1, step): + o = env.step(1) + inner += 1 + while inner * vectorize < K: + env.observation_space = "loop_tree" + for i in range(step): + if i == step - 1: + env.observation_space = "flops" + o = env.step(1) + inner += 1 + print(f"{K}, {inner}, {vectorize}: {o[0]}", flush=True) + step *= 2 +else: + for i in range(K // (vectorize * 1024)): + env.observation_space = "action_state" + for j in range(1022 if i == 0 else 1023): + o = env.step(1) + env.observation_space = "flops" + o = env.step(1) + print(f"{K}, {(i + 1) * 1024}, {vectorize}: {o[0]}", flush=True) diff --git a/examples/run_loop_tool_sweep.sh b/examples/run_loop_tool_sweep.sh new file mode 100755 index 000000000..ee1ca6438 --- /dev/null +++ b/examples/run_loop_tool_sweep.sh @@ -0,0 +1,30 @@ +#!/bin/bash +set -ve +mkdir -p results + +python run_loop_tool_sweep.py 1 4 1 | tee results/s1_v4_log.txt +python run_loop_tool_sweep.py 1 1 1 | tee results/s1_v1_log.txt + +python run_loop_tool_sweep.py 2 4 1 | tee results/s2_v4_log.txt +python run_loop_tool_sweep.py 2 1 1 | tee results/s2_v1_log.txt + +python run_loop_tool_sweep.py 4 4 1 | tee results/s4_v4_log.txt +python run_loop_tool_sweep.py 4 1 1 | tee results/s4_v1_log.txt + +python run_loop_tool_sweep.py 8 4 1 | tee results/s8_v4_log.txt +python run_loop_tool_sweep.py 8 1 1 | tee results/s8_v1_log.txt + +python run_loop_tool_sweep.py 16 4 1 | tee results/s16_v4_log.txt +python run_loop_tool_sweep.py 16 1 1 | tee results/s16_v1_log.txt + +python run_loop_tool_sweep.py 1 4 0 | tee results/s1_v4_linear.txt +python run_loop_tool_sweep.py 1 1 0 | tee results/s1_v1_linear.txt + +python run_loop_tool_sweep.py 2 4 0 | tee results/s2_v4_linear.txt +python run_loop_tool_sweep.py 2 1 0 | tee results/s2_v1_linear.txt + +python run_loop_tool_sweep.py 4 4 0 | tee results/s4_v4_linear.txt +python run_loop_tool_sweep.py 4 1 0 | tee results/s4_v1_linear.txt + +python run_loop_tool_sweep.py 8 4 0 | tee results/s8_v4_linear.txt +python run_loop_tool_sweep.py 8 1 0 | tee results/s8_v1_linear.txt From e2f5b058ecae90a0b81a4d742d720687c740ac62 Mon Sep 17 00:00:00 2001 From: Chris Cummins Date: Mon, 25 Oct 2021 19:30:34 +0100 Subject: [PATCH 2/3] [examples] Add license header to new sources. --- examples/run_loop_tool_sweep.py | 4 ++++ examples/run_loop_tool_sweep.sh | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/examples/run_loop_tool_sweep.py b/examples/run_loop_tool_sweep.py index 022510268..6f69c2b65 100644 --- a/examples/run_loop_tool_sweep.py +++ b/examples/run_loop_tool_sweep.py @@ -1,3 +1,7 @@ +# Copyright (c) Facebook, Inc. and its affiliates. +# +# This source code is licensed under the MIT license found in the +# LICENSE file in the root directory of this source tree. import sys import compiler_gym diff --git a/examples/run_loop_tool_sweep.sh b/examples/run_loop_tool_sweep.sh index ee1ca6438..0dad73f5b 100755 --- a/examples/run_loop_tool_sweep.sh +++ b/examples/run_loop_tool_sweep.sh @@ -1,4 +1,8 @@ #!/bin/bash +# Copyright (c) Facebook, Inc. and its affiliates. +# +# This source code is licensed under the MIT license found in the +# LICENSE file in the root directory of this source tree. set -ve mkdir -p results From 10f52f642da4adbe9589149e56caa280fdb3fa13 Mon Sep 17 00:00:00 2001 From: Chris Cummins Date: Mon, 25 Oct 2021 19:33:09 +0100 Subject: [PATCH 3/3] [examples] Refactor to `with` syntax. --- examples/run_loop_tool_sweep.py | 62 ++++++++++++++++----------------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/examples/run_loop_tool_sweep.py b/examples/run_loop_tool_sweep.py index 6f69c2b65..05bcf9cb5 100644 --- a/examples/run_loop_tool_sweep.py +++ b/examples/run_loop_tool_sweep.py @@ -13,38 +13,38 @@ vectorize = int(sys.argv[2]) run_log = int(sys.argv[3]) -env = compiler_gym.make("loop_tool-v0") -env.reset( - benchmark=env.datasets.benchmark(uri="benchmark://loop_tool-v0/{}".format(K)), - action_space="simple", -) -if vectorize - 1: - vs = [1] * (vectorize - 1) - actions += vs + [0, 1, 0] + vs + [0, 2, 0] -for a in actions: - o = env.step(a) +with compiler_gym.make("loop_tool-v0") as env: + env.reset( + benchmark=env.datasets.benchmark(uri="benchmark://loop_tool-v0/{}".format(K)), + action_space="simple", + ) + if vectorize - 1: + vs = [1] * (vectorize - 1) + actions += vs + [0, 1, 0] + vs + [0, 2, 0] + for a in actions: + o = env.step(a) -if run_log: - env.observation_space = "action_state" - inner = 1 - step = 512 - for i in range(1, step): - o = env.step(1) - inner += 1 - while inner * vectorize < K: - env.observation_space = "loop_tree" - for i in range(step): - if i == step - 1: - env.observation_space = "flops" + if run_log: + env.observation_space = "action_state" + inner = 1 + step = 512 + for i in range(1, step): o = env.step(1) inner += 1 - print(f"{K}, {inner}, {vectorize}: {o[0]}", flush=True) - step *= 2 -else: - for i in range(K // (vectorize * 1024)): - env.observation_space = "action_state" - for j in range(1022 if i == 0 else 1023): + while inner * vectorize < K: + env.observation_space = "loop_tree" + for i in range(step): + if i == step - 1: + env.observation_space = "flops" + o = env.step(1) + inner += 1 + print(f"{K}, {inner}, {vectorize}: {o[0]}", flush=True) + step *= 2 + else: + for i in range(K // (vectorize * 1024)): + env.observation_space = "action_state" + for j in range(1022 if i == 0 else 1023): + o = env.step(1) + env.observation_space = "flops" o = env.step(1) - env.observation_space = "flops" - o = env.step(1) - print(f"{K}, {(i + 1) * 1024}, {vectorize}: {o[0]}", flush=True) + print(f"{K}, {(i + 1) * 1024}, {vectorize}: {o[0]}", flush=True)