-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathdffram.py
More file actions
executable file
·210 lines (188 loc) · 5.88 KB
/
dffram.py
File metadata and controls
executable file
·210 lines (188 loc) · 5.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
#!/usr/bin/env python3
# -*- coding: utf8 -*-
# SPDX-License-Identifier: Apache-2.0
# Copyright ©2020-2025, The American University in Cairo
# Copyright ©2023 Efabless Corporation
import os
import re
from fnmatch import fnmatch
from decimal import Decimal
import yaml
import cloup
from librelane.common import mkdirp
from librelane.logging import err
from librelane.flows import cloup_flow_opts, Flow
@cloup.command()
@cloup.option("-b", "--building-blocks", default="ram")
@cloup.option(
"-v", "--variant", default=None, help="Use design variants (such as 1RW1R)"
)
@cloup.option(
"-C",
"--clock-period",
"default_clock_period",
default=20,
type=Decimal,
help="Fallback clock period for STA (when unspecified by the platform)",
)
@cloup.option(
"--horizontal-halo",
default=2.5,
type=Decimal,
help="Horizontal halo in µm",
)
@cloup.option(
"--vertical-halo",
default=2.5,
type=Decimal,
help="Vertical halo in µm",
)
@cloup.option(
"-H",
"--min-height",
default=0.0,
type=Decimal,
help="Minimum height in µm",
)
@cloup.option("--latch/--dff", default=True, help="Whether to use latches or dffs")
@cloup_flow_opts(accept_config_files=False)
@cloup.argument("size", default="32x32", nargs=1)
def main(
pdk,
scl,
frm,
to,
skip,
tag,
last_run,
with_initial_state,
size,
building_blocks,
variant,
horizontal_halo,
vertical_halo,
default_clock_period,
min_height,
flow_name,
pdk_root,
latch,
**kwargs,
):
if variant == "DEFAULT":
variant = None
scl = scl or "sky130_fd_sc_hd"
platform = f"{pdk}:{scl}"
bb_dir = os.path.join(".", "models", building_blocks)
if not os.path.isdir(bb_dir):
err(f"Generic building blocks {building_blocks} not found.")
exit(os.EX_NOINPUT)
pdk_dir = os.path.join(".", "platforms", pdk, scl)
if not os.path.isdir(pdk_dir):
err(f"Definitions for platform {platform} not found.")
exit(os.EX_NOINPUT)
block_definitions_used = os.path.join(pdk_dir, "block_definitions.v")
bb_used = os.path.join(bb_dir, "model.v")
platform_config_file = os.path.join(bb_dir, "config.yml")
platform_config = yaml.safe_load(open(platform_config_file))
pin_order_file = os.path.join(bb_dir, "pin_order.cfg")
m = re.match(r"(\d+)x(\d+)", size)
if m is None:
err(f"Invalid RAM size '{size}'.")
exit(os.EX_USAGE)
words = int(m[1])
word_width = int(m[2])
word_width_bytes = word_width // 8
if os.getenv("FORCE_ACCEPT_SIZE") != 1:
if (
words not in platform_config["counts"]
or word_width not in platform_config["widths"]
):
err("Size %s not supported by %s." % (size, building_blocks))
exit(os.EX_USAGE)
if variant not in platform_config["variants"]:
err("Variant %s is unsupported by %s." % (variant, building_blocks))
exit(os.EX_USAGE)
variant_string = ("_%s" % variant) if variant is not None else ""
design_name_template = platform_config["design_name_template"]
design = os.getenv("FORCE_DESIGN_NAME") or design_name_template.format(
**{
"count": words,
"width": word_width,
"width_bytes": word_width_bytes,
"variant": variant_string,
}
)
build_dir = os.path.join(
"build", f"{pdk}-{scl}-{'latch' if latch else 'dff'}", design
)
mkdirp(build_dir)
tech_info_path = os.path.join(".", "platforms", pdk, scl, "tech.yml")
tech_info = yaml.safe_load(open(tech_info_path))
clock_period = default_clock_period
block_clock_periods = tech_info["sta"]["clock_periods"].get(building_blocks)
if block_clock_periods is not None:
for wildcard, period in block_clock_periods.items():
if fnmatch(size, wildcard):
clock_period = period
break
logical_width = word_width_bytes
if building_blocks == "rf":
logical_width = word_width
rt_max_layer = tech_info["metal_layers"]["rt-max-layer"]
TargetFlow = Flow.factory.get(flow_name) or Flow.factory.get("DFFRAMFlow")
dffram_flow = TargetFlow(
{
"DESIGN_NAME": design,
"CLOCK_PORT": "CLK",
"CLOCK_PERIOD": clock_period,
"GPL_CELL_PADDING": 0,
"DPL_CELL_PADDING": 0,
"RT_MAX_LAYER": rt_max_layer,
"GRT_ALLOW_CONGESTION": True,
"PDK": pdk,
"STD_CELL_LIBRARY": scl,
"RAM_SIZE": size,
"BUILDING_BLOCKS": building_blocks,
"VERILOG_FILES": [
block_definitions_used,
bb_used,
],
"SYNTH_ELABORATE_ONLY": True,
"SYNTH_ELABORATE_FLATTEN": True,
"SYNTH_PARAMETERS": [f"WSIZE={logical_width}", f"USE_LATCH={int(latch)}"],
"GRT_REPAIR_ANTENNAS": False,
"MINIMUM_HEIGHT": min_height,
"VERTICAL_HALO": vertical_halo,
"HORIZONTAL_HALO": horizontal_halo,
"CLOCK_PERIOD": clock_period,
# IO Placement
"FP_PIN_ORDER_CFG": pin_order_file,
"FP_IO_VTHICKNESS_MULT": Decimal(2),
"FP_IO_HTHICKNESS_MULT": Decimal(2),
"FP_IO_HEXTEND": Decimal(0),
"FP_IO_VEXTEND": Decimal(0),
"FP_IO_VLENGTH": 2,
"FP_IO_HLENGTH": 2,
# PDN
"FP_PDN_MULTILAYER": False,
},
design_dir=os.path.abspath(build_dir),
pdk_root=pdk_root,
)
final_state = dffram_flow.start(
frm=frm,
to=to,
skip=skip,
tag=tag,
last_run=last_run,
with_initial_state=with_initial_state,
)
mkdirp("products")
final_state.save_snapshot(
os.path.join(
"products",
design,
)
)
if __name__ == "__main__":
main()