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

Separate magic gds streamout to two step def to mag then mag to gds #211

Closed
wants to merge 2 commits into from
Closed
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
1 change: 1 addition & 0 deletions openlane/flows/classic.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ class Classic(SequentialFlow):
OpenROAD.RCX,
OpenROAD.STAPostPNR,
OpenROAD.IRDropReport,
Magic.StreamOutMag,
Magic.StreamOut,
KLayout.StreamOut,
Magic.WriteLEF,
Expand Down
55 changes: 0 additions & 55 deletions openlane/scripts/magic/def/mag_gds.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -44,58 +44,3 @@ select top cell
cellname filepath $::env(DESIGN_NAME) $::env(STEP_DIR)

save


# mark the incoming cell defs as readonly so that their
# GDS data gets copied verbatim
gds readonly true
gds rescale false

if { $::env(MAGIC_GDS_POLYGON_SUBCELLS) } {
gds polygon subcells true
}
# # Can be obtained from the PDK's .mag files.
# set gds_files_in $::env(CELL_GDS)
# foreach gds_file $gds_files_in {
# puts "> gds read $gds_file"
# gds read $gds_file
# }
if { [info exist ::env(MACRO_GDS_FILES)] } {
set gds_files_in $::env(MACRO_GDS_FILES)
foreach gds_file $gds_files_in {
puts "> gds read $gds_file"
gds read $gds_file
}
}
if { [info exist ::env(EXTRA_GDS_FILES)] } {
set gds_files_in $::env(EXTRA_GDS_FILES)
foreach gds_file $gds_files_in {
puts "> gds read $gds_file"
gds read $gds_file
}
}

load $::env(DESIGN_NAME)

# if { $::env(MAGIC_GDS_FLATTEN) } {
# puts "Flattening cell"
# flatten top cell
# }

select top cell

if { $::env(MAGIC_DISABLE_CIF_INFO) } {
cif *hier write disable
cif *array write disable
}

gds nodatestamp yes

if { $::env(MAGIC_GDS_ALLOW_ABSTRACT) } {
gds abstract allow
}

gds write $::env(SAVE_MAG_GDS)
puts "\[INFO\] GDS Write Complete"

exit 0
27 changes: 27 additions & 0 deletions openlane/scripts/magic/mag/mag_gds.tcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Copyright 2020 Efabless Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
drc off
crashbackups stop

source $::env(SCRIPTS_DIR)/magic/mag/read.tcl

select top cell
expand
if { $::env(MAGIC_DISABLE_CIF_INFO) } {
cif *hier write disable
cif *array write disable
}
gds write $::env(SAVE_MAG_GDS)

exit 0
25 changes: 25 additions & 0 deletions openlane/scripts/magic/mag/read.tcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
addpath [file dirname $::env(CURRENT_MAG)]

if { [info exist ::env(MACRO_GDS_FILES)] } {
set gds_files_in $::env(MACRO_GDS_FILES)
foreach gds_file $gds_files_in {
puts "> load $gds_file"
load [file rootname [file rootname [file tail $gds_file]]]
property LEFview true
property GDS_FILE [string map {" " ""} $gds_file]
property GDS_START 0
}
}
if { [info exist ::env(EXTRA_GDS_FILES)] } {
set gds_files_in $::env(EXTRA_GDS_FILES)
foreach gds_file $gds_files_in {
puts "> load $gds_file"
load [file rootname [file rootname [file tail $gds_file]]]
property LEFview true
property GDS_FILE [string map {" " ""} $gds_file]
property GDS_START 0
}
}

load [file rootname [file tail $::env(CURRENT_MAG)]] -dereference
puts "> load [file rootname [file tail $::env(CURRENT_MAG)]] -dereference"
85 changes: 53 additions & 32 deletions openlane/steps/magic.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,24 +41,12 @@ class MagicStep(TclStep):
'A flag to enable polygon subcells in magic for gds read potentially speeding up magic. From magic docs: "Put non-Manhattan polygons. This prevents interations with other polygons on the same plane and so reduces tile splitting."',
default=False,
),
Variable(
"MAGIC_GDS_ALLOW_ABSTRACT",
bool,
"A flag to allow abstract view of macros when processing GDS files in Magic.",
default=False,
),
Variable(
"MAGIC_DEF_NO_BLOCKAGES",
bool,
"If set to true, blockages in DEF files are ignored. Otherwise, they are read as sheets of metal by Magic.",
default=True,
),
Variable(
"MAGIC_INCLUDE_GDS_POINTERS",
bool,
"A flag to choose whether to include GDS pointers in the generated mag files or not.",
default=False,
),
Variable(
"MAGICRC",
Path,
Expand Down Expand Up @@ -158,20 +146,17 @@ def run(self, state_in: State, **kwargs) -> Tuple[ViewsUpdate, MetricsUpdate]:


@Step.factory.register()
class StreamOut(MagicStep):
class StreamOutMag(MagicStep):
"""
Converts DEF views into GDSII streams using Magic.
Converts DEF views into MAG streams using Magic.

If ``PRIMARY_SIGNOFF_TOOL`` is set to ``"magic"``, both GDS and MAG_GDS
will be updated, and if set to another tool, only ``MAG_GDS`` will be
updated.
"""

id = "Magic.StreamOut"
name = "GDSII Stream Out (Magic)"
id = "Magic.StreamOutMag"
name = "Mag Stream Out (Magic)"

inputs = [DesignFormat.DEF]
outputs = [DesignFormat.GDS, DesignFormat.MAG_GDS, DesignFormat.MAG]
outputs = [DesignFormat.MAG]

config_vars = MagicStep.config_vars + [
Variable(
Expand All @@ -186,13 +171,6 @@ class StreamOut(MagicStep):
"A flag to move the layout such that it's origin in the lef generated by magic is 0,0.",
default=False,
),
Variable(
"MAGIC_DISABLE_CIF_INFO",
bool,
"A flag to disable writing Caltech Intermediate Format (CIF) hierarchy and subcell array information to the GDSII file.",
default=True,
deprecated_names=["MAGIC_DISABLE_HIER_GDS"],
),
# Variable(
# "MAGIC_GDS_FLATTEN",
# bool,
Expand All @@ -211,6 +189,53 @@ def run(self, state_in: State, **kwargs) -> Tuple[ViewsUpdate, MetricsUpdate]:

magic_log_dir = os.path.join(self.step_dir, "magic.log")

views_updates, metrics_updates = super().run(
state_in,
env=env,
log_to=magic_log_dir,
**kwargs,
)
views_updates[DesignFormat.MAG] = Path(
os.path.join(self.step_dir, f"{self.config['DESIGN_NAME']}.mag")
)

return views_updates, metrics_updates


@Step.factory.register()
class StreamOut(MagicStep):
"""
Converts MAG views into GDSII streams using Magic.

If ``PRIMARY_SIGNOFF_TOOL`` is set to ``"magic"``, both GDS and MAG_GDS
will be updated, and if set to another tool, only ``MAG_GDS`` will be
updated.
"""

id = "Magic.StreamOut"
name = "GDSII Stream Out (Magic)"

inputs = [DesignFormat.MAG]
outputs = [DesignFormat.MAG, DesignFormat.MAG_GDS]

config_vars = MagicStep.config_vars + [
Variable(
"MAGIC_DISABLE_CIF_INFO",
bool,
"A flag to disable writing Caltech Intermediate Format (CIF) hierarchy and subcell array information to the GDSII file.",
default=True,
deprecated_names=["MAGIC_DISABLE_HIER_GDS"],
),
]

def get_script_path(self):
return os.path.join(get_script_dir(), "magic", "mag", "mag_gds.tcl")

def run(self, state_in: State, **kwargs) -> Tuple[ViewsUpdate, MetricsUpdate]:
kwargs, env = self.extract_env(kwargs)

magic_log_dir = os.path.join(self.step_dir, "magic.log")

views_updates, metrics_updates = super().run(
state_in,
env=env,
Expand All @@ -223,12 +248,8 @@ def run(self, state_in: State, **kwargs) -> Tuple[ViewsUpdate, MetricsUpdate]:
shutil.copy(magic_gds_out, gds_path)
views_updates[DesignFormat.GDS] = Path(gds_path)

views_updates[DesignFormat.MAG] = Path(
os.path.join(self.step_dir, f"{self.config['DESIGN_NAME']}.mag")
)

for line in open(magic_log_dir, encoding="utf8"):
if "Calma output error" in line:
if "File may be incompletely written." in line:
raise StepError("Magic GDS was written with errors.")

return views_updates, metrics_updates
Expand Down
Loading