Skip to content
Snippets Groups Projects
Commit e19e2baf authored by HenniOVP's avatar HenniOVP
Browse files

HLSSynth_IPGen subclasses NodeLocalTransformation

parent ccbe08d0
No related branches found
No related tags found
No related merge requests found
...@@ -28,50 +28,53 @@ ...@@ -28,50 +28,53 @@
import finn.custom_op.registry as registry import finn.custom_op.registry as registry
import finn.util.basic as util import finn.util.basic as util
from finn.transformation import Transformation from finn.transformation import NodeLocalTransformation
class HLSSynth_IPGen(Transformation): class HLSSynth_IPGen(NodeLocalTransformation):
"""For each node: generate IP block from code in folder """For each node: generate IP block from code in folder
that is referenced in node attribute "code_gen_dir_ipgen" that is referenced in node attribute "code_gen_dir_ipgen"
and save path of generated project in node attribute "ipgen_path". and save path of generated project in node attribute "ipgen_path".
All nodes in the graph must have the fpgadataflow backend attribute. All nodes in the graph must have the fpgadataflow backend attribute.
This transformation calls Vivado HLS for synthesis, so it will run for This transformation calls Vivado HLS for synthesis, so it will run for
some time (several minutes)""" some time (several minutes)
* NUM_DEFAULT_WORKERS (int or None) number of parallel workers. Default is 1. None: Use all available cores.
"""
def __init__(self): def __init__(self, NUM_DEFAULT_WORKERS=1):
super().__init__() super().__init__(NUM_DEFAULT_WORKERS=NUM_DEFAULT_WORKERS)
def apply(self, model): def applyNodeLocal(self, node):
for node in model.graph.node: op_type = node.op_type
op_type = node.op_type if node.domain == "finn":
if node.domain == "finn": backend_attribute = util.get_by_name(node.attribute, "backend")
backend_attribute = util.get_by_name(node.attribute, "backend") if backend_attribute is None:
if backend_attribute is None: return (node, False)
continue backend_value = backend_attribute.s.decode("UTF-8")
backend_value = backend_attribute.s.decode("UTF-8") if backend_value == "fpgadataflow":
if backend_value == "fpgadataflow": 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
# ensure that code is generated assert (
assert ( inst.get_nodeattr("code_gen_dir_ipgen") != ""
inst.get_nodeattr("code_gen_dir_ipgen") != "" ), """Node
), """Node attribute "code_gen_dir_ipgen" is empty. Please run
attribute "code_gen_dir_ipgen" is empty. Please run transformation CodeGen_ipgen first."""
transformation CodeGen_ipgen first.""" # call the compilation function for this node
# call the compilation function for this node inst.ipgen_singlenode_code()
inst.ipgen_singlenode_code() # ensure that executable path is now set
# ensure that executable path is now set assert (
assert ( inst.get_nodeattr("ipgen_path") != ""
inst.get_nodeattr("ipgen_path") != "" ), """Transformation
), """Transformation HLSSynth_IPGen was not successful. Node attribute "ipgen_path"
HLSSynth_IPGen was not successful. Node attribute "ipgen_path" is empty."""
is empty.""" except KeyError:
except KeyError: # exception if op_type is not supported
# exception if op_type is not supported raise Exception(
raise Exception( "Custom op_type %s is currently not supported." % op_type
"Custom op_type %s is currently not supported." % op_type )
)
return (model, False) return (node, False)
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