Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Autotuner] - Tunable variables check #2452

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions docs/user/FlowVariables.md
Original file line number Diff line number Diff line change
Expand Up @@ -319,5 +319,4 @@ configuration file.
- [SYNTH_ARGS](#SYNTH_ARGS)
- [TAP_CELL_NAME](#TAP_CELL_NAME)
- [TECH_LEF](#TECH_LEF)
- [USE_FILL](#USE_FILL)

luarss marked this conversation as resolved.
Show resolved Hide resolved
- [USE_FILL](#USE_FILL)
11 changes: 10 additions & 1 deletion flow/scripts/variables.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ GENERATE_ARTIFACTS_ON_FAILURE:
use a lot of memory, this allows inspecting results on a laptop for
a build that ran on a server.
default: 0

TNS_END_PERCENT:
description: >
Default TNS_END_PERCENT value for post CTS timing repair.
Expand Down Expand Up @@ -56,6 +55,7 @@ SKIP_INCREMENTAL_REPAIR:
Skip incremental repair in global route.
stages:
- grt
tunable: false
DETAILED_METRICS:
description: >
If set, then calls report_metrics prior to repair operations in the CTS
Expand All @@ -75,6 +75,7 @@ CORE_UTILIZATION:
The core utilization percentage (0-100).
stages:
- floorplan
tunable: 1
CORE_AREA:
description: >
The core area specified as a list of lower-left and upper-right corners in microns
Expand Down Expand Up @@ -264,6 +265,7 @@ GUI_TIMING:
be quite time consuming. Useful to disable when investigating non-timing
aspects like floorplan, placement, routing, etc.
default: 1
tunable: 1
FILL_CELLS:
description: >
Fill cells are used to fill empty sites. If not set or empty, fill cell insertion is skipped.
Expand All @@ -278,13 +280,15 @@ CELL_PAD_IN_SITES_GLOBAL_PLACEMENT:
stages:
- place
- floorplan
tunable: 1
CELL_PAD_IN_SITES_DETAIL_PLACEMENT:
description: >
Cell padding on both sides in site widths to ease routability in detail placement.
stages:
- place
- cts
- grt
tunable: 1
PLACE_PINS_ARGS:
description: >
Arguments to place_pins
Expand All @@ -301,6 +305,7 @@ PLACE_DENSITY:
PLACE_DENSITY_LB_ADDON:
description: >
Check the lower boundary of the PLACE_DENSITY and add PLACE_DENSITY_LB_ADDON if it exists.
tunable: 1
REPAIR_PDN_VIA_LAYER:
description: >
Remove power grid vias which generate DRC violations after detailed routing.
Expand Down Expand Up @@ -511,13 +516,15 @@ CORE_ASPECT_RATIO:
is undefined.
stages:
- floorplan
tunable: 1
CORE_MARGIN:
description: >
The margin between the core area and die area, in multiples of SITE heights.
The margin is applied to each side. This variable is ignored if `CORE_UTILIZATION`
is undefined.
stages:
- floorplan
tunable: 1
DIE_AREA:
description: >
The die area specified as a list of lower-left and upper-right corners in microns
Expand Down Expand Up @@ -559,11 +566,13 @@ CTS_CLUSTER_DIAMETER:
Maximum diameter (in microns) of sink cluster. Default 20.
stages:
- cts
tunable: 1
CTS_CLUSTER_SIZE:
description: >
Maximum number of sinks per cluster. Default 50.
stages:
- cts
tunable: 1
CTS_SNAPSHOT:
description: >
Creates ODB/SDC files prior to clock net and setup/hold repair.
Expand Down
1 change: 1 addition & 0 deletions tools/AutoTuner/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ tensorboard>=2.14.0,<=2.16.2
protobuf==3.20.3
SQLAlchemy==1.4.17
urllib3<=1.26.15
pyyaml==6.0.1
58 changes: 18 additions & 40 deletions tools/AutoTuner/src/autotuner/distributed.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import glob
import subprocess
import random
import yaml
from datetime import datetime
from multiprocessing import cpu_count
from subprocess import run
Expand Down Expand Up @@ -360,42 +361,22 @@ def read_tune_pbt(name, this):
return config, sdc_file, fr_file


def parse_flow_variables():
def parse_tunable_variables():
"""
Parse the flow variables from source
- Code: Makefile `vars` target output

Parse the tunable variables from variables.yaml
TODO: Tests.

Output:
- flow_variables: set of flow variables
"""
cur_path = os.path.dirname(os.path.realpath(__file__))

# first, generate vars.tcl
makefile_path = os.path.join(cur_path, "../../../../flow/")
initial_path = os.path.abspath(os.getcwd())
os.chdir(makefile_path)
result = subprocess.run(["make", "vars", f"PLATFORM={args.platform}"])
if result.returncode != 0:
print(f"[ERROR TUN-0018] Makefile failed with error code {result.returncode}.")
sys.exit(1)
if not os.path.exists("vars.tcl"):
print(f"[ERROR TUN-0019] Makefile did not generate vars.tcl.")
sys.exit(1)
os.chdir(initial_path)

# for code parsing, you need to parse from both scripts and vars.tcl file.
pattern = r"(?:::)?env\((.*?)\)"
files = glob.glob(os.path.join(cur_path, "../../../../flow/scripts/*.tcl"))
files.append(os.path.join(cur_path, "../../../../flow/vars.tcl"))
variables = set()
for file in files:
with open(file) as fp:
matches = re.findall(pattern, fp.read())
for match in matches:
for variable in match.split("\n"):
variables.add(variable.strip().upper())
vars_path = os.path.join(cur_path, "../../../../flow/scripts/variables.yaml")

# Read from variables.yaml and get variables with tunable = 1
with open(vars_path) as file:
try:
result = yaml.safe_load(file)
except yaml.YAMLError as exc:
print("[ERROR TUN-0018] Error parsing variables.yaml.")
sys.exit(1)
variables = {key for key, value in result.items() if value.get("tunable", 0) == 1}
return variables


Expand All @@ -406,7 +387,7 @@ def parse_config(config, path=os.getcwd()):
options = ""
sdc = {}
fast_route = {}
flow_variables = parse_flow_variables()
flow_variables = parse_tunable_variables()
for key, value in config.items():
# Keys that begin with underscore need special handling.
if key.startswith("_"):
Expand All @@ -424,15 +405,12 @@ def parse_config(config, path=os.getcwd()):
"[WARNING TUN-0013] Non-flatten the designs are not "
"fully supported, ignoring _SYNTH_FLATTEN parameter."
)
# Default case is VAR=VALUE
else:
# FIXME there is no robust way to get this metainformation from
# ORFS about the variables, so disable this code for now.

# Default case is VAR=VALUE
# Sanity check: ignore all flow variables that are not tunable
# if key not in flow_variables:
# print(f"[ERROR TUN-0017] Variable {key} is not tunable.")
# sys.exit(1)
if key in flow_variables:
print(f"[ERROR TUN-0017] Variable {key} is not tunable.")
sys.exit(1)
options += f" {key}={value}"
if bool(sdc):
write_sdc(sdc, path)
Expand Down
Loading