Пример #1
0
def min_execution_time(tg, ag, shm, logging):
    """
    :param tg: Task Graph
    :param ag: Architecture Graph
    :param shm: System Health Map
    :param logging: logging file
    :return: (TG, AG)
    """
    # this sounds a little stupid because there are no job specific machines...
    # we can Add Specific Accelerators or define different run time on different
    # PEs so this becomes more interesting...
    print ("===========================================")
    print ("STARTING MIN EXECUTION TIME MAPPING")
    for task_to_be_mapped in tg.nodes():
        chosen_node = random.choice(Mapping_Functions.fastest_nodes(ag, shm))
        tg.node[task_to_be_mapped]['task'].node = chosen_node
        ag.node[chosen_node]['PE'].mapped_tasks.append(task_to_be_mapped)
        ag.node[chosen_node]['PE'].utilization += tg.node[task_to_be_mapped]['task'].wcet

        node_speed_down = 1+((100.0-shm.node[chosen_node]['NodeSpeed'])/100)
        task_execution_on_node = tg.node[task_to_be_mapped]['task'].wcet*node_speed_down
        completion_on_node = tg.node[task_to_be_mapped]['task'].release + task_execution_on_node

        Scheduling_Functions_Nodes.add_tg_task_to_node(tg, ag, task_to_be_mapped, chosen_node,
                                                       tg.node[task_to_be_mapped]['task'].release,
                                                       completion_on_node, None)

        print ("\tTASK "+str(task_to_be_mapped)+" MAPPED ON NODE: "+str(chosen_node))
    print ("MIN EXECUTION TIME MAPPING FINISHED...")
    Scheduling_Reports.report_mapped_tasks(ag, logging)
    return tg, ag
Пример #2
0
def minimum_completion_time(tg, ag, shm, logging):
    """
    :param tg: Task Graph
    :param ag: Architecture Graph
    :param shm: System Health Map
    :param logging: logging File
    :return: (TG, AG)
    """
    # The difference with Min Min or Max Min is that we don't add priorities to
    # tasks based on their WCET but we randomly choose a task and schedule it...
    # Note :: This heuristic is not taking task ciriticality into account...
    print ("===========================================")
    print ("STARTING MIN COMPLETION TIME MAPPING")
    for task_to_be_mapped in tg.nodes():
        chosen_node = random.choice(Mapping_Functions.nodes_with_smallest_ct(ag, tg, shm, task_to_be_mapped))
        tg.node[task_to_be_mapped]['task'].node = chosen_node
        ag.node[chosen_node]['PE'].mapped_tasks.append(task_to_be_mapped)
        ag.node[chosen_node]['PE'].utilization += tg.node[task_to_be_mapped]['task'].wcet

        node_speed_down = 1+((100.0-shm.node[chosen_node]['NodeSpeed'])/100)
        task_execution_on_node = tg.node[task_to_be_mapped]['task'].wcet*node_speed_down
        completion_on_node = tg.node[task_to_be_mapped]['task'].release + task_execution_on_node

        Scheduling_Functions_Nodes.add_tg_task_to_node(tg, ag, task_to_be_mapped, chosen_node,
                                                       tg.node[task_to_be_mapped]['task'].release,
                                                       completion_on_node, None)

        print ("\tTASK "+str(task_to_be_mapped)+" MAPPED ON NODE: "+str(chosen_node))
    print ("MIN COMPLETION TIME MAPPING FINISHED...")
    Scheduling_Reports.report_mapped_tasks(ag, logging)
    return tg, ag
def MinExecutionTime(TG, AG, SHM, logging):
    """
    :param TG: Task Graph
    :param AG: Architecture Graph
    :param SHM: System Health Map
    :param logging: logging file
    :return: (TG, AG)
    """
    # this sounds a little stupid because there are no job specific machines...
    # we can Add Specific Accelerators or define different run time on different
    # PEs so this becomes more interesting...
    print("===========================================")
    print("STARTING MIN EXECUTION TIME MAPPING")
    for TaskToBeMapped in TG.nodes():
        ChosenNode = random.choice(
            Mapping_Functions.fastest_nodes(AG, SHM, TaskToBeMapped))
        TG.node[TaskToBeMapped]['Node'] = ChosenNode
        AG.node[ChosenNode]['PE'].MappedTasks.append(TaskToBeMapped)
        AG.node[ChosenNode]['PE'].Utilization += TG.node[TaskToBeMapped][
            'WCET']

        NodeSpeedDown = 1 + ((100.0 - SHM.node[ChosenNode]['NodeSpeed']) / 100)
        TaskExecutionOnNode = TG.node[TaskToBeMapped]['WCET'] * NodeSpeedDown
        CompletionOnNode = TG.node[TaskToBeMapped][
            'Release'] + TaskExecutionOnNode

        Scheduling_Functions_Nodes.Add_TG_TaskToNode(
            TG, AG, TaskToBeMapped, ChosenNode,
            TG.node[TaskToBeMapped]['Release'], CompletionOnNode, logging)

        print("\tTASK " + str(TaskToBeMapped) + " MAPPED ON NODE: " +
              str(ChosenNode))
    print("MIN EXECUTION TIME MAPPING FINISHED...")
    Scheduling_Reports.report_mapped_tasks(AG, logging)
    return TG, AG
Пример #4
0
def first_free(tg, ag, logging):
    print ("===========================================")
    print ("STARTING FIRST FREE MAPPING")
    # Todo: to write the function

    print ("FIRST FREE MAPPING FINISHED...")
    Scheduling_Reports.report_mapped_tasks(ag, logging)
    return tg, ag
def FirstFree(TG, AG, SHM, logging):
    print("===========================================")
    print("STARTING FIRST FREE MAPPING")
    # Todo: to write the function

    print("FIRST FREE MAPPING FINISHED...")
    Scheduling_Reports.report_mapped_tasks(AG, logging)
    return TG, AG
Пример #6
0
def first_free(tg, ag, logging):
    print("===========================================")
    print("STARTING FIRST FREE MAPPING")
    # Todo: to write the function

    print("FIRST FREE MAPPING FINISHED...")
    Scheduling_Reports.report_mapped_tasks(ag, logging)
    return tg, ag
Пример #7
0
def min_min_mapping(tg, ag, shm, logging):
    """
    :param tg: Task Graph
    :param ag: Architecture Graph
    :param shm: System Health Map
    :param logging: logging file
    :return: (TG, AG)
    """
    # this function finds the task with the smallest WCET and
    # maps it on the machine that can offer smallest completion time...
    # this means that the mapping algorithm has to take into account the mapping
    # of the edges of the task graph on the links.
    # Note:: this is a heuristic for independent tasks... so we are not going to
    # schedule any link
    # Note 2:: This heuristic is not taking task ciriticality into account...
    print("===========================================")
    print("STARTING MIN-MIN MAPPING")
    shortest_tasks = Mapping_Functions.unmapped_task_with_smallest_wcet(
        tg, logging)
    while len(shortest_tasks) > 0:
        task_to_be_mapped = shortest_tasks.pop()
        # map the task on the Node that yields smallest Completion time
        candidate_nodes = Mapping_Functions.nodes_with_smallest_ct(
            ag, tg, shm, task_to_be_mapped)
        print("\tCANDIDATE NODES FOR MAPPING: " + str(candidate_nodes))
        if len(candidate_nodes) > 0:
            chosen_node = random.choice(candidate_nodes)
            print("\t\tMAPPING TASK " + str(task_to_be_mapped) +
                  " WITH RELEASE: " +
                  str(tg.node[task_to_be_mapped]['task'].release) +
                  " ---> NODE: " + str(chosen_node))
            tg.node[task_to_be_mapped]['task'].node = chosen_node
            ag.node[chosen_node]['PE'].mapped_tasks.append(task_to_be_mapped)
            ag.node[chosen_node]['PE'].utilization += tg.node[
                task_to_be_mapped]['task'].wcet

            node_speed_down = 1 + (
                (100.0 - shm.node[chosen_node]['NodeSpeed']) / 100)
            task_execution_on_node = tg.node[task_to_be_mapped][
                'task'].wcet * node_speed_down
            completion_on_node = tg.node[task_to_be_mapped][
                'task'].release + task_execution_on_node

            Scheduling_Functions_Nodes.add_tg_task_to_node(
                tg, ag, task_to_be_mapped, chosen_node,
                tg.node[task_to_be_mapped]['task'].release, completion_on_node,
                None)
        if len(shortest_tasks) == 0:
            shortest_tasks = Mapping_Functions.unmapped_task_with_smallest_wcet(
                tg, logging)
    print("MIN-MIN MAPPING FINISHED...")
    Scheduling_Reports.report_mapped_tasks(ag, logging)
    return tg, ag
def Min_Min_Mapping(TG, AG, NoCRG, SHM, logging):
    """
    :param TG: Task Graph
    :param AG: Architecture Graph
    :param NoCRG: NoC Routing Graph
    :param SHM: System Health Map
    :param logging: logging file
    :return: (TG, AG)
    """
    # this function finds the task with the smallest WCET and
    # maps it on the machine that can offer smallest completion time...
    # this means that the mapping algorithm has to take into account the mapping
    # of the edges of the task graph on the links.
    # Note:: this is a heuristic for independent tasks... so we are not going to
    # schedule any link
    # Note 2:: This heuristic is not taking task ciriticality into account...
    print("===========================================")
    print("STARTING MIN-MIN MAPPING")
    ShortestTasks = Mapping_Functions.unmapped_task_with_smallest_wcet(
        TG, logging)
    while len(ShortestTasks) > 0:
        TaskToBeMapped = ShortestTasks.pop()
        # map the task on the Node that yields smallest Completion time
        CandidateNodes = Mapping_Functions.nodes_with_smallest_ct(
            AG, TG, SHM, TaskToBeMapped)
        print("\tCANDIDATE NODES FOR MAPPING: " + str(CandidateNodes))
        if len(CandidateNodes) > 0:
            ChosenNode = random.choice(CandidateNodes)
            print("\t\tMAPPING TASK " + str(TaskToBeMapped) +
                  " WITH RELEASE: " + str(TG.node[TaskToBeMapped]['Release']) +
                  " ---> NODE: " + str(ChosenNode))
            TG.node[TaskToBeMapped]['Node'] = ChosenNode
            AG.node[ChosenNode]['PE'].MappedTasks.append(TaskToBeMapped)
            AG.node[ChosenNode]['PE'].Utilization += TG.node[TaskToBeMapped][
                'WCET']

            NodeSpeedDown = 1 + (
                (100.0 - SHM.node[ChosenNode]['NodeSpeed']) / 100)
            TaskExecutionOnNode = TG.node[TaskToBeMapped][
                'WCET'] * NodeSpeedDown
            CompletionOnNode = TG.node[TaskToBeMapped][
                'Release'] + TaskExecutionOnNode

            Scheduling_Functions_Nodes.Add_TG_TaskToNode(
                TG, AG, TaskToBeMapped, ChosenNode,
                TG.node[TaskToBeMapped]['Release'], CompletionOnNode, logging)
        if len(ShortestTasks) == 0:
            ShortestTasks = Mapping_Functions.unmapped_task_with_smallest_wcet(
                TG, logging)
    print("MIN-MIN MAPPING FINISHED...")
    Scheduling_Reports.report_mapped_tasks(AG, logging)
    return TG, AG
Пример #9
0
def max_min_mapping(tg, ag, shm, logging):
    """

    :param tg: Task Graph
    :param ag: Architecture Graph
    :param shm: System Health Map
    :param logging: logging file
    :return: (TG, AG)
    """
    # this function finds the task with the biggest WCET and
    # maps it on the machine that can offer smallest completion time...
    # this means that the mapping algorithm has to take into account the mapping
    # of the edges of the task graph on the links.
    # Note:: this is a heuristic for independent tasks... so we are not going to
    # schedule any link
    # Note 2:: This heuristic is not taking task ciriticality into account...
    print ("===========================================")
    print ("STARTING MAX-MIN MAPPING")
    longest_tasks = Mapping_Functions.unmapped_task_with_biggest_wcet(tg, logging)
    while len(longest_tasks) > 0:
        task_to_be_mapped = longest_tasks.pop()
        # map the task on the Node that yields smallest Completion time
        candidate_nodes = Mapping_Functions.nodes_with_smallest_ct(ag, tg, shm, task_to_be_mapped)
        print ("CANDIDATE NODES FOR MAPPING: "+str(candidate_nodes))
        if len(candidate_nodes) > 0:
            chosen_node = random.choice(candidate_nodes)
            if len(candidate_nodes) > 1:
                print ("\tMAPPING TASK "+str(task_to_be_mapped)+" WITH RELEASE: " +
                       str(tg.node[task_to_be_mapped]['task'].release) +
                       " ---> NODE: "+str(chosen_node)+" (RANDOMLY CHOSEN FROM CANDIDATES)")
            else:
                print ("\tMAPPING TASK "+str(task_to_be_mapped)+" WITH RELEASE: " +
                       str(tg.node[task_to_be_mapped]['task'].release) +
                       " ---> NODE: "+str(chosen_node))
            tg.node[task_to_be_mapped]['task'].node = chosen_node
            ag.node[chosen_node]['PE'].mapped_tasks.append(task_to_be_mapped)
            ag.node[chosen_node]['PE'].utilization += tg.node[task_to_be_mapped]['task'].wcet

            node_speed_down = 1+((100.0-shm.node[chosen_node]['NodeSpeed'])/100)
            task_execution_on_node = tg.node[task_to_be_mapped]['task'].wcet*node_speed_down
            completion_on_node = tg.node[task_to_be_mapped]['task'].release + task_execution_on_node

            Scheduling_Functions_Nodes.add_tg_task_to_node(tg, ag, task_to_be_mapped, chosen_node,
                                                           tg.node[task_to_be_mapped]['task'].release,
                                                           completion_on_node, None)

        if len(longest_tasks) == 0:
            longest_tasks = Mapping_Functions.unmapped_task_with_biggest_wcet(tg, logging)
    print ("MIN-MAX MAPPING FINISHED...")
    Scheduling_Reports.report_mapped_tasks(ag, logging)
    return tg, ag
Пример #10
0
def minimum_completion_time(tg, ag, shm, logging):
    """
    :param tg: Task Graph
    :param ag: Architecture Graph
    :param shm: System Health Map
    :param logging: logging File
    :return: (TG, AG)
    """
    # The difference with Min Min or Max Min is that we don't add priorities to
    # tasks based on their WCET but we randomly choose a task and schedule it...
    # Note :: This heuristic is not taking task ciriticality into account...
    print("===========================================")
    print("STARTING MIN COMPLETION TIME MAPPING")
    for task_to_be_mapped in tg.nodes():
        chosen_node = random.choice(
            Mapping_Functions.nodes_with_smallest_ct(ag, tg, shm,
                                                     task_to_be_mapped))
        tg.node[task_to_be_mapped]['task'].node = chosen_node
        ag.node[chosen_node]['PE'].mapped_tasks.append(task_to_be_mapped)
        ag.node[chosen_node]['PE'].utilization += tg.node[task_to_be_mapped][
            'task'].wcet

        node_speed_down = 1 + (
            (100.0 - shm.node[chosen_node]['NodeSpeed']) / 100)
        task_execution_on_node = tg.node[task_to_be_mapped][
            'task'].wcet * node_speed_down
        completion_on_node = tg.node[task_to_be_mapped][
            'task'].release + task_execution_on_node

        Scheduling_Functions_Nodes.add_tg_task_to_node(
            tg, ag, task_to_be_mapped, chosen_node,
            tg.node[task_to_be_mapped]['task'].release, completion_on_node,
            None)

        print("\tTASK " + str(task_to_be_mapped) + " MAPPED ON NODE: " +
              str(chosen_node))
    print("MIN COMPLETION TIME MAPPING FINISHED...")
    Scheduling_Reports.report_mapped_tasks(ag, logging)
    return tg, ag
Пример #11
0
def min_execution_time(tg, ag, shm, logging):
    """
    :param tg: Task Graph
    :param ag: Architecture Graph
    :param shm: System Health Map
    :param logging: logging file
    :return: (TG, AG)
    """
    # this sounds a little stupid because there are no job specific machines...
    # we can Add Specific Accelerators or define different run time on different
    # PEs so this becomes more interesting...
    print("===========================================")
    print("STARTING MIN EXECUTION TIME MAPPING")
    for task_to_be_mapped in tg.nodes():
        chosen_node = random.choice(Mapping_Functions.fastest_nodes(ag, shm))
        tg.node[task_to_be_mapped]['task'].node = chosen_node
        ag.node[chosen_node]['PE'].mapped_tasks.append(task_to_be_mapped)
        ag.node[chosen_node]['PE'].utilization += tg.node[task_to_be_mapped][
            'task'].wcet

        node_speed_down = 1 + (
            (100.0 - shm.node[chosen_node]['NodeSpeed']) / 100)
        task_execution_on_node = tg.node[task_to_be_mapped][
            'task'].wcet * node_speed_down
        completion_on_node = tg.node[task_to_be_mapped][
            'task'].release + task_execution_on_node

        Scheduling_Functions_Nodes.add_tg_task_to_node(
            tg, ag, task_to_be_mapped, chosen_node,
            tg.node[task_to_be_mapped]['task'].release, completion_on_node,
            None)

        print("\tTASK " + str(task_to_be_mapped) + " MAPPED ON NODE: " +
              str(chosen_node))
    print("MIN EXECUTION TIME MAPPING FINISHED...")
    Scheduling_Reports.report_mapped_tasks(ag, logging)
    return tg, ag
def MinimumCompletionTime(TG, AG, SHM, logging):
    """
    :param TG: Task Graph
    :param AG: Architecture Graph
    :param SHM: System Health Map
    :param logging: logging File
    :return: (TG, AG)
    """
    # The difference with Min Min or Max Min is that we don't add priorities to
    # tasks based on their WCET but we randomly choose a task and schedule it...
    # Note :: This heuristic is not taking task ciriticality into account...
    print("===========================================")
    print("STARTING MIN COMPLETION TIME MAPPING")
    for TaskToBeMapped in TG.nodes():
        ChosenNode = random.choice(
            Mapping_Functions.nodes_with_smallest_ct(AG, TG, SHM,
                                                     TaskToBeMapped))
        TG.node[TaskToBeMapped]['Node'] = ChosenNode
        AG.node[ChosenNode]['PE'].MappedTasks.append(TaskToBeMapped)
        AG.node[ChosenNode]['PE'].Utilization += TG.node[TaskToBeMapped][
            'WCET']

        NodeSpeedDown = 1 + ((100.0 - SHM.node[ChosenNode]['NodeSpeed']) / 100)
        TaskExecutionOnNode = TG.node[TaskToBeMapped]['WCET'] * NodeSpeedDown
        CompletionOnNode = TG.node[TaskToBeMapped][
            'Release'] + TaskExecutionOnNode

        Scheduling_Functions_Nodes.Add_TG_TaskToNode(
            TG, AG, TaskToBeMapped, ChosenNode,
            TG.node[TaskToBeMapped]['Release'], CompletionOnNode, logging)

        print("\tTASK " + str(TaskToBeMapped) + " MAPPED ON NODE: " +
              str(ChosenNode))
    print("MIN COMPLETION TIME MAPPING FINISHED...")
    Scheduling_Reports.report_mapped_tasks(AG, logging)
    return TG, AG
Пример #13
0
def run_simulator(runtime, tg, ag, shmu, noc_rg, critical_rg, noncritical_rg, logging):
    """
    prepares and runs the simulator
    :param runtime: duration of which the user wants to run the program in cycles
    :param ag: architecture graph
    :param shmu: system health monitoring unit
    :param noc_rg: noc routing graph
    :param logging: logging file
    :return: None
    """
    print "==========================================="
    print "SETTING UP THE SIMULATOR..."
    env = simpy.Environment()
    print "SETTING UP counter-threshold MODULE..."
    if Config.classification_method == "counter_threshold":

        counter_threshold = CounterThreshold.CounterThreshold(Config.fault_counter_threshold,
                                                              Config.health_counter_threshold,
                                                              Config.intermittent_counter_threshold)
    elif Config.classification_method == "machine_learning":
        counter_threshold = MachineLearning.MachineLearning(Config.fault_counter_threshold,     # Rene's addition
                                                            Config.health_counter_threshold*3,
                                                            Config.intermittent_counter_threshold)
    else:
        raise ValueError("Unknown Classification Method!! Check config file")

    # the fault_time_dictionary looks like this:
    # fault_time_dictionary[fault_time] = (fault_location, fault_type)
    fault_time_dict = {}
    schedule_length = Scheduling_Functions.find_schedule_make_span(ag)
    if Config.EventDrivenFaultInjection:
        if Config.fault_injection_method == "random":
            fault_time_dict = copy.deepcopy(generate_random_fault_time_dict(runtime, shmu.SHM))
        elif Config.fault_injection_method == "from_file":
            fault_time_dict = generate_fault_time_dict_from_file()

        env.process(fault_event(env, ag, shmu, noc_rg, schedule_length, fault_time_dict,
                                counter_threshold, logging))

    print "SETTING UP ROUTERS AND PES..."
    for node in ag.nodes():
        # print node, AG.node[node]["Scheduling"]
        env.process(processor_sim(env, ag, shmu, node, schedule_length,
                                  fault_time_dict, counter_threshold,  logging))
        env.process(router_sim(env, ag, shmu, node, schedule_length,
                               fault_time_dict, counter_threshold, logging))

    print "SETTING UP LINKS..."
    for link in ag.edges():
        # print link, AG.edge[link[0]][link[1]]["Scheduling"]
        env.process(link_sim(env, ag, shmu, link, schedule_length,
                             fault_time_dict, counter_threshold, logging))

    env.process(sim_report(env, ag, shmu, counter_threshold))
    print "STARTING SIMULATION..."
    env.run()
    iteration = 1
    time_passed = env.now
    del env

    while time_passed < Config.ProgramRunTime:
        print "==========================================="
        Config.ProgramRunTime -= time_passed
        shmu.signal_reconfiguration = False
        tg, ag = copy.deepcopy(system_reconfiguration(tg, ag, shmu, noc_rg, critical_rg, noncritical_rg,
                                                      iteration, logging))
        print "SETTING UP THE SIMULATOR..."
        env = simpy.Environment()

        # fault_time_dict = {}
        schedule_length = Scheduling_Functions.find_schedule_make_span(ag)
        if Config.EventDrivenFaultInjection:
            fault_time_dict = copy.deepcopy(update_fault_time_dict(time_passed, fault_time_dict))
            env.process(fault_event(env, ag, shmu, noc_rg, schedule_length, fault_time_dict,
                                    counter_threshold, logging))
        print "SETTING UP ROUTERS AND PES..."
        for node in ag.nodes():
            # print node, AG.node[node]["Scheduling"]
            env.process(processor_sim(env, ag, shmu, node, schedule_length,
                                      fault_time_dict, counter_threshold,  logging))
            env.process(router_sim(env, ag, shmu, node, schedule_length,
                                   fault_time_dict, counter_threshold, logging))
        print "SETTING UP LINKS..."
        for link in ag.edges():
            # print link, AG.edge[link[0]][link[1]]["Scheduling"]
            env.process(link_sim(env, ag, shmu, link, schedule_length,
                                 fault_time_dict, counter_threshold, logging))
        print "SETTING UP SIM MONITORS..."
        env.process(sim_report(env, ag, shmu, counter_threshold))

        print "RESTARTING SIMULATION..."
        print "REMAINING SIM TIME:", Config.ProgramRunTime
        env.run()
        iteration += 1
        time_passed = env.now
        del env
    print "SIMULATION FINISHED..."
    print "SYSTEM DEGRADATION:", shmu.system_degradation
    counter_threshold.report(len(ag.nodes()), len(ag.edges()))
    Counter_Threshold_Viz.counter_threshold_viz(ag, counter_threshold)
    Scheduling_Reports.report_scheduling_memory_usage(ag)
    return None
def initialize_system(logging):
    """
    Generates the Task graph, Architecture Graph, System Health Monitoring Unit, NoC routing graph(s) and
    Test Task Graphs and does the mapping and scheduling and returns to the user the initial system
    :param logging: logging file
    :return:  tg, ag, shmu, noc_rg, critical_rg, noncritical_rg, pmcg
    """
    tg = copy.deepcopy(TG_Functions.generate_tg())
    if Config.DebugInfo:
        Task_Graph_Reports.report_task_graph(tg, logging)
    Task_Graph_Reports.draw_task_graph(tg)
    if Config.TestMode:
        TG_Test.check_acyclic(tg, logging)
    ####################################################################
    ag = copy.deepcopy(AG_Functions.generate_ag(logging))
    AG_Functions.update_ag_regions(ag)
    AG_Functions.random_darkness(ag)
    if Config.EnablePartitioning:
        AG_Functions.setup_network_partitioning(ag)
    if Config.FindOptimumAG:
        Arch_Graph_Reports.draw_ag(ag, "AG_Full")
    else:
        Arch_Graph_Reports.draw_ag(ag, "AG")
    ####################################################################
    Config.setup_turns_health()

    shmu = SystemHealthMonitoringUnit.SystemHealthMonitoringUnit()
    shmu.setup_noc_shm(ag, Config.TurnsHealth, True)
    # Here we are injecting initial faults of the system: we assume these fault
    # information is obtained by post manufacturing system diagnosis
    if Config.FindOptimumAG:
        vl_opt.optimize_ag_vertical_links(ag, shmu, logging)
        vl_opt_functions.cleanup_ag(ag, shmu)
        Arch_Graph_Reports.draw_ag(ag, "AG_VLOpt")
    SHMU_Functions.apply_initial_faults(shmu)
    if Config.viz.shm:
        SHMU_Reports.draw_shm(shmu.SHM)
        SHMU_Reports.draw_temp_distribution(shmu.SHM)
    # SHM_Reports.report_noc_shm()
    ####################################################################
    routing_graph_start_time = time.time()
    if Config.SetRoutingFromFile:
        noc_rg = copy.deepcopy(Routing.gen_noc_route_graph_from_file(ag, shmu, Config.RoutingFilePath,
                                                                     Config.DebugInfo, Config.DebugDetails))
    else:
        noc_rg = copy.deepcopy(Routing.generate_noc_route_graph(ag, shmu, Config.UsedTurnModel,
                                                                Config.DebugInfo, Config.DebugDetails))
    Routing_Functions.check_deadlock_freeness(noc_rg)
    print ("\033[92mTIME::\033[0m ROUTING GRAPH GENERATION TOOK: " +
           str(round(time.time()-routing_graph_start_time))+" SECONDS")
    # this is for double checking...
    if Config.FindOptimumAG:
        Calculate_Reachability.reachability_metric(ag, noc_rg, True)
    # Some visualization...
    if Config.viz.rg:
        RoutingGraph_Reports.draw_rg(noc_rg)
    ####################################################################
    # in case of partitioning, we have to route based on different Route-graphs
    if Config.EnablePartitioning:
        critical_rg, noncritical_rg = Calculate_Reachability.calculate_reachability_with_regions(ag, shmu)
        ReachabilityReports.report_gsnoc_friendly_reachability_in_file(ag)
    else:
        critical_rg, noncritical_rg = None, None
        Calculate_Reachability.calculate_reachability(ag, noc_rg)
        Calculate_Reachability.optimize_reachability_rectangles(ag, Config.NumberOfRects)
        # ReachabilityReports.report_reachability(ag)
        ReachabilityReports.report_reachability_in_file(ag, "ReachAbilityNodeReport")
        ReachabilityReports.report_gsnoc_friendly_reachability_in_file(ag)
    ####################################################################
    if Config.read_mapping_from_file:
        Mapping_Functions.read_mapping_from_file(tg, ag, shmu.SHM, noc_rg, critical_rg, noncritical_rg,
                                                 Config.mapping_file_path, logging)
        Scheduler.schedule_all(tg, ag, shmu.SHM, False, logging)
    else:
        best_tg, best_ag = Mapping.mapping(tg, ag, noc_rg, critical_rg, noncritical_rg, shmu.SHM, logging)
        if best_ag is not None and best_tg is not None:
            tg = copy.deepcopy(best_tg)
            ag = copy.deepcopy(best_ag)
            del best_tg, best_ag
            # SHM.add_current_mapping_to_mpm(tg)
            Mapping_Functions.write_mapping_to_file(ag, "mapping_report")
    if Config.viz.mapping_distribution:
        Mapping_Reports.draw_mapping_distribution(ag, shmu)
    if Config.viz.mapping:
        Mapping_Reports.draw_mapping(tg, ag, shmu.SHM, "Mapping_post_opt")
    if Config.viz.scheduling:
        Scheduling_Reports.generate_gantt_charts(tg, ag, "SchedulingTG")
    ####################################################################
    # PMC-Graph
    # at this point we assume that the system health map knows about the initial faults from
    # the diagnosis process
    if Config.GeneratePMCG:
        pmcg_start_time = time.time()
        if Config.OneStepDiagnosable:
            pmcg = TestSchedulingUnit.gen_one_step_diagnosable_pmcg(ag, shmu.SHM)
        else:
            pmcg = TestSchedulingUnit.gen_sequentially_diagnosable_pmcg(ag, shmu.SHM)
        test_tg = TestSchedulingUnit.generate_test_tg_from_pmcg(pmcg)
        print ("\033[92mTIME::\033[0m PMCG AND TTG GENERATION TOOK: " +
               str(round(time.time()-pmcg_start_time)) + " SECONDS")
        if Config.viz.pmcg:
            TestSchedulingUnit.draw_pmcg(pmcg)
        if Config.viz.ttg:
            TestSchedulingUnit.draw_ttg(test_tg)
        TestSchedulingUnit.insert_test_tasks_in_tg(pmcg, tg)
        Task_Graph_Reports.draw_task_graph(tg, ttg=test_tg)
        TestSchedulingUnit.map_test_tasks(tg, ag, shmu.SHM, noc_rg, logging)
        Scheduler.schedule_test_in_tg(tg, ag, shmu.SHM, False, logging)
        Scheduling_Reports.report_mapped_tasks(ag, logging)
        # TestSchedulingUnit.remove_test_tasks_from_tg(test_tg, tg)
        # Task_Graph_Reports.draw_task_graph(tg, TTG=test_tg)
        Scheduling_Reports.generate_gantt_charts(tg, ag, "SchedulingWithTTG")
    else:
        pmcg = None
    Arch_Graph_Reports.gen_latex_ag(ag, shmu.SHM)
    print ("===========================================")
    print ("SYSTEM IS UP...")

    TrafficTableGenerator.generate_noxim_traffic_table(ag, tg)
    if Config.viz.mapping_frames:
        Mapping_Animation.generate_frames(ag, shmu.SHM)
    return tg, ag, shmu, noc_rg, critical_rg, noncritical_rg, pmcg
Пример #15
0
def initialize_system(logging):
    """
    Generates the Task graph, Architecture Graph, System Health Monitoring Unit, NoC routing graph(s) and
    Test Task Graphs and does the mapping and scheduling and returns to the user the initial system
    :param logging: logging file
    :return:  tg, ag, shmu, noc_rg, critical_rg, noncritical_rg, pmcg
    """
    tg = copy.deepcopy(TG_Functions.generate_tg())
    if Config.DebugInfo:
        Task_Graph_Reports.report_task_graph(tg, logging)
    Task_Graph_Reports.draw_task_graph(tg)
    if Config.TestMode:
        TG_Test.check_acyclic(tg, logging)
    ####################################################################
    ag = copy.deepcopy(AG_Functions.generate_ag(logging))
    AG_Functions.update_ag_regions(ag)
    AG_Functions.random_darkness(ag)
    if Config.EnablePartitioning:
        AG_Functions.setup_network_partitioning(ag)
    if Config.FindOptimumAG:
        Arch_Graph_Reports.draw_ag(ag, "AG_Full")
    else:
        Arch_Graph_Reports.draw_ag(ag, "AG")
    ####################################################################
    Config.setup_turns_health()

    shmu = SystemHealthMonitoringUnit.SystemHealthMonitoringUnit()
    shmu.setup_noc_shm(ag, Config.TurnsHealth, True)
    # Here we are injecting initial faults of the system: we assume these fault
    # information is obtained by post manufacturing system diagnosis
    if Config.FindOptimumAG:
        vl_opt.optimize_ag_vertical_links(ag, shmu, logging)
        vl_opt_functions.cleanup_ag(ag, shmu)
        Arch_Graph_Reports.draw_ag(ag, "AG_VLOpt")
    SHMU_Functions.apply_initial_faults(shmu)
    if Config.viz.shm:
        SHMU_Reports.draw_shm(shmu.SHM)
        SHMU_Reports.draw_temp_distribution(shmu.SHM)
    # SHM_Reports.report_noc_shm()
    ####################################################################
    routing_graph_start_time = time.time()
    if Config.SetRoutingFromFile:
        noc_rg = copy.deepcopy(Routing.gen_noc_route_graph_from_file(ag, shmu, Config.RoutingFilePath,
                                                                     Config.DebugInfo, Config.DebugDetails))
    else:
        noc_rg = copy.deepcopy(Routing.generate_noc_route_graph(ag, shmu, Config.UsedTurnModel,
                                                                Config.DebugInfo, Config.DebugDetails))
    Routing_Functions.check_deadlock_freeness(noc_rg)
    print("\033[92mTIME::\033[0m ROUTING GRAPH GENERATION TOOK: " +
           str(round(time.time()-routing_graph_start_time))+" SECONDS")
    # this is for double checking...
    if Config.FindOptimumAG:
        Calculate_Reachability.reachability_metric(ag, noc_rg, True)
    # Some visualization...
    if Config.viz.rg:
        RoutingGraph_Reports.draw_rg(noc_rg)
    ####################################################################
    # in case of partitioning, we have to route based on different Route-graphs
    if Config.EnablePartitioning:
        critical_rg, noncritical_rg = Calculate_Reachability.calculate_reachability_with_regions(ag, shmu)
        ReachabilityReports.report_gsnoc_friendly_reachability_in_file(ag)
    else:
        critical_rg, noncritical_rg = None, None
        Calculate_Reachability.calculate_reachability(ag, noc_rg)
        Calculate_Reachability.optimize_reachability_rectangles(ag, Config.NumberOfRects)
        # ReachabilityReports.report_reachability(ag)
        ReachabilityReports.report_reachability_in_file(ag, "ReachAbilityNodeReport")
        ReachabilityReports.report_gsnoc_friendly_reachability_in_file(ag)
    ####################################################################
    if Config.read_mapping_from_file:
        Mapping_Functions.read_mapping_from_file(tg, ag, shmu.SHM, noc_rg, critical_rg, noncritical_rg,
                                                 Config.mapping_file_path, logging)
        Scheduler.schedule_all(tg, ag, shmu.SHM, False, logging)
    else:
        best_tg, best_ag = Mapping.mapping(tg, ag, noc_rg, critical_rg, noncritical_rg, shmu.SHM, logging)
        if best_ag is not None and best_tg is not None:
            tg = copy.deepcopy(best_tg)
            ag = copy.deepcopy(best_ag)
            del best_tg, best_ag
            # SHM.add_current_mapping_to_mpm(tg)
            Mapping_Functions.write_mapping_to_file(ag, "mapping_report")
    if Config.viz.mapping_distribution:
        Mapping_Reports.draw_mapping_distribution(ag, shmu)
    if Config.viz.mapping:
        Mapping_Reports.draw_mapping(tg, ag, shmu.SHM, "Mapping_post_opt")
    if Config.viz.scheduling:
        Scheduling_Reports.generate_gantt_charts(tg, ag, "SchedulingTG")
    ####################################################################
    # PMC-Graph
    # at this point we assume that the system health map knows about the initial faults from
    # the diagnosis process
    if Config.GeneratePMCG:
        pmcg_start_time = time.time()
        if Config.OneStepDiagnosable:
            pmcg = TestSchedulingUnit.gen_one_step_diagnosable_pmcg(ag, shmu.SHM)
        else:
            pmcg = TestSchedulingUnit.gen_sequentially_diagnosable_pmcg(ag, shmu.SHM)
        test_tg = TestSchedulingUnit.generate_test_tg_from_pmcg(pmcg)
        print("\033[92mTIME::\033[0m PMCG AND TTG GENERATION TOOK: " +
               str(round(time.time()-pmcg_start_time)) + " SECONDS")
        if Config.viz.pmcg:
            TestSchedulingUnit.draw_pmcg(pmcg)
        if Config.viz.ttg:
            TestSchedulingUnit.draw_ttg(test_tg)
        TestSchedulingUnit.insert_test_tasks_in_tg(pmcg, tg)
        Task_Graph_Reports.draw_task_graph(tg, ttg=test_tg)
        TestSchedulingUnit.map_test_tasks(tg, ag, shmu.SHM, noc_rg, logging)
        Scheduler.schedule_test_in_tg(tg, ag, shmu.SHM, False, logging)
        Scheduling_Reports.report_mapped_tasks(ag, logging)
        # TestSchedulingUnit.remove_test_tasks_from_tg(test_tg, tg)
        # Task_Graph_Reports.draw_task_graph(tg, TTG=test_tg)
        Scheduling_Reports.generate_gantt_charts(tg, ag, "SchedulingWithTTG")
    else:
        pmcg = None
    Arch_Graph_Reports.gen_latex_ag(ag, shmu.SHM)
    print("===========================================")
    print("SYSTEM IS UP...")

    TrafficTableGenerator.generate_noxim_traffic_table(ag, tg)
    if Config.viz.mapping_frames:
        Mapping_Animation.generate_frames(ag, shmu.SHM)
    return tg, ag, shmu, noc_rg, critical_rg, noncritical_rg, pmcg
Пример #16
0
def mapping(tg, ag, noc_rg, critical_rg, non_critical_rg, shm, logging, iteration=None
            , initial_mapping_string = None):
    """
    Calculate different mapping algorithms
    Returns tg And ag after Mapping in case of success
    :param tg: Task Graph
    :param ag: Architecture Graph
    :param noc_rg: NoC Routing Graph
    :param critical_rg: NoC Routing Graph for Critical Region
    :param non_critical_rg: NoC Routing Graph for non-Critical Region
    :param shm: System Health Map! (Please note that mapper should not even have access to ful SHMU info)
    :param logging: logging file
    :return: (tg, ag) in case of failing returns (None, None)
    """
    # to run the following heuristics (Min_Min,Max_Min), one needs to use independent
    # tasks... Please use: generate_random_independent_tg
    if Config.Mapping_Function == 'MinMin':
        if Config.tg.type == 'RandomIndependent':
            return SimpleGreedy.min_min_mapping(tg, ag, shm, logging)
        else:
            raise ValueError('WRONG TG TYPE FOR THIS MAPPING FUNCTION. SHOULD USE::RandomIndependent')

    elif Config.Mapping_Function == 'MaxMin':
        if Config.tg.type == 'RandomIndependent':
            return SimpleGreedy.max_min_mapping(tg, ag, shm, logging)
        else:
            raise ValueError('WRONG TG TYPE FOR THIS MAPPING FUNCTION. SHOULD USE::RandomIndependent')

    elif Config.Mapping_Function == 'MinExecutionTime':
        if Config.tg.type == 'RandomIndependent':
            return SimpleGreedy.min_execution_time(tg, ag, shm, logging)
        else:
            raise ValueError('WRONG TG TYPE FOR THIS MAPPING FUNCTION. SHOULD USE::RandomIndependent')

    elif Config.Mapping_Function == 'MinimumCompletionTime':
        if Config.tg.type == 'RandomIndependent':
            return SimpleGreedy.minimum_completion_time(tg, ag, shm, logging)
        else:
            raise ValueError('WRONG TG TYPE FOR THIS MAPPING FUNCTION. SHOULD USE::RandomIndependent')

    elif Config.Mapping_Function == 'NMap':
        return NMap.n_map(tg, ag, noc_rg, critical_rg, non_critical_rg, shm, logging)

    elif Config.Mapping_Function in ['LocalSearch', 'IterativeLocalSearch', 'SimulatedAnnealing']:
        if Config.tg.type in ['RandomDependent', 'Manual', 'FromDOTFile']:
            pass
        else:
            raise ValueError('WRONG TG TYPE FOR THIS MAPPING FUNCTION. SHOULD USE::RandomDependent')
        clustering_start_time = time.time()
        # clustered task graph
        if Config.task_clustering:
            ctg = copy.deepcopy(Clustering.generate_ctg(len(ag.nodes())))
            if Clustering.initial_clustering(tg, ctg):
                # Clustered Task Graph Optimization
                if Config.Clustering_Optimization:
                    (best_clustering, best_task_graph) = \
                        Clustering.ctg_opt_local_search(tg, ctg, Config.clustering.iterations, logging)
                    tg = copy.deepcopy(best_task_graph)
                    ctg = copy.deepcopy(best_clustering)
                    del best_clustering, best_task_graph
                    # Clustering_Test.double_check_ctg(tg, ctg)
                    Clustering_Reports.report_ctg(ctg, "CTG_PostOpt.png")
                    Clustering_Reports.viz_clustering_opt()
                else:
                    print ("CLUSTERING OPTIMIZATION TURNED OFF...")
                    print ("REMOVING EMPTY CLUSTERS...")
                    Clustering_Functions.remove_empty_clusters(ctg)
                    Clustering_Reports.report_ctg(ctg, "CTG_PostCleaning.png")

                print ("\033[92mTIME::\033[0m CLUSTERING AND OPTIMIZATION TOOK: "
                       + str(round(time.time()-clustering_start_time))+" SECONDS")
            else:
                print ("Initial Clustering Failed....")
                raise ValueError("INITIAL CLUSTERING FAILED...")
        else:
            ctg = copy.deepcopy(Clustering.gen_transparent_clusters(tg))
        mapping_start_time = time.time()
        # Mapping CTG on AG
        random_seed = Config.mapping_random_seed
        if Mapping_Functions.make_initial_mapping(tg, ctg, ag, shm, noc_rg, critical_rg, non_critical_rg,
                                                  True, logging, random_seed, iteration):
            #if Config.DistanceBetweenMapping:
            #    init_mapping_string = Mapping_Functions.mapping_into_string(tg)
                # print (init_mapping_string)
            #else:
            #    init_mapping_string = None

            Mapping_Reports.report_mapping(ag, logging)
            # Schedule all tasks
            Scheduling_Functions.clear_scheduling(ag)
            Scheduler.schedule_all(tg, ag, shm, Config.DebugDetails, logging)
            Scheduling_Reports.report_mapped_tasks(ag, logging)
            Mapping_Functions.mapping_cost_function(tg, ag, shm, Config.DebugInfo)
            if Config.Mapping_Function == 'LocalSearch':
                mapping_cost_file = open('Generated_Files/Internal/LocalSearchMappingCost.txt', 'w')
                current_cost = Mapping_Functions.mapping_cost_function(tg, ag, shm, False, initial_mapping_string=initial_mapping_string)
                mapping_cost_file.write(str(current_cost)+"\n")
                mapping_cost_file.close()

                mapping_process_file = open('Generated_Files/Internal/MappingProcess.txt', 'w')
                mapping_process_file.write(Mapping_Functions.mapping_into_string(tg)+"\n")
                mapping_process_file.close()

                (best_tg, best_ctg, best_ag) = \
                    Local_Search.mapping_opt_local_search(tg, ctg, ag, noc_rg, critical_rg,
                                                          non_critical_rg, shm,
                                                          Config.LocalSearchIteration,
                                                          Config.DebugInfo, Config.DebugDetails, logging,
                                                          "LocalSearchMappingCost", "MappingProcess",
                                                          Config.mapping_random_seed, initial_mapping_string=initial_mapping_string)
                tg = copy.deepcopy(best_tg)
                ag = copy.deepcopy(best_ag)
                del best_tg, best_ctg, best_ag
                Mapping_Reports.viz_mapping_opt('LocalSearchMappingCost', iteration)
            elif Config.Mapping_Function == 'IterativeLocalSearch':
                (best_tg, best_ctg, best_ag) = \
                    Local_Search.mapping_opt_iterative_local_search(tg, ctg, ag, noc_rg, critical_rg,
                                                                    non_critical_rg, shm,
                                                                    Config.IterativeLocalSearchIterations,
                                                                    Config.LocalSearchIteration,
                                                                    Config.DebugInfo, Config.DebugDetails,
                                                                    logging)
                tg = copy.deepcopy(best_tg)
                ag = copy.deepcopy(best_ag)
                del best_tg, best_ctg, best_ag
                Mapping_Reports.viz_mapping_opt('LocalSearchMappingCost', iteration)
            elif Config.Mapping_Function == 'SimulatedAnnealing':
                (best_tg, best_ctg, best_ag) = SimulatedAnnealing.optimize_mapping_sa(tg, ctg, ag, noc_rg,
                                                                                      critical_rg, non_critical_rg,
                                                                                      shm, 'SA_MappingCost',
                                                                                      logging)
                Mapping_Reports.viz_mapping_opt('SA_MappingCost', iteration=None)
                if Config.SA_AnnealingSchedule == 'Adaptive':
                    Mapping_Reports.viz_cost_slope()
                elif Config.SA_AnnealingSchedule == 'Huang':
                    Mapping_Reports.viz_huang_race()
                tg = copy.deepcopy(best_tg)
                ag = copy.deepcopy(best_ag)
                del best_tg, best_ctg, best_ag
            # print (Mapping_Functions.mapping_into_string(TG))
            print ("\033[92mTIME::\033[0m MAPPING AND OPTIMIZATION TOOK: "
                   + str(round(time.time()-mapping_start_time))+" SECONDS")

            Mapping_Reports.report_mapping(ag, logging)
            Scheduling_Functions.clear_scheduling(ag)
            Scheduler.schedule_all(tg, ag, shm, False, logging)
            Scheduling_Reports.report_mapped_tasks(ag, logging)
            if not Scheduling_Functions.check_if_all_deadlines_are_met(tg,ag):
                raise ValueError("not all critical tasks have met their deadline!")
            Mapping_Functions.mapping_cost_function(tg, ag, shm, True,  initial_mapping_string=initial_mapping_string)
            return tg, ag
        else:
            Mapping_Reports.report_mapping(ag, logging)
            print ("===========================================")
            raise ValueError("INITIAL MAPPING FAILED...")

    return None, None
Пример #17
0
def run_simulator(runtime, ag, shmu, noc_rg, logging):
    """
    prepares and runs the simulator
    :param runtime: duration of which the user wants to run the program in cycles
    :param ag: architecture graph
    :param shmu: system health monitoring unit
    :param noc_rg: noc routing graph
    :param logging: logging file
    :return: None
    """
    print "==========================================="
    print "SETTING UP THE SIMULATOR..."
    env = simpy.Environment()
    print "SETTING UP counter-threshold MODULE..."
    if Config.classification_method == "counter_threshold":

        counter_threshold = CounterThreshold.CounterThreshold(
            Config.fault_counter_threshold, Config.health_counter_threshold,
            Config.intermittent_counter_threshold)
    elif Config.classification_method == "machine_learning":
        counter_threshold = MachineLearning.MachineLearning(
            Config.fault_counter_threshold,  # Rene's addition
            Config.health_counter_threshold * 3,
            Config.intermittent_counter_threshold)
    else:
        raise ValueError("Unknown Classification Method!! Check config file")

    fault_time_dict = {}
    fault_time = 0
    schedule_length = Scheduling_Functions.FindScheduleMakeSpan(ag)
    if Config.EventDrivenFaultInjection:
        time_until_next_fault = numpy.random.normal(Config.MTBF,
                                                    Config.SD4MTBF)
        fault_time += time_until_next_fault
        while fault_time < runtime:
            fault_location, fault_type = SHMU_Functions.RandomFaultGeneration(
                shmu.SHM)
            fault_time_dict[float(
                "{0:.1f}".format(fault_time))] = (fault_location, fault_type)
            time_until_next_fault = numpy.random.normal(
                Config.MTBF, Config.SD4MTBF)
            fault_time += time_until_next_fault

        env.process(
            fault_event(env, ag, shmu, noc_rg, schedule_length,
                        fault_time_dict, counter_threshold, logging))

    print "SETTING UP ROUTERS AND PES..."
    for node in ag.nodes():
        # print node, AG.node[node]["Scheduling"]
        env.process(
            processor_sim(env, ag, node, ag.node[node]['PE'].Scheduling,
                          schedule_length, fault_time_dict, counter_threshold,
                          logging))
        env.process(
            router_sim(env, ag, node, ag.node[node]['Router'].Scheduling,
                       schedule_length, fault_time_dict, counter_threshold,
                       logging))

    print "SETTING UP LINKS..."
    for link in ag.edges():
        # print link, AG.edge[link[0]][link[1]]["Scheduling"]
        env.process(
            link_sim(env, ag, link, ag.edge[link[0]][link[1]]["Scheduling"],
                     schedule_length, fault_time_dict, counter_threshold,
                     logging))

    env.process(sim_report(env, ag, counter_threshold))
    print "STARTING SIMULATION..."
    env.run(until=runtime)
    print "SIMULATION FINISHED..."
    counter_threshold.report(len(ag.nodes()), len(ag.edges()))
    Counter_Threshold_Viz.counter_threshold_viz(ag, counter_threshold)
    Scheduling_Reports.report_scheduling_memory_usage(ag)
    return None
Пример #18
0
def run_simulator(runtime, tg, ag, shmu, noc_rg, critical_rg, noncritical_rg,
                  logging):
    """
    prepares and runs the simulator
    :param runtime: duration of which the user wants to run the program in cycles
    :param ag: architecture graph
    :param shmu: system health monitoring unit
    :param noc_rg: noc routing graph
    :param logging: logging file
    :return: None
    """
    print("===========================================")
    print("SETTING UP THE SIMULATOR...")
    env = simpy.Environment()
    print("SETTING UP counter-threshold MODULE...")
    if Config.classification_method == "counter_threshold":

        counter_threshold = CounterThreshold.CounterThreshold(
            Config.fault_counter_threshold, Config.health_counter_threshold,
            Config.intermittent_counter_threshold)
    elif Config.classification_method == "machine_learning":
        counter_threshold = MachineLearning.MachineLearning(
            Config.fault_counter_threshold,  # Rene's addition
            Config.health_counter_threshold * 3,
            Config.intermittent_counter_threshold)
    else:
        raise ValueError("Unknown Classification Method!! Check config file")

    # the fault_time_dictionary looks like this:
    # fault_time_dictionary[fault_time] = (fault_location, fault_type)
    fault_time_dict = {}
    schedule_length = Scheduling_Functions.find_schedule_make_span(ag)
    if Config.EventDrivenFaultInjection:
        if Config.fault_injection_method == "random":
            fault_time_dict = copy.deepcopy(
                generate_random_fault_time_dict(runtime, shmu.SHM))
        elif Config.fault_injection_method == "from_file":
            fault_time_dict = generate_fault_time_dict_from_file()

        env.process(
            fault_event(env, ag, shmu, noc_rg, schedule_length,
                        fault_time_dict, counter_threshold, logging))

    print("SETTING UP ROUTERS AND PES...")
    for node in ag.nodes():
        # print node, AG.node[node]["Scheduling"]
        env.process(
            processor_sim(env, ag, shmu, node, schedule_length,
                          fault_time_dict, counter_threshold, logging))
        env.process(
            router_sim(env, ag, shmu, node, schedule_length, fault_time_dict,
                       counter_threshold, logging))

    print("SETTING UP LINKS...")
    for link in ag.edges():
        # print link, AG.edge[link[0]][link[1]]["Scheduling"]
        env.process(
            link_sim(env, ag, shmu, link, schedule_length, fault_time_dict,
                     counter_threshold, logging))

    env.process(sim_report(env, ag, shmu, counter_threshold))
    print("STARTING SIMULATION...")
    env.run()
    iteration = 1
    time_passed = env.now
    del env

    while time_passed < Config.ProgramRunTime:
        print("===========================================")
        Config.ProgramRunTime -= time_passed
        shmu.signal_reconfiguration = False
        tg, ag = copy.deepcopy(
            system_reconfiguration(tg, ag, shmu, noc_rg, critical_rg,
                                   noncritical_rg, iteration, logging))
        print("SETTING UP THE SIMULATOR...")
        env = simpy.Environment()

        # fault_time_dict = {}
        schedule_length = Scheduling_Functions.find_schedule_make_span(ag)
        if Config.EventDrivenFaultInjection:
            fault_time_dict = copy.deepcopy(
                update_fault_time_dict(time_passed, fault_time_dict))
            env.process(
                fault_event(env, ag, shmu, noc_rg, schedule_length,
                            fault_time_dict, counter_threshold, logging))
        print("SETTING UP ROUTERS AND PES...")
        for node in ag.nodes():
            # print node, AG.node[node]["Scheduling"]
            env.process(
                processor_sim(env, ag, shmu, node, schedule_length,
                              fault_time_dict, counter_threshold, logging))
            env.process(
                router_sim(env, ag, shmu, node, schedule_length,
                           fault_time_dict, counter_threshold, logging))
        print("SETTING UP LINKS...")
        for link in ag.edges():
            # print link, AG.edge[link[0]][link[1]]["Scheduling"]
            env.process(
                link_sim(env, ag, shmu, link, schedule_length, fault_time_dict,
                         counter_threshold, logging))
        print("SETTING UP SIM MONITORS...")
        env.process(sim_report(env, ag, shmu, counter_threshold))

        print("RESTARTING SIMULATION...")
        print("REMAINING SIM TIME:", Config.ProgramRunTime)
        env.run()
        iteration += 1
        time_passed = env.now
        del env
    print("SIMULATION FINISHED...")
    print("SYSTEM DEGRADATION:", shmu.system_degradation)
    counter_threshold.report(len(ag.nodes()), len(ag.edges()))
    Counter_Threshold_Viz.counter_threshold_viz(ag, counter_threshold)
    Scheduling_Reports.report_scheduling_memory_usage(ag)
    return None
def initialize_system(logging):
    """
    Generates the Task graph, Architecture Graph, System Health Monitoring Unit, NoC routing graph(s) and
    Test Task Graphs and does the mapping and scheduling and returns to the user the initial system
    :param logging: logging file
    :return:  tg, ag, shmu, noc_rg, critical_rg, noncritical_rg, pmcg
    """
    tg = copy.deepcopy(TG_Functions.generate_tg())
    if Config.DebugInfo:
        Task_Graph_Reports.report_task_graph(tg, logging)
    Task_Graph_Reports.draw_task_graph(tg)
    if Config.TestMode:
        TG_Test.CheckAcyclic(tg, logging)
    ####################################################################
    ag = copy.deepcopy(AG_Functions.generate_ag(logging))
    AG_Functions.update_ag_regions(ag)
    AG_Functions.random_darkness(ag)
    if Config.EnablePartitioning:
        AG_Functions.setup_network_partitioning(ag)
    if Config.TestMode:
        AG_Test.ag_test()
    if Config.FindOptimumAG:
        Arch_Graph_Reports.draw_ag(ag, "AG_Full")
    else:
        Arch_Graph_Reports.draw_ag(ag, "AG")
    ####################################################################
    Config.setup_turns_health()
    if Config.TestMode:
        SHMU_Test.test_shmu(ag)
    shmu = SystemHealthMonitoringUnit.SystemHealthMonitoringUnit()
    shmu.setup_noc_shm(ag, Config.TurnsHealth)
    # Here we are injecting initial faults of the system: we assume these fault
    # information is obtained by post manufacturing system diagnosis
    if Config.FindOptimumAG:
        Optimize_3D_AG.optimize_ag_vertical_links(ag, shmu, logging)
        Optimize_3D_AG.cleanup_ag(ag, shmu)
        Arch_Graph_Reports.draw_ag(ag, "AG_VLOpt")
    SHMU_Functions.ApplyInitialFaults(shmu)
    if Config.SHM_Drawing:
        SHMU_Reports.DrawSHM(shmu.SHM)
        SHMU_Reports.DrawTempDistribution(shmu.SHM)
    # SHM_Reports.Report_NoC_SystemHealthMap()
    ####################################################################
    routing_graph_start_time = time.time()
    if Config.SetRoutingFromFile:
        noc_rg = copy.deepcopy(
            Routing.GenerateNoCRouteGraphFromFile(ag, shmu,
                                                  Config.RoutingFilePath,
                                                  Config.DebugInfo,
                                                  Config.DebugDetails))
    else:
        noc_rg = copy.deepcopy(
            Routing.GenerateNoCRouteGraph(ag, shmu, Config.UsedTurnModel,
                                          Config.DebugInfo,
                                          Config.DebugDetails))
    print("\033[92mTIME::\033[0m ROUTING GRAPH GENERATION TOOK: " +
          str(round(time.time() - routing_graph_start_time)) + " SECONDS")
    # this is for double checking...
    if Config.FindOptimumAG:
        Calculate_Reachability.ReachabilityMetric(ag, noc_rg, True)
    # Some visualization...
    if Config.RG_Draw:
        RoutingGraph_Reports.draw_rg(noc_rg)
    ####################################################################
    # in case of partitioning, we have to route based on different Route-graphs
    if Config.EnablePartitioning:
        critical_rg, noncritical_rg = Calculate_Reachability.calculate_reachability_with_regions(
            ag, shmu)
        ReachabilityReports.ReportGSNoCFriendlyReachabilityInFile(ag)
    else:
        if Config.TestMode:
            Reachability_Test.ReachabilityTest()
        critical_rg, noncritical_rg = None, None
        Calculate_Reachability.calculate_reachability(ag, noc_rg)
        Calculate_Reachability.OptimizeReachabilityRectangles(
            ag, Config.NumberOfRects)
        # ReachabilityReports.ReportReachability(ag)
        ReachabilityReports.ReportReachabilityInFile(ag,
                                                     "ReachAbilityNodeReport")
        ReachabilityReports.ReportGSNoCFriendlyReachabilityInFile(ag)
    ####################################################################
    if Config.read_mapping_from_file:
        Mapping_Functions.read_mapping_from_file(tg, ag, shmu.SHM, noc_rg,
                                                 critical_rg, noncritical_rg,
                                                 Config.mapping_file_path,
                                                 logging)
        Scheduler.schedule_all(tg, ag, shmu.SHM, False, False, logging)
    else:
        best_tg, best_ag = Mapping.mapping(tg, ag, noc_rg, critical_rg,
                                           noncritical_rg, shmu.SHM, logging)
        if best_ag is not None and best_tg is not None:
            tg = copy.deepcopy(best_tg)
            ag = copy.deepcopy(best_ag)
            del best_tg, best_ag
            # SHM.AddCurrentMappingToMPM(tg)
            Mapping_Functions.write_mapping_to_file(ag, "mapping_report")
    if Config.Mapping_Dstr_Drawing:
        Mapping_Reports.draw_mapping_distribution(ag, shmu)
    if Config.Mapping_Drawing:
        Mapping_Reports.draw_mapping(tg, ag, shmu.SHM, "Mapping_post_opt")
    if Config.Scheduling_Drawing:
        Scheduling_Reports.generate_gantt_charts(tg, ag, "SchedulingTG")
    ####################################################################
    # PMC-Graph
    # at this point we assume that the system health map knows about the initial faults from
    # the diagnosis process
    if Config.GeneratePMCG:
        pmcg_start_time = time.time()
        if Config.OneStepDiagnosable:
            pmcg = TestSchedulingUnit.GenerateOneStepDiagnosablePMCG(
                ag, shmu.SHM)
        else:
            pmcg = TestSchedulingUnit.GenerateSequentiallyDiagnosablePMCG(
                ag, shmu.SHM)
        test_tg = TestSchedulingUnit.GenerateTestTGFromPMCG(pmcg)
        print("\033[92mTIME::\033[0m PMCG AND TTG GENERATION TOOK: " +
              str(round(time.time() - pmcg_start_time)) + " SECONDS")
        if Config.PMCG_Drawing:
            TestSchedulingUnit.DrawPMCG(pmcg)
        if Config.TTG_Drawing:
            TestSchedulingUnit.DrawTTG(test_tg)
        TestSchedulingUnit.InsertTestTasksInTG(pmcg, tg)
        Task_Graph_Reports.draw_task_graph(tg, ttg=test_tg)
        TestSchedulingUnit.MapTestTasks(tg, ag, shmu.SHM, noc_rg, logging)
        Scheduler.schedule_test_in_tg(tg, ag, shmu.SHM, False, logging)
        Scheduling_Reports.report_mapped_tasks(ag, logging)
        # TestSchedulingUnit.RemoveTestTasksFromTG(test_tg, tg)
        # Task_Graph_Reports.draw_task_graph(tg, TTG=test_tg)
        Scheduling_Reports.generate_gantt_charts(tg, ag, "SchedulingWithTTG")
    else:
        pmcg = None

    print("===========================================")
    print("SYSTEM IS UP...")

    TrafficTableGenerator.generate_noxim_traffic_table(ag, tg)
    TrafficTableGenerator.generate_gsnoc_traffic_table(ag, tg)
    if Config.GenMappingFrames:
        Mapping_Animation.generate_frames(tg, ag, shmu.SHM)
    return ag, shmu, noc_rg, critical_rg, noncritical_rg, pmcg
Пример #20
0
def mapping_opt_local_search(tg, ctg, ag, noc_rg, critical_rg, noncritical_rg, shm,
                             iteration_num, report, detailed_report, logging,
                             cost_data_file_name, mapping_process_file_name, random_seed,
                             initial_mapping_string=None):
    random.seed(random_seed)
    if report:
        print("===========================================")
        print("STARTING MAPPING OPTIMIZATION...USING LOCAL SEARCH...")
        print("NUMBER OF ITERATIONS: "+str(iteration_num))

    if type(cost_data_file_name) is str:
        mapping_cost_file = open('Generated_Files/Internal/'+cost_data_file_name+'.txt', 'a')
    else:
        raise ValueError("cost_data_file_name name is not string: "+str(cost_data_file_name))

    if type(mapping_process_file_name) is str:
        mapping_process_file = open('Generated_Files/Internal/'+mapping_process_file_name+'.txt', 'a')
    else:
        raise ValueError("mapping_process_file name is not string: "+str(mapping_process_file_name))

    best_tg = copy.deepcopy(tg)
    best_ag = copy.deepcopy(ag)
    best_ctg = copy.deepcopy(ctg)
    best_cost = Mapping_Functions.mapping_cost_function(tg, ag, shm, False, initial_mapping_string=initial_mapping_string)
    starting_cost = best_cost
    for iteration in range(0, iteration_num):
        logging.info("       ITERATION:"+str(iteration))
        cluster_to_move = random.choice(list(ctg.nodes()))
        current_node = ctg.node[cluster_to_move]['Node']
        Mapping_Functions.remove_cluster_from_node(tg, ctg, ag, noc_rg, critical_rg, noncritical_rg,
                                                   cluster_to_move, current_node, logging)
        destination_node = random.choice(list(ag.nodes()))
        if Config.EnablePartitioning:
            while ctg.node[cluster_to_move]['Criticality'] != ag.node[destination_node]['Region']:
                destination_node = random.choice(list(ag.nodes()))
        # print(ctg.node[cluster_to_move]['Criticality'],AG.node[destination_node]['Region'])

        try_counter = 0
        while not Mapping_Functions.add_cluster_to_node(tg, ctg, ag, shm, noc_rg, critical_rg, noncritical_rg,
                                                        cluster_to_move, destination_node, logging):

            # If add_cluster_to_node fails it automatically removes all the connections...
            # we need to add the cluster to the old place...
            Mapping_Functions.add_cluster_to_node(tg, ctg, ag, shm, noc_rg, critical_rg, noncritical_rg,
                                                  cluster_to_move, current_node, logging)

            # choosing another cluster to move
            cluster_to_move = random.choice(list(ctg.nodes()))
            current_node = ctg.node[cluster_to_move]['Node']
            Mapping_Functions.remove_cluster_from_node(tg, ctg, ag, noc_rg, critical_rg, noncritical_rg,
                                                       cluster_to_move, current_node, logging)
            destination_node = random.choice(list(ag.nodes()))
            if Config.EnablePartitioning:
                while ctg.node[cluster_to_move]['Criticality'] != ag.node[destination_node]['Region']:
                    destination_node = random.choice(list(ag.nodes()))
            # print(ctg.node[cluster_to_move]['Criticality'],AG.node[destination_node]['Region'])

            if try_counter >= 3*len(ag.nodes()):
                if report:
                    print("CAN NOT FIND ANY FEASIBLE SOLUTION... ABORTING LOCAL SEARCH...")
                logging.info("CAN NOT FIND ANY FEASIBLE SOLUTION... ABORTING LOCAL SEARCH...")
                tg = copy.deepcopy(best_tg)
                ag = copy.deepcopy(best_ag)
                ctg = copy.deepcopy(ctg)
                if report:
                    Scheduling_Reports.report_mapped_tasks(ag, logging)
                    Mapping_Functions.mapping_cost_function(tg, ag, shm, True, initial_mapping_string=initial_mapping_string)
                return best_tg, best_ctg, best_ag
            try_counter += 1

        Scheduling_Functions.clear_scheduling(ag)
        Scheduler.schedule_all(tg, ag, shm, False, logging)

        current_cost = Mapping_Functions.mapping_cost_function(tg, ag, shm, detailed_report, initial_mapping_string= initial_mapping_string)
        mapping_process_file.write(Mapping_Functions.mapping_into_string(tg)+"\n")
        mapping_cost_file.write(str(current_cost)+"\n")
        if current_cost <= best_cost:
            if current_cost < best_cost:
                if report:
                    print("\033[32m* NOTE::\033[0mBETTER SOLUTION FOUND WITH COST: "+str(current_cost) +
                           "\t ITERATION:"+str(iteration))
                logging.info("NOTE:: MOVED TO SOLUTION WITH COST: "+str(current_cost)+"ITERATION: "+str(iteration))
            else:
                logging.info("NOTE:: MOVED TO SOLUTION WITH COST: "+str(current_cost)+"ITERATION: "+str(iteration))

            best_tg = copy.deepcopy(tg)
            best_ag = copy.deepcopy(ag)
            best_ctg = copy.deepcopy(ctg)
            best_cost = current_cost
        else:
            tg = copy.deepcopy(best_tg)
            ag = copy.deepcopy(best_ag)
            ctg = copy.deepcopy(best_ctg)
            mapping_process_file.write(Mapping_Functions.mapping_into_string(tg)+"\n")

    Scheduling_Functions.clear_scheduling(ag)
    Scheduler.schedule_all(tg, ag, shm, False, logging)
    mapping_process_file.close()
    mapping_cost_file.close()
    if report:
        print("-------------------------------------")
        print("STARTING COST: "+str(starting_cost)+"\tFINAL COST: "+str(best_cost) +
               "\tAFTER "+str(iteration_num)+" ITERATIONS")
        print("IMPROVEMENT:"+str("{0:.2f}".format(100*(starting_cost-best_cost)/starting_cost))+" %")
    return best_tg, best_ctg, best_ag
Пример #21
0
def mapping_opt_local_search(tg, ctg, ag, noc_rg, critical_rg, noncritical_rg, shm,
                             iteration_num, report, detailed_report, logging,
                             cost_data_file_name, mapping_process_file_name, random_seed,
                             initial_mapping_string=None):
    random.seed(random_seed)
    if report:
        print ("===========================================")
        print ("STARTING MAPPING OPTIMIZATION...USING LOCAL SEARCH...")
        print ("NUMBER OF ITERATIONS: "+str(iteration_num))

    if type(cost_data_file_name) is str:
        mapping_cost_file = open('Generated_Files/Internal/'+cost_data_file_name+'.txt', 'a')
    else:
        raise ValueError("cost_data_file_name name is not string: "+str(cost_data_file_name))

    if type(mapping_process_file_name) is str:
        mapping_process_file = open('Generated_Files/Internal/'+mapping_process_file_name+'.txt', 'a')
    else:
        raise ValueError("mapping_process_file name is not string: "+str(mapping_process_file_name))

    best_tg = copy.deepcopy(tg)
    best_ag = copy.deepcopy(ag)
    best_ctg = copy.deepcopy(ctg)
    best_cost = Mapping_Functions.mapping_cost_function(tg, ag, shm, False, initial_mapping_string=initial_mapping_string)
    starting_cost = best_cost
    for iteration in range(0, iteration_num):
        logging.info("       ITERATION:"+str(iteration))
        cluster_to_move = random.choice(ctg.nodes())
        current_node = ctg.node[cluster_to_move]['Node']
        Mapping_Functions.remove_cluster_from_node(tg, ctg, ag, noc_rg, critical_rg, noncritical_rg,
                                                   cluster_to_move, current_node, logging)
        destination_node = random.choice(ag.nodes())
        if Config.EnablePartitioning:
            while ctg.node[cluster_to_move]['Criticality'] != ag.node[destination_node]['Region']:
                destination_node = random.choice(ag.nodes())
        # print (ctg.node[cluster_to_move]['Criticality'],AG.node[destination_node]['Region'])

        try_counter = 0
        while not Mapping_Functions.add_cluster_to_node(tg, ctg, ag, shm, noc_rg, critical_rg, noncritical_rg,
                                                        cluster_to_move, destination_node, logging):

            # If add_cluster_to_node fails it automatically removes all the connections...
            # we need to add the cluster to the old place...
            Mapping_Functions.add_cluster_to_node(tg, ctg, ag, shm, noc_rg, critical_rg, noncritical_rg,
                                                  cluster_to_move, current_node, logging)

            # choosing another cluster to move
            cluster_to_move = random.choice(ctg.nodes())
            current_node = ctg.node[cluster_to_move]['Node']
            Mapping_Functions.remove_cluster_from_node(tg, ctg, ag, noc_rg, critical_rg, noncritical_rg,
                                                       cluster_to_move, current_node, logging)
            destination_node = random.choice(ag.nodes())
            if Config.EnablePartitioning:
                while ctg.node[cluster_to_move]['Criticality'] != ag.node[destination_node]['Region']:
                    destination_node = random.choice(ag.nodes())
            # print (ctg.node[cluster_to_move]['Criticality'],AG.node[destination_node]['Region'])

            if try_counter >= 3*len(ag.nodes()):
                if report:
                    print ("CAN NOT FIND ANY FEASIBLE SOLUTION... ABORTING LOCAL SEARCH...")
                logging.info("CAN NOT FIND ANY FEASIBLE SOLUTION... ABORTING LOCAL SEARCH...")
                tg = copy.deepcopy(best_tg)
                ag = copy.deepcopy(best_ag)
                ctg = copy.deepcopy(ctg)
                if report:
                    Scheduling_Reports.report_mapped_tasks(ag, logging)
                    Mapping_Functions.mapping_cost_function(tg, ag, shm, True, initial_mapping_string=initial_mapping_string)
                return best_tg, best_ctg, best_ag
            try_counter += 1

        Scheduling_Functions.clear_scheduling(ag)
        Scheduler.schedule_all(tg, ag, shm, False, logging)

        current_cost = Mapping_Functions.mapping_cost_function(tg, ag, shm, detailed_report, initial_mapping_string= initial_mapping_string)
        mapping_process_file.write(Mapping_Functions.mapping_into_string(tg)+"\n")
        mapping_cost_file.write(str(current_cost)+"\n")
        if current_cost <= best_cost:
            if current_cost < best_cost:
                if report:
                    print ("\033[32m* NOTE::\033[0mBETTER SOLUTION FOUND WITH COST: "+str(current_cost) +
                           "\t ITERATION:"+str(iteration))
                logging.info("NOTE:: MOVED TO SOLUTION WITH COST: "+str(current_cost)+"ITERATION: "+str(iteration))
            else:
                logging.info("NOTE:: MOVED TO SOLUTION WITH COST: "+str(current_cost)+"ITERATION: "+str(iteration))

            best_tg = copy.deepcopy(tg)
            best_ag = copy.deepcopy(ag)
            best_ctg = copy.deepcopy(ctg)
            best_cost = current_cost
        else:
            tg = copy.deepcopy(best_tg)
            ag = copy.deepcopy(best_ag)
            ctg = copy.deepcopy(best_ctg)
            mapping_process_file.write(Mapping_Functions.mapping_into_string(tg)+"\n")

    Scheduling_Functions.clear_scheduling(ag)
    Scheduler.schedule_all(tg, ag, shm, False, logging)
    mapping_process_file.close()
    mapping_cost_file.close()
    if report:
        print ("-------------------------------------")
        print ("STARTING COST: "+str(starting_cost)+"\tFINAL COST: "+str(best_cost) +
               "\tAFTER "+str(iteration_num)+" ITERATIONS")
        print ("IMPROVEMENT:"+str("{0:.2f}".format(100*(starting_cost-best_cost)/starting_cost))+" %")
    return best_tg, best_ctg, best_ag