Skip to content

Commit

Permalink
Merge pull request #497 from byuccl/speed_up_cmp
Browse files Browse the repository at this point in the history
Speed up Comparison
  • Loading branch information
reillymck authored Aug 21, 2024
2 parents 6f6f4ed + 6335b4f commit 158a5d6
Show file tree
Hide file tree
Showing 23 changed files with 376 additions and 295 deletions.
8 changes: 6 additions & 2 deletions bfasst/flows/vivado_bit_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@
class VivadoBitAnalysis(Flow):
"""Flow to reverse a netlist from a bitstream using x-ray."""

def __init__(self, design, synth_options=""):
def __init__(self, design, synth_options="", logging_level="INFO"):
# pylint: disable=duplicate-code
super().__init__(design)
self.logging_level = logging_level
self.vivado_synth_tool = VivadoSynth(self, design, synth_options=synth_options)
self.vivado_impl_tool = VivadoImpl(
self,
Expand All @@ -30,7 +31,10 @@ def __init__(self, design, synth_options=""):
bitstream=self.vivado_impl_tool.outputs["bitstream"],
)
self.netlist_cleanup_tool = NetlistCleanup(
self, design, rev_netlist=self.xrev_tool.outputs["rev_netlist"]
self,
design,
rev_netlist=self.xrev_tool.outputs["rev_netlist"],
logging_level=self.logging_level,
)
self.netlist_phys_to_logical = NetlistPhysToLogical(
self, design, cleaned_netlist=self.netlist_cleanup_tool.outputs["netlist_cleaned_path"]
Expand Down
4 changes: 3 additions & 1 deletion bfasst/flows/vivado_phys_netlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@
class VivadoPhysNetlist(Flow):
"""Creates a Vivado netlist that has only physical primitives."""

def __init__(self, design, synth_options=""):
def __init__(self, design, synth_options="", logging_level="INFO"):
# pylint: disable=duplicate-code
super().__init__(design)

self.synth_options = VivadoPhysNetlist.add_required_synth_options(synth_options)
self.logging_level = logging_level

self.vivado_synth_tool = VivadoSynth(self, design, synth_options=self.synth_options)
self.vivado_impl_tool = VivadoImpl(
Expand All @@ -28,6 +29,7 @@ def __init__(self, design, synth_options=""):
design,
impl_checkpoint=self.vivado_impl_tool.outputs["impl_dcp"],
impl_edf=self.vivado_impl_tool.outputs["impl_edf"],
logging_level=self.logging_level,
)
# pylint: enable=duplicate-code

Expand Down
6 changes: 4 additions & 2 deletions bfasst/flows/vivado_phys_netlist_cmp.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
class VivadoPhysNetlistCmp(Flow):
"""Structural Comparison of physical netlist and reversed netlist"""

def __init__(self, design, synth_options="", debug=False):
def __init__(self, design, synth_options="", debug=False, logging_level="INFO"):
# pylint: disable=duplicate-code
super().__init__(design)

self.synth_options = VivadoPhysNetlist.add_required_synth_options(synth_options)
self.debug = debug

self.logging_level = logging_level
self.vivado_synth_tool = VivadoSynth(self, design, synth_options=self.synth_options)
self.vivado_impl_tool = VivadoImpl(
self,
Expand All @@ -32,6 +32,7 @@ def __init__(self, design, synth_options="", debug=False):
design,
impl_edf=self.vivado_impl_tool.outputs["impl_edf"],
impl_checkpoint=self.vivado_impl_tool.outputs["impl_dcp"],
logging_level=self.logging_level,
)
self.xray_tool = Xray(
self,
Expand All @@ -46,6 +47,7 @@ def __init__(self, design, synth_options="", debug=False):
golden_netlist=self.phys_netlist_tool.outputs["viv_impl_physical_v"],
rev_netlist=self.xray_tool.outputs["rev_netlist"],
debug=self.debug,
logging_level=self.logging_level,
)
# pylint: enable=duplicate-code

Expand Down
8 changes: 6 additions & 2 deletions bfasst/flows/vivado_structural_error_injection.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@
class VivadoStructuralErrorInjection(Flow):
"""Inject an error into a xrev netlist and run a structural compare to detect it."""

def __init__(self, design, num_runs=100, seed=None, synth_options=""):
def __init__(self, design, num_runs=100, seed=None, synth_options="", logging_level="INFO"):
# pylint: disable=duplicate-code
super().__init__(design)
self.design = design
self.num_runs = num_runs
self.seed = seed
self.logging_level = logging_level
if self.seed is not None:
random.seed(self.seed)

Expand All @@ -41,6 +42,7 @@ def __init__(self, design, num_runs=100, seed=None, synth_options=""):
design,
impl_checkpoint=self.vivado_impl_tool.outputs["impl_dcp"],
impl_edf=self.vivado_impl_tool.outputs["impl_edf"],
logging_level=self.logging_level,
)
self.xrev_tool = Xray(
self,
Expand All @@ -49,7 +51,7 @@ def __init__(self, design, num_runs=100, seed=None, synth_options=""):
bitstream=self.vivado_impl_tool.outputs["bitstream"],
)
self.default_comparison_tool = Structural(self, design)
self.default_injection_tool = ErrorInjector(self, design)
self.default_injection_tool = ErrorInjector(self, design, logging_level)
# pylint: enable=duplicate-code

def create_build_snippets(self):
Expand All @@ -68,6 +70,7 @@ def create_build_snippets(self):
num=i,
multiplier=random_seed_multiplier,
reversed_netlist=self.xrev_tool.outputs["rev_netlist"],
logging_level=self.logging_level,
)

error_injector_tool.create_build_snippets()
Expand All @@ -79,6 +82,7 @@ def create_build_snippets(self):
golden_netlist=error_injector_tool.outputs["corrupt_netlist"],
rev_netlist=self.xrev_tool.outputs["rev_netlist"],
expect_fail=True,
logging_level=self.logging_level,
).create_build_snippets()

def get_top_level_flow_path(self) -> str:
Expand Down
3 changes: 3 additions & 0 deletions bfasst/tools/compare/structural/structural.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def __init__(
rev_netlist=None,
expect_fail=False,
debug=False,
logging_level=None,
):
super().__init__(flow, design)
self.build_path = self.design_build_path / "struct_cmp"
Expand All @@ -24,6 +25,7 @@ def __init__(
self.rev_netlist = rev_netlist
self.expect_fail = expect_fail
self.debug = debug
self.logging_level = logging_level
self._init_outputs()
self.rule_snippet_path = COMPARE_TOOLS_PATH / "structural" / "structural_rules.ninja"

Expand All @@ -37,6 +39,7 @@ def create_build_snippets(self):
"compare_script_path": str(BFASST_UTILS_PATH / "structural.py"),
"expect_fail": "--expect_fail" if self.expect_fail else "",
"debug": "--debug True" if self.debug else "",
"logging_level": f"--logging_level {self.logging_level}",
},
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
build {{ log_path }}: compare {{ netlist_a }} {{ netlist_b }} | {{ compare_script_path }} bfasst/utils/sdn_helpers.py
expect_fail = {{ expect_fail }}
debug = {{ debug }}
logging_level = {{ logging_level }}


2 changes: 1 addition & 1 deletion bfasst/tools/compare/structural/structural_rules.ninja
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
rule compare
command = python bfasst/utils/structural.py --netlists $in --log_path $out $expect_fail $debug
command = python bfasst/utils/structural.py --netlists $in --log_path $out $expect_fail $debug $logging_level
description = structurally compare $in

2 changes: 1 addition & 1 deletion bfasst/tools/impl/vivado_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def _init_outputs(self):
self.outputs["impl_verilog"] = self.build_path / "viv_impl.v"
self.outputs["impl_edf"] = self.build_path / "viv_impl.edf"
self.outputs["impl_dcp"] = self.build_path / "impl.dcp"
self.outputs["utilization"] = self.build_path / "utiliztion.txt"
self.outputs["utilization"] = self.build_path / "utilization.txt"
self.outputs["timing"] = self.build_path / "timing_summary.txt"
self.outputs["journal"] = self.build_path / "vivado.jou"
self.outputs["log"] = self.build_path / "vivado.log"
Expand Down
11 changes: 10 additions & 1 deletion bfasst/tools/transform/error_injector.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,21 @@ class ErrorInjector(Tool):
"""Create the rule and build snippets for error injection into an xray netlist."""

def __init__(
self, flow, design, error_type=None, num=None, multiplier=None, reversed_netlist=None
self,
flow,
design,
logging_level,
error_type=None,
num=None,
multiplier=None,
reversed_netlist=None,
):
super().__init__(flow, design)
self.error_type = error_type
self.num = num
self.multiplier = multiplier
self.reversed_netlist = reversed_netlist
self.logging_level = logging_level
self.build_path = self.design_build_path / "error_injection"
if error_type is not None and num is not None:
self.injection_log = self.build_path / f"{self.error_type.name.lower()}_{self.num}.log"
Expand All @@ -40,6 +48,7 @@ def create_build_snippets(self):
"seed": self.num * self.multiplier,
"error_injector_script_path": str(BFASST_UTILS_PATH / "error_injector.py"),
"reversed_netlist": self.reversed_netlist,
"logging_level": f"--logging_level {self.logging_level}",
},
)

Expand Down
1 change: 1 addition & 0 deletions bfasst/tools/transform/error_injector_build.ninja.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ build {{ log_path }} {{ corrupt_netlist_path }}: inject | {{ build_dir }}/xray/{
error_type = {{ error_type }}
log_path = {{ log_path }}
reversed_netlist = {{ reversed_netlist }}
logging_level = {{ logging_level }}

2 changes: 1 addition & 1 deletion bfasst/tools/transform/error_injector_rules.ninja
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
rule inject
command = python bfasst/utils/error_injector.py --build_dir $build_dir --log_path $log_path --seed $seed --error_type $error_type --reversed_netlist $reversed_netlist
command = python bfasst/utils/error_injector.py --build_dir $build_dir --log_path $log_path --seed $seed --error_type $error_type --reversed_netlist $reversed_netlist $logging_level
description = inject a $error_type into xrev netlist for $build_dir

4 changes: 3 additions & 1 deletion bfasst/tools/transform/netlist_cleanup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@
class NetlistCleanup(Tool):
"""Create rule and build snippets for phys netlist creation."""

def __init__(self, flow, design, rev_netlist):
def __init__(self, flow, design, rev_netlist, logging_level):
super().__init__(flow, design)

self.rev_netlist = rev_netlist
self.logging_level = logging_level

self.build_path = self.design_build_path / "netlist_cleanup"
self._init_outputs()
Expand All @@ -34,5 +35,6 @@ def create_build_snippets(self):
"netlist_cleanup_output": self.build_path,
"netlist_in": self.rev_netlist,
"netlist_out": self.outputs["netlist_cleaned_path"],
"logging_level": f"--logging_level {self.logging_level}",
},
)
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ build {{ netlist_out }} {{ netlist_cleanup_output }}/log.txt: netlist_cleanup {{
build_path = {{ netlist_cleanup_output }}
netlist_in = {{ netlist_in }}
netlist_out = {{ netlist_out }}
logging_level = {{ logging_level }}
2 changes: 1 addition & 1 deletion bfasst/tools/transform/netlist_cleanup_rules.ninja
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
rule netlist_cleanup
command = python bfasst/utils/netlist_cleanup.py $build_path $netlist_in $netlist_out
command = python bfasst/utils/netlist_cleanup.py $build_path $netlist_in $netlist_out $logging_level
description = netlist cleanup for $in
4 changes: 3 additions & 1 deletion bfasst/tools/transform/phys_netlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@
class PhysNetlist(Tool):
"""Create rule and build snippets for phys netlist creation."""

def __init__(self, flow, design, impl_checkpoint, impl_edf):
def __init__(self, flow, design, impl_checkpoint, impl_edf, logging_level):
super().__init__(flow, design)

self.impl_checkpoint = impl_checkpoint
self.impl_edf = impl_edf
self.logging_level = logging_level

self.build_path = self.design_build_path / "vivado_phys_netlist"

Expand Down Expand Up @@ -53,6 +54,7 @@ def __append_build_snippets(self):
"phys_netlist_output": self.build_path,
"phys_netlist_library": NINJA_TRANSFORM_TOOLS_PATH,
"build_dir": self.build_path.parent,
"logging_level": f"--logging_level {self.logging_level}",
"impl_dcp": self.impl_checkpoint,
"impl_edf": self.impl_edf,
},
Expand Down
1 change: 1 addition & 0 deletions bfasst/tools/transform/phys_netlist_build.ninja.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ build {{ phys_netlist_output }}/checkpoint_to_v.tcl: template {{ phys_netlist_ou

build {{ phys_netlist_output }}/viv_impl_physical.edf {{ phys_netlist_output }}/phys_netlist.dcp {{ phys_netlist_output }}/log.txt {{ phys_netlist_output }}/rapidwright_stdout.log: phys_netlist | bfasst/utils/rw_phys_netlist.py {{ impl_edf }} {{ impl_dcp }}
build_dir = {{ build_dir }}
logging_level = {{ logging_level }}
impl_dcp = {{ impl_dcp }}
impl_edf = {{ impl_edf }}

Expand Down
2 changes: 1 addition & 1 deletion bfasst/tools/transform/phys_netlist_rules.ninja
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
rule phys_netlist
command = python bfasst/utils/rw_phys_netlist.py --build_dir $build_dir --impl_dcp $impl_dcp --impl_edf $impl_edf
command = python bfasst/utils/rw_phys_netlist.py --build_dir $build_dir --impl_dcp $impl_dcp --impl_edf $impl_edf $logging_level
description = generate physical netlist for $build_dir

17 changes: 14 additions & 3 deletions bfasst/utils/error_injector.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,16 @@ class ErrorInjectorException(Exception):
class ErrorInjector:
"""Inject errors into an xrev netlist"""

def __init__(self, build_dir, log_path, seed, error_type, reversed_netlist):
def __init__(
self, build_dir, log_path, seed, error_type, reversed_netlist, logging_level=logging.DEBUG
):
self.build_dir = Path(build_dir)
self.stage_dir = self.build_dir / "error_injection"
self.log_path = self.stage_dir / log_path
self.logging_level = logging_level
logging.basicConfig(
filename=self.log_path,
level=logging.DEBUG,
level=self.logging_level,
format="%(asctime)s %(message)s",
datefmt="%Y%m%d%H%M%S",
)
Expand Down Expand Up @@ -264,6 +267,14 @@ def __log_wire_swap(self, selected_input, selected_input2, two_instances):
parser.add_argument("--seed", help="Seed for random number generator")
parser.add_argument("--error_type", type=str, help="Type of error to inject")
parser.add_argument("--reversed_netlist", type=str, help="Path to reversed netlist")
parser.add_argument("--logging_level", help="Decides what levels of logs to display")
args = parser.parse_args()

ErrorInjector(args.build_dir, args.log_path, args.seed, args.error_type, args.reversed_netlist)
ErrorInjector(
args.build_dir,
args.log_path,
args.seed,
args.error_type,
args.reversed_netlist,
args.logging_level,
)
Loading

0 comments on commit 158a5d6

Please sign in to comment.