Skip to content
Snippets Groups Projects
Commit 1fd0e91b authored by Yaman Umuroglu's avatar Yaman Umuroglu
Browse files

[HLSCustomOp] add rtlsim prepare/retrieve fxns to base

parent affa7a22
No related branches found
No related tags found
No related merge requests found
...@@ -38,6 +38,11 @@ from finn.util.fpgadataflow import ( ...@@ -38,6 +38,11 @@ from finn.util.fpgadataflow import (
) )
from . import templates from . import templates
try:
from pyverilator import PyVerilator
except ModuleNotFoundError:
PyVerilator = None
class HLSCustomOp(CustomOp): class HLSCustomOp(CustomOp):
"""HLSCustomOp class all custom ops that correspond to a finn-hlslib """HLSCustomOp class all custom ops that correspond to a finn-hlslib
...@@ -76,8 +81,64 @@ class HLSCustomOp(CustomOp): ...@@ -76,8 +81,64 @@ class HLSCustomOp(CustomOp):
"res_estimate": ("s", False, ""), "res_estimate": ("s", False, ""),
"res_hls": ("s", False, ""), "res_hls": ("s", False, ""),
"res_synth": ("s", False, ""), "res_synth": ("s", False, ""),
"rtlsim_so": ("s", False, ""),
} }
def get_verilog_top_module_name(self):
"Return the Verilog top module name for this node."
node = self.onnx_node
prefixed_top_name = "%s_%s" % (node.name, node.name)
return prefixed_top_name
def get_verilog_top_filename(self):
"Return the Verilog top module filename for this node."
verilog_file = "{}/project_{}/sol1/impl/verilog/{}.v".format(
self.get_nodeattr("code_gen_dir_ipgen"),
self.onnx_node.name,
self.get_verilog_top_module_name(),
)
return verilog_file
def prepare_rtlsim(self):
"""Creates a Verilator emulation library for the RTL code generated
for this node, sets the rtlsim_so attribute to its path and returns
a PyVerilator wrapper around it."""
if PyVerilator is None:
raise ImportError("Installation of PyVerilator is required.")
# ensure that code is generated
code_gen_dir = self.get_nodeattr("code_gen_dir_ipgen")
assert (
code_gen_dir != ""
), """Node attribute "code_gen_dir_ipgen" is
not set. Please run HLSSynth_IPGen first."""
verilog_file = self.get_verilog_top_filename()
assert os.path.isfile(verilog_file), "Cannot find top-level Verilog file."
# build the Verilator emu library
sim = PyVerilator.build(
verilog_file,
verilog_path=[
"{}/project_{}/sol1/impl/verilog/".format(
code_gen_dir, self.onnx_node.name
)
],
)
# save generated lib filename in attribute
self.set_nodeattr("rtlsim_so", sim.lib._name)
return sim
def get_rtlsim(self):
"""Return a PyVerilator wrapper for the Verilator emulation library
for this node."""
rtlsim_so = self.get_nodeattr("rtlsim_so")
assert os.path.isfile(rtlsim_so), "Cannot find rtlsim library."
# create PyVerilator wrapper
sim = PyVerilator(rtlsim_so)
return sim
def node_res_estimation(self): def node_res_estimation(self):
"""Returns summarized resource estimation of BRAMs and LUTs """Returns summarized resource estimation of BRAMs and LUTs
of the node as a dictionary.""" of the node as a dictionary."""
......
...@@ -63,16 +63,6 @@ class PrepareRTLSim(NodeLocalTransformation): ...@@ -63,16 +63,6 @@ class PrepareRTLSim(NodeLocalTransformation):
try: try:
# lookup op_type in registry of CustomOps # lookup op_type in registry of CustomOps
inst = registry.custom_op[op_type](node) inst = registry.custom_op[op_type](node)
# ensure that code is generated
assert (
inst.get_nodeattr("code_gen_dir_ipgen") != ""
), """Node
attribute "code_gen_dir_ipgen" is not set. Please run
HLSSynth_IPGen first."""
if PyVerilator is None:
raise ImportError(
"Installation of PyVerilator is required."
)
inst.prepare_rtlsim() inst.prepare_rtlsim()
# ensure that executable path is now set # ensure that executable path is now set
assert ( assert (
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment