コード例 #1
0
ファイル: reachability_tests.py プロジェクト: thigg/SoCDep2
    def test_how_many_paths_from_source(self):
        initial_config_ag = deepcopy(Config.ag)
        initial_turn_model = Config.UsedTurnModel
        initial_routing_type = Config.RotingType

        Config.ag.type = "Generic"
        Config.ag.topology = "2DMesh"
        Config.ag.x_size = 3
        Config.ag.y_size = 3
        Config.ag.z_size = 1

        turn_model = PackageFile.XY_TurnModel
        Config.UsedTurnModel = deepcopy(turn_model)
        Config.TurnsHealth = deepcopy(Config.setup_turns_health())
        ag_4_test = deepcopy(generate_ag(logging=None))
        shmu_4_test = SystemHealthMonitoringUnit.SystemHealthMonitoringUnit()
        shmu_4_test.setup_noc_shm(ag_4_test, Config.TurnsHealth, False)
        noc_rg = generate_noc_route_graph(ag_4_test, shmu_4_test, turn_model,
                                          False, False)
        for source_node in ag_4_test.nodes():
            for destination_node in ag_4_test.nodes():
                if source_node != destination_node:
                    self.assertEqual(
                        how_many_paths_from_source(noc_rg, source_node,
                                                   destination_node), 1)

        Config.ag = deepcopy(initial_config_ag)
        Config.UsedTurnModel = initial_turn_model
        Config.TurnsHealth = deepcopy(Config.setup_turns_health())
        Config.RotingType = initial_routing_type
コード例 #2
0
def evaluate_actual_odd_even_turn_model():
    turns_health_2d_network = {
        "N2W": False,
        "N2E": False,
        "S2W": False,
        "S2E": False,
        "W2N": False,
        "W2S": False,
        "E2N": False,
        "E2S": False
    }
    Config.ag.topology = '2DMesh'
    Config.ag.x_size = 3
    Config.ag.y_size = 3
    Config.ag.z_size = 1
    Config.RotingType = 'MinimalPath'
    ag = copy.deepcopy(AG_Functions.generate_ag())
    number_of_pairs = len(ag.nodes()) * (len(ag.nodes()) - 1)

    turn_model_odd = ['E2N', 'E2S', 'W2N', 'W2S', 'S2E', 'N2E']
    turn_model_even = ['E2N', 'E2S', 'S2W', 'S2E', 'N2W', 'N2E']

    if not check_tm_domination(turn_model_odd,
                               turn_model_even):  # taking out the domination!
        turns_health = copy.deepcopy(turns_health_2d_network)
        shmu = SystemHealthMonitoringUnit.SystemHealthMonitoringUnit()
        shmu.setup_noc_shm(ag, turns_health, False)
        noc_rg = copy.deepcopy(
            Routing.generate_noc_route_graph(ag, shmu, [], False, False))

        for node in ag.nodes():
            node_x, node_y, node_z = AG_Functions.return_node_location(node)
            if node_x % 2 == 1:
                for turn in turn_model_odd:
                    shmu.restore_broken_turn(node, turn, False)
                    from_port = str(node) + str(turn[0]) + "I"
                    to_port = str(node) + str(turn[2]) + "O"
                    Routing.update_noc_route_graph(noc_rg, from_port, to_port,
                                                   'ADD')
            else:
                for turn in turn_model_even:
                    shmu.restore_broken_turn(node, turn, False)
                    from_port = str(node) + str(turn[0]) + "I"
                    to_port = str(node) + str(turn[2]) + "O"
                    Routing.update_noc_route_graph(noc_rg, from_port, to_port,
                                                   'ADD')
        draw_rg(noc_rg)
        connectivity_metric = reachability_metric(ag, noc_rg, False)
        print("connectivity_metric:", connectivity_metric)
        if check_deadlock_freeness(noc_rg):
            print("Deadlock free!")

        doa = degree_of_adaptiveness(ag, noc_rg,
                                     False) / float(number_of_pairs)
        doa_ex = extended_degree_of_adaptiveness(
            ag, noc_rg, False) / float(number_of_pairs)
        print("doa:", doa)
        print("doa_ex", doa_ex)

        sys.stdout.flush()
コード例 #3
0
    def test_shmu_breaking_and_restore(self):
        ag_4_test = copy.deepcopy(generate_ag(logging=None))
        shmu_4_test = SystemHealthMonitoringUnit.SystemHealthMonitoringUnit()
        shmu_4_test.setup_noc_shm(ag_4_test, Config.TurnsHealth, False)
        for node in shmu_4_test.SHM.nodes():
            shmu_4_test.break_node(node, False)
            self.assertEqual(shmu_4_test.SHM.node[node]['NodeHealth'], False)

            for Turn in shmu_4_test.SHM.node[node]['TurnsHealth']:
                shmu_4_test.break_turn(node, Turn, False)
                self.assertEqual(
                    shmu_4_test.SHM.node[node]['TurnsHealth'][Turn], False)

        for link in shmu_4_test.SHM.edges():
            shmu_4_test.break_link(link, False)
            self.assertEqual(shmu_4_test.SHM.edges[link]['LinkHealth'], False)
        # testing Restore
        for node in shmu_4_test.SHM.nodes():
            shmu_4_test.restore_broken_node(node, False)
            self.assertEqual(shmu_4_test.SHM.node[node]['NodeHealth'], True)

            for turn in shmu_4_test.SHM.node[node]['TurnsHealth']:
                shmu_4_test.restore_broken_turn(node, turn, False)
                self.assertEqual(
                    shmu_4_test.SHM.node[node]['TurnsHealth'][turn], True)

        for link in shmu_4_test.SHM.edges():
            shmu_4_test.restore_broken_link(link, False)
            self.assertEqual(shmu_4_test.SHM.edges[link]['LinkHealth'], True)
        del ag_4_test
        del shmu_4_test
コード例 #4
0
 def test_shmu_aging(self):
     ag_4_test = copy.deepcopy(generate_ag(logging=None))
     shmu_4_test = SystemHealthMonitoringUnit.SystemHealthMonitoringUnit()
     shmu_4_test.setup_noc_shm(ag_4_test, Config.TurnsHealth, False)
     for Node in shmu_4_test.SHM.nodes():
         shmu_4_test.introduce_aging(Node, 0.5, False)
         self.assertEqual(shmu_4_test.SHM.node[Node]['NodeSpeed'], 50)
         shmu_4_test.introduce_aging(Node, 0.5, False)
         self.assertEqual(shmu_4_test.SHM.node[Node]['NodeSpeed'], 25)
     del ag_4_test
     del shmu_4_test
コード例 #5
0
    def test_return_healthy_nodes(self):
        ag_4_test = copy.deepcopy(generate_ag(logging=None))
        shmu_4_test = SystemHealthMonitoringUnit.SystemHealthMonitoringUnit()
        shmu_4_test.setup_noc_shm(ag_4_test, Config.TurnsHealth, False)

        healthy_nodes = list(ag_4_test.nodes())[:]
        for node in ag_4_test.nodes():
            if random.choice(['Healthy', 'Faulty']) == 'Faulty':
                healthy_nodes.remove(node)
                shmu_4_test.break_node(node, False)

        test_healthy_nodes = return_healthy_nodes(ag_4_test, shmu_4_test.SHM)
        self.assertEqual(test_healthy_nodes, healthy_nodes, msg=f"heathy nodes {healthy_nodes}, test healthy nodes: {test_healthy_nodes}")
        del ag_4_test
        del shmu_4_test
コード例 #6
0
def evaluate_actual_odd_even_turn_model():
    """
    evaluates the classic odd-even turn model in terms of DoA and DoA_ex
    :return: None
    """
    turns_health_2d_network = {
        "N2W": False,
        "N2E": False,
        "S2W": False,
        "S2E": False,
        "W2N": False,
        "W2S": False,
        "E2N": False,
        "E2S": False
    }
    Config.ag.topology = '2DMesh'
    Config.ag.x_size = 3
    Config.ag.y_size = 3
    Config.ag.z_size = 1
    Config.RotingType = 'MinimalPath'
    ag = copy.deepcopy(AG_Functions.generate_ag())
    number_of_pairs = len(ag.nodes()) * (len(ag.nodes()) - 1)

    turn_model_odd = ['E2N', 'E2S', 'W2N', 'W2S', 'S2E', 'N2E']
    turn_model_even = ['E2N', 'E2S', 'S2W', 'S2E', 'N2W', 'N2E']

    if not check_tm_domination(turn_model_odd,
                               turn_model_even):  # taking out the domination!
        turns_health = copy.deepcopy(turns_health_2d_network)
        shmu = SystemHealthMonitoringUnit.SystemHealthMonitoringUnit()
        shmu.setup_noc_shm(ag, turns_health, False)
        noc_rg = copy.deepcopy(
            Routing.generate_noc_route_graph(ag, shmu, [], False, False))
        update_rg_odd_even(ag, turn_model_odd, turn_model_even, shmu, noc_rg)
        draw_rg(noc_rg)
        connectivity_metric = reachability_metric(ag, noc_rg, False)
        print("connectivity_metric:", connectivity_metric)
        if check_deadlock_freeness(noc_rg):
            print("Deadlock free!")

        doa = degree_of_adaptiveness(ag, noc_rg,
                                     False) / float(number_of_pairs)
        doa_ex = extended_degree_of_adaptiveness(
            ag, noc_rg, False) / float(number_of_pairs)
        print("doa:", doa)
        print("doa_ex", doa_ex)
    return None
コード例 #7
0
def initialize_system_DoS(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:  ag, shmu, noc_rg
    """

    ####################################################################
    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
    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()
    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")
    # Some visualization...
    if Config.viz.rg:
        RoutingGraph_Reports.draw_rg(noc_rg)
    return ag, shmu, noc_rg
コード例 #8
0
 def test_apply_initial_faults(self):
     # todo: generate some random faults and put them in Config and then return to normal
     ag_4_test = copy.deepcopy(generate_ag(logging=None))
     shmu_4_test = SystemHealthMonitoringUnit.SystemHealthMonitoringUnit()
     shmu_4_test.setup_noc_shm(ag_4_test, Config.TurnsHealth, False)
     SHMU_Functions.apply_initial_faults(shmu_4_test)
     for broken_link in Config.ListOfBrokenLinks:
         self.assertEqual(shmu_4_test.SHM.edges[broken_link]['LinkHealth'],
                          False)
     for router_with_broken_turn in Config.ListOfBrokenTurns:
         broken_turn = Config.ListOfBrokenTurns[router_with_broken_turn]
         self.assertEqual(
             shmu_4_test.SHM.node[router_with_broken_turn]['TurnsHealth']
             [broken_turn], False)
     for broken_node in Config.ListOfBrokenPEs:
         self.assertEqual(shmu_4_test.SHM.node[broken_node]['NodeHealth'],
                          False)
     for aged_pe in Config.ListOfAgedPEs:
         self.assertEqual(shmu_4_test.SHM.node[aged_pe]['NodeSpeed'],
                          Config.ListOfAgedPEs[aged_pe])
     del ag_4_test
     del shmu_4_test
コード例 #9
0
ファイル: reachability_tests.py プロジェクト: thigg/SoCDep2
    def test_is_destination_reachable_from_source(self):
        initial_config_ag = deepcopy(Config.ag)
        initial_turn_model = Config.UsedTurnModel
        initial_routing_type = Config.RotingType

        Config.ag.type = "Generic"
        Config.ag.topology = "2DMesh"
        Config.ag.x_size = 3
        Config.ag.y_size = 3
        Config.ag.z_size = 1

        for turn_model in PackageFile.routing_alg_list_2d:
            Config.UsedTurnModel = deepcopy(turn_model)
            Config.TurnsHealth = deepcopy(Config.setup_turns_health())
            ag_4_test = deepcopy(generate_ag(logging=None))
            shmu_4_test = SystemHealthMonitoringUnit.SystemHealthMonitoringUnit(
            )
            shmu_4_test.setup_noc_shm(ag_4_test, Config.TurnsHealth, False)
            noc_rg = generate_noc_route_graph(ag_4_test, shmu_4_test,
                                              turn_model, False, False)
            for source_node in ag_4_test.nodes():
                for destination_node in ag_4_test.nodes():
                    if source_node != destination_node:
                        self.assertEqual(
                            is_destination_reachable_from_source(
                                noc_rg, source_node, destination_node), True)
                        s_x, s_y, s_z = return_node_location(source_node)
                        d_x, d_y, d_z = return_node_location(destination_node)
                        # is_destination_reachable_via_port checks output ports only
                        self.assertEqual(
                            is_destination_reachable_via_port(
                                noc_rg, source_node, 'L', destination_node,
                                False), False)
                        if turn_model == PackageFile.XY_TurnModel:
                            if s_x > d_x:
                                self.assertEqual(
                                    is_destination_reachable_via_port(
                                        noc_rg, source_node, 'W',
                                        destination_node, False), True)
                            if s_x < d_x:
                                self.assertEqual(
                                    is_destination_reachable_via_port(
                                        noc_rg, source_node, 'E',
                                        destination_node, False), True)
                            if s_x == d_x:
                                if s_y < d_y:
                                    self.assertEqual(
                                        is_destination_reachable_via_port(
                                            noc_rg, source_node, 'N',
                                            destination_node, False), True)
                                else:
                                    self.assertEqual(
                                        is_destination_reachable_via_port(
                                            noc_rg, source_node, 'S',
                                            destination_node, False), True)
            del ag_4_test
            del shmu_4_test
            del noc_rg

        Config.ag.type = "Generic"
        Config.ag.topology = "3DMesh"
        Config.ag.x_size = 3
        Config.ag.y_size = 3
        Config.ag.z_size = 3
        Config.RotingType = "MinimalPath"

        for turn_model in PackageFile.routing_alg_list_3d:
            Config.UsedTurnModel = deepcopy(turn_model)
            Config.TurnsHealth = deepcopy(Config.setup_turns_health())
            ag_4_test = deepcopy(generate_ag(logging=None))
            shmu_4_test = SystemHealthMonitoringUnit.SystemHealthMonitoringUnit(
            )
            shmu_4_test.setup_noc_shm(ag_4_test, Config.TurnsHealth, False)
            noc_rg = generate_noc_route_graph(ag_4_test, shmu_4_test,
                                              turn_model, False, False)
            for source_node in ag_4_test.nodes():
                for destination_node in ag_4_test.nodes():
                    if source_node != destination_node:
                        self.assertEqual(
                            is_destination_reachable_from_source(
                                noc_rg, source_node, destination_node), True)
                    # todo: check is_destination_reachable_via_port
            del ag_4_test
            del shmu_4_test
            del noc_rg

        Config.ag = deepcopy(initial_config_ag)
        Config.UsedTurnModel = initial_turn_model
        Config.TurnsHealth = deepcopy(Config.setup_turns_health())
        Config.RotingType = initial_routing_type
コード例 #10
0
def test():
    all_odd_evens_file = open(
        'Generated_Files/Turn_Model_Lists/all_odd_evens_doa.txt', 'w')
    turns_health_2d_network = {
        "N2W": False,
        "N2E": False,
        "S2W": False,
        "S2E": False,
        "W2N": False,
        "W2S": False,
        "E2N": False,
        "E2S": False
    }
    Config.ag.topology = '2DMesh'
    Config.ag.x_size = 3
    Config.ag.y_size = 3
    Config.ag.z_size = 1
    Config.RotingType = 'NonMinimalPath'
    ag = copy.deepcopy(AG_Functions.generate_ag())
    number_of_pairs = len(ag.nodes()) * (len(ag.nodes()) - 1)

    max_ratio = 0
    classes_of_doa_ratio = []
    turn_model_class_dict = {}
    for turn_model in all_odd_even_list:
        #for item in selected_turn_models:
        #print item
        #turn_model = all_odd_even_list[item]
        #print turn_model
        turn_model_index = all_odd_even_list.index(turn_model)
        turn_model_odd = turn_model[0]
        turn_model_even = turn_model[1]

        turns_health = copy.deepcopy(turns_health_2d_network)
        shmu = SystemHealthMonitoringUnit.SystemHealthMonitoringUnit()
        shmu.setup_noc_shm(ag, turns_health, False)
        noc_rg = copy.deepcopy(
            Routing.generate_noc_route_graph(ag, shmu, [], False, False))

        for node in ag.nodes():
            node_x, node_y, node_z = AG_Functions.return_node_location(node)
            if node_x % 2 == 1:
                for turn in turn_model_odd:
                    shmu.restore_broken_turn(node, turn, False)
                    from_port = str(node) + str(turn[0]) + "I"
                    to_port = str(node) + str(turn[2]) + "O"
                    Routing.update_noc_route_graph(noc_rg, from_port, to_port,
                                                   'ADD')
            else:
                for turn in turn_model_even:
                    shmu.restore_broken_turn(node, turn, False)
                    from_port = str(node) + str(turn[0]) + "I"
                    to_port = str(node) + str(turn[2]) + "O"
                    Routing.update_noc_route_graph(noc_rg, from_port, to_port,
                                                   'ADD')
        #draw_rg(noc_rg)
        number_of_pairs = len(ag.nodes()) * (len(ag.nodes()) - 1)
        doa_ex = extended_degree_of_adaptiveness(
            ag, noc_rg, False) / float(number_of_pairs)
        doa = degree_of_adaptiveness(ag, noc_rg,
                                     False) / float(number_of_pairs)
        sum_of_paths = 0
        sum_of_sim_ratio = 0

        for source_node in ag.nodes():
            for destination_node in ag.nodes():
                if source_node != destination_node:
                    if is_destination_reachable_from_source(
                            noc_rg, source_node, destination_node):
                        #print source_node, "--->", destination_node
                        if Config.RotingType == 'MinimalPath':
                            shortest_paths = list(
                                all_shortest_paths(
                                    noc_rg,
                                    str(source_node) + str('L') + str('I'),
                                    str(destination_node) + str('L') +
                                    str('O')))
                            paths = []
                            for path in shortest_paths:
                                minimal_hop_count = manhattan_distance(
                                    source_node, destination_node)
                                if (len(path) / 2) - 1 <= minimal_hop_count:
                                    paths.append(path)
                        else:
                            paths = list(
                                all_simple_paths(
                                    noc_rg,
                                    str(source_node) + str('L') + str('I'),
                                    str(destination_node) + str('L') +
                                    str('O')))
                        #for path in paths:
                        #    print path
                        local_sim_ratio = 0
                        counter = 0
                        if len(paths) > 1:
                            for i in range(0, len(paths)):
                                for j in range(i, len(paths)):
                                    if paths[i] != paths[j]:
                                        sm = difflib.SequenceMatcher(
                                            None, paths[i], paths[j])
                                        counter += 1
                                        local_sim_ratio += sm.ratio()
                            #print float(local_sim_ratio)/counter
                            sum_of_sim_ratio += float(
                                local_sim_ratio) / counter
                        else:

                            sum_of_sim_ratio += 1
        if Config.RotingType == 'MinimalPath':
            print("Turn Model ", '%5s' % turn_model_index, "\tdoa:",
                  "{:3.3f}".format(doa), "\tsimilarity ratio:",
                  "{:3.3f}".format(sum_of_sim_ratio),
                  "\t\tfault tolerance metric:",
                  "{:3.5f}".format(float(doa) / sum_of_sim_ratio))
            doa_ratio = float("{:3.5f}".format(
                float(doa) / sum_of_sim_ratio, 5))
        else:
            print("Turn Model ", '%5s' % turn_model_index, "\tdoa:",
                  "{:3.3f}".format(doa_ex), "\tsimilarity ratio:",
                  "{:3.3f}".format(sum_of_sim_ratio),
                  "\t\tfault tolerance metric:",
                  "{:3.5f}".format(float(doa_ex) / sum_of_sim_ratio))
            doa_ratio = float("{:3.5f}".format(
                float(doa_ex) / sum_of_sim_ratio, 5))

        if doa_ratio not in classes_of_doa_ratio:
            classes_of_doa_ratio.append(doa_ratio)
        if doa_ratio in list(turn_model_class_dict.keys()):
            turn_model_class_dict[doa_ratio].append(turn_model_index)
        else:
            turn_model_class_dict[doa_ratio] = [turn_model_index]
        if max_ratio < doa_ratio:
            max_ratio = doa_ratio

        #print "--------------------------------------------"
        del noc_rg
    print("max doa_ratio", max_ratio)
    print("classes of doa_ratio", classes_of_doa_ratio)
    for item in sorted(turn_model_class_dict.keys()):
        print(item, turn_model_class_dict[item])
    return None
コード例 #11
0
def report_odd_even_turn_model_fault_tolerance(viz, routing_type, combination):
    """
    generates 2D architecture graph with all combinations C(len(ag.nodes), combination)
    of links and writes the average connectivity metric in a file.
    :param viz: if true, generates the visualization files
    :param routing_type: can be "minimal" or "nonminimal"
    :param combination: number of links to be present in the network
    :return: None
    """
    turns_health_2d_network = {
        "N2W": False,
        "N2E": False,
        "S2W": False,
        "S2E": False,
        "W2N": False,
        "W2S": False,
        "E2N": False,
        "E2S": False
    }
    tm_counter = 0
    Config.ag.topology = '2DMesh'
    Config.ag.x_size = 3
    Config.ag.y_size = 3
    Config.ag.z_size = 1

    selected_turn_models = [
        677, 678, 697, 699, 717, 718, 737, 739, 757, 759, 778, 779, 797, 799,
        818, 819, 679, 738, 777, 798
    ]
    #selected_turn_models = [677, 798]
    if routing_type == "minimal":
        Config.RotingType = 'MinimalPath'
    else:
        Config.RotingType = 'NonMinimalPath'

    for turn_id in selected_turn_models:
        counter = 0
        metric_sum = 0
        turn_model = all_odd_even_list[turn_id]

        ag = copy.deepcopy(AG_Functions.generate_ag(report=False))
        turn_model_odd = turn_model[0]
        turn_model_even = turn_model[1]

        file_name = str(tm_counter) + '_eval'
        turn_model_eval_file = open(
            'Generated_Files/Turn_Model_Eval/' + file_name + '.txt', 'a+')
        if viz:
            file_name_viz = str(tm_counter) + '_eval_' + str(
                len(ag.edges()) - counter)
            turn_model_eval_viz_file = open(
                'Generated_Files/Internal/odd_even' + file_name_viz + '.txt',
                'w')
        else:
            turn_model_eval_viz_file = None

        sub_ag_list = list(itertools.combinations(ag.edges(), combination))
        turns_health = copy.deepcopy(turns_health_2d_network)
        shmu = SystemHealthMonitoringUnit.SystemHealthMonitoringUnit()
        shmu.setup_noc_shm(ag, turns_health, False)

        for sub_ag in sub_ag_list:
            for link in list(sub_ag):
                shmu.break_link(link, False)

            noc_rg = copy.deepcopy(
                Routing.generate_noc_route_graph(ag, shmu, [], False, False))
            for node in ag.nodes():
                node_x, node_y, node_z = AG_Functions.return_node_location(
                    node)
                if node_x % 2 == 1:
                    for turn in turn_model_odd:
                        shmu.restore_broken_turn(node, turn, False)
                        from_port = str(node) + str(turn[0]) + "I"
                        to_port = str(node) + str(turn[2]) + "O"
                        Routing.update_noc_route_graph(noc_rg, from_port,
                                                       to_port, 'ADD')
                else:
                    for turn in turn_model_even:
                        shmu.restore_broken_turn(node, turn, False)
                        from_port = str(node) + str(turn[0]) + "I"
                        to_port = str(node) + str(turn[2]) + "O"
                        Routing.update_noc_route_graph(noc_rg, from_port,
                                                       to_port, 'ADD')

            connectivity_metric = reachability_metric(ag, noc_rg, False)
            counter += 1
            metric_sum += connectivity_metric
            if viz:
                turn_model_eval_viz_file.write(
                    str(float(metric_sum) / counter) + "\n")
            # print "#:"+str(counter)+"\t\tC.M.:"+str(connectivity_metric)+"\t\t avg:", \
            #     float(metric_sum)/counter, "\t\tstd:", std
            for link in list(sub_ag):
                shmu.restore_broken_link(link, False)
            del noc_rg

        shuffle(sub_ag_list)

        if counter > 0:
            avg_connectivity = float(metric_sum) / counter
        else:
            avg_connectivity = 0
        turn_model_eval_file.write(
            str(len(ag.edges()) - combination) + "\t\t" +
            str(avg_connectivity) + "\n")
        if viz:
            turn_model_eval_viz_file.close()
        turn_model_eval_file.close()
        sys.stdout.write("\rchecked TM: %i " % tm_counter +
                         "\t\t\tnumber of healthy links: %i " % combination)
        sys.stdout.flush()
        tm_counter += 1
    return None
コード例 #12
0
ファイル: odd_even_evaluation.py プロジェクト: thigg/SoCDep2
def odd_even_fault_tolerance_metric(network_size, routing_type):

    turns_health_2d_network = {
        "N2W": False,
        "N2E": False,
        "S2W": False,
        "S2E": False,
        "W2N": False,
        "W2S": False,
        "E2N": False,
        "E2S": False
    }
    Config.ag.topology = '2DMesh'
    Config.ag.x_size = network_size
    Config.ag.y_size = network_size
    Config.ag.z_size = 1
    Config.RotingType = routing_type

    all_odd_evens_file = open(
        'Generated_Files/Turn_Model_Eval/' + str(network_size) + "x" +
        str(network_size) + '_OE_metric_' + Config.RotingType + '.txt', 'w')
    all_odd_evens_file.write("TOPOLOGY::" + str(Config.ag.topology) + "\n")
    all_odd_evens_file.write("X SIZE:" + str(Config.ag.x_size) + "\n")
    all_odd_evens_file.write("Y SIZE:" + str(Config.ag.y_size) + "\n")
    all_odd_evens_file.write("Z SIZE:" + str(Config.ag.z_size) + "\n")
    ag = copy.deepcopy(AG_Functions.generate_ag())
    shmu = SystemHealthMonitoringUnit.SystemHealthMonitoringUnit()
    turns_health = copy.deepcopy(turns_health_2d_network)
    shmu.setup_noc_shm(ag, turns_health, False)
    noc_rg = copy.deepcopy(
        Routing.generate_noc_route_graph(ag, shmu, [], False, False))

    classes_of_doa_ratio = []
    turn_model_class_dict = {}
    tm_counter = 0
    """
    selected_turn_models = []
    for tm in all_odd_even_list:
        if len(tm[0])+len(tm[1]) == 11 or len(tm[0])+len(tm[1]) == 12:
            selected_turn_models.append(all_odd_even_list.index(tm))
    """
    #selected_turn_models = [677, 678, 697, 699, 717, 718, 737, 739, 757, 759, 778, 779, 797, 799, 818, 819,
    #                        679, 698, 719, 738, 758, 777, 798, 817]

    for turn_model in all_odd_even_list:
        #for item in selected_turn_models:
        # print item
        # turn_model = all_odd_even_list[item]

        sys.stdout.write("\rnumber of processed turn models: %i " % tm_counter)
        sys.stdout.flush()
        tm_counter += 1
        link_dict = {}
        turn_model_index = all_odd_even_list.index(turn_model)
        turn_model_odd = turn_model[0]
        turn_model_even = turn_model[1]

        for node in ag.nodes():
            node_x, node_y, node_z = AG_Functions.return_node_location(node)
            if node_x % 2 == 1:
                for turn in turn_model_odd:
                    shmu.restore_broken_turn(node, turn, False)
                    from_port = str(node) + str(turn[0]) + "I"
                    to_port = str(node) + str(turn[2]) + "O"
                    Routing.update_noc_route_graph(noc_rg, from_port, to_port,
                                                   'ADD')
            else:
                for turn in turn_model_even:
                    shmu.restore_broken_turn(node, turn, False)
                    from_port = str(node) + str(turn[0]) + "I"
                    to_port = str(node) + str(turn[2]) + "O"
                    Routing.update_noc_route_graph(noc_rg, from_port, to_port,
                                                   'ADD')

        number_of_pairs = len(ag.nodes()) * (len(ag.nodes()) - 1)

        all_paths_in_graph = []
        for source_node in ag.nodes():
            for destination_node in ag.nodes():
                if source_node != destination_node:
                    if is_destination_reachable_from_source(
                            noc_rg, source_node, destination_node):
                        # print source_node, "--->", destination_node
                        if Config.RotingType == 'MinimalPath':
                            shortest_paths = list(
                                all_shortest_paths(
                                    noc_rg,
                                    str(source_node) + str('L') + str('I'),
                                    str(destination_node) + str('L') +
                                    str('O')))
                            paths = []
                            for path in shortest_paths:
                                minimal_hop_count = manhattan_distance(
                                    source_node, destination_node)
                                if (len(path) / 2) - 1 <= minimal_hop_count:
                                    paths.append(path)
                                    all_paths_in_graph.append(path)
                        else:
                            paths = list(
                                all_simple_paths(
                                    noc_rg,
                                    str(source_node) + str('L') + str('I'),
                                    str(destination_node) + str('L') +
                                    str('O')))
                            all_paths_in_graph += paths
                        link_dict = find_similarity_in_paths(link_dict, paths)

        metric = 0
        for item in link_dict.keys():
            metric += link_dict[item]

        if Config.RotingType == 'MinimalPath':
            doa = degree_of_adaptiveness(ag, noc_rg,
                                         False) / float(number_of_pairs)
            #metric = doa/(float(metric)/len(ag.edges()))
            metric = 1 / (float(metric) / len(ag.edges()))
            metric = float("{:3.3f}".format(metric))
            # print "Turn Model ", '%5s' %turn_model_index, "\tdoa:", "{:3.3f}".format(doa),
            #       "\tmetric:", "{:3.3f}".format(metric)
        else:
            doa_ex = extended_degree_of_adaptiveness(
                ag, noc_rg, False) / float(number_of_pairs)
            #metric = doa_ex/(float(metric)/len(ag.edges()))
            metric = 1 / (float(metric) / len(ag.edges()))
            metric = float("{:3.3f}".format(metric))
            # print "Turn Model ", '%5s' %turn_model_index, "\tdoa:", "{:3.3f}".format(doa_ex),
            #       "\tmetric:", "{:3.3f}".format(metric)

        if metric not in classes_of_doa_ratio:
            classes_of_doa_ratio.append(metric)
        if metric in turn_model_class_dict.keys():
            turn_model_class_dict[metric].append(turn_model_index)
        else:
            turn_model_class_dict[metric] = [turn_model_index]

        # return SHMU and RG back to default
        for node in ag.nodes():
            node_x, node_y, node_z = AG_Functions.return_node_location(node)
            if node_x % 2 == 1:
                for turn in turn_model_odd:
                    shmu.break_turn(node, turn, False)
                    from_port = str(node) + str(turn[0]) + "I"
                    to_port = str(node) + str(turn[2]) + "O"
                    Routing.update_noc_route_graph(noc_rg, from_port, to_port,
                                                   'REMOVE')
            else:
                for turn in turn_model_even:
                    shmu.break_turn(node, turn, False)
                    from_port = str(node) + str(turn[0]) + "I"
                    to_port = str(node) + str(turn[2]) + "O"
                    Routing.update_noc_route_graph(noc_rg, from_port, to_port,
                                                   'REMOVE')

    all_odd_evens_file.write("classes of metric" + str(classes_of_doa_ratio) +
                             "\n")
    all_odd_evens_file.write("----------" * 3 + "\n")
    all_odd_evens_file.write("turn models of class" + "\n")
    # print "classes of metric", classes_of_doa_ratio
    for item in sorted(turn_model_class_dict.keys()):
        # print item, turn_model_class_dict[item]
        all_odd_evens_file.write(
            str(item) + " " + str(turn_model_class_dict[item]) + "\n")

    all_odd_evens_file.write("----------" * 3 + "\n")
    all_odd_evens_file.write("distribution of turn models" + "\n")
    for item in sorted(turn_model_class_dict.keys()):
        temp_list = []
        for tm in turn_model_class_dict[item]:
            turn_model = all_odd_even_list[tm]
            number_of_turns = len(turn_model[0]) + len(turn_model[1])
            temp_list.append(number_of_turns)
        # print item, temp_list.count(8), temp_list.count(9), temp_list.count(10),
        # temp_list.count(11), temp_list.count(12)
        all_odd_evens_file.write(
            str(item) + " " + str(temp_list.count(8)) + " " +
            str(temp_list.count(9)) + " " + str(temp_list.count(10)) + " " +
            str(temp_list.count(11)) + " " + str(temp_list.count(12)) + "\n")
    all_odd_evens_file.close()
    return turn_model_class_dict
コード例 #13
0
ファイル: odd_even_evaluation.py プロジェクト: thigg/SoCDep2
def enumerate_all_odd_even_turn_models(network_size, routing_type):
    all_odd_evens_file = open(
        'Generated_Files/Turn_Model_Lists/' + str(network_size) + "x" +
        str(network_size) + "_" + str(routing_type) + "_" +
        'odd_even_tm_list_dl_free.txt', 'w')
    turns_health_2d_network = {
        "N2W": False,
        "N2E": False,
        "S2W": False,
        "S2E": False,
        "W2N": False,
        "W2S": False,
        "E2N": False,
        "E2S": False
    }
    Config.ag.topology = '2DMesh'
    Config.ag.x_size = network_size
    Config.ag.y_size = network_size
    Config.ag.z_size = 1
    Config.RotingType = routing_type
    ag = copy.deepcopy(AG_Functions.generate_ag())
    number_of_pairs = len(ag.nodes()) * (len(ag.nodes()) - 1)

    turn_model_list = []
    for length in range(0, len(turns_health_2d_network.keys()) + 1):
        for item in list(
                itertools.combinations(turns_health_2d_network.keys(),
                                       length)):
            if len(item) > 0:
                turn_model_list.append(list(item))

    connected_counter = 0
    deadlock_free_counter = 0
    tm_counter = 0
    turns_health = copy.deepcopy(turns_health_2d_network)
    shmu = SystemHealthMonitoringUnit.SystemHealthMonitoringUnit()
    shmu.setup_noc_shm(ag, turns_health, False)
    noc_rg = copy.deepcopy(
        Routing.generate_noc_route_graph(ag, shmu, [], False, False))

    for turn_model_odd in turn_model_list:
        for turn_model_even in turn_model_list:
            if not check_tm_domination(
                    turn_model_odd,
                    turn_model_even):  # taking out the domination!
                for node in ag.nodes():
                    node_x, node_y, node_z = AG_Functions.return_node_location(
                        node)
                    if node_x % 2 == 1:
                        for turn in turn_model_odd:
                            shmu.restore_broken_turn(node, turn, False)
                            from_port = str(node) + str(turn[0]) + "I"
                            to_port = str(node) + str(turn[2]) + "O"
                            Routing.update_noc_route_graph(
                                noc_rg, from_port, to_port, 'ADD')
                    else:
                        for turn in turn_model_even:
                            shmu.restore_broken_turn(node, turn, False)
                            from_port = str(node) + str(turn[0]) + "I"
                            to_port = str(node) + str(turn[2]) + "O"
                            Routing.update_noc_route_graph(
                                noc_rg, from_port, to_port, 'ADD')
                connectivity_metric = reachability_metric(ag, noc_rg, False)
                if connectivity_metric == number_of_pairs:
                    connected_counter += 1
                    if check_deadlock_freeness(noc_rg):
                        deadlock_free_counter += 1
                        all_odd_evens_file.write("[" + str(turn_model_odd) +
                                                 "," + str(turn_model_even) +
                                                 "],\n")

                tm_counter += 1
                sys.stdout.write("\rchecked TM: %i " % tm_counter +
                                 " number of fully connected TM: %i" %
                                 connected_counter +
                                 " number of deadlock free connected TM: %i" %
                                 deadlock_free_counter)
                sys.stdout.flush()

                for node in ag.nodes():
                    node_x, node_y, node_z = AG_Functions.return_node_location(
                        node)
                    if node_x % 2 == 1:
                        for turn in turn_model_odd:
                            shmu.restore_broken_turn(node, turn, False)
                            from_port = str(node) + str(turn[0]) + "I"
                            to_port = str(node) + str(turn[2]) + "O"
                            Routing.update_noc_route_graph(
                                noc_rg, from_port, to_port, 'REMOVE')
                    else:
                        for turn in turn_model_even:
                            shmu.restore_broken_turn(node, turn, False)
                            from_port = str(node) + str(turn[0]) + "I"
                            to_port = str(node) + str(turn[2]) + "O"
                            Routing.update_noc_route_graph(
                                noc_rg, from_port, to_port, 'REMOVE')

    all_odd_evens_file.write("checked TM: %i " + str(tm_counter) +
                             " number of fully connected TM: %i" +
                             str(connected_counter) +
                             " number of deadlock free connected TM: %i" +
                             str(deadlock_free_counter))
    all_odd_evens_file.close()
    return None
コード例 #14
0
def report_odd_even_turn_model_fault_tolerance(viz, routing_type, combination,
                                               network_size, ft_dictionary,
                                               selected_turn_models):
    """
    generates 2D architecture graph with all combinations C(len(ag.nodes), combination)
    of links and writes the average connectivity metric in a file.
    :param viz: if true, generates the visualization files
    :param routing_type: can be "minimal" or "nonminimal"
    :param combination: number of links to be present in the network
    :return: ft_dictionary a dictionary with turn mode id (from selected_turn_models)
    as keys and average connectivity_metric as value.
    """

    turns_health_2d_network = {
        "N2W": False,
        "N2E": False,
        "S2W": False,
        "S2E": False,
        "W2N": False,
        "W2S": False,
        "E2N": False,
        "E2S": False
    }
    tm_counter = 0
    Config.ag.topology = '2DMesh'
    Config.ag.x_size = network_size
    Config.ag.y_size = network_size
    Config.ag.z_size = 1

    Config.RotingType = routing_type

    ag = copy.deepcopy(AG_Functions.generate_ag(report=False))
    sub_ag_list = list(itertools.combinations(ag.edges(), combination))
    turns_health = copy.deepcopy(turns_health_2d_network)
    shmu = SystemHealthMonitoringUnit.SystemHealthMonitoringUnit()
    shmu.setup_noc_shm(ag, turns_health, False)

    for turn_id in selected_turn_models:
        counter = 0
        metric_sum = 0
        turn_model = all_odd_even_list[turn_id]

        turn_model_odd = turn_model[0]
        turn_model_even = turn_model[1]

        file_name = str(tm_counter) + '_eval'
        turn_model_eval_file = open(
            'Generated_Files/Turn_Model_Eval/' + file_name + '.txt', 'a+')
        if viz:
            file_name_viz = str(tm_counter) + '_eval_' + str(
                len(ag.edges()) - counter)
            turn_model_eval_viz_file = open(
                'Generated_Files/Internal/odd_even' + file_name_viz + '.txt',
                'w')
        else:
            turn_model_eval_viz_file = None

        for sub_ag in sub_ag_list:
            for link in list(sub_ag):
                shmu.break_link(link, False)

            noc_rg = copy.deepcopy(
                Routing.generate_noc_route_graph(ag, shmu, [], False, False))
            update_rg_odd_even(ag, turn_model_odd, turn_model_even, shmu,
                               noc_rg)

            connectivity_metric = reachability_metric(ag, noc_rg, False)
            counter += 1
            metric_sum += connectivity_metric
            if viz:
                turn_model_eval_viz_file.write(
                    str(float(metric_sum) / counter) + "\n")

            for link in list(sub_ag):
                shmu.restore_broken_link(link, False)
            clean_rg_from_odd_even(ag, turn_model_odd, turn_model_even, shmu,
                                   noc_rg)

        shuffle(sub_ag_list)

        if counter > 0:
            avg_connectivity = float(metric_sum) / counter
        else:
            avg_connectivity = 0
        turn_model_eval_file.write(
            str(len(ag.edges()) - combination) + "\t\t" +
            str(avg_connectivity) + "\n")
        if turn_id in ft_dictionary.keys():
            ft_dictionary[turn_id].append(avg_connectivity)
        else:
            ft_dictionary[turn_id] = [avg_connectivity]
        if viz:
            turn_model_eval_viz_file.close()
        turn_model_eval_file.close()
        sys.stdout.write("\rchecked TM: %i " % tm_counter +
                         "\t\t\tnumber of broken links: %i " % combination)
        sys.stdout.flush()
        tm_counter += 1
    return ft_dictionary
コード例 #15
0
ファイル: odd_even_evaluation.py プロジェクト: thigg/SoCDep2
def report_odd_even_turn_model_router_fault_tolerance(viz, routing_type,
                                                      combination,
                                                      network_size,
                                                      ft_dictionary,
                                                      selected_turn_models):
    """
    generates 2D architecture graph with all combinations C(len(ag.nodes), combination)
    of links and writes the average connectivity metric in a file.
    :param viz: if true, generates the visualization files
    :param routing_type: can be "minimal" or "nonminimal"
    :param combination: number of links to be present in the network
    :return: None
    """

    turns_health_2d_network = {
        "N2W": False,
        "N2E": False,
        "S2W": False,
        "S2E": False,
        "W2N": False,
        "W2S": False,
        "E2N": False,
        "E2S": False
    }
    tm_counter = 0
    Config.ag.topology = '2DMesh'
    Config.ag.x_size = network_size
    Config.ag.y_size = network_size
    Config.ag.z_size = 1

    Config.RotingType = routing_type

    ag = copy.deepcopy(AG_Functions.generate_ag(report=False))
    router_list = list(itertools.combinations(ag.nodes(), combination))

    for turn_id in selected_turn_models:
        counter = 0
        metric_sum = 0
        turn_model = all_odd_even_list[turn_id]

        turn_model_odd = turn_model[0]
        turn_model_even = turn_model[1]

        file_name = str(tm_counter) + '_eval'
        turn_model_eval_file = open(
            'Generated_Files/Turn_Model_Eval/' + file_name + '.txt', 'a+')
        if viz:
            file_name_viz = str(tm_counter) + '_eval_' + str(
                len(ag.nodes()) - counter)
            turn_model_eval_viz_file = open(
                'Generated_Files/Internal/odd_even' + file_name_viz + '.txt',
                'w')
        else:
            turn_model_eval_viz_file = None

        for sub_router_list in router_list:
            turns_health = copy.deepcopy(turns_health_2d_network)
            shmu = SystemHealthMonitoringUnit.SystemHealthMonitoringUnit()
            shmu.setup_noc_shm(ag, turns_health, False)
            noc_rg = copy.deepcopy(
                Routing.generate_noc_route_graph(ag, shmu, [], False, False))

            for node in ag.nodes():
                if node not in sub_router_list:
                    node_x, node_y, node_z = AG_Functions.return_node_location(
                        node)
                    if node_x % 2 == 1:
                        for turn in turn_model_odd:
                            shmu.restore_broken_turn(node, turn, False)
                            from_port = str(node) + str(turn[0]) + "I"
                            to_port = str(node) + str(turn[2]) + "O"
                            Routing.update_noc_route_graph(
                                noc_rg, from_port, to_port, 'ADD')
                    else:
                        for turn in turn_model_even:
                            shmu.restore_broken_turn(node, turn, False)
                            from_port = str(node) + str(turn[0]) + "I"
                            to_port = str(node) + str(turn[2]) + "O"
                            Routing.update_noc_route_graph(
                                noc_rg, from_port, to_port, 'ADD')
                else:
                    for port_1 in ["N", "S", "E", "W", "L"]:
                        for port_2 in ["N", "S", "E", "W", "L"]:
                            if port_1 != port_2:
                                from_port = str(node) + str(port_1) + "I"
                                to_port = str(node) + str(port_2) + "O"
                                if (from_port, to_port) in noc_rg.edges():
                                    Routing.update_noc_route_graph(
                                        noc_rg, from_port, to_port, 'REMOVE')

            connectivity_metric = reachability_metric(ag, noc_rg, False)
            counter += 1
            metric_sum += connectivity_metric
            if viz:
                turn_model_eval_viz_file.write(
                    str(float(metric_sum) / counter) + "\n")
            # print "#:"+str(counter)+"\t\tC.M.:"+str(connectivity_metric)+"\t\t avg:", \
            #     float(metric_sum)/counter, "\t\tstd:", std

        shuffle(router_list)

        if counter > 0:
            avg_connectivity = float(metric_sum) / counter
        else:
            avg_connectivity = 0
        turn_model_eval_file.write(
            str(len(ag.nodes()) - combination) + "\t\t" +
            str(avg_connectivity) + "\n")
        if turn_id in ft_dictionary.keys():
            ft_dictionary[turn_id].append(avg_connectivity)
        else:
            ft_dictionary[turn_id] = [avg_connectivity]
        if viz:
            turn_model_eval_viz_file.close()
        turn_model_eval_file.close()
        sys.stdout.write("\rchecked TM: %i " % tm_counter +
                         "\t\t\tnumber of broken routers: %i " % combination)
        sys.stdout.flush()
        tm_counter += 1
    return ft_dictionary
コード例 #16
0
def report_3d_turn_model_fault_tolerance(turn_model, viz, combination):
    """
    generates 3D architecture graph with all combinations C(len(ag.nodes), combination)
    of links and writes the average connectivity metric in a file.
    :param turn_model: list of allowed turns for generating the routing graph
    :param combination: number of links to be present in the network
    :param viz: if true, generates the visualization files
    :return: None
    """
    if combination == 108:
        raise ValueError(
            "breaking 108 edges out of 108 edges is not possible your connectivity is 0!"
        )

    Config.UsedTurnModel = copy.deepcopy(turn_model)
    Config.TurnsHealth = copy.deepcopy(Config.setup_turns_health())

    ag = copy.deepcopy(AG_Functions.generate_ag(report=False))

    turn_model_name = return_turn_model_name(Config.UsedTurnModel)

    file_name = str(turn_model_name) + '_eval'
    turn_model_eval_file = open(
        'Generated_Files/Turn_Model_Eval/' + file_name + '.txt', 'a+')
    if viz:
        file_name_viz = str(turn_model_name) + '_eval_' + str(
            len(ag.edges()) - combination)
        turn_model_eval_viz_file = open(
            'Generated_Files/Internal/' + file_name_viz + '.txt', 'w')
    else:
        turn_model_eval_viz_file = None
    counter = 0
    metric_sum = 0

    list_of_avg = []
    number_of_combinations = comb(108, combination)
    while True:
        sub_ag = sample(ag.edges(), combination)
        shmu = SystemHealthMonitoringUnit.SystemHealthMonitoringUnit()
        shmu.setup_noc_shm(ag, copy.deepcopy(Config.TurnsHealth), False)
        for link in list(sub_ag):
            shmu.break_link(link, False)
        noc_rg = copy.deepcopy(
            Routing.generate_noc_route_graph(ag, shmu, Config.UsedTurnModel,
                                             False, False))
        connectivity_metric = reachability_metric(ag, noc_rg, False)
        counter += 1
        metric_sum += connectivity_metric
        # std = None
        list_of_avg.append(float(metric_sum) / counter)
        if len(list_of_avg) > 5000:
            list_of_avg.pop(0)
            std = stdev(list_of_avg)
            if std < 0.009:
                # turn_model_eval_file.write("STD of the last 5000 average samples is bellow 0.009\n")
                # turn_model_eval_file.write("Terminating the search!\n")
                del shmu
                del noc_rg
                break
        if viz:
            turn_model_eval_viz_file.write(
                str(float(metric_sum) / counter) + "\n")

        if counter >= number_of_combinations:
            del shmu
            del noc_rg
            break

        # print("#:"+str(counter)+"\t\tC.M.:"+str(connectivity_metric)+"\t\t avg:", \
        #    float(metric_sum)/counter, "\t\tstd:", std)
        del shmu
        del noc_rg

    if counter > 0:
        avg_connectivity = float(metric_sum) / counter
    else:
        avg_connectivity = 0
    turn_model_eval_file.write(
        str(len(ag.edges()) - combination) + "\t\t" + str(avg_connectivity) +
        "\n")
    turn_model_eval_file.close()
    if viz:
        turn_model_eval_viz_file.close()
    return None
コード例 #17
0
def enumerate_all_3d_turn_models_based_on_df(combination):
    """
    Lists all 3D deadlock free turn models in "deadlock_free_turns" in "Generated_Files"
    folder!
    ---------------------
        We have 16,777,216 turns in 3D Mesh NoC! if it takes one second to calculate
        deadlock freeness Then it takes almost 194.2 Days (almost 6.4 Months) to
        check all of them. that is the reason we need to make this parallel!
    ---------------------
    :param combination: number of turns which should be checked for combination!
    :return: None
    """
    counter = 0
    all_turns_file = open(
        'Generated_Files/Turn_Model_Lists/all_3D_turn_models_' +
        str(combination) + '.txt', 'w')
    turns_health_3d_network = {
        "N2W": False,
        "N2E": False,
        "S2W": False,
        "S2E": False,
        "W2N": False,
        "W2S": False,
        "E2N": False,
        "E2S": False,
        "N2U": False,
        "N2D": False,
        "S2U": False,
        "S2D": False,
        "W2U": False,
        "W2D": False,
        "E2U": False,
        "E2D": False,
        "U2W": False,
        "U2E": False,
        "U2N": False,
        "U2S": False,
        "D2W": False,
        "D2E": False,
        "D2N": False,
        "D2S": False
    }
    Config.ag.topology = '3DMesh'
    Config.ag.x_size = 3
    Config.ag.y_size = 3
    Config.ag.z_size = 3

    ag = copy.deepcopy(AG_Functions.generate_ag())
    turn_model_list = copy.deepcopy(PackageFile.FULL_TurnModel_3D)

    deadlock_free_counter = 0
    deadlock_counter = 0
    # print("Number of Turns:", combination)
    for turns in itertools.combinations(turn_model_list, combination):
        turns_health = copy.deepcopy(turns_health_3d_network)
        for turn in turns:
            turns_health[turn] = True
        counter += 1
        shmu = SystemHealthMonitoringUnit.SystemHealthMonitoringUnit()
        shmu.setup_noc_shm(ag, turns_health, False)
        noc_rg = copy.deepcopy(
            Routing.generate_noc_route_graph(ag, shmu, list(turns), False,
                                             False))
        if check_deadlock_freeness(noc_rg):
            connectivity_metric = reachability_metric(ag, noc_rg, False)
            doa = degree_of_adaptiveness(ag, noc_rg, False)
            deadlock_free_counter += 1
            all_turns_file.write(
                str(counter) + "\t\tDF\t" + str(list(turns)) + "\t\t" +
                str(connectivity_metric) + "\t\t" + str(doa) + "\n")
        else:
            deadlock_counter += 1
            all_turns_file.write(
                str(counter) + "\t\tDL\t" + str(list(turns)) + "\t\t-----"
                "\n")
        del shmu
        del noc_rg
    all_turns_file.write("---------------------------" + "\n")
    all_turns_file.write("Number of turn models with deadlock: " +
                         str(deadlock_counter) + "\n")
    all_turns_file.write("Number of turn models without deadlock: " +
                         str(deadlock_free_counter) + "\n")
    all_turns_file.write("==========================================" + "\n")
    all_turns_file.close()
    return None
コード例 #18
0
def mixed_critical_rg(network_size, routing_type, critical_nodes, critical_rg_nodes, turn_model, viz, report):

    turns_health_2d_network = {"N2W": True, "N2E": True, "S2W": True, "S2E": True,
                               "W2N": True, "W2S": True, "E2N": True, "E2S": True}

    Config.ag.topology = '2DMesh'
    Config.ag.x_size = network_size
    Config.ag.y_size = network_size
    Config.ag.z_size = 1
    Config.RotingType = routing_type

    ag = copy.deepcopy(AG_Functions.generate_ag())
    shmu = SystemHealthMonitoringUnit.SystemHealthMonitoringUnit()
    shmu.setup_noc_shm(ag, turns_health_2d_network, False)
    noc_rg = copy.deepcopy(Routing.generate_noc_route_graph(ag, shmu, turns_health_2d_network.keys(), False,  False))
    copy_rg =copy.deepcopy(noc_rg)

    for node in critical_rg_nodes:
        if node not in noc_rg.nodes():
            raise ValueError(str(node)+" doesnt exist in noc_rg")

    for node in noc_rg.nodes():
        if node in critical_rg_nodes:
            noc_rg.node[node]["criticality"] = "H"
        else:
            noc_rg.node[node]["criticality"] = "L"

    edges_to_be_removed = []
    for edge in noc_rg.edges():
        if noc_rg.node[edge[0]]["criticality"] != noc_rg.node[edge[1]]["criticality"]:
            edges_to_be_removed.append(edge)
        else:
            if noc_rg.node[edge[0]]["criticality"] == "L":
                if edge[0][:-2] == edge[1][:-2]:
                    if str(edge[0][-2])+"2"+str(edge[1][-2]) not in turn_model:
                        if edge[0][-2] == "L" or  edge[1][-2] == "L":
                            pass
                        elif edge[0][-2] == "E" and edge[1][-2] == "W":
                            pass
                        elif edge[0][-2] == "W" and edge[1][-2] == "E":
                            pass
                        elif edge[0][-2] == "S" and edge[1][-2] == "N":
                            pass
                        elif edge[0][-2] == "N" and edge[1][-2] == "S":
                            pass
                        else:
                            edges_to_be_removed.append(edge)

    for edge in edges_to_be_removed:
        noc_rg.remove_edge(edge[0], edge[1])
    if viz:
        noc_rg = copy.deepcopy(cleanup_routing_graph(ag, noc_rg))
        RoutingGraph_Reports.draw_rg(noc_rg)

    reachability_counter = 0
    connectivity_counter = 0
    print "its deadlock free:", check_deadlock_freeness(noc_rg)
    for node_1 in ag.nodes():
        for node_2 in ag.nodes():
            if node_1 != node_2:
                if node_1 in critical_nodes or node_2 in critical_nodes:
                    pass
                else:

                    if is_destination_reachable_from_source(noc_rg, node_1, node_2):
                        connectivity_counter += 1
                        if routing_type == "MinimalPath":
                            paths = return_minimal_paths(noc_rg, node_1, node_2)
                            all_minimal_paths = return_minimal_paths(copy_rg, node_1, node_2)
                            valid_path = True
                            for path in paths:
                                for node in path:
                                    successors = noc_rg.successors(node)
                                    if str(node_2)+str('L')+str('O') in successors:
                                        #print node_2, successors
                                        break
                                    else:
                                        for successor in successors:
                                            valid_successor = False

                                            for path_1 in all_minimal_paths:
                                                if successor in path_1:
                                                    valid_successor = True
                                                    break
                                            if valid_successor:
                                                #print path, node, node_2, successor
                                                if not has_path(noc_rg, successor, str(node_2)+str('L')+str('O')):
                                                    valid_path = False
                                                    break
                            if valid_path:
                                reachability_counter += 1
                            else:
                                print node_1,"can not reach  ", node_2
                        else:
                            reachability_counter += 1
                    else:
                        if report:
                            print node_1,"can not connect", node_2
    print "average connectivity for non-critical nodes:", float(connectivity_counter)/(len(ag.nodes())-len(critical_nodes))
    print "average reachability for non-critical nodes:", float(reachability_counter)/(len(ag.nodes())-len(critical_nodes))
    return float(connectivity_counter)/(len(ag.nodes())-len(critical_nodes)), noc_rg
コード例 #19
0
def odd_even_fault_tolerance_metric(network_size, routing_type):

    turns_health_2d_network = {
        "N2W": False,
        "N2E": False,
        "S2W": False,
        "S2E": False,
        "W2N": False,
        "W2S": False,
        "E2N": False,
        "E2S": False
    }
    Config.ag.topology = '2DMesh'
    Config.ag.x_size = network_size
    Config.ag.y_size = network_size
    Config.ag.z_size = 1
    Config.RotingType = routing_type

    all_odd_evens_file = open(
        'Generated_Files/Turn_Model_Eval/' + str(network_size) + "x" +
        str(network_size) + '_OE_metric_' + Config.RotingType + '.txt', 'w')
    all_odd_evens_file.write("TOPOLOGY::" + str(Config.ag.topology) + "\n")
    all_odd_evens_file.write("X SIZE:" + str(Config.ag.x_size) + "\n")
    all_odd_evens_file.write("Y SIZE:" + str(Config.ag.y_size) + "\n")
    all_odd_evens_file.write("Z SIZE:" + str(Config.ag.z_size) + "\n")
    ag = copy.deepcopy(AG_Functions.generate_ag())
    shmu = SystemHealthMonitoringUnit.SystemHealthMonitoringUnit()
    turns_health = copy.deepcopy(turns_health_2d_network)
    shmu.setup_noc_shm(ag, turns_health, False)
    noc_rg = copy.deepcopy(
        Routing.generate_noc_route_graph(ag, shmu, [], False, False))

    classes_of_doa_ratio = []
    turn_model_class_dict = {}
    tm_counter = 0

    for turn_model in all_odd_even_list:

        sys.stdout.write("\rnumber of processed turn models: %i " % tm_counter)
        sys.stdout.flush()
        tm_counter += 1
        link_dict = {}
        turn_model_index = all_odd_even_list.index(turn_model)
        turn_model_odd = turn_model[0]
        turn_model_even = turn_model[1]

        update_rg_odd_even(ag, turn_model_odd, turn_model_even, shmu, noc_rg)

        number_of_pairs = len(ag.nodes()) * (len(ag.nodes()) - 1)

        all_paths_in_graph = []
        for source_node in ag.nodes():
            for destination_node in ag.nodes():
                if source_node != destination_node:
                    if is_destination_reachable_from_source(
                            noc_rg, source_node, destination_node):
                        if Config.RotingType == 'MinimalPath':
                            shortest_paths = list(
                                all_shortest_paths(
                                    noc_rg,
                                    str(source_node) + str('L') + str('I'),
                                    str(destination_node) + str('L') +
                                    str('O')))
                            paths = []
                            for path in shortest_paths:
                                minimal_hop_count = manhattan_distance(
                                    source_node, destination_node)
                                if (len(path) / 2) - 1 <= minimal_hop_count:
                                    paths.append(path)
                                    all_paths_in_graph.append(path)
                        else:
                            paths = list(
                                all_simple_paths(
                                    noc_rg,
                                    str(source_node) + str('L') + str('I'),
                                    str(destination_node) + str('L') +
                                    str('O')))
                            all_paths_in_graph += paths
                        link_dict = find_similarity_in_paths(link_dict, paths)

        metric = 0
        for item in link_dict.keys():
            metric += link_dict[item]

        if Config.RotingType == 'MinimalPath':
            doa = degree_of_adaptiveness(ag, noc_rg,
                                         False) / float(number_of_pairs)
            metric = 1 / (float(metric) / len(ag.edges()))
            metric = float("{:3.3f}".format(metric))
        else:
            doa_ex = extended_degree_of_adaptiveness(
                ag, noc_rg, False) / float(number_of_pairs)
            metric = 1 / (float(metric) / len(ag.edges()))
            metric = float("{:3.3f}".format(metric))

        if metric not in classes_of_doa_ratio:
            classes_of_doa_ratio.append(metric)
        if metric in turn_model_class_dict.keys():
            turn_model_class_dict[metric].append(turn_model_index)
        else:
            turn_model_class_dict[metric] = [turn_model_index]
        # return SHMU and RG back to default
        clean_rg_from_odd_even(ag, turn_model_odd, turn_model_even, shmu,
                               noc_rg)

    all_odd_evens_file.write("classes of metric" + str(classes_of_doa_ratio) +
                             "\n")
    all_odd_evens_file.write("----------" * 3 + "\n")
    all_odd_evens_file.write("turn models of class" + "\n")
    for item in sorted(turn_model_class_dict.keys()):
        all_odd_evens_file.write(
            str(item) + " " + str(turn_model_class_dict[item]) + "\n")

    all_odd_evens_file.write("----------" * 3 + "\n")
    all_odd_evens_file.write("distribution of turn models" + "\n")
    for item in sorted(turn_model_class_dict.keys()):
        temp_list = []
        for tm in turn_model_class_dict[item]:
            turn_model = all_odd_even_list[tm]
            number_of_turns = len(turn_model[0]) + len(turn_model[1])
            temp_list.append(number_of_turns)
        all_odd_evens_file.write(
            str(item) + " " + str(temp_list.count(8)) + " " +
            str(temp_list.count(9)) + " " + str(temp_list.count(10)) + " " +
            str(temp_list.count(11)) + " " + str(temp_list.count(12)) + "\n")
    all_odd_evens_file.close()
    return turn_model_class_dict
コード例 #20
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
コード例 #21
0
def mixed_critical_rg(network_size, routing_type, critical_nodes,
                      critical_rg_nodes, broken_links, turn_model, viz,
                      report):

    turns_health_2d_network = {
        "N2W": True,
        "N2E": True,
        "S2W": True,
        "S2E": True,
        "W2N": True,
        "W2S": True,
        "E2N": True,
        "E2S": True
    }

    Config.ag.topology = '2DMesh'
    Config.ag.x_size = network_size
    Config.ag.y_size = network_size
    Config.ag.z_size = 1
    Config.RotingType = routing_type

    ag = copy.deepcopy(AG_Functions.generate_ag())
    shmu = SystemHealthMonitoringUnit.SystemHealthMonitoringUnit()
    shmu.setup_noc_shm(ag, turns_health_2d_network, False)
    noc_rg = copy.deepcopy(
        Routing.generate_noc_route_graph(ag, shmu,
                                         turns_health_2d_network.keys(), False,
                                         False))
    copy_rg = copy.deepcopy(noc_rg)

    for node in critical_rg_nodes:
        if node not in noc_rg.nodes():
            raise ValueError(str(node) + " doesnt exist in noc_rg")

    for node in noc_rg.nodes():
        if node in critical_rg_nodes:
            noc_rg.node[node]["criticality"] = "H"
        else:
            noc_rg.node[node]["criticality"] = "L"

    edges_to_be_removed = []
    for edge in noc_rg.edges():
        if (int(edge[0][:-2]), int(edge[1][:-2])) in broken_links:
            edges_to_be_removed.append(edge)
        # removing edges that go from non-critical ports to ports used by critical ports
        if noc_rg.node[edge[0]]["criticality"] != noc_rg.node[
                edge[1]]["criticality"]:
            edges_to_be_removed.append(edge)
        else:
            if noc_rg.node[edge[0]]["criticality"] == "L":
                if edge[0][:-2] == edge[1][:-2]:
                    # remove the links that do not follow the turn model rules!
                    if str(edge[0][-2]) + "2" + str(
                            edge[1][-2]) not in turn_model:
                        if edge[0][-2] == "L" or edge[1][-2] == "L":
                            pass
                        elif edge[0][-2] == "E" and edge[1][-2] == "W":
                            pass
                        elif edge[0][-2] == "W" and edge[1][-2] == "E":
                            pass
                        elif edge[0][-2] == "S" and edge[1][-2] == "N":
                            pass
                        elif edge[0][-2] == "N" and edge[1][-2] == "S":
                            pass
                        else:
                            edges_to_be_removed.append(edge)

    for edge in edges_to_be_removed:
        noc_rg.remove_edge(edge[0], edge[1])
    if viz:
        noc_rg = copy.deepcopy(cleanup_routing_graph(ag, noc_rg))
        RoutingGraph_Reports.draw_rg(noc_rg)

    reachability_counter = 0
    connectivity_counter = 0
    print("deadlock freeness:", check_deadlock_freeness(noc_rg))
    for node_1 in ag.nodes():
        for node_2 in ag.nodes():
            if node_1 != node_2:
                if node_1 in critical_nodes or node_2 in critical_nodes:
                    pass
                else:

                    if is_destination_reachable_from_source(
                            noc_rg, node_1, node_2):
                        connectivity_counter += 1
                        if routing_type == "MinimalPath":
                            paths = return_minimal_paths(
                                noc_rg, node_1, node_2)
                            all_minimal_paths = return_minimal_paths(
                                copy_rg, node_1, node_2)
                            valid_path = True
                            for path in paths:
                                for node in path:
                                    successors = noc_rg.successors(node)
                                    if str(node_2) + str('L') + str(
                                            'O') in successors:
                                        #print(node_2, successors)
                                        break
                                    else:
                                        for successor in successors:
                                            valid_successor = False

                                            for path_1 in all_minimal_paths:
                                                if successor in path_1:
                                                    valid_successor = True
                                                    break
                                            if valid_successor:
                                                sucessor_paths = []
                                                max_hop_count = manhattan_distance(
                                                    int(successor[:-2]),
                                                    node_2)
                                                if has_path(
                                                        noc_rg, successor,
                                                        str(node_2) +
                                                        str('L') + str('O')):
                                                    all_paths_from_sucessor = list(
                                                        all_shortest_paths(
                                                            noc_rg, successor,
                                                            str(node_2) +
                                                            str('L') +
                                                            str('O')))
                                                    for Path in all_paths_from_sucessor:
                                                        if (
                                                                len(Path) - 2
                                                        ) / 2 <= max_hop_count:
                                                            sucessor_paths.append(
                                                                Path)
                                                if len(sucessor_paths) == 0:
                                                    valid_path = False
                                                    #print(path, node, node_2, successor, "FALSE")
                                                    break
                                                else:
                                                    pass
                                                    #print(path, node, node_2, successor, "TRUE")

                            if valid_path:
                                reachability_counter += 1
                            else:
                                if report:
                                    print(node_1, "can not reach  ", node_2)
                        else:
                            reachability_counter += 1
                    else:
                        if report:
                            print(node_1, "can not connect", node_2)
    print(
        "average connectivity for non-critical nodes:",
        float(connectivity_counter) / (len(ag.nodes()) - len(critical_nodes)))
    print(
        "average reachability for non-critical nodes:",
        float(reachability_counter) / (len(ag.nodes()) - len(critical_nodes)))
    return float(connectivity_counter) / (len(ag.nodes()) -
                                          len(critical_nodes)), noc_rg
コード例 #22
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.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
コード例 #23
0
def enumerate_all_2d_turn_models_based_on_df(combination):
    """
    Lists all 2D deadlock free turn models in "deadlock_free_turns" in "Generated_Files"
    folder!
    ---------------------
        We have 256 turns in 2D Mesh NoC!
    ---------------------
    :param combination: number of turns which should be checked for combination!
    :return: None
    """
    counter = 0
    all_turns_file = open(
        'Generated_Files/Turn_Model_Lists/all_2D_turn_models_' +
        str(combination) + '.txt', 'w')
    turns_health_2d_network = {
        "N2W": False,
        "N2E": False,
        "S2W": False,
        "S2E": False,
        "W2N": False,
        "W2S": False,
        "E2N": False,
        "E2S": False
    }
    Config.ag.topology = '2DMesh'
    Config.ag.x_size = 3
    Config.ag.y_size = 3
    Config.ag.z_size = 1
    Config.RotingType = 'NonMinimalPath'

    all_turns_file.write("#" + "\t\tDF/D\t" + '%25s' % "turns" + '%20s' % " " +
                         "\t\t" + '%10s' % "c-metric" + "\t\t" +
                         '%10s' % "DoA" + "\t\t" + '%10s' % "DoAx" + "\n")
    all_turns_file.write("--------------" * 8 + "\n")
    ag = copy.deepcopy(AG_Functions.generate_ag())
    number_of_pairs = len(ag.nodes()) * (len(ag.nodes()) - 1)
    turn_model_list = copy.deepcopy(PackageFile.FULL_TurnModel_2D)

    deadlock_free_counter = 0
    deadlock_counter = 0
    # print("Number of Turns:", combination)
    for turns in itertools.combinations(turn_model_list, combination):
        turns_health = copy.deepcopy(turns_health_2d_network)
        for turn in turns:
            turns_health[turn] = True
        counter += 1
        shmu = SystemHealthMonitoringUnit.SystemHealthMonitoringUnit()
        shmu.setup_noc_shm(ag, turns_health, False)
        noc_rg = copy.deepcopy(
            Routing.generate_noc_route_graph(ag, shmu, list(turns), False,
                                             False))
        if check_deadlock_freeness(noc_rg):
            connectivity_metric = reachability_metric(ag, noc_rg, False)
            doa = degree_of_adaptiveness(ag, noc_rg,
                                         False) / float(number_of_pairs)
            doa_ex = extended_degree_of_adaptiveness(
                ag, noc_rg, False) / float(number_of_pairs)
            deadlock_free_counter += 1
            all_turns_file.write(
                str(counter) + "\t\tDF\t" + '%51s' % str(list(turns)) +
                "\t\t" + '%10s' % str(connectivity_metric) + "\t\t" +
                '%10s' % str(round(doa, 2)) + "\t\t" +
                '%10s' % str(round(doa_ex, 2)) + "\n")
        else:
            deadlock_counter += 1
            all_turns_file.write(
                str(counter) + "\t\tDL\t" + '%51s' % str(list(turns)) +
                "\t\t-----" + "\t\t-----" + "\t\t-----" + "\n")
        del shmu
        del noc_rg
    all_turns_file.write("---------------------------" + "\n")
    all_turns_file.write("Number of turn models with deadlock: " +
                         str(deadlock_counter) + "\n")
    all_turns_file.write("Number of turn models without deadlock: " +
                         str(deadlock_free_counter) + "\n")
    all_turns_file.write("==========================================" + "\n")
    all_turns_file.close()
    return None
コード例 #24
0
    def test_routing_functions(self):
        initial_config_ag = deepcopy(Config.ag)
        initial_turn_model = Config.UsedTurnModel
        initial_routing_type = Config.RotingType
        Config.ag.type = "Generic"
        Config.ag.topology = "2DMesh"
        Config.ag.x_size = 3
        Config.ag.y_size = 3
        Config.ag.z_size = 1

        for turn_model in PackageFile.routing_alg_list_2d:
            Config.UsedTurnModel = deepcopy(turn_model)
            Config.TurnsHealth = deepcopy(Config.setup_turns_health())
            ag_4_test = deepcopy(generate_ag(logging=None))
            shmu_4_test = SystemHealthMonitoringUnit.SystemHealthMonitoringUnit(
            )
            shmu_4_test.setup_noc_shm(ag_4_test, Config.TurnsHealth, False)
            noc_rg = generate_noc_route_graph(ag_4_test, shmu_4_test,
                                              turn_model, False, False)
            self.assertEqual(check_deadlock_freeness(noc_rg), True)
            if turn_model in [
                    PackageFile.XY_TurnModel, PackageFile.YX_TurnModel
            ]:
                if turn_model == PackageFile.XY_TurnModel:
                    self.assertEqual(return_turn_model_name(turn_model), '0')
                else:
                    self.assertEqual(return_turn_model_name(turn_model), '13')
                self.assertEqual(
                    degree_of_adaptiveness(ag_4_test, noc_rg, False) / 72, 1)
                self.assertEqual(
                    extended_degree_of_adaptiveness(ag_4_test, noc_rg, False) /
                    72, 1)
            del ag_4_test
            del shmu_4_test

        Config.ag.type = "Generic"
        Config.ag.topology = "3DMesh"
        Config.ag.x_size = 3
        Config.ag.y_size = 3
        Config.ag.z_size = 3
        Config.RotingType = "NonMinimalPath"

        for turn_model in PackageFile.routing_alg_list_3d:
            Config.UsedTurnModel = deepcopy(turn_model)
            Config.TurnsHealth = deepcopy(Config.setup_turns_health())
            ag_4_test = deepcopy(generate_ag(logging=None))
            shmu_4_test = SystemHealthMonitoringUnit.SystemHealthMonitoringUnit(
            )
            shmu_4_test.setup_noc_shm(ag_4_test, Config.TurnsHealth, False)
            noc_rg = generate_noc_route_graph(ag_4_test, shmu_4_test,
                                              turn_model, False, False)
            self.assertEqual(check_deadlock_freeness(noc_rg), True)
            if turn_model == PackageFile.XYZ_TurnModel:
                self.assertEqual(return_turn_model_name(turn_model), "3d_XYZ")
                self.assertEqual(
                    degree_of_adaptiveness(ag_4_test, noc_rg, False) / 702, 1)
                self.assertEqual(
                    extended_degree_of_adaptiveness(ag_4_test, noc_rg, False) /
                    702, 1)
            if turn_model == PackageFile.NegativeFirst3D_TurnModel:
                self.assertEqual(return_turn_model_name(turn_model),
                                 "3d_NegFirst")
            del ag_4_test
            del shmu_4_test
            del noc_rg

        Config.ag = deepcopy(initial_config_ag)
        Config.UsedTurnModel = initial_turn_model
        Config.TurnsHealth = deepcopy(Config.setup_turns_health())
        Config.RotingType = initial_routing_type
コード例 #25
0
ファイル: odd_even_evaluation.py プロジェクト: thigg/SoCDep2
def evaluate_doa_for_all_odd_even_turn_model_list(network_size):
    all_odd_evens_file = open(
        'Generated_Files/Turn_Model_Lists/all_odd_evens_doa.txt', 'w')
    turns_health_2d_network = {
        "N2W": False,
        "N2E": False,
        "S2W": False,
        "S2E": False,
        "W2N": False,
        "W2S": False,
        "E2N": False,
        "E2S": False
    }
    Config.ag.topology = '2DMesh'
    Config.ag.x_size = network_size
    Config.ag.y_size = network_size
    Config.ag.z_size = 1
    ag = copy.deepcopy(AG_Functions.generate_ag())
    number_of_pairs = len(ag.nodes()) * (len(ag.nodes()) - 1)

    turn_model_list = []
    for length in range(0, len(turns_health_2d_network.keys()) + 1):
        for item in list(
                itertools.combinations(turns_health_2d_network.keys(),
                                       length)):
            if len(item) > 0:
                turn_model_list.append(list(item))

    classes_of_doa = {}
    classes_of_doax = {}
    tm_counter = 0

    all_odd_evens_file.write("    #  |                  " + '%51s' % " " +
                             " \t|")
    all_odd_evens_file.write(" DoA    |   DoAx | \tC-metric\n")
    all_odd_evens_file.write(
        "-------|--------------------------------------------" +
        "----------------------------|--------|--------|-------------" + "\n")
    for turn_model in all_odd_even_list:
        turn_model_odd = turn_model[0]
        turn_model_even = turn_model[1]

        turns_health = copy.deepcopy(turns_health_2d_network)
        shmu = SystemHealthMonitoringUnit.SystemHealthMonitoringUnit()
        shmu.setup_noc_shm(ag, turns_health, False)
        noc_rg = copy.deepcopy(
            Routing.generate_noc_route_graph(ag, shmu, [], False, False))

        for node in ag.nodes():
            node_x, node_y, node_z = AG_Functions.return_node_location(node)
            if node_x % 2 == 1:
                for turn in turn_model_odd:
                    shmu.restore_broken_turn(node, turn, False)
                    from_port = str(node) + str(turn[0]) + "I"
                    to_port = str(node) + str(turn[2]) + "O"
                    Routing.update_noc_route_graph(noc_rg, from_port, to_port,
                                                   'ADD')
            else:
                for turn in turn_model_even:
                    shmu.restore_broken_turn(node, turn, False)
                    from_port = str(node) + str(turn[0]) + "I"
                    to_port = str(node) + str(turn[2]) + "O"
                    Routing.update_noc_route_graph(noc_rg, from_port, to_port,
                                                   'ADD')
        doa = degree_of_adaptiveness(ag, noc_rg,
                                     False) / float(number_of_pairs)
        doa_ex = extended_degree_of_adaptiveness(
            ag, noc_rg, False) / float(number_of_pairs)

        if round(doa, 2) not in classes_of_doa.keys():
            classes_of_doa[round(doa, 2)] = [tm_counter]
        else:
            classes_of_doa[round(doa, 2)].append(tm_counter)

        if round(doa_ex, 2) not in classes_of_doax.keys():
            classes_of_doax[round(doa_ex, 2)] = [tm_counter]
        else:
            classes_of_doax[round(doa_ex, 2)].append(tm_counter)

        all_odd_evens_file.write('%5s' % str(tm_counter) +
                                 "  | even turn model:" +
                                 '%53s' % str(turn_model_even) + "\t|")
        all_odd_evens_file.write("        |        |\n")
        all_odd_evens_file.write("       | odd turn model: " +
                                 '%53s' % str(turn_model_odd) + " \t|")

        all_odd_evens_file.write(
            '%8s' % str(round(doa, 2)) + "|" + '%8s' % str(round(doa_ex, 2)) +
            "|\n")  # +'%8s' % str(round(connectivity_metric,2))+"\n")
        all_odd_evens_file.write(
            "-------|--------------------------------------------" +
            "----------------------------|--------|--------|-------------" +
            "\n")
        tm_counter += 1
        sys.stdout.write("\rchecked TM: %i " % tm_counter)
        sys.stdout.flush()
    # print
    # print "----------------------------------------"
    # print "classes of DOA:", sorted(classes_of_doa.keys())
    #for item in sorted(classes_of_doa.keys()):
    #    print item,  sorted(classes_of_doa[item])

    all_odd_evens_file.write("----------" * 3 + "\n")
    all_odd_evens_file.write("distribution of turn models" + "\n")
    for item in sorted(classes_of_doa.keys()):
        temp_list = []
        for tm in classes_of_doa[item]:
            turn_model = all_odd_even_list[tm]
            number_of_turns = len(turn_model[0]) + len(turn_model[1])
            temp_list.append(number_of_turns)
        # print item, temp_list.count(8), temp_list.count(9), temp_list.count(10),
        #       temp_list.count(11), temp_list.count(12)
        all_odd_evens_file.write(
            str(item) + " " + str(temp_list.count(8)) + " " +
            str(temp_list.count(9)) + " " + str(temp_list.count(10)) + " " +
            str(temp_list.count(11)) + " " + str(temp_list.count(12)) + "\n")

    # print "------------------------------"
    # print "classes of DOA_ex:", sorted(classes_of_doax.keys())
    # for item in sorted(classes_of_doax.keys()):
    #     print item,  sorted(classes_of_doax[item])

    all_odd_evens_file.write("----------" * 3 + "\n")
    all_odd_evens_file.write("distribution of turn models" + "\n")
    for item in sorted(classes_of_doax.keys()):
        temp_list = []
        for tm in classes_of_doax[item]:
            turn_model = all_odd_even_list[tm]
            number_of_turns = len(turn_model[0]) + len(turn_model[1])
            temp_list.append(number_of_turns)
        # print item, temp_list.count(8), temp_list.count(9), temp_list.count(10),
        #      temp_list.count(11), temp_list.count(12)
        all_odd_evens_file.write(
            str(item) + " " + str(temp_list.count(8)) + " " +
            str(temp_list.count(9)) + " " + str(temp_list.count(10)) + " " +
            str(temp_list.count(11)) + " " + str(temp_list.count(12)) + "\n")

    all_odd_evens_file.close()
    return classes_of_doa, classes_of_doax
コード例 #26
0
    def test_routing_functions(self):
        # backing up the original config...
        initial_config_ag = deepcopy(Config.ag)
        initial_turn_model = Config.UsedTurnModel
        initial_routing_type = Config.RotingType
        # -----------------------------------------------------
        Config.ag.type = "Generic"
        Config.ag.topology = "2DMesh"
        Config.RotingType = "MinimalPath"
        Config.ag.x_size = 3
        Config.ag.y_size = 3
        Config.ag.z_size = 1

        for turn_model in PackageFile.routing_alg_list_2d:
            tmName = return_turn_model_name(turn_model)
            Config.UsedTurnModel = deepcopy(turn_model)
            Config.TurnsHealth = deepcopy(Config.setup_turns_health())
            ag_4_test = deepcopy(generate_ag(logging=None))
            shmu_4_test = SystemHealthMonitoringUnit.SystemHealthMonitoringUnit(
            )
            shmu_4_test.setup_noc_shm(ag_4_test, Config.TurnsHealth, False)
            noc_rg = generate_noc_route_graph(ag_4_test, shmu_4_test,
                                              turn_model, False, False)

            self.assertEqual(check_deadlock_freeness(noc_rg),
                             True,
                             msg=f"TM {tmName} Deadlock freeness failed")
            if turn_model in [
                    PackageFile.XY_TurnModel, PackageFile.YX_TurnModel
            ]:
                if turn_model == PackageFile.XY_TurnModel:
                    self.assertEqual(tmName,
                                     '0',
                                     msg=f"TM name {tmName} is not 0")
                else:
                    self.assertEqual(tmName,
                                     '13',
                                     msg=f"TM name {tmName} is not 13")
                self.assertEqual(
                    degree_of_adaptiveness(ag_4_test, noc_rg, report=False) /
                    72.0,
                    1.0,
                    msg=f"TM: {tmName} DOA failed")
                self.assertEqual(extended_degree_of_adaptiveness(
                    ag_4_test, noc_rg, report=False) / 72.0,
                                 1.0,
                                 msg=f"TM: {tmName} DOAex failed")
            del ag_4_test
            del shmu_4_test

        # -----------------------------------------------------
        Config.ag.type = "Generic"
        Config.ag.topology = "3DMesh"
        Config.RotingType = "NonMinimalPath"
        Config.ag.x_size = 3
        Config.ag.y_size = 3
        Config.ag.z_size = 3

        for turn_model in PackageFile.routing_alg_list_3d:
            Config.UsedTurnModel = deepcopy(turn_model)
            Config.TurnsHealth = deepcopy(Config.setup_turns_health())
            ag_4_test = deepcopy(generate_ag(logging=None))
            shmu_4_test = SystemHealthMonitoringUnit.SystemHealthMonitoringUnit(
            )
            shmu_4_test.setup_noc_shm(ag_4_test, Config.TurnsHealth, False)
            noc_rg = generate_noc_route_graph(ag_4_test, shmu_4_test,
                                              turn_model, False, False)
            self.assertEqual(check_deadlock_freeness(noc_rg),
                             True,
                             msg=f"TM: {turn_model} deadlock freeness Failed!")
            if turn_model == PackageFile.XYZ_TurnModel:
                self.assertEqual(return_turn_model_name(turn_model),
                                 "3d_XYZ",
                                 msg="Turn Model is not 3d_XYZ")
                self.assertEqual(
                    degree_of_adaptiveness(ag_4_test, noc_rg, False) / 702,
                    1,
                    msg="DoA test failed")
                self.assertEqual(
                    extended_degree_of_adaptiveness(ag_4_test, noc_rg, False) /
                    702,
                    1,
                    msg="ExDoA test failed")
            if turn_model == PackageFile.NegativeFirst3D_TurnModel:
                self.assertEqual(return_turn_model_name(turn_model),
                                 "3d_NegFirst",
                                 msg="TM name is not 3d_NegFirst")
            del ag_4_test
            del shmu_4_test
            del noc_rg
        # -----------------------------------------------------
        # going back to original config
        Config.ag = deepcopy(initial_config_ag)
        Config.UsedTurnModel = initial_turn_model
        Config.TurnsHealth = deepcopy(Config.setup_turns_health())
        Config.RotingType = initial_routing_type