def constructPSFlow(self, dose, neighbour_node_id):
     
     # construct new flow        
     src_nodeid = self.node.get_id()
     dst_nodeid = neighbour_node_id
     nextid = self.node.resource_manager_instance.flow_table.nextid                    
     route = self.node.resource_manager_instance.interconnect.getRouteXY(src_nodeid, dst_nodeid)
     priority = SimParams.PSALGO_FLOWBASEPRIORITY + nextid
     #priority = nextid
     basicLatency = self.node.resource_manager_instance.interconnect.getRouteCostXY(src_nodeid, 
                                                                                    dst_nodeid,
                                                                                    SimParams.PSALGO_PSFLOWPAYLOADSIZE)
     relase_time = self.env.now
     payload = SimParams.PSALGO_PSFLOWPAYLOADSIZE
     endTime_wrt_BL = relase_time + basicLatency
     payload_metadata  = {'ps_hd' : dose }     # ps-dose information   
     
     newflow = NoCFlow(nextid,
                       None, None, None, None,
                       src_nodeid, dst_nodeid, route,
                       priority, 
                       None, 
                       basicLatency, payload, endTime_wrt_BL, 
                       type=FlowType.FLOWTYPE_PSALGOSIGNALLING,
                       payload_metadata=payload_metadata)        
     
     return (newflow, basicLatency)
 def receivedQueenStatusMessageRequest(self, flw_payload):
     # construct new flow        
     src_nodeid = self.node.get_id()
     dst_nodeid = flw_payload.get_payload_metadata()['worker_node_id']
     nextid = self.node.resource_manager_instance.flow_table.nextid                    
     route = self.node.resource_manager_instance.interconnect.getRouteXY(src_nodeid, dst_nodeid)
     priority = SimParams.PSALGO_FLOWBASEPRIORITY + nextid
     #priority = nextid
     basicLatency = self.node.resource_manager_instance.interconnect.getRouteCostXY(src_nodeid, 
                                                                                    dst_nodeid,
                                                                                    1) # 1 byte
     relase_time = self.env.now
     payload = 1 # 1 byte
     endTime_wrt_BL = relase_time + basicLatency
     payload_metadata  = {'null' : None }     # some info about queen remapping status   
     
     newflow = NoCFlow(nextid,
                       None, None, None, None,
                       src_nodeid, dst_nodeid, route,
                       priority, 
                       None, 
                       basicLatency, payload, endTime_wrt_BL, 
                       type=FlowType.FLOWTYPE_PSALGOSIGNALLING_QUEENSTAT_REP,
                       payload_metadata=payload_metadata)    
     
     self.node.lock_RM_FLWtbl()        
     # add to the flow table        
     self.node.resource_manager_instance.flow_table.addFlow(newflow, self.env.now, basicLatency)
     self.node.release_RM_FLWtbl()        
     
     # update the table        
     self.node.resource_manager_instance.flow_table.updateTable(fire=True)
    def _constructFlow(self, src_nodeid, dst_nodeid, metadata, pri,
                       payload_size):

        # construct new flow
        nextid = self.RMinstance.flow_table.nextid
        route = self.RMinstance.interconnect.getRouteXY(src_nodeid, dst_nodeid)
        priority = nextid
        basicLatency = self.RMinstance.interconnect.getRouteCostXY(
            src_nodeid, dst_nodeid, payload_size)
        relase_time = self.env.now
        payload = payload_size
        endTime_wrt_BL = relase_time + basicLatency
        payload_metadata = metadata

        newflow = NoCFlow(nextid,
                          None,
                          None,
                          None,
                          None,
                          src_nodeid,
                          dst_nodeid,
                          route,
                          priority,
                          None,
                          basicLatency,
                          payload,
                          endTime_wrt_BL,
                          type=FlowType.FLOWTYPE_MASTERSLAVESIGNALLING,
                          payload_metadata=payload_metadata)

        return (newflow, basicLatency)
def _get_minmax_ccr(Iwcc, Pwcc, Bwcc, Ibcc, Pbcc, Bbcc, gop_len, max_payload):

    nPmax = gop_len - 1
    nPmin = int(float(gop_len - 1) / float(NBMAX + 1))

    nBmax = (gop_len - 1) - nPmin
    nBmin = 0
    nhops = (NOC_H - 1) + (NOC_W - 1)
    #nhops = (NOC_H) + (NOC_W)
    max_bl = NoCFlow.getCommunicationCost(max_payload * 0.5, nhops, NOC_PERIOD,
                                          NOC_ARBITRATION_COST)

    #     print "Iwcc, %.9f" % Iwcc
    #     print "Pwcc, %.9f" % Pwcc
    #     print "Bwcc, %.9f" % Bwcc

    print "max_bl: ", max_bl

    ## calculate upper-bound CCR ##

    # how many num P's and B's do we consider ?
    nP = nPmin
    nB = nBmax

    # upper ccr occurs when there are as many as possible edges, when there are max amount of B-frames
    # B frames can have max 3 incoming edges
    # P frames can have only 1 incoming edge
    # and have to take best-case ccs

    num_edges = (nP * 1) + (nB * 3)
    print "w.c. num_edges:", num_edges
    wc_comm_cost = num_edges * max_bl

    bc_comp_cost = Ibcc + (nP * Pbcc) + (nB * Bbcc)
    ub_ccr = float(wc_comm_cost) / float(bc_comp_cost)

    ## calculate best-case CCR ##
    # how many num P's and B's do we consider ?
    nP = nPmax
    nB = nBmin

    # bc ccr occurs when there are as less as possible edges, when there are min amount of B-frames
    # B frames can have max 3 incoming edges
    # P frames can have only 1 incoming edge

    num_edges = (nP * 1) + (nB * 2)
    print "b.c. num_edges:", num_edges
    bl = max_bl
    #print bl
    bc_comm_cost = float(num_edges) * bl

    wc_comp_cost = Iwcc + (nP * Pwcc) + (nB * Bwcc)

    #print bc_comm_cost, bc_comp_cost

    lb_ccr = float(bc_comm_cost) / float(wc_comp_cost)

    return (lb_ccr, ub_ccr)
    def _sendMsgFlow(self,
                     finished_task=None,
                     src_node_id=None,
                     dst_node_id=None,
                     payload=None,
                     payload_metadata=None,
                     type=None,
                     update_flw_table=True):

        #         curframe = inspect.currentframe()
        #         calframe = inspect.getouterframes(curframe, 2)
        #         print 'caller name:', calframe[1][3]

        if (finished_task != None):
            finished_task_id = finished_task.get_id()
        else:
            finished_task_id = None

        release_time = self.env.now
        nextid = self.RMInstance.flow_table.nextid
        route = self.RMInstance.interconnect.getRouteXY(
            dst_node_id, src_node_id)
        priority = SimParams.CCP_FLOWBASEPRIORITY + nextid
        basic_latency = self.RMInstance.interconnect.getRouteCostXY(
            dst_node_id, src_node_id, payload)
        endTime_wrt_BL = release_time + basic_latency
        newflow = NoCFlow(
            nextid,
            finished_task,
            finished_task_id,
            None,  # list of dst task ids
            None,  # list of dst task ixs
            src_node_id,
            dst_node_id,
            route,
            priority,
            None,
            basic_latency,
            payload,
            endTime_wrt_BL,
            type=type,
            payload_metadata=payload_metadata)

        self.node_instance.lock_RM_FLWtbl()
        # add to the flow table
        self.RMInstance.flow_table.addFlow(newflow, release_time,
                                           basic_latency)
        self.node_instance.release_RM_FLWtbl()

        if (update_flw_table == True):
            # update the table
            self.RMInstance.flow_table.updateTable(fire=True)

        return (newflow, release_time, basic_latency)
Exemple #6
0
    def _get_max_ccr(self, vid_res, I_wcc, P_wcc, B_wcc):
        # assuming fixed gop seq - "IPBBPBBPBBBB"
        total_nodes_cost = I_wcc + (P_wcc * 3.0) + (B_wcc * 8.0)
        each_edge_payload = (vid_res[0] * vid_res[1] * 2)
        nhops = (NOC_H - 1) + (NOC_W - 1)
        total_edges_cost = NoCFlow.getCommunicationCost(
            each_edge_payload, nhops, NOC_PERIOD, NOC_ARBITRATION_COST) * 19.0

        max_ratio_ccr = float(total_edges_cost) / float(total_nodes_cost)

        return max_ratio_ccr
    def startMMCTONodeDataTransfer(self, task, node, ibuff_id):

        #src_node_id = self.getClosestMMCPort(node.get_id())
        src_node_id = self.getMMCPort_handler(task.get_id(), node.get_id())
        dst_node_id = node.get_id()

        Debug.PPrint(
            "%f" % self.env.now + "," + self.label + "," +
            'startMMCTONodeDataTransfer:: before GOP execution, : task=%s, %s->%s'
            % (str(task.get_id()), str(src_node_id), str(dst_node_id)),
            DebugCat.DEBUG_CAT_MMCNODEDATATRANSFER)

        release_time = self.env.now
        nextid = self.RMInstance.flow_table.nextid
        route = self.RMInstance.interconnect.getRouteXY(
            src_node_id, dst_node_id)
        priority = SimParams.MMC_DATAREAD_FLOW_PRIORITY + nextid
        payload = task.get_mpeg_tasksize()
        basic_latency = self.RMInstance.interconnect.getRouteCostXY(
            src_node_id, dst_node_id, payload)

        endTime_wrt_BL = release_time + basic_latency
        payload_metadata = {
            'target_task': task,
            'mapped_node': node,
            'ibuff_id': ibuff_id
        }

        newflow = NoCFlow(
            nextid,
            None,
            None,
            None,  # list of dst task ids
            None,  # list of dst task ixs
            src_node_id,
            dst_node_id,
            route,
            priority,
            None,
            basic_latency,
            payload,
            endTime_wrt_BL,
            type=FlowType.FLOWTYPE_MMCTONODE_DATATRANSFER_RD,
            payload_metadata=payload_metadata)

        self.mmc_to_node_data_transfer_started_task_ids.append(
            task.get_id())  # temporarily record

        self.RMInstance.lock_RM_FLWtbl()
        # add to the flow table
        self.RMInstance.flow_table.addFlow(newflow, release_time,
                                           basic_latency)
        self.RMInstance.release_RM_FLWtbl()
    def _sendMsgAfterDelay(self,
                           finished_task=None,
                           src_node_id=None,
                           dst_node_id=None,
                           payload=None,
                           payload_metadata=None,
                           type=None,
                           update_flw_table=True):

        yield self.env.timeout(SimParams.CCP_LOAN_DELIVERY_MSG_SEND_OFFSET *
                               self.node_instance.get_id())

        if (finished_task != None):
            finished_task_id = finished_task.get_id()
        else:
            finished_task_id = None

        release_time = self.env.now
        nextid = self.RMInstance.flow_table.nextid
        route = self.RMInstance.interconnect.getRouteXY(
            dst_node_id, src_node_id)
        priority = SimParams.CCP_FLOWBASEPRIORITY + nextid
        basic_latency = self.RMInstance.interconnect.getRouteCostXY(
            dst_node_id, src_node_id, payload)
        endTime_wrt_BL = release_time + basic_latency
        newflow = NoCFlow(
            nextid,
            finished_task,
            finished_task_id,
            None,  # list of dst task ids
            None,  # list of dst task ixs
            src_node_id,
            dst_node_id,
            route,
            priority,
            None,
            basic_latency,
            payload,
            endTime_wrt_BL,
            type=type,
            payload_metadata=payload_metadata)

        self.node_instance.lock_RM_FLWtbl()
        # add to the flow table
        self.RMInstance.flow_table.addFlow(newflow, release_time,
                                           basic_latency)
        self.node_instance.release_RM_FLWtbl()

        if (update_flw_table == True):
            # update the table
            self.RMInstance.flow_table.updateTable(fire=True)
def get_ccr_range(enable_print=True):

    result_data = []

    frame_h = res_list[0][0]
    frame_w = res_list[0][1]

    for cpu_exec_speed_ratio in [0.1]:
        #for cpu_exec_speed_ratio in np.arange(cpu_exec_rat_min,cpu_exec_rat_max,(cpu_exec_rat_max-cpu_exec_rat_min)/2):
        for noc_period in np.arange(noc_period_min, noc_period_max,
                                    (noc_period_max - noc_period_min) / 10):

            # computation cost
            (iframe_cc, pframe_cc,
             bframe_cc) = MPEG2FrameTask.getStaticComputationCost(
                 frame_h, frame_w, cpu_exec_speed_ratio)
            mean_computation_cost = float(iframe_cc + pframe_cc +
                                          bframe_cc) / 3.0

            # communication cost
            max_hop_count = (SimParams.NOC_W - 1) + (SimParams.NOC_H - 1)
            payload = ((frame_h * frame_w) * 16) / 8
            arb_cost = noc_period * 7
            noc_flow_cc = NoCFlow.getCommunicationCost(payload, max_hop_count,
                                                       noc_period, arb_cost)

            # CCR : communication to computation ratio
            ccr = noc_flow_cc / mean_computation_cost

            # CCS : communication + computation (summation)
            ccs = noc_flow_cc + mean_computation_cost

            entry = {
                'cpu_exec_speed_ratio': cpu_exec_speed_ratio,
                'noc_period': noc_period,
                'mean_computation_cost': mean_computation_cost,
                'noc_flow_cc': noc_flow_cc,
                'ccr': ccr,
                'ccs': ccs,
            }

            result_data.append(entry)

    # print table of results
    if (enable_print == True):
        _report_ccr(result_data)

    return result_data
Exemple #10
0
    def _get_ccr(self, payloads, fr_ccs, num_nodes, num_edges):
        # checks
        assert (len(payloads) == num_edges)
        assert (len(fr_ccs) == num_nodes)

        total_nodes_cost = np.sum(fr_ccs)
        total_edges_cost = 0

        nhops = (NOC_H - 1) + (NOC_W - 1)
        for each_flw_payload in payloads:
            total_edges_cost += NoCFlow.getCommunicationCost(
                each_flw_payload, nhops, NOC_PERIOD, NOC_ARBITRATION_COST)

        ratio_ccr = float(total_edges_cost) / float(total_nodes_cost)

        return ratio_ccr
Exemple #11
0
 def notifyRMTaskCompletion(self, finished_task):
     
     if(SimParams.MS_SIGNALLING_NOTIFY_TASK_COMPLETE_ENABLE == True):
     
         Debug.PPrint("%f"%self.env.now + "," + self.label + "," +'notifyRMTaskCompletion::, : finished_task='+str(finished_task.get_id()), DebugCat.DEBUG_CAT_MSSIGNALLING)
         
         src_node_id = self.get_id()
         dst_node_id = SimParams.RESOURCEMANAGER_NODEID
         release_time = self.env.now
         nextid = self.resource_manager_instance.flow_table.nextid                    
         route = self.resource_manager_instance.interconnect.getRouteXY(dst_node_id, src_node_id)
         priority = SimParams.NOC_FLOW_MS_SIGNALLING_MAXPRIORITY + nextid        
         basic_latency = self.resource_manager_instance.interconnect.getRouteCostXY(dst_node_id, 
                                                                     src_node_id,
                                                                     SimParams.NOC_PAYLOAD_32BYTES)
         payload = SimParams.NOC_PAYLOAD_32BYTES
         endTime_wrt_BL = release_time + basic_latency
         payload_metadata = {
                             'finished_task_id' : finished_task.get_id(),
                             'node_id' : self.get_id(),
                             'finished_task_starttime' : finished_task.get_taskStartTime(),
                             'finished_task_endtime' : finished_task.get_taskCompleteTime(),
                             }
                     
         newflow = NoCFlow(nextid,
                        finished_task,
                        finished_task.get_id(),
                        None, # list of dst task ids
                        None, # list of dst task ixs
                        src_node_id, 
                        dst_node_id, 
                        route,
                        priority, 
                        None, 
                        basic_latency, 
                        payload,
                        endTime_wrt_BL,
                        type=FlowType.FLOWTYPE_MASTERSLAVESIGNALLING_TASKCOMPLETE,                           
                        payload_metadata=payload_metadata)
         
         self.lock_RM_FLWtbl()
         # add to the flow table
         self.resource_manager_instance.flow_table.addFlow(newflow, release_time, basic_latency)                        
         self.release_RM_FLWtbl()
         
         # update the table        
         self.resource_manager_instance.flow_table.updateTable(fire=True)   
    def addTo_RM_FlowTable(self, task_list, releaseTime):

        for each_task in task_list:

            task_mapped_nodeid = self.RM_instance.task_mapping_table[
                each_task.get_id()]['node_id']
            child_tasks = each_task.get_children()

            # find unique flows
            # e.g. if task has two children both mapped on same node, then we only have 1 flow
            dst_node_list = []
            for each_child in child_tasks:
                child_task_nodeid = self.RM_instance.task_mapping_table[
                    each_child]['node_id']

                if (child_task_nodeid not in dst_node_list):
                    dst_node_list.append(child_task_nodeid)

                    # new flow
                    if (child_task_nodeid != task_mapped_nodeid):
                        nextid = self.RM_instance.flow_table.nextid
                        route = self.RM_instance.interconnect.getRouteXY(
                            task_mapped_nodeid, child_task_nodeid)
                        priority = random.randint(
                            0, SimParams.NOC_FLOW_PRIORITY_LEVELS)
                        basicLatency = self.RM_instance.interconnect.getRouteCostXY(
                            task_mapped_nodeid, child_task_nodeid,
                            each_task.get_completedTaskSize())
                        payload = each_task.get_completedTaskSize()
                        #                        releaseTime = self.RM_instance.task_mapping_table[each_task.get_id()]['release_time'] + \
                        #                                    self.RM_instance.task_mapping_table[each_task.get_id()]['wcc']
                        endTime_wrt_BL = releaseTime + basicLatency

                        newflow = NoCFlow(nextid,
                                          each_task.get_id(),
                                          task_mapped_nodeid,
                                          child_task_nodeid,
                                          route,
                                          priority,
                                          None,
                                          basicLatency,
                                          payload,
                                          releaseTime,
                                          None,
                                          endTime_wrt_BL,
                                          None,
                                          type=FlowType)
def _get_runtime_ccr(Iwcc, Pwcc, Bwcc, max_payload, num_edges, gop_seq):

    total_node_cost = 0.0
    for ft_type in gop_seq:

        if ft_type == "I": total_node_cost += Iwcc
        elif ft_type == "P": total_node_cost += Pwcc
        elif ft_type == "B": total_node_cost += Bwcc
        else:
            sys.exit("Error - _get_runtime_ccr")

    nhops = (NOC_H - 1) + (NOC_W - 1)
    max_bl = NoCFlow.getCommunicationCost(max_payload, nhops, NOC_PERIOD,
                                          NOC_ARBITRATION_COST)

    total_edges_cost = max_bl * float(num_edges)

    runtime_ccr = float(total_edges_cost) / float(total_node_cost)
    return runtime_ccr
    def getNodeCongestionRating(self, node_id, task_pri=None, nextid=None):
        
        # what are the links connected to the node ?
        node_connected_linkids = [l.get_id() for l in self.RMinstance.interconnect.getLinksConnectedToNode(node_id)]
        
        # link to flow mapping
        link_to_flow_mapping = self.getLinkToFlowMapping()

        node_congestion = 0 # number of flows that will block a given task
        
        for each_link_id in node_connected_linkids:
            if(each_link_id in link_to_flow_mapping):
                for each_flow in link_to_flow_mapping[each_link_id]:
                    if(task_pri != None):
                        flow_pri = NoCFlow.getPriorityFromTask(task_pri, self.RMinstance, nextid)
                        if(flow_pri < each_flow.get_priority()):
                            node_congestion += 1
                    else:   # if supplied task priority is None then this flow will by default be counted as congestion
                        node_congestion += 1
        
        return node_congestion
    def _notifyRMRegardingDataFlowCompletion_viaAnotherFlow_AfterDelay(
            self, completed_flow):

        if (SimParams.MS_SIGNALLING_NOTIFY_FLOW_COMPLETE_ENABLE == True):

            yield self.env.timeout(
                SimParams.INTERRUPT_RM_AFTER_DELAY
            )  # delay (to stop flow being updated too quickly)

            Debug.PPrint(
                "%f" % self.env.now + "," + self.label + "," +
                '_notifyRMRegardingDataFlowCompletion_viaAnotherFlow_AfterDelay::, : finished_flow='
                + str(completed_flow.get_id()),
                DebugCat.DEBUG_CAT_MSSIGNALLING)

            ## notify the RM regarding flow completion (emit another flow to RM)
            src_task_id = completed_flow.get_respectiveSrcTaskId()
            dst_task_ids = [
            ]  # could be alot of dst tasks, mapped on the same dst core
            dst_task_ids = completed_flow.get_respectiveDstTaskId()

            # construct flow
            src_node_id = completed_flow.get_destination()
            dst_node_id = SimParams.RESOURCEMANAGER_NODEID
            release_time = self.env.now
            nextid = self.RM_instance.flow_table.nextid
            route = self.RM_instance.interconnect.getRouteXY(
                dst_node_id, src_node_id)
            priority = SimParams.NOC_FLOW_MS_SIGNALLING_MAXPRIORITY + nextid
            basic_latency = self.RM_instance.interconnect.getRouteCostXY(
                dst_node_id, src_node_id, SimParams.NOC_PAYLOAD_32BYTES)
            payload = SimParams.NOC_PAYLOAD_32BYTES
            endTime_wrt_BL = release_time + basic_latency
            payload_metadata = {
                'finished_flow_id': completed_flow.get_id(),
                'finished_flow_endtime': self.env.now,
                'finished_flow_src_task_id': src_task_id,
                'finished_flow_dst_task_ids': dst_task_ids
            }

            newflow = NoCFlow(
                nextid,
                None,
                None,
                None,  # list of dst task ids
                None,  # list of dst task ixs
                src_node_id,
                dst_node_id,
                route,
                priority,
                None,
                basic_latency,
                payload,
                endTime_wrt_BL,
                type=FlowType.FLOWTYPE_MASTERSLAVESIGNALLING_FLOWCOMPLETE,
                payload_metadata=payload_metadata)

            self.lock_RM_FLWtbl()
            # add to the flow table
            self.RM_instance.flow_table.addFlow(newflow, release_time,
                                                basic_latency)
            self.release_RM_FLWtbl()

            # update the table
            self.RM_instance.flow_table.updateTable(fire=True)
def get_specific_ccr(cpu_exec_speed_ratio, noc_period):

    list_ipb_frame_cost = []
    list_mean_computation_cost = []
    list_sum_computation_cost_all_tasks = []
    list_mean_computation_cost_all_tasks = []
    list_noc_flow_cc_all_edges = []
    list_noc_flow_cc = []
    list_ccr = []
    list_ccs = []

    for each_res in res_list:
        frame_h = each_res[0]
        frame_w = each_res[1]

        # computation cost
        (iframe_cc, pframe_cc,
         bframe_cc) = MPEG2FrameTask.getStaticComputationCost(
             frame_h, frame_w, cpu_exec_speed_ratio)
        mean_computation_cost = float(iframe_cc + pframe_cc + bframe_cc) / 3.0
        sum_computation_cost_all_tasks = (iframe_cc * 1.0) + (
            pframe_cc * 3.0) + (bframe_cc * 8.0)
        mean_computation_cost_all_tasks = (iframe_cc) + (pframe_cc) + (
            bframe_cc)

        # communication cost
        max_hop_count = (SimParams.NOC_W - 1) + (SimParams.NOC_H - 1)
        payload = ((frame_h * frame_w) * 16) / 8
        arb_cost = noc_period * 7
        noc_flow_cc = NoCFlow.getCommunicationCost(payload, max_hop_count,
                                                   noc_period, arb_cost)
        num_edges = 19
        noc_flow_cc_all_edges = (noc_flow_cc * num_edges)

        # CCR : communication to computation
        #ccr = noc_flow_cc/mean_computation_cost
        ccr = (noc_flow_cc_all_edges / sum_computation_cost_all_tasks)

        # CCS : communication + computation (summation)
        #ccs = noc_flow_cc + mean_computation_cost
        ccs = (noc_flow_cc_all_edges + sum_computation_cost_all_tasks)

        list_mean_computation_cost.append(mean_computation_cost)
        list_noc_flow_cc.append(noc_flow_cc)
        list_sum_computation_cost_all_tasks.append(
            sum_computation_cost_all_tasks)
        list_mean_computation_cost_all_tasks.append(
            mean_computation_cost_all_tasks)
        list_noc_flow_cc_all_edges.append(noc_flow_cc_all_edges)
        list_ccr.append(ccr)
        list_ccs.append(ccs)
        list_ipb_frame_cost.append((iframe_cc, pframe_cc, bframe_cc))


#     print list_ccr
#     print list_ccs

    entry = {
        'cpu_exec_speed_ratio':
        cpu_exec_speed_ratio,
        'noc_period':
        noc_period,
        'mean_computation_cost':
        np.mean(list_mean_computation_cost),
        'noc_flow_cc':
        np.mean(list_noc_flow_cc),
        'sum_computation_cost_all_tasks':
        list_sum_computation_cost_all_tasks,
        'mean_computation_cost_all_tasks':
        list_mean_computation_cost_all_tasks,
        'noc_flow_cc_all_edges':
        list_noc_flow_cc_all_edges,
        'list_ipb_frame_cost':
        list_ipb_frame_cost,
        'list_ccr':
        list_ccr,
        'list_ccs':
        list_ccs,
        'mean_ccr':
        np.mean(list_ccr),
        'mean_ccs':
        np.mean(list_ccs),
        'ccr_v2':
        np.sum(list_noc_flow_cc_all_edges) /
        np.sum(list_mean_computation_cost_all_tasks),
        'csr_v2':
        np.sum(list_noc_flow_cc_all_edges) +
        np.sum(list_mean_computation_cost_all_tasks)
    }

    pprint.pprint(entry)
    def addTo_RM_FlowTable(self, finished_taskList, releaseTime,
                           debug_which_cpu):
        debug_ftl = [x.get_id() for x in finished_taskList]
        Debug.PPrint(
            "%f" % self.env.now + "," + self.label + "," +
            'addTo_RM_FlowTable::, : Enter - fin_tsk_lst=' + str(debug_ftl) +
            ", which_cpu=" + str(debug_which_cpu),
            DebugCat.DEBUG_CAT_MAPPERINFO)

        num_flows_added = []
        for each_task in finished_taskList:

            task_mapped_nodeid = self.RM_instance.task_mapping_table[
                each_task.get_id()]['node_id']
            child_tasks_ids = each_task.get_children()  #ids
            child_tasks_ixs = each_task.get_children_frames()  #ixs
            child_tasks_id_ix_rel = self._get_tid_tix_dict(
                child_tasks_ids, child_tasks_ixs)

            # find unique flows
            # e.g. if task has two children both mapped on same node, then we only have 1 flow
            dst_node_list = []
            temp_destinations_dict = {}
            for each_child_id in child_tasks_ids:
                child_task_nodeid = self.RM_instance.task_mapping_table[
                    each_child_id]['node_id']

                if (child_task_nodeid not in temp_destinations_dict):
                    temp_destinations_dict[child_task_nodeid] = [each_child_id]
                else:
                    temp_destinations_dict[child_task_nodeid].append(
                        each_child_id)

                if (child_task_nodeid not in dst_node_list):
                    dst_node_list.append(child_task_nodeid)

                    #                    ## DEBUG ##
                    #                    if(each_task.get_id() == 721):
                    #                        print "each_child_id = " + str(each_child_id)
                    #                        print "child_task_nodeid = " + str(child_task_nodeid)
                    #                        pprint.pprint(temp_destinations_dict)
                    #                        print "dst_node_list = " + str(dst_node_list)
                    #                    ###########

                    # new flow
                    if (child_task_nodeid != task_mapped_nodeid):
                        nextid = self.RM_instance.flow_table.nextid
                        route = self.RM_instance.interconnect.getRouteXY(
                            task_mapped_nodeid, child_task_nodeid)
                        priority = each_task.get_priority() + (
                            self.RM_instance.flow_priority_offset +
                            100) + nextid
                        basicLatency = self.RM_instance.interconnect.getRouteCostXY(
                            task_mapped_nodeid, child_task_nodeid,
                            each_task.get_completedTaskSize())
                        payload = each_task.get_completedTaskSize()
                        endTime_wrt_BL = releaseTime + basicLatency

                        newflow = NoCFlow(
                            nextid,
                            each_task,
                            each_task.get_id(),
                            temp_destinations_dict[child_task_nodeid],
                            self._get_tixs_from_tids(
                                temp_destinations_dict[child_task_nodeid],
                                child_tasks_id_ix_rel),
                            task_mapped_nodeid,
                            child_task_nodeid,
                            route,
                            priority,
                            None,
                            basicLatency,
                            payload,
                            endTime_wrt_BL,
                            type=FlowType.FLOWTYPE_DATA)

                        #                         ## DEBUG ##
                        #                        if(each_task.get_id() == 721):
                        #                            print newflow
                        #                        ###########

                        # add to the flow table
                        self.RM_instance.flow_table.addFlow(
                            newflow, releaseTime, basicLatency)
                        num_flows_added.append(newflow.get_id())

        # update the table
        if (len(num_flows_added) > 0):
            self.RM_instance.flow_table.updateTable(
                fire=True)  # one update for many additions
    def addTo_RM_FlowTable_HEVC_FrameLevel(self, finished_taskList,
                                           releaseTime, debug_which_cpu):
        debug_ftl = [x.get_id() for x in finished_taskList]
        Debug.PPrint(
            "%f" % self.env.now + "," + self.label + "," +
            'addTo_RM_FlowTable::, : Enter - fin_tsk_lst=' + str(debug_ftl) +
            ", which_cpu=" + str(debug_which_cpu),
            DebugCat.DEBUG_CAT_MAPPERINFO)

        TEMP_BYTE_OFFSET = 32

        num_flows_added = []
        for each_task in finished_taskList:

            task_mapped_nodeid = self.RM_instance.task_mapping_table[
                each_task.get_id()]['node_id']
            child_tasks_info = each_task.get_expected_data_to_children(
            )  # children and the data payload size

            # if we are sending two flows to the same node, corresponding to two child tasks,
            # then we have to make sure the payload is different (i.e. TEMP_BYTE_OFFSET), else there will be event firing isues
            temp_node_id_payload_dict = {}
            for each_child_id, each_child_payload in child_tasks_info.iteritems(
            ):
                child_task_nodeid = self.RM_instance.task_mapping_table[
                    each_child_id]['node_id']

                flow_payload = each_child_payload

                if child_task_nodeid in temp_node_id_payload_dict:  # redundancy
                    if (each_child_payload == temp_node_id_payload_dict[
                            child_task_nodeid]):  # same payload
                        temp_node_id_payload_dict[
                            child_task_nodeid] += TEMP_BYTE_OFFSET
                        flow_payload += TEMP_BYTE_OFFSET
                else:
                    temp_node_id_payload_dict[
                        child_task_nodeid] = each_child_payload

                # new flow
                if (child_task_nodeid != task_mapped_nodeid):
                    nextid = self.RM_instance.flow_table.nextid
                    route = self.RM_instance.interconnect.getRouteXY(
                        task_mapped_nodeid, child_task_nodeid)
                    priority = each_task.get_priority() + (
                        self.RM_instance.flow_priority_offset + 100) + nextid
                    payload = flow_payload
                    basicLatency = self.RM_instance.interconnect.getRouteCostXY(
                        task_mapped_nodeid, child_task_nodeid, payload)
                    payload_metadata = {
                        'child_id': each_child_id,
                        'each_child_payload': each_child_payload,
                    }
                    endTime_wrt_BL = releaseTime + basicLatency

                    newflow = NoCFlow(
                        nextid,
                        each_task,
                        each_task.get_id(),
                        [each_child_id],
                        None,  #self._get_tixs_from_tids(temp_destinations_dict[child_task_nodeid], child_tasks_id_ix_rel),
                        task_mapped_nodeid,
                        child_task_nodeid,
                        route,
                        priority,
                        None,
                        basicLatency,
                        payload,
                        endTime_wrt_BL,
                        type=FlowType.FLOWTYPE_DATA_HEVC,
                        payload_metadata=payload_metadata)

                    # add to the flow table
                    self.RM_instance.flow_table.addFlow(
                        newflow, releaseTime, basicLatency)
                    num_flows_added.append(newflow.get_id())

        # update the table
        if (len(num_flows_added) > 0):
            self.RM_instance.flow_table.updateTable(
                fire=True)  # one update for many additions
Exemple #19
0
    def startNodeToMMCDataTransfer(self, finished_task, node):
        src_node_id = node.get_id()
        #dst_node_id = self.getClosestMMCPort(src_node_id)
        dst_node_id = self.getMMCPort_handler(finished_task.get_id(),
                                              node.get_id())

        Debug.PPrint(
            "%f" % self.env.now + "," + self.label + "," +
            'startNodeToMMCDataTransfer:: after task finishes execution, : task=%s, %s->%s'
            %
            (str(finished_task.get_id()), str(src_node_id), str(dst_node_id)),
            DebugCat.DEBUG_CAT_MMCNODEDATATRANSFER)

        release_time = self.env.now
        nextid = self.RMInstance.flow_table.nextid
        route = self.RMInstance.interconnect.getRouteXY(
            src_node_id, dst_node_id)
        #priority = SimParams.MMC_DATAWRITE_FLOW_PRIORITY + nextid

        if SimParams.SIM_ENTITY_MAPPER_CLASS == MapperTypes.OPENLOOP_WITH_HEVCTILE:  # this changed for hevc tile experiments
            #priority = sys.maxint - (finished_task.get_priority() + (self.RMInstance.flow_priority_offset+100) + nextid)
            priority = finished_task.get_priority() + (
                self.RMInstance.flow_priority_offset + 100) + nextid
        else:
            priority = finished_task.get_priority() + (
                self.RMInstance.flow_priority_offset + 100) + nextid

        payload = finished_task.get_completedTaskSize()
        basic_latency = self.RMInstance.interconnect.getRouteCostXY(
            src_node_id, dst_node_id, payload)

        endTime_wrt_BL = release_time + basic_latency
        payload_metadata = {
            'finished_task': finished_task,
            'src_node': node,
        }

        newflow = NoCFlow(
            nextid,
            None,
            None,
            None,  # list of dst task ids
            None,  # list of dst task ixs
            src_node_id,
            dst_node_id,
            route,
            priority,
            None,
            basic_latency,
            payload,
            endTime_wrt_BL,
            type=FlowType.FLOWTYPE_MMCTONODE_DATATRANSFER_WR,
            payload_metadata=payload_metadata,
            creation_time=self.env.now)

        self.RMInstance.lock_RM_FLWtbl()
        # add to the flow table
        self.RMInstance.flow_table.addFlow(newflow, release_time,
                                           basic_latency)
        self.RMInstance.release_RM_FLWtbl()

        # update the table
        self.RMInstance.flow_table.updateTable(fire=True)
def get_properties_fixed_ccs_fixed_ccr_range(ccs_range,
                                             ccr_range,
                                             enable_print=True):

    random.seed(1234)
    result_data = []
    n = 0
    count = 0
    result_ccr_list = []

    while (n < len(ccr_range)):

        #cpu_exec_speed_ratio = random.choice(np.arange(cpu_exec_rat_min,cpu_exec_rat_max,(cpu_exec_rat_max-cpu_exec_rat_min)/10000))
        #noc_period = random.choice(np.arange(noc_period_min,noc_period_max,(noc_period_max-noc_period_min)/10000))

        cpu_exec_speed_ratio = 0.8
        noc_period = random.uniform(noc_period_min, noc_period_max)

        list_mean_computation_cost = []
        list_sum_computation_cost_all_tasks = []
        list_mean_computation_cost_all_tasks = []
        list_noc_flow_cc_all_edges = []
        list_noc_flow_cc = []
        list_ccr = []
        list_ccs = []

        for each_res in res_list:

            frame_h = each_res[0]
            frame_w = each_res[1]

            # computation cost
            (iframe_cc, pframe_cc,
             bframe_cc) = MPEG2FrameTask.getStaticComputationCost(
                 frame_h, frame_w, cpu_exec_speed_ratio)
            mean_computation_cost = float(iframe_cc + pframe_cc +
                                          bframe_cc) / 3.0
            sum_computation_cost_all_tasks = (iframe_cc * 1.0) + (
                pframe_cc * 3.0) + (bframe_cc * 8.0)
            mean_computation_cost_all_tasks = (iframe_cc) + (pframe_cc) + (
                bframe_cc)

            # communication cost
            max_hop_count = (SimParams.NOC_W - 1) + (SimParams.NOC_H - 1)
            payload = ((frame_h * frame_w) * 16) / 8
            arb_cost = noc_period * 7
            noc_flow_cc = NoCFlow.getCommunicationCost(payload, max_hop_count,
                                                       noc_period, arb_cost)
            num_edges = 19
            noc_flow_cc_all_edges = (noc_flow_cc * num_edges)

            # CCR : communication to computation
            #ccr = noc_flow_cc/mean_computation_cost
            ccr = (noc_flow_cc_all_edges / sum_computation_cost_all_tasks)

            # CCS : communication + computation (summation)
            #ccs = noc_flow_cc + mean_computation_cost
            ccs = (noc_flow_cc_all_edges + sum_computation_cost_all_tasks)

            list_mean_computation_cost.append(mean_computation_cost)
            list_noc_flow_cc.append(noc_flow_cc)
            list_sum_computation_cost_all_tasks.append(
                sum_computation_cost_all_tasks)
            list_mean_computation_cost_all_tasks.append(
                mean_computation_cost_all_tasks)
            list_noc_flow_cc_all_edges.append(noc_flow_cc_all_edges)
            list_ccr.append(ccr)
            list_ccs.append(ccs)

        if (((np.mean(list_ccs) >= float(ccs_range[0])) and
             (np.mean(list_ccs) <= float(ccs_range[1])))
                and (round(np.mean(list_ccr), 3) not in result_ccr_list)
                and (round(np.mean(list_ccr), 3) in ccr_range)):
            entry = {
                'cpu_exec_speed_ratio': cpu_exec_speed_ratio,
                'noc_period': noc_period,
                'mean_computation_cost': np.mean(list_mean_computation_cost),
                'noc_flow_cc': np.mean(list_noc_flow_cc),
                'ccr': np.mean(list_ccr),
                'ccs': np.mean(list_ccs),
            }

            result_data.append(entry)
            result_ccr_list.append(round(np.mean(list_ccr), 3))
            n += 1
            print n, np.mean(list_ccr)

        count += 1

    # print table of results
    if (enable_print == True):
        # sort
        new_result_data = sorted(result_data, key=lambda k: k['ccr'])
        _report_ccr(new_result_data)

        ## write data file output
        fname = 'ccr_list_output_' + str(ccr_range[0]) + "_" + str(
            ccr_range[-1]) + ".js"
        _write_formatted_file(fname, new_result_data, "json")

    return result_data
def _gen_ccr(result_ccr_list, ccs_range, ccr_range, param_res_list):

    #cpu_exec_speed_ratio = random.choice(np.arange(cpu_exec_rat_min,cpu_exec_rat_max,(cpu_exec_rat_max-cpu_exec_rat_min)/10000))
    #noc_period = random.choice(np.arange(noc_period_min,noc_period_max,(noc_period_max-noc_period_min)/10000))
    #         global_noc_period_list.append(noc_period)
    #         while(noc_period in global_noc_period_list):
    #             global_noc_period_list.append(noc_period)
    #             noc_period = random.choice(np.arange(noc_period_min,noc_period_max,(noc_period_max-noc_period_min)/1000000))

    cpu_exec_speed_ratio = 0.8
    noc_period = random.uniform(noc_period_min, noc_period_max)

    list_mean_computation_cost = []
    list_sum_computation_cost_all_tasks = []
    list_mean_computation_cost_all_tasks = []
    list_noc_flow_cc_all_edges = []
    list_noc_flow_cc = []
    list_ccr = []
    list_ccs = []

    for each_res in param_res_list:

        frame_h = each_res[0]
        frame_w = each_res[1]

        # computation cost
        (iframe_cc, pframe_cc,
         bframe_cc) = MPEG2FrameTask.getStaticComputationCost(
             frame_h, frame_w, cpu_exec_speed_ratio)

        mean_computation_cost = float(iframe_cc + pframe_cc + bframe_cc) / 3.0
        sum_computation_cost_all_tasks = (iframe_cc * 1.0) + (
            pframe_cc * 3.0) + (bframe_cc * 8.0)
        mean_computation_cost_all_tasks = (
            sum_computation_cost_all_tasks) / 12.0

        # communication cost
        noc_w = np.sqrt(len(param_res_list) - 3)
        max_hop_count = (noc_w) + (noc_w)
        payload = ((frame_h * frame_w) * 16) / 8
        arb_cost = noc_period * 7
        noc_flow_cc = NoCFlow.getCommunicationCost(payload, max_hop_count,
                                                   noc_period, arb_cost)
        num_edges = 19
        noc_flow_cc_all_edges = (noc_flow_cc * num_edges)

        # CCR : communication to computation
        #ccr = noc_flow_cc/mean_computation_cost
        ccr = (noc_flow_cc_all_edges / sum_computation_cost_all_tasks)

        # CCS : communication + computation (summation)
        #ccs = noc_flow_cc + mean_computation_cost
        ccs = (noc_flow_cc_all_edges + sum_computation_cost_all_tasks)

        list_mean_computation_cost.append(mean_computation_cost)
        list_noc_flow_cc.append(noc_flow_cc)
        list_sum_computation_cost_all_tasks.append(
            sum_computation_cost_all_tasks)
        list_mean_computation_cost_all_tasks.append(
            mean_computation_cost_all_tasks)
        list_noc_flow_cc_all_edges.append(noc_flow_cc_all_edges)
        list_ccr.append(ccr)
        list_ccs.append(ccs)

    if (((np.mean(list_ccs) >= float(ccs_range[0])) and
         (np.mean(list_ccs) <= float(ccs_range[1])))
            and (round(np.mean(list_ccr), 3) not in result_ccr_list)
            and (round(np.mean(list_ccr), 3) in ccr_range)):
        entry = {
            'cpu_exec_speed_ratio': cpu_exec_speed_ratio,
            'noc_period': noc_period,
            'mean_computation_cost': np.mean(list_mean_computation_cost),
            'noc_flow_cc': np.mean(list_noc_flow_cc),
            'ccr': np.mean(list_ccr),
            'ccs': np.mean(list_ccs),
        }

        return entry
    else:
        return None