-
Notifications
You must be signed in to change notification settings - Fork 4
feat: integrate ecc-sizer timing opt tool #110
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
Open
zhaoxueyan1
wants to merge
3
commits into
main
Choose a base branch
from
integrate-sizer
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| #!/usr/bin/env bash | ||
| # Install ECC-Sizer Bazel build artifacts into the source tree for dev use. | ||
| # Usage: bazel run //bazel/scripts:install_sizer | ||
| # bazel run //bazel/scripts:install_sizer -- --clean | ||
| set -euo pipefail | ||
|
|
||
| WS="${BUILD_WORKSPACE_DIRECTORY:?Must run via: bazel run //bazel/scripts:install_sizer}" | ||
| SIZER_RUNTIME_DIR="${WS}/chipcompiler/tools/ecc_sizer/bin" | ||
| MANIFEST="${SIZER_RUNTIME_DIR}/.install_manifest.txt" | ||
|
|
||
| if [[ "${1:-}" == "--clean" ]]; then | ||
| if [[ ! -f "${MANIFEST}" ]]; then | ||
| echo "Nothing to clean (no install manifest found)." | ||
| exit 0 | ||
| fi | ||
| echo "Cleaning installed ECC-Sizer artifacts..." | ||
| while IFS= read -r file; do | ||
| rm -f "${SIZER_RUNTIME_DIR}/${file}" | ||
| echo " Removed: chipcompiler/tools/ecc_sizer/bin/${file}" | ||
| done < "${MANIFEST}" | ||
| rm -f "${MANIFEST}" | ||
| rmdir "${SIZER_RUNTIME_DIR}" 2>/dev/null || true | ||
| echo "Done." | ||
| exit 0 | ||
| fi | ||
|
|
||
| RF="${RUNFILES_DIR:-${BASH_SOURCE[0]}.runfiles}" | ||
| SIZER_BIN="" | ||
| for arg in "$@"; do | ||
| for candidate_root in "$arg" "${RF}/_main/${arg}" "${RF}/${arg}"; do | ||
| if [[ -f "${candidate_root}" && "$(basename "${candidate_root}")" == "Sizer" ]]; then | ||
| SIZER_BIN="${candidate_root}" | ||
| break 2 | ||
| fi | ||
| if [[ -d "${candidate_root}" ]]; then | ||
| found="$(find "${candidate_root}" -type f -name Sizer -perm /111 -print -quit)" | ||
| if [[ -n "${found}" ]]; then | ||
| SIZER_BIN="${found}" | ||
| break 2 | ||
| fi | ||
| fi | ||
| done | ||
| done | ||
|
|
||
| if [[ -z "${SIZER_BIN}" ]]; then | ||
| echo "ERROR: Could not locate Sizer executable in args: $*" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| echo "Bazel output: ${SIZER_BIN}" | ||
| echo "Installing to: ${SIZER_RUNTIME_DIR}/" | ||
|
|
||
| mkdir -p "${SIZER_RUNTIME_DIR}" | ||
| cp -f --no-preserve=ownership "${SIZER_BIN}" "${SIZER_RUNTIME_DIR}/Sizer" | ||
| chmod +x "${SIZER_RUNTIME_DIR}/Sizer" | ||
| echo "Sizer" > "${MANIFEST}" | ||
| echo "Done. Installed chipcompiler/tools/ecc_sizer/bin/Sizer." | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| from .builder import build_step, build_step_config, build_step_space | ||
| from .runner import run_step | ||
| from .utility import get_sizer_command, get_sizer_root, is_eda_exist | ||
|
|
||
| __all__ = [ | ||
| "build_step", | ||
| "build_step_config", | ||
| "build_step_space", | ||
| "get_sizer_command", | ||
| "get_sizer_root", | ||
| "is_eda_exist", | ||
| "run_step", | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,119 @@ | ||
| from __future__ import annotations | ||
|
|
||
| import os | ||
| import shutil | ||
|
|
||
| from chipcompiler.data import Workspace, WorkspaceStep | ||
| from chipcompiler.tools.ecc import builder as ecc_builder | ||
|
|
||
| from .utility import get_sizer_root | ||
|
|
||
|
|
||
| def build_step( | ||
| workspace: Workspace, | ||
| step_name: str, | ||
| input_def: str, | ||
| input_verilog: str, | ||
| input_db: str | None = None, | ||
| output_def: str | None = None, | ||
| output_verilog: str | None = None, | ||
| output_gds: str | None = None, | ||
| ) -> WorkspaceStep: | ||
| step = ecc_builder.build_step( | ||
| workspace=workspace, | ||
| step_name=step_name, | ||
| input_def=input_def, | ||
| input_verilog=input_verilog, | ||
| input_db=input_db, | ||
| output_def=output_def, | ||
| output_verilog=output_verilog, | ||
| output_gds=output_gds, | ||
| tool="sizer", | ||
| ) | ||
| step.script["sizer_env"] = f"{step.script['dir']}/{workspace.design.name}.env_file" | ||
| step.script["sizer_cmd"] = f"{step.script['dir']}/{workspace.design.name}.cmd_file" | ||
| return step | ||
|
|
||
|
|
||
| def build_step_space(step: WorkspaceStep) -> None: | ||
| ecc_builder.build_step_space(step) | ||
|
|
||
|
|
||
| def _copy_or_seed_template(template: str, target: str, fallback: str) -> None: | ||
| os.makedirs(os.path.dirname(target), exist_ok=True) | ||
| if os.path.exists(template): | ||
| shutil.copy2(template, target) | ||
| return | ||
|
|
||
| with open(target, "w", encoding="utf-8") as file: | ||
| file.write(fallback) | ||
|
|
||
|
|
||
| def _append_lines(path: str, lines: list[str]) -> None: | ||
| with open(path, "a", encoding="utf-8") as file: | ||
| for line in lines: | ||
| if line: | ||
| file.write(f"{line}\n") | ||
|
|
||
|
|
||
| def _sizer_templates() -> tuple[str, str]: | ||
| submit_dir = get_sizer_root() / "submit" | ||
| return str(submit_dir / "env_base_file"), str(submit_dir / "cmd_base_file") | ||
|
|
||
|
|
||
| def _tech_lines(workspace: Workspace) -> list[str]: | ||
| lines = [] | ||
| if workspace.pdk.tech: | ||
| lines.append(f"-lef {workspace.pdk.tech}") | ||
| lines.extend(f"-lef {lef}" for lef in workspace.pdk.lefs) | ||
| lines.extend(f"-lib {lib}" for lib in workspace.pdk.libs) | ||
|
|
||
| tcl_path = get_sizer_root() / "src" / "sizer_os.tcl" | ||
| lines.append(f"-tclFile {tcl_path}") | ||
| return lines | ||
|
|
||
|
|
||
| def _route_layer_lines(workspace: Workspace) -> list[str]: | ||
| bottom = workspace.parameters.data.get("Bottom layer", "") | ||
| top = workspace.parameters.data.get("Top layer", "") | ||
|
|
||
| lines = [] | ||
| if bottom: | ||
| lines.append(f"-min_route_layer {bottom}") | ||
| if top: | ||
| lines.append(f"-max_route_layer {top}") | ||
| return lines | ||
|
|
||
|
|
||
| def build_step_config(workspace: Workspace, step: WorkspaceStep) -> None: | ||
| env_template, cmd_template = _sizer_templates() | ||
| env_path = step.script["sizer_env"] | ||
| cmd_path = step.script["sizer_cmd"] | ||
|
|
||
| _copy_or_seed_template(env_template, env_path, "-num_vt 1\n") | ||
| _copy_or_seed_template(cmd_template, cmd_path, "") | ||
|
|
||
| output_dir = step.data.get(step.name, step.data["dir"]) | ||
| cmd_lines = [ | ||
| "", | ||
| f"-top {workspace.design.top_module or workspace.design.name}", | ||
| f"-def {step.input.get('def', '')}", | ||
| ] | ||
| input_verilog = step.input.get("verilog", "") | ||
| if input_verilog: | ||
| cmd_lines.append(f"-v {input_verilog}") | ||
| if workspace.pdk.sdc: | ||
| cmd_lines.append(f"-sdc {workspace.pdk.sdc}") | ||
| if workspace.pdk.spef: | ||
| cmd_lines.append(f"-spef {workspace.pdk.spef}") | ||
| cmd_lines.extend( | ||
| [ | ||
| f"-outputPath {output_dir}", | ||
| f"-def_out_path {step.output['def']}", | ||
| f"-verilog_out_path {step.output['verilog']}", | ||
| ] | ||
| ) | ||
| cmd_lines.extend(_route_layer_lines(workspace)) | ||
|
|
||
| _append_lines(env_path, _tech_lines(workspace)) | ||
| _append_lines(cmd_path, cmd_lines) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is sizer added to
chipcompiler/tools/ecc_sizer/binas an executable file? I think injecting the executable file path intoget_sizer_commandis a better way to handle it.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Due to the need to distribute ecc cli, it may be necessary to consider building sizer as an independent python wheel or ecc monorepo.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CC @Anillc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be better to build outside the tree and provide the executable by PATH like yosys.