Skip to content

Commit cd230dc

Browse files
luarssvvbandeira
andauthored
[AutoTuner] Add distributed.py ref file checks + Tests (#2068)
* Fix for distributed.py todo ref file check * Fix requirements * Fix black * Only run ref file check once. Signed-off-by: Song Luar <[email protected]> Co-authored-by: Vitor Bandeira <[email protected]>
1 parent 4b6001d commit cd230dc

File tree

6 files changed

+225
-3
lines changed

6 files changed

+225
-3
lines changed

flow/designs/asap7/gcd/autotuner.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,5 +64,5 @@
6464
],
6565
"step": 1
6666
},
67-
"_FR_FILE_PATH": ""
67+
"_FR_FILE_PATH": "fastroute.tcl"
6868
}

flow/test/test_helper.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,11 @@ if [ $RUN_AUTOTUNER -eq 1 ]; then
111111
echo "Running Autotuner smoke sweep test"
112112
python3 -m unittest tools.AutoTuner.test.smoke_test_sweep.${PLATFORM}SweepSmokeTest.test_sweep
113113

114+
echo "Running Autotuner ref file test (only once)"
115+
if [ "$PLATFORM" == "asap7" ] && [ "$DESIGN" == "gcd" ]; then
116+
python3 -m unittest tools.AutoTuner.test.ref_file_check.RefFileCheck.test_files
117+
fi
118+
114119
echo "Running Autotuner smoke algorithm & evaluation test"
115120
python3 -m unittest tools.AutoTuner.test.smoke_test_algo_eval.${PLATFORM}AlgoEvalSmokeTest.test_algo_eval
116121
fi

tools/AutoTuner/src/autotuner/distributed.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,10 @@ def read_config(file_name):
209209
"""
210210

211211
def read(path):
212+
# if file path does not exist, return empty string
213+
print(os.path.abspath(path))
214+
if not os.path.isfile(os.path.abspath(path)):
215+
return ""
212216
with open(os.path.abspath(path), "r") as file:
213217
ret = file.read()
214218
return ret
@@ -442,7 +446,10 @@ def write_sdc(variables, path):
442446
"""
443447
Create a SDC file with parameters for current tuning iteration.
444448
"""
445-
# TODO: handle case where the reference file does not exist
449+
# Handle case where the reference file does not exist
450+
if SDC_ORIGINAL == "":
451+
print("[ERROR TUN-0020] No SDC reference file provided.")
452+
sys.exit(1)
446453
new_file = SDC_ORIGINAL
447454
for key, value in variables.items():
448455
if key == "CLK_PERIOD":
@@ -481,7 +488,10 @@ def write_fast_route(variables, path):
481488
"""
482489
Create a FastRoute Tcl file with parameters for current tuning iteration.
483490
"""
484-
# TODO: handle case where the reference file does not exist
491+
# Handle case where the reference file does not exist (asap7 doesn't have reference)
492+
if FR_ORIGINAL == "" and args.platform != "asap7":
493+
print("[ERROR TUN-0021] No FastRoute Tcl reference file provided.")
494+
sys.exit(1)
485495
layer_cmd = "set_global_routing_layer_adjustment"
486496
new_file = FR_ORIGINAL
487497
for key, value in variables.items():
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
{
2+
"_SDC_FILE_PATH": "../../../../flow/designs/asap7/gcd/constraint.sdc",
3+
"_SDC_CLK_PERIOD": {
4+
"type": "float",
5+
"minmax": [
6+
50,
7+
1000
8+
],
9+
"step": 0
10+
},
11+
"CORE_UTILIZATION": {
12+
"type": "int",
13+
"minmax": [
14+
5,
15+
100
16+
],
17+
"step": 1
18+
},
19+
"CORE_ASPECT_RATIO": {
20+
"type": "float",
21+
"minmax": [
22+
0.5,
23+
2.0
24+
],
25+
"step": 0
26+
},
27+
"CORE_MARGIN": {
28+
"type": "int",
29+
"minmax": [
30+
2,
31+
2
32+
],
33+
"step": 0
34+
},
35+
"CELL_PAD_IN_SITES_GLOBAL_PLACEMENT": {
36+
"type": "int",
37+
"minmax": [
38+
0,
39+
5
40+
],
41+
"step": 1
42+
},
43+
"CELL_PAD_IN_SITES_DETAIL_PLACEMENT": {
44+
"type": "int",
45+
"minmax": [
46+
0,
47+
5
48+
],
49+
"step": 1
50+
},
51+
"_FR_LAYER_ADJUST": {
52+
"type": "float",
53+
"minmax": [
54+
0.1,
55+
0.3
56+
],
57+
"step": 0
58+
},
59+
"PLACE_DENSITY_LB_ADDON": {
60+
"type": "float",
61+
"minmax": [
62+
0.0,
63+
0.99
64+
],
65+
"step": 0
66+
},
67+
"CTS_CLUSTER_SIZE": {
68+
"type": "int",
69+
"minmax": [
70+
10,
71+
200
72+
],
73+
"step": 1
74+
},
75+
"CTS_CLUSTER_DIAMETER": {
76+
"type": "int",
77+
"minmax": [
78+
20,
79+
400
80+
],
81+
"step": 1
82+
},
83+
"_FR_FILE_PATH": ""
84+
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
{
2+
"_SDC_FILE_PATH": "",
3+
"_SDC_CLK_PERIOD": {
4+
"type": "float",
5+
"minmax": [
6+
50,
7+
1000
8+
],
9+
"step": 0
10+
},
11+
"CORE_UTILIZATION": {
12+
"type": "int",
13+
"minmax": [
14+
5,
15+
100
16+
],
17+
"step": 1
18+
},
19+
"CORE_ASPECT_RATIO": {
20+
"type": "float",
21+
"minmax": [
22+
0.5,
23+
2.0
24+
],
25+
"step": 0
26+
},
27+
"CORE_MARGIN": {
28+
"type": "int",
29+
"minmax": [
30+
2,
31+
2
32+
],
33+
"step": 0
34+
},
35+
"CELL_PAD_IN_SITES_GLOBAL_PLACEMENT": {
36+
"type": "int",
37+
"minmax": [
38+
0,
39+
5
40+
],
41+
"step": 1
42+
},
43+
"CELL_PAD_IN_SITES_DETAIL_PLACEMENT": {
44+
"type": "int",
45+
"minmax": [
46+
0,
47+
5
48+
],
49+
"step": 1
50+
},
51+
"_FR_LAYER_ADJUST": {
52+
"type": "float",
53+
"minmax": [
54+
0.1,
55+
0.3
56+
],
57+
"step": 0
58+
},
59+
"PLACE_DENSITY_LB_ADDON": {
60+
"type": "float",
61+
"minmax": [
62+
0.0,
63+
0.99
64+
],
65+
"step": 0
66+
},
67+
"CTS_CLUSTER_SIZE": {
68+
"type": "int",
69+
"minmax": [
70+
10,
71+
200
72+
],
73+
"step": 1
74+
},
75+
"CTS_CLUSTER_DIAMETER": {
76+
"type": "int",
77+
"minmax": [
78+
20,
79+
400
80+
],
81+
"step": 1
82+
},
83+
"_FR_FILE_PATH" : ""
84+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import unittest
2+
import subprocess
3+
import os
4+
5+
cur_dir = os.path.dirname(os.path.abspath(__file__))
6+
src_dir = os.path.join(cur_dir, "../src/autotuner")
7+
orfs_dir = os.path.join(cur_dir, "../../../flow")
8+
os.chdir(src_dir)
9+
10+
11+
class RefFileCheck(unittest.TestCase):
12+
# only test 1 platform/design.
13+
platform = "asap7"
14+
design = "gcd"
15+
16+
def setUp(self):
17+
configs = [
18+
"../../test/files/no_sdc_ref.json",
19+
"../../test/files/no_fr_ref.json",
20+
]
21+
self.commands = [
22+
f"python3 distributed.py"
23+
f" --design {self.design}"
24+
f" --platform {self.platform}"
25+
f" --config {c}"
26+
f" tune --samples 1"
27+
for c in configs
28+
]
29+
30+
# Make this a test case
31+
def test_files(self):
32+
for c in self.commands:
33+
out = subprocess.run(c, shell=True)
34+
failed = out.returncode != 0
35+
self.assertTrue(failed)
36+
37+
38+
if __name__ == "__main__":
39+
unittest.main()

0 commit comments

Comments
 (0)