Пример #1
0
    def __init__(self, name, xml_file):
        super().__init__(name)

        log.info("Start parsing the PnGraph")

        log.debug("Reading from file: %s" % xml_file)
        tree = ET.parse(to_absolute_path(xml_file))
        xmlroot = tree.getroot()

        for channel in xmlroot.iter("PNchannel"):
            name = channel.find("Name").text
            token_size = int(channel.find("EntrySizeHint").text)
            log.debug("".join([
                "Found the channel ",
                name,
                " with a token size of ",
                str(token_size),
                " bytes",
            ]))
            self.add_channel(DataflowChannel(name, token_size))

        for process in xmlroot.iter("PNprocess"):
            name = process.find("Name").text
            outgoing = []
            incoming = []

            for c in process.find("PNin").iter("Expr"):
                incoming.append(c.text)
            for c in process.find("PNout").iter("Expr"):
                outgoing.append(c.text)

            log.debug("Found the process " + name)
            log.debug("It reads from the channels " + str(incoming) + " ...")
            log.debug("and writes to the channels " + str(outgoing))

            process = DataflowProcess(name)
            self.add_process(process)

            for cn in outgoing:
                channel = None
                for c in self.channels():
                    if cn == c.name:
                        channel = c
                        break
                assert channel is not None
                process.connect_to_outgoing_channel(channel)

            for cn in incoming:
                channel = None
                for c in self.channels():
                    if cn == c.name:
                        channel = c
                        break
                assert channel is not None
                process.connect_to_incomming_channel(channel)
        log.info("Done parsing the PnGraph")
Пример #2
0
def graph():
    k = DataflowGraph("graph")
    channel = DataflowChannel("ch", 1)
    k.add_channel(channel)
    process_a = DataflowProcess("a")
    process_a.connect_to_outgoing_channel(channel)
    process_b = DataflowProcess("b")
    process_b.connect_to_incomming_channel(channel)
    k.add_process(DataflowProcess("a"))
    k.add_process(DataflowProcess("b"))
    return k
Пример #3
0
    def __init__(self):
        super().__init__("example")

        a = DataflowProcess("a")
        b = DataflowProcess("b")
        c = DataflowChannel("c", 16)

        self.add_process(a)
        self.add_process(b)
        self.add_channel(c)

        a.connect_to_outgoing_channel(c)
        b.connect_to_incomming_channel(c)
Пример #4
0
    def to_dataflow_graph(self):
        """Transfers the the tgff graph into a dataflow graph
        :returns: the equivalent dataflow graph representation
        :rtype: DataflowGraph
        """
        graph = DataflowGraph(self.identifier)
        tasks = []
        channels = []

        # Create process for each node in
        for task in self.tasks:
            task = DataflowProcess(task)
            tasks.append(task)

        # Create channel for each edge in
        for key, properties in self.channels.items():
            name = key
            token_size = int(self._quantities[0][int(properties[2])])
            channel = DataflowChannel(name, token_size)

            for task in tasks:
                if task.name == properties[0]:
                    task.connect_to_outgoing_channel(channel)
                if task.name == properties[1]:
                    task.connect_to_incomming_channel(channel)

            channels.append(channel)

        # Add channels and processes to empty
        for task in tasks:
            graph.add_process(task)

        for channel in channels:
            graph.add_channel(channel)

        return graph