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
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()
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 # print counter, "\t \033[92mDF\033[0m \t", list(turns), "\t\t", connectivity_metric 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 # print counter, "\t \033[31mDL\033[0m \t", list(turns), "\t\t----" 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
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 # print counter, "\t \033[92mDF\033[0m \t", list(turns), "\t\t", connectivity_metric 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 # print counter, "\t \033[31mDL\033[0m \t", list(turns), "\t\t----" 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
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! update_rg_odd_even(ag, turn_model_odd, turn_model_even, shmu, noc_rg) 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() clean_rg_from_odd_even(ag, turn_model_odd, turn_model_even, shmu, noc_rg) 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
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
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
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
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
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
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
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: 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)) 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") 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
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)) update_rg_odd_even(ag, turn_model_odd, turn_model_even, shmu, noc_rg) 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() 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) 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.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) 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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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