Skip to content
Snippets Groups Projects
Commit eed62723 authored by auphelia's avatar auphelia
Browse files

[Transformation] Added trafo to set "sim_mode" attribute

parent 034fe080
No related branches found
No related tags found
No related merge requests found
import finn.core.utils as util
import finn.custom_op.registry as registry
from finn.transformation import Transformation
class SetSimMode(Transformation):
"""Set attribute sim_mode in all fpgadataflow nodes"""
def __init__(self, mode):
super().__init__()
self.mode = mode
def apply(self, model):
for node in model.graph.node:
op_type = node.op_type
if node.domain == "finn":
backend_attribute = util.get_by_name(node.attribute, "backend")
if backend_attribute is None:
continue
backend_value = backend_attribute.s.decode("UTF-8")
if backend_value == "fpgadataflow":
try:
# lookup op_type in registry of CustomOps
inst = registry.custom_op[op_type](node)
# set sim_mode accordingly to argument mode
inst.set_nodeattr("sim_mode", self.mode)
# ensure that sim_mode is now set
assert inst.get_nodeattr("sim_mode") != ""
except KeyError:
# exception if op_type is not supported
raise Exception(
"Custom op_type %s is currently not supported." % op_type
)
return (model, 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