From eed627235c4e31bd283a44eb0be530e5fe520fbf Mon Sep 17 00:00:00 2001 From: auphelia <jakobapk@web.de> Date: Wed, 15 Jan 2020 14:24:54 +0000 Subject: [PATCH] [Transformation] Added trafo to set "sim_mode" attribute --- .../fpgadataflow/set_sim_mode.py | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/finn/transformation/fpgadataflow/set_sim_mode.py diff --git a/src/finn/transformation/fpgadataflow/set_sim_mode.py b/src/finn/transformation/fpgadataflow/set_sim_mode.py new file mode 100644 index 000000000..31692c89b --- /dev/null +++ b/src/finn/transformation/fpgadataflow/set_sim_mode.py @@ -0,0 +1,34 @@ +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) -- GitLab