Skip to content

Commit e15157e

Browse files
committed
Implementando suporte ao fluxo do OpenRoad
1 parent 43edd6d commit e15157e

File tree

10 files changed

+427
-200
lines changed

10 files changed

+427
-200
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,4 +182,5 @@ repositories.txt
182182
work-obj93.cf
183183
rvx.txt
184184
execution_trace.txt
185-
blink2/
185+
blink2/
186+
demo/

constraints/openroad.sdc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
set clk_name main_clk
2+
set clk_port clk
3+
set clk_ports_list [list $clk_port]
4+
set clk_period 10
5+
set input_delay 0.46
6+
set output_delay 0.11
7+
create_clock [get_ports $clk_port] -name $clk_name -period $clk_period

core/__init__.py

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import os
2+
import re
3+
import csv
4+
import json
5+
import subprocess
6+
from core.log import print_blue, print_red, print_yellow, print_green
7+
from typing import Any, Dict, List, Optional
8+
from jinja2 import Environment, FileSystemLoader, Template
9+
from abc import ABC, abstractmethod
10+
11+
12+
# Diretórios principais
13+
CORE_DIR: str = os.path.dirname(os.path.abspath(__file__))
14+
TEMPLATES_DIR: str = os.path.normpath(
15+
os.path.join(CORE_DIR, '..', 'templates')
16+
)
17+
CONSTRAINTS_DIR: str = os.path.normpath(
18+
os.path.join(CORE_DIR, '..', 'constraints')
19+
)
20+
21+
22+
def write_template_to_file(
23+
env: Environment,
24+
template_name: str,
25+
context: Dict[str, Any],
26+
filename: str,
27+
) -> str:
28+
template: Template = env.get_template(template_name)
29+
output: str = template.render(context)
30+
with open(filename, 'w') as f:
31+
f.write(output)
32+
return filename
33+
34+
35+
def run_cmd(command: List[str], cwd: Optional[str] = None) -> None:
36+
print_yellow(f"Running command: {' '.join(command)}")
37+
subprocess.run(command, cwd=cwd, check=True)
38+
39+
40+
# -------------------------
41+
# Classe base para flows
42+
# -------------------------
43+
class ImplementationFlow(ABC):
44+
def __init__(
45+
self,
46+
technology: str,
47+
project_files: List[str],
48+
constraint_file: str,
49+
top_module: str,
50+
env: Environment,
51+
) -> None:
52+
self.technology: str = technology
53+
self.project_files: List[str] = project_files
54+
self.constraint_file: str = constraint_file
55+
self.top_module: str = top_module
56+
self.env: Environment = env
57+
58+
@abstractmethod
59+
def generate_project(self) -> None:
60+
pass
61+
62+
@abstractmethod
63+
def run_tool(self) -> None:
64+
pass
65+
66+
@abstractmethod
67+
def clean(self) -> None:
68+
pass
69+
70+
@abstractmethod
71+
def report(self, report_path: str = 'reports') -> None:
72+
pass
73+
74+
def run(self) -> None:
75+
self.generate_project()
76+
self.run_tool()

core/asic.py

Lines changed: 109 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,115 @@
11
import os
2-
import subprocess
32
from core.pdk_defines import DEFINES_BY_PDK, SUPPORTED_PDKS
3+
from core.log import print_blue, print_red, print_yellow, print_green
4+
from core import run_cmd, write_template_to_file
5+
from jinja2 import Environment, FileSystemLoader
6+
from core import ImplementationFlow
7+
from typing import Any, Dict
8+
from core import TEMPLATES_DIR, CONSTRAINTS_DIR
49

510

6-
def run_asic_flow(pdk_name: str, project_files: list[str]) -> None:
7-
pdk_name = pdk_name.lower()
11+
TOOLCHAINS_INSTALL_PATH = {
12+
'openroad': os.getenv('OPENROAD_INSTALL_PATH', '/eda/asic/OpenROAD-flow-scripts/'),
13+
}
14+
15+
16+
# -------------------------
17+
# OpenRoad Flow
18+
# -------------------------
19+
class OpenRoadFlow(ImplementationFlow):
20+
def generate_project(self) -> None:
21+
print_blue(f"Running OpenRoad flow for PDK: '{self.technology}'")
22+
23+
constraints: str = (
24+
f'{CONSTRAINTS_DIR}/openroad.sdc'
25+
if self.constraint_file == 'default'
26+
else self.constraint_file
27+
)
28+
29+
context: Dict[str, Any] = {
30+
'design_name': self.top_module,
31+
'verilog_files': self.project_files,
32+
'sdc_file': constraints,
33+
'design_nickname': self.top_module,
34+
'platform': self.technology,
35+
'core_utilization': 5,
36+
'place_density': 0.10,
37+
'synth_hdl_frontend': 'slang',
38+
'synth_hierarchical': False,
39+
'synth_min_keep_size': 0,
40+
'additional_lefs': False,
41+
'additional_lef_files': DEFINES_BY_PDK[self.technology].get(
42+
'additional_lef_files', []
43+
),
44+
'additional_libs': False,
45+
'additional_lib_files': DEFINES_BY_PDK[self.technology].get(
46+
'additional_lib_files', []
47+
),
48+
}
49+
50+
write_template_to_file(self.env, 'openroad.j2', context, 'openroad.mk')
51+
print_green(
52+
f"OpenRoad project files generated for '{self.technology}' PDK."
53+
)
54+
55+
def run_tool(self) -> None:
56+
openroad_path = TOOLCHAINS_INSTALL_PATH.get('openroad', '')
57+
if not openroad_path or not os.path.exists(openroad_path):
58+
raise EnvironmentError(
59+
'OpenRoad toolchain path is not set or does not exist.'
60+
)
61+
62+
openroad_makefile_path = os.path.join(openroad_path, 'flow/Makefile')
63+
64+
run_cmd(
65+
[
66+
'make',
67+
f'--file={openroad_makefile_path}',
68+
'DESIGN_CONFIG=openroad.mk',
69+
]
70+
)
71+
72+
def clean(self) -> None:
73+
run_cmd(['rm', '-rf', 'build', 'reports', '*.jou', '*.log', '*.bit'])
874

75+
def report(self, report_path: str = 'reports') -> None:
76+
pass
77+
78+
79+
def run_asic_flow(
80+
pdk_name: str,
81+
project_files: list[str],
82+
constraint_file: str = 'default',
83+
top_module: str = 'processorci_top',
84+
get_reports: bool = False,
85+
clean: bool = False,
86+
report_path: str = 'reports',
87+
) -> None:
88+
89+
pdk_name = pdk_name.lower()
990
if pdk_name not in SUPPORTED_PDKS:
10-
raise ValueError(f"PDK '{pdk_name}' is not supported.")
91+
raise ValueError(
92+
f"PDK '{pdk_name}' is not supported. Supported PDKs: {SUPPORTED_PDKS}"
93+
)
94+
95+
env: Environment = Environment(
96+
loader=FileSystemLoader(TEMPLATES_DIR),
97+
trim_blocks=True,
98+
lstrip_blocks=True,
99+
)
100+
101+
flow = OpenRoadFlow(
102+
technology=pdk_name,
103+
project_files=project_files,
104+
constraint_file=constraint_file,
105+
top_module=top_module,
106+
env=env,
107+
)
108+
109+
flow.run()
110+
111+
if get_reports:
112+
flow.report(report_path=report_path)
113+
114+
if clean:
115+
flow.clean()

0 commit comments

Comments
 (0)