From ba652d0728ad505765e526e9742ca09320d1655c Mon Sep 17 00:00:00 2001 From: Eryk Szpotanski Date: Mon, 21 Oct 2024 14:37:21 +0200 Subject: [PATCH] tools: Autotuner: Update smoke tests to use AutoTuner as module Signed-off-by: Eryk Szpotanski --- tools/AutoTuner/test/smoke_test_algo_eval.py | 42 +++++-------------- .../test/smoke_test_sample_iteration.py | 30 ++++--------- tools/AutoTuner/test/smoke_test_sweep.py | 31 ++++---------- tools/AutoTuner/test/smoke_test_tune.py | 27 +++--------- 4 files changed, 34 insertions(+), 96 deletions(-) diff --git a/tools/AutoTuner/test/smoke_test_algo_eval.py b/tools/AutoTuner/test/smoke_test_algo_eval.py index a695489b48..d5c0a1d4a5 100644 --- a/tools/AutoTuner/test/smoke_test_algo_eval.py +++ b/tools/AutoTuner/test/smoke_test_algo_eval.py @@ -3,9 +3,7 @@ import os cur_dir = os.path.dirname(os.path.abspath(__file__)) -src_dir = os.path.join(cur_dir, "../src/autotuner") orfs_dir = os.path.join(cur_dir, "../../../flow") -os.chdir(src_dir) class BaseAlgoEvalSmokeTest(unittest.TestCase): @@ -22,7 +20,7 @@ def setUp(self): _eval = ["default", "ppa-improv"] self.matrix = [(a, e) for a in _algo for e in _eval] self.commands = [ - f"python3 distributed.py" + f"python3 -m autotuner.distributed" f" --design {self.design}" f" --platform {self.platform}" f" --experiment {self.experiment}" @@ -34,23 +32,18 @@ def setUp(self): ] def make_base(self): - os.chdir(orfs_dir) commands = [ - f"make DESIGN_CONFIG=./designs/{self.platform}/{self.design}/config.mk clean_all", - f"make DESIGN_CONFIG=./designs/{self.platform}/{self.design}/config.mk EQUIVALENCE_CHECK=0", - f"make DESIGN_CONFIG=./designs/{self.platform}/{self.design}/config.mk update_metadata_autotuner", + f"make -C {orfs_dir} DESIGN_CONFIG=./designs/{self.platform}/{self.design}/config.mk clean_all", + f"make -C {orfs_dir} DESIGN_CONFIG=./designs/{self.platform}/{self.design}/config.mk EQUIVALENCE_CHECK=0", + f"make -C {orfs_dir} DESIGN_CONFIG=./designs/{self.platform}/{self.design}/config.mk update_metadata_autotuner", ] for command in commands: out = subprocess.run(command, shell=True, check=True) self.assertTrue(out.returncode == 0) - os.chdir(src_dir) - - -class ASAP7AlgoEvalSmokeTest(BaseAlgoEvalSmokeTest): - platform = "asap7" - design = "gcd" def test_algo_eval(self): + if not (self.platform and self.design): + raise unittest.SkipTest("Platform and design have to be defined") # Run `make` to get baseline metrics (metadata-base-ok.json) self.make_base() for command in self.commands: @@ -60,33 +53,20 @@ def test_algo_eval(self): self.assertTrue(successful) +class ASAP7AlgoEvalSmokeTest(BaseAlgoEvalSmokeTest): + platform = "asap7" + design = "gcd" + + class IHPSG13G2AlgoEvalSmokeTest(BaseAlgoEvalSmokeTest): platform = "ihp-sg13g2" design = "gcd" - def test_algo_eval(self): - # Run `make` to get baseline metrics (metadata-base-ok.json) - self.make_base() - for command in self.commands: - print(command) - out = subprocess.run(command, shell=True, check=True) - successful = out.returncode == 0 - self.assertTrue(successful) - class SKY130HDAlgoEvalSmokeTest(BaseAlgoEvalSmokeTest): platform = "sky130hd" design = "gcd" - def test_algo_eval(self): - # Run `make` to get baseline metrics (metadata-base-ok.json) - self.make_base() - for command in self.commands: - print(command) - out = subprocess.run(command, shell=True, check=True) - successful = out.returncode == 0 - self.assertTrue(successful) - if __name__ == "__main__": unittest.main() diff --git a/tools/AutoTuner/test/smoke_test_sample_iteration.py b/tools/AutoTuner/test/smoke_test_sample_iteration.py index f49c22a088..2991eed1aa 100644 --- a/tools/AutoTuner/test/smoke_test_sample_iteration.py +++ b/tools/AutoTuner/test/smoke_test_sample_iteration.py @@ -3,8 +3,6 @@ import os cur_dir = os.path.dirname(os.path.abspath(__file__)) -src_dir = os.path.join(cur_dir, "../src/autotuner") -os.chdir(src_dir) class BaseSampleIterationSmokeTest(unittest.TestCase): @@ -19,7 +17,7 @@ def setUp(self): self.experiment = f"smoke-test-sample-iteration-{self.platform}" self.matrix = [(5, 1), (1, 5), (2, 2), (1, 1)] self.commands = [ - f"python3 distributed.py" + f"python3 -m autotuner.distributed" f" --design {self.design}" f" --platform {self.platform}" f" --experiment {self.experiment}" @@ -28,12 +26,9 @@ def setUp(self): for s, i in self.matrix ] - -class ASAP7SampleIterationSmokeTest(BaseSampleIterationSmokeTest): - platform = "asap7" - design = "gcd" - def test_sample_iteration(self): + if not (self.platform and self.design): + raise unittest.SkipTest("Platform and design have to be defined") for command in self.commands: print(command) out = subprocess.run(command, shell=True, check=True) @@ -41,29 +36,20 @@ def test_sample_iteration(self): self.assertTrue(successful) +class ASAP7SampleIterationSmokeTest(BaseSampleIterationSmokeTest): + platform = "asap7" + design = "gcd" + + class SKY130HDSampleIterationSmokeTest(BaseSampleIterationSmokeTest): platform = "sky130hd" design = "gcd" - def test_sample_iteration(self): - for command in self.commands: - print(command) - out = subprocess.run(command, shell=True, check=True) - successful = out.returncode == 0 - self.assertTrue(successful) - class IHPSG13G2SampleIterationSmokeTest(BaseSampleIterationSmokeTest): platform = "ihp-sg13g2" design = "gcd" - def test_sample_iteration(self): - for command in self.commands: - print(command) - out = subprocess.run(command, shell=True, check=True) - successful = out.returncode == 0 - self.assertTrue(successful) - if __name__ == "__main__": unittest.main() diff --git a/tools/AutoTuner/test/smoke_test_sweep.py b/tools/AutoTuner/test/smoke_test_sweep.py index 7a1b013911..209d2828d2 100644 --- a/tools/AutoTuner/test/smoke_test_sweep.py +++ b/tools/AutoTuner/test/smoke_test_sweep.py @@ -4,8 +4,6 @@ import json cur_dir = os.path.dirname(os.path.abspath(__file__)) -src_dir = os.path.join(cur_dir, "../src/autotuner") -os.chdir(src_dir) class BaseSweepSmokeTest(unittest.TestCase): @@ -13,7 +11,9 @@ class BaseSweepSmokeTest(unittest.TestCase): design = "" def setUp(self): - self.config = "distributed-sweep-example.json" + self.config = os.path.abspath( + os.path.join(cur_dir, "../src/autotuner/distributed-sweep-example.json") + ) # make sure this json only has 1 key called "CTS_CLUSTER_SIZE" and 4 possible values with open(self.config) as f: contents = json.load(f) @@ -31,7 +31,7 @@ def setUp(self): self.jobs = 4 if core >= 4 else core self.experiment = f"smoke-test-sweep-{self.platform}" self.command = ( - "python3 distributed.py" + "python3 -m autotuner.distributed" f" --design {self.design}" f" --platform {self.platform}" f" --experiment {self.experiment}" @@ -41,40 +41,27 @@ def setUp(self): ) def test_sweep(self): - raise NotImplementedError( - "This method needs to be implemented in the derivative classes." - ) + if not (self.platform and self.design): + raise unittest.SkipTest("Platform and design have to be defined") + out = subprocess.run(self.command, shell=True, check=True) + successful = out.returncode == 0 + self.assertTrue(successful) class ASAP7SweepSmokeTest(BaseSweepSmokeTest): platform = "asap7" design = "gcd" - def test_sweep(self): - out = subprocess.run(self.command, shell=True, check=True) - successful = out.returncode == 0 - self.assertTrue(successful) - class SKY130HDSweepSmokeTest(BaseSweepSmokeTest): platform = "sky130hd" design = "gcd" - def test_sweep(self): - out = subprocess.run(self.command, shell=True, check=True) - successful = out.returncode == 0 - self.assertTrue(successful) - class IHPSG13G2SweepSmokeTest(BaseSweepSmokeTest): platform = "ihp-sg13g2" design = "gcd" - def test_sweep(self): - out = subprocess.run(self.command, shell=True, check=True) - successful = out.returncode == 0 - self.assertTrue(successful) - if __name__ == "__main__": unittest.main() diff --git a/tools/AutoTuner/test/smoke_test_tune.py b/tools/AutoTuner/test/smoke_test_tune.py index 9710416745..4ddeafa0cc 100644 --- a/tools/AutoTuner/test/smoke_test_tune.py +++ b/tools/AutoTuner/test/smoke_test_tune.py @@ -3,8 +3,6 @@ import os cur_dir = os.path.dirname(os.path.abspath(__file__)) -src_dir = os.path.join(cur_dir, "../src/autotuner") -os.chdir(src_dir) class BaseTuneSmokeTest(unittest.TestCase): @@ -18,7 +16,7 @@ def setUp(self): ) self.experiment = f"smoke-test-tune-{self.platform}" self.command = ( - "python3 distributed.py" + "python3 -m autotuner.distributed" f" --design {self.design}" f" --platform {self.platform}" f" --experiment {self.experiment}" @@ -27,40 +25,27 @@ def setUp(self): ) def test_tune(self): - raise NotImplementedError( - "This method needs to be implemented in the derivative classes." - ) + if not (self.platform and self.design): + raise unittest.SkipTest("Platform and design have to be defined") + out = subprocess.run(self.command, shell=True, check=True) + successful = out.returncode == 0 + self.assertTrue(successful) class ASAP7TuneSmokeTest(BaseTuneSmokeTest): platform = "asap7" design = "gcd" - def test_tune(self): - out = subprocess.run(self.command, shell=True, check=True) - successful = out.returncode == 0 - self.assertTrue(successful) - class SKY130HDTuneSmokeTest(BaseTuneSmokeTest): platform = "sky130hd" design = "gcd" - def test_tune(self): - out = subprocess.run(self.command, shell=True, check=True) - successful = out.returncode == 0 - self.assertTrue(successful) - class IHPSG13G2TuneSmokeTest(BaseTuneSmokeTest): platform = "ihp-sg13g2" design = "gcd" - def test_tune(self): - out = subprocess.run(self.command, shell=True, check=True) - successful = out.returncode == 0 - self.assertTrue(successful) - if __name__ == "__main__": unittest.main()