Пример #1
0
    def send_message(self, message):

        instance_count = 1
        for i in range(self.hyperperiod):
            if i % message.period == 0:
                message_instance = MessageInstance(message, instance_count)
                event = Event(EventType.SEND_MESSAGE, message_instance,
                              i + message_instance.offset)
                EVENT_LIST.push(event)

                # Instance Saving
                self._message_instance_tab.append(message_instance)
                instance_count += 1
Пример #2
0
    def send_to_router(self, message_instance, time):

        # Getting Packets from Message
        packets = copy.copy(message_instance.packets)
        message_instance.set_depart_time(time)

        # We assume that we have more place in VCs than packets
        while len(packets) > 0:
            packet = packets.pop()
            self.logger.debug('Time : (%d) - packet sending number (%d)' %
                              (time, packet.id))

            # VC Allocation
            vc_allotted = self.router.inPE.vc_allocator()

            if vc_allotted is not None:
                self.send_packet(packet, vc_allotted)
            else:
                self.logger.debug('Time : (%d) - Not VC allowed' % time)

        # event push
        event = Event(EventType.VC_ELECTION, self.router, time)
        EVENT_LIST.push(event)
Пример #3
0
    def send_flit(self, vc, outport, time):

        if len(vc.flits) <= 0:
            return

        # getting the first flit in VC
        flit = vc.dequeue()
        if flit is None:
            return

        # if is a Head Flit
        if flit.type == FlitType.head:
            self.logger.debug('Time : (%d) - %s ready to be sent' % (time, flit))

            # Get idle VC from next Input
            vc_allotted = outport.inPort.vc_allocator()

            if vc_allotted is not None:
                self.logger.debug('Time : (%d) - VC (%s) allotted' % (time, vc_allotted))

                # send flit
                vc_allotted.enqueue(flit)
                self.logger.info('(%d) : %s - %s -> %s -> %s' % (time, flit, self, vc_allotted, vc_allotted.router))
                vc.credit_out()
                # registering VC allotted in dictionary
                self.vcs_dictionary.add(Node(vc, vc_allotted))
                # Next routing
                event = Event(EventType.VC_ELECTION, vc_allotted.router, time + 1)
                EVENT_LIST.push(event)

            else:  # No idle VC
                vc.restore(flit)  # restore
                # event push
                event = Event(EventType.SEND_FLIT, {'router': self,
                                                    'vc': vc,
                                                    'outport': outport}, time + 1)

                EVENT_LIST.push(event)
                self.logger.debug('Time : (%d) - %s was not sent - VC not allotted' % (time, flit))

        # if is a Body Flit
        elif flit.type == FlitType.body:
            self.logger.debug('Time : (%d) - %s ready to be sent' % (time, flit))
            # Getting the alloted vc
            vc_allotted = self.vcs_dictionary.get_target(vc)
            self.logger.debug('Time : (%d) - Retreiving allotted VC (%s)' % (time, vc_allotted))

            # Sending to the next router
            sent = vc_allotted.enqueue(flit)

            if not sent:  # No Place
                vc.restore(flit)  # restore
                # event push
                event = Event(EventType.SEND_FLIT, {'router': self,
                                                    'vc': vc,
                                                    'outport': outport}, time + 1)
                EVENT_LIST.push(event)
                self.logger.debug('Time : (%d) - %s was not sent - No Place in VC (%s)' % (time, flit, vc_allotted))

            else:
                # Next routing
                event = Event(EventType.VC_ELECTION, vc_allotted.router, time + 1)
                EVENT_LIST.push(event)
                self.logger.info('(%d) : %s - %s -> %s -> %s' % (time, flit, self, vc_allotted, vc_allotted.router))
                vc.credit_out()

        # if is a Tail Flit
        elif flit.type == FlitType.tail:
            self.logger.debug('Time : (%d) - %s ready to be sent' % (time, flit))

            # Getting the alloted vc
            vc_allotted = self.vcs_dictionary.get_target(vc)

            # Sending to the next router
            sent = vc_allotted.enqueue(flit)

            if not sent:  # No Place
                vc.restore(flit)  # restore
                # event push
                event = Event(EventType.SEND_FLIT, {'router': self,
                                                    'vc': vc,
                                                    'outport': outport}, time + 1)
                EVENT_LIST.push(event)
                self.logger.debug('Time : (%d) - %s was not sent - No Place in VC (%s)' % (time, flit, vc_allotted))

            else:
                self.logger.info('(%d) : %s - %s -> %s -> %s' % (time, flit, self, vc_allotted, vc_allotted.router))
                # Next routing
                event = Event(EventType.VC_ELECTION, vc_allotted.router, time + 1)
                EVENT_LIST.push(event)

                self.vcs_dictionary.remove(vc)
                vc.lock = False
                vc.credit_out()
                self.logger.debug('Time : (%d) - VC (%s) - released' % (time, vc))

        # If Quantum is finished
        if vc.quantum <= 0:
            # print('Quantum or VC finished for : %s' % vc)
            self.logger.debug('Time : (%d) - VC (%s) - quantum finished' % (time, vc))
            # new VC Election - event push
            event = Event(EventType.VC_ELECTION, self, time + 1)
            EVENT_LIST.push(event)
        elif len(vc.flits) <= 0:
            self.logger.debug('Time : (%d) - VC (%s) - NO Flits' % (time, vc))
            # new VC Election - event push
            event = Event(EventType.VC_ELECTION, self, time + 1)
            EVENT_LIST.push(event)

        # Another Quantum
        else:
            self.logger.debug('Time : (%d) - VC (%s) - quantum NOT finished' % (time, vc))
            event = Event(EventType.SEND_FLIT, {'router': self,
                                                'vc': vc,
                                                'outport': outport}, time + 1)
            EVENT_LIST.push(event)
Пример #4
0
    def priority_arbiter(self, time):
        for vc in self.inPE.vcs:
            self.vc_target_outport(vc)
        # Checking North VC
        for vc in self.inNorth.vcs:
            self.vc_target_outport(vc)
        # Checking South VC
        for vc in self.inSouth.vcs:
            self.vc_target_outport(vc)
        # Checking East VC
        for vc in self.inEast.vcs:
            self.vc_target_outport(vc)
        # Checking West VC
        for vc in self.inWest.vcs:
            self.vc_target_outport(vc)

        # VC targeting -> North
        if len(self.vcs_target_north) > 0:
            vc = self.get_most_prioritized_vc(self.vcs_target_north)
            self.logger.debug('Time : (%d) - %s -> Elected' % (time, vc))
            # event push
            event = Event(EventType.SEND_FLIT, {'router': self,
                                                'vc': vc,
                                                'outport': self.outNorth}, time)
            EVENT_LIST.push(event)

        # VC targeting -> South
        if len(self.vcs_target_south) > 0:
            vc = self.get_most_prioritized_vc(self.vcs_target_south)
            self.logger.debug('Time : (%d) - %s -> Elected' % (time, vc))
            # event push
            event = Event(EventType.SEND_FLIT, {'router': self,
                                                'vc': vc,
                                                'outport': self.outSouth}, time)
            EVENT_LIST.push(event)

        # VC targeting -> East
        if len(self.vcs_target_east) > 0:
            vc = self.get_most_prioritized_vc(self.vcs_target_east)
            self.logger.debug('Time : (%d) - %s -> Elected' % (time, vc))
            # event push
            event = Event(EventType.SEND_FLIT, {'router': self,
                                                'vc': vc,
                                                'outport': self.outEast}, time)
            EVENT_LIST.push(event)

        # VC targeting -> West
        if len(self.vcs_target_west) > 0:
            vc = self.get_most_prioritized_vc(self.vcs_target_west)
            self.logger.debug('Time : (%d) - %s -> Elected' % (time, vc))
            # event push
            event = Event(EventType.SEND_FLIT, {'router': self,
                                                'vc': vc,
                                                'outport': self.outWest}, time)
            EVENT_LIST.push(event)

        # VC targeting -> PE
        if len(self.vcs_target_pe) > 0:
            vc = self.get_most_prioritized_vc(self.vcs_target_pe)
            self.logger.debug('Time : (%d) - %s -> Elected' % (time, vc))
            # event push
            event = Event(EventType.ARR_FLIT, {'router': self, 'vc': vc}, time)
            EVENT_LIST.push(event)
Пример #5
0
    def simulate(self, arbitration):
        global CLOCK
        while not EVENT_LIST.isEmpty() and CLOCK < self.hyperperiod:

            events = EVENT_LIST.pull(CLOCK)

            # print('------------------- %d -------------------' % CLOCK)
            # if events is not None:
            #     for ev in events:
            #         print(ev)

            # for key in EVENT_LIST.register.keys():
            #     for router in EVENT_LIST.register[key]:
            #         print('%d -> %s' % (key, router))

            if events is not None and len(events) > 0:
                current_event = events.pop()

                if current_event.event_type == EventType.SEND_MESSAGE:
                    # get Event Entity
                    message = current_event.entity

                    # get source and destination message
                    src = message.src

                    # get Processing Engine
                    proc_engine = self.noc.router_matrix[src.i][
                        src.j].proc_engine

                    # Send Message
                    proc_engine.send_to_router(message, CLOCK)

                elif current_event.event_type == EventType.SEND_FLIT:
                    # get Event Entity
                    router = current_event.entity['router']
                    vc = current_event.entity['vc']
                    outport = current_event.entity['outport']

                    # FLIT Sending
                    if arbitration == 'RR':
                        router.send_flit(vc, outport, CLOCK)
                    elif arbitration == 'Priority':
                        router.send_flit_by_priority(vc, outport, CLOCK)

                elif current_event.event_type == EventType.VC_ELECTION:
                    # Get Event Entity
                    router = current_event.entity

                    # VC Election
                    if arbitration == 'RR':
                        router.rr_arbiter(CLOCK)
                    elif arbitration == 'Priority':
                        router.priority_arbiter(CLOCK)

                elif current_event.event_type == EventType.ARR_FLIT:

                    # get Event Entity
                    router = current_event.entity['router']
                    vc = current_event.entity['vc']

                    # Flit -> PE
                    router.arrived_flit(vc, CLOCK)

            else:
                CLOCK += 1
Пример #6
0
    def simulate(self, arbitration):
        global CLOCK
        global TRACESET
        while not EVENT_LIST.isEmpty() and CLOCK < self.hyperperiod:

            # time.sleep(1)

            events = EVENT_LIST.pull(CLOCK)

            # print('------------------- %d -------------------' % CLOCK)
            # if events is not None:
            #     for ev in events:
            #         print(ev)

            # for key in EVENT_LIST.register.keys():
            #     for router in EVENT_LIST.register[key]:
            #         print('%d -> %s' % (key, router))

            if events is not None and len(events) > 0:
                current_event = events.pop()

                #### Processing Engine Events ####
                if current_event.event_type == EventType.SEND_MESSAGE:
                    # get Event Entity
                    message = current_event.entity

                    # get source and destination message
                    src = message.src

                    # get Processing Engine
                    proc_engine = self.noc.router_matrix[src.i][
                        src.j].proc_engine

                    # Send Message
                    proc_engine.send_to_router(message, CLOCK)

                elif current_event.event_type == EventType.PE_SEND_PACKET:
                    # Get event Entity
                    pe = current_event.entity

                    pe.send_packet(CLOCK)

                #### Router Events ####
                elif current_event.event_type == EventType.SEND_FLIT:
                    # get Event Entity
                    router = current_event.entity['router']
                    vc = current_event.entity['vc']
                    outport = current_event.entity['outport']

                    # FLIT Sending
                    if arbitration == 'RR':
                        router.send_flit_by_credit(vc, outport, CLOCK)
                    elif arbitration == 'PRIORITY_PREEMPT':
                        router.send_flit_by_priority(vc, outport, CLOCK)

                elif current_event.event_type == EventType.VC_ELECTION:
                    # Get Event Entity
                    router = current_event.entity

                    # VC Election
                    if arbitration == 'RR':
                        router.rr_arbiter(CLOCK)
                    elif arbitration == 'PRIORITY_PREEMPT':
                        router.priority_arbiter(CLOCK)
                    elif arbitration == 'PRIORITY_NON_PREEMPT':
                        router.preemptive_priority_arbiter(CLOCK)

                elif current_event.event_type == EventType.ARR_FLIT:
                    # get Event Entity
                    router = current_event.entity['router']
                    vc = current_event.entity['vc']

                    # Flit -> PE
                    router.arrived_flit(vc, CLOCK)

                elif current_event.event_type == EventType.ROUTER_CHECK:
                    # get Event Entity
                    router = current_event.entity

                    router.router_check(CLOCK, arbitration)

            else:
                CLOCK += 1