Skip to content

Commit 00a5dec

Browse files
committed
Rework FakeRAM integration for in-tree FakeRAM2.0
- Remove external FakeRAM MODULE.bazel git_override and patches - Implement PDK-agnostic ORFS generator backend in tools/FakeRAM2.0/orfs/ - Add unit test with mocking in tools/FakeRAM2.0/orfs_generate_test.py - Update flow/scripts/memories/gen_memories.py to use --orfs_backend - Declare Bazel BUILD targets for FakeRAM2.0 and wire into //flow:memories_tests Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
1 parent 91913b2 commit 00a5dec

13 files changed

Lines changed: 271 additions & 222 deletions

File tree

‎.bazelignore‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
tools/
1+
tools/OpenROAD/
2+
tools/yosys/
3+
tools/kepler-formal/
4+
tools/codespace/
25
dependencies/
36
docker/
47
etc/

‎MODULE.bazel‎

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -131,16 +131,7 @@ git_override(
131131
remote = "https://github.com/povik/yosys-slang.git",
132132
)
133133

134-
bazel_dep(name = "fakeram", dev_dependency = True)
135-
git_override(
136-
module_name = "fakeram",
137-
commit = "6f62c655952b683cda679d80850cb557cc3c262e",
138-
patch_strip = 1,
139-
patches = [
140-
"//patches/fakeram:0001-Add-ORFS-ASAP7-backend.patch",
141-
],
142-
remote = "https://github.com/The-OpenROAD-Project/FakeRAM2.0.git",
143-
)
134+
144135

145136
# --- Extensions ---
146137

‎flow/BUILD‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ py_library(
197197
),
198198
imports = ["scripts/memories"],
199199
data = [
200-
"@fakeram//:all_files",
200+
"//tools/FakeRAM2.0:all_files",
201201
"platforms/asap7/fakeram.json",
202202
],
203203
)
@@ -222,6 +222,10 @@ MEMORIES_TESTS = [
222222
name = "memories_" + test,
223223
srcs = ["scripts/memories/{}.py".format(test)],
224224
main = "scripts/memories/{}.py".format(test),
225+
data = [
226+
"//tools/FakeRAM2.0:all_files",
227+
"platforms/asap7/fakeram.json",
228+
],
225229
deps = [
226230
":memories",
227231
":memories_test_fixtures",
@@ -230,5 +234,7 @@ MEMORIES_TESTS = [
230234

231235
test_suite(
232236
name = "memories_tests",
233-
tests = ["memories_" + test for test in MEMORIES_TESTS],
237+
tests = ["memories_" + test for test in MEMORIES_TESTS] + [
238+
"//tools/FakeRAM2.0:fakeram_tests",
239+
],
234240
)

‎flow/scripts/memories/gen_memories.py‎

Lines changed: 42 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,16 @@ def find_fakeram_run() -> str | None:
3636
fakeram_run = os.environ.get("FAKERAM_RUN_PY")
3737
if fakeram_run and os.path.isfile(fakeram_run):
3838
return fakeram_run
39-
runfiles_dir = os.environ.get("RUNFILES_DIR")
40-
if runfiles_dir:
41-
for p in Path(runfiles_dir).rglob("run.py"):
42-
if "fakeram" in p.parts[-2]:
43-
return str(p)
39+
40+
base_dir = Path(schema.__file__).parent
41+
for p in [base_dir] + list(base_dir.parents):
42+
candidate = p / "tools" / "FakeRAM2.0" / "run.py"
43+
sys.stderr.write(
44+
f"DEBUG: checking candidate {candidate} (exists: {candidate.is_file()})\n"
45+
)
46+
if candidate.is_file():
47+
return str(candidate)
48+
4449
return None
4550

4651

@@ -52,10 +57,6 @@ def run(
5257
json_path: Path,
5358
yosys_json: Path | None = None,
5459
) -> int:
55-
if platform != "asap7":
56-
sys.stderr.write(f"gen_memories: unsupported platform {platform}\n")
57-
return 1
58-
5960
if yosys_json and yosys_json.is_file():
6061
found = detect.scan_yosys_json(yosys_json)
6162
else:
@@ -84,30 +85,51 @@ def run(
8485
return 1
8586

8687
fakeram_tech_cfg = (
87-
Path(__file__).resolve().parent.parent.parent
88+
Path(schema.__file__).parent.parent.parent
8889
/ "platforms"
8990
/ platform
9091
/ "fakeram.json"
9192
)
9293
if not fakeram_tech_cfg.is_file() and os.environ.get("RUNFILES_DIR"):
93-
runfiles_candidates = list(
94-
Path(os.environ["RUNFILES_DIR"]).rglob("fakeram.json")
94+
candidate = (
95+
Path(os.environ["RUNFILES_DIR"])
96+
/ "_main"
97+
/ "flow"
98+
/ "platforms"
99+
/ platform
100+
/ "fakeram.json"
95101
)
96-
if runfiles_candidates:
97-
fakeram_tech_cfg = runfiles_candidates[0]
102+
if candidate.is_file():
103+
fakeram_tech_cfg = candidate
98104

105+
if not fakeram_tech_cfg.is_file():
106+
sys.stderr.write(
107+
f"gen_memories: platform {platform} has no fakeram.json configuration file\n"
108+
)
109+
return 1
110+
111+
python_bin = str(Path(sys.executable).resolve())
99112
cmd = [
100-
sys.executable,
113+
python_bin,
101114
fakeram_run,
102-
"--orfs_asap7_backend",
115+
"--orfs_backend",
116+
"--tech_config",
117+
str(fakeram_tech_cfg),
103118
"--output_dir",
104119
str(out_dir),
120+
str(json_path),
105121
]
106-
if fakeram_tech_cfg.is_file():
107-
cmd.extend(["--tech_config", str(fakeram_tech_cfg)])
108-
cmd.append(str(json_path))
109122

110-
subprocess.check_call(cmd)
123+
env = dict(os.environ)
124+
for k in ("__PYTHON_ELIDE_PRE__", "PYTHONPATH"):
125+
env.pop(k, None)
126+
127+
res = subprocess.run(cmd, capture_output=True, text=True, env=env)
128+
if res.returncode != 0:
129+
sys.stderr.write(
130+
f"gen_memories: FakeRAM failed with returncode {res.returncode}:\n{res.stderr}\n{res.stdout}\n"
131+
)
132+
raise subprocess.CalledProcessError(res.returncode, cmd, res.stdout, res.stderr)
111133

112134
for mem in sorted(memories, key=lambda m: m.name):
113135
verdict = "macro" if mem.idiomatic else "flops"

‎flow/scripts/memories/gen_memories_test.py‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,16 @@
1414
if "TEST_WORKSPACE" in os.environ:
1515
# Bazel test execution
1616
runfiles_dir = Path(os.environ.get("RUNFILES_DIR", "."))
17-
candidates = list(runfiles_dir.glob("**/fakeram*/run.py")) + list(
18-
runfiles_dir.glob("**/run.py")
17+
candidates = [
18+
p
19+
for p in runfiles_dir.rglob("run.py")
20+
if "FakeRAM2.0" in p.parts or "fakeram" in p.parts
21+
]
22+
fakeram_run = (
23+
candidates[0]
24+
if candidates
25+
else runfiles_dir / "_main" / "tools" / "FakeRAM2.0" / "run.py"
1926
)
20-
fakeram_run = candidates[0] if candidates else runfiles_dir / "fakeram" / "run.py"
2127
else:
2228
fakeram_run = (
2329
Path(__file__).resolve().parent.parent.parent.parent

‎patches/fakeram/0001-Add-ORFS-ASAP7-backend.patch‎

Lines changed: 0 additions & 182 deletions
This file was deleted.

‎patches/fakeram/BUILD.bazel‎

Lines changed: 0 additions & 3 deletions
This file was deleted.

‎tools/FakeRAM2.0/BUILD‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
filegroup(
2+
name = "all_files",
3+
srcs = glob(["**/*"]),
4+
visibility = ["//visibility:public"],
5+
)
6+
7+
py_library(
8+
name = "fakeram_lib",
9+
srcs = glob(
10+
["**/*.py"],
11+
exclude = ["*_test.py"],
12+
),
13+
imports = ["."],
14+
visibility = ["//visibility:public"],
15+
)
16+
17+
py_test(
18+
name = "orfs_generate_test",
19+
srcs = ["orfs_generate_test.py"],
20+
main = "orfs_generate_test.py",
21+
imports = ["."],
22+
deps = [":fakeram_lib"],
23+
)
24+
25+
test_suite(
26+
name = "fakeram_tests",
27+
tests = [":orfs_generate_test"],
28+
)

‎tools/FakeRAM2.0/orfs/__init__.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# ORFS FakeRAM package

0 commit comments

Comments
 (0)