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 opt_ag_vertical_link_local_search(ag, shmu, cost_file_name, logging): """ optimizes vertical link placement using greedy local search algorithm :param ag: architecture graph :param shmu: system health monitoring unit :param cost_file_name: name of the file for dumping the cost values during the process :param logging: logging file :return: None """ logging.info("STARTING LS FOR VL PLACEMENT...") if type(cost_file_name) is str: ag_cost_file = open('Generated_Files/Internal/'+cost_file_name+'.txt', 'a') else: raise ValueError("ag_cost_file name is not string: "+str(cost_file_name)) remove_all_vertical_links(shmu, ag) vertical_link_list = find_feasible_ag_vertical_link_placement(ag, shmu) routing_graph = copy.deepcopy(Routing.generate_noc_route_graph(ag, shmu, Config.UsedTurnModel, Config.DebugInfo, Config.DebugDetails)) cost = vl_cost_function(ag, routing_graph) print ("=====================================") print ("STARTING AG VERTICAL LINK PLACEMENT OPTIMIZATION") print ("NUMBER OF LINKS: "+str(Config.vl_opt.vl_num)) print ("NUMBER OF ITERATIONS: "+str(Config.vl_opt.ls_iteration)) print ("INITIAL REACHABILITY METRIC: "+str(cost)) starting_cost = cost best_cost = cost ag_temp = copy.deepcopy(ag) cleanup_ag(ag_temp, shmu) Arch_Graph_Reports.draw_ag(ag_temp, "AG_VLOpt_init") del ag_temp ag_cost_file.write(str(cost)+"\n") for i in range(0, Config.vl_opt.ls_iteration): new_vertical_link_list = copy.deepcopy(move_to_new_vertical_link_configuration(ag, shmu, vertical_link_list)) new_routing_graph = copy.deepcopy(Routing.generate_noc_route_graph(ag, shmu, Config.UsedTurnModel, False, False)) cost = vl_cost_function(ag, new_routing_graph) ag_cost_file.write(str(cost)+"\n") if cost >= best_cost: vertical_link_list = copy.deepcopy(new_vertical_link_list) if cost > best_cost: best_cost = cost print ("\033[32m* NOTE::\033[0mFOUND BETTER SOLUTION WITH COST:" + str(cost) + "\t ITERATION: "+str(i)) else: # print ("\033[33m* NOTE::\033[0mMOVED TO SOLUTION WITH COST:" + str(Cost) + "\t ITERATION: "+str(i)) pass else: return_to_solution(ag, shmu, vertical_link_list) vertical_link_list = copy.deepcopy(vertical_link_list) ag_cost_file.close() print ("-------------------------------------") print ("STARTING COST:"+str(starting_cost)+"\tFINAL COST:"+str(best_cost)) print ("IMPROVEMENT:"+str("{0:.2f}".format(100*(best_cost-starting_cost)/starting_cost))+" %") logging.info("LS FOR VL PLACEMENT FINISHED...") 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)) 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 return None
def opt_ag_vertical_link_local_search(ag, shmu, logging): remove_all_vertical_links(shmu, ag) vertical_link_list = find_feasible_ag_vertical_link_placement(ag, shmu) routing_graph = copy.deepcopy( Routing.GenerateNoCRouteGraph(ag, shmu, Config.UsedTurnModel, Config.DebugInfo, Config.DebugDetails)) cost = Calculate_Reachability.ReachabilityMetric(ag, routing_graph, False) print("=====================================") print("STARTING AG VERTICAL LINK PLACEMENT OPTIMIZATION") print("NUMBER OF LINKS: " + str(Config.VerticalLinksNum)) print("NUMBER OF ITERATIONS: " + str(Config.AG_Opt_Iterations_LS)) print("INITIAL REACHABILITY METRIC: " + str(cost)) starting_cost = cost best_cost = cost ag_temp = copy.deepcopy(ag) cleanup_ag(ag_temp, shmu) draw_ag(ag_temp, "AG_VLOpt_init") del ag_temp for i in range(0, Config.AG_Opt_Iterations_LS): new_vertical_link_list = copy.deepcopy( move_to_new_vertical_link_configuration(ag, shmu, vertical_link_list)) new_routing_graph = copy.deepcopy( Routing.GenerateNoCRouteGraph(ag, shmu, Config.UsedTurnModel, False, False)) cost = Calculate_Reachability.ReachabilityMetric( ag, new_routing_graph, False) if cost >= best_cost: vertical_link_list = copy.deepcopy(new_vertical_link_list) if cost > best_cost: best_cost = cost print( "\033[32m* NOTE::\033[0mFOUND BETTER SOLUTION WITH COST:" + str(cost) + "\t ITERATION: " + str(i)) else: # print ("\033[33m* NOTE::\033[0mMOVED TO SOLUTION WITH COST:" + str(Cost) + "\t ITERATION: "+str(i)) pass else: return_to_solution(ag, shmu, vertical_link_list) vertical_link_list = copy.deepcopy(vertical_link_list) print("-------------------------------------") print("STARTING COST:" + str(starting_cost) + "\tFINAL COST:" + str(best_cost)) print("IMPROVEMENT:" + str("{0:.2f}".format(100 * (best_cost - starting_cost) / starting_cost)) + " %") return shmu
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 remove_task_from_node(tg, ag, noc_rg, critical_rg, noncritical_rg, task, node, logging): """ Removes a task from TG from a certain Node in AG :param tg: Task Graph :param ag: Architecture Graph :param noc_rg: NoC routing graph :param critical_rg: NoC routing Graph for Critical Section :param noncritical_rg: NoC routing graph for non-Critical Section :param task: Task ID to be removed from Node :param node: Node with Task Mapped on it :param logging: logging File :return: True if it removes task with sucess """ if task not in ag.node[node]['PE'].mapped_tasks: raise ValueError( "Trying removing Task from Node which is not the host") logging.info("\tREMOVING TASK:" + str(task) + "FROM NODE:" + str(node)) for edge in tg.edges(): if task in edge: source_node = tg.node[edge[0]]['task'].node destination_node = tg.node[edge[1]]['task'].node if source_node is not None and destination_node is not None: if source_node != destination_node: # Find the links to be used list_of_links, number_of_paths = Routing.find_route_in_route_graph( noc_rg, critical_rg, noncritical_rg, source_node, destination_node, False) if list_of_links is not None: # logging.info("\t\t\tREMOVING PATH FROM NODE:"+str(source_node) + # "TO NODE"+str(destination_node)) # logging.info("\t\t\tLIST OF LINKS:"+str(list_of_links)) for path in list_of_links: for link in path: if edge in ag.edge[link[0]][ link[1]]['MappedTasks'].keys(): del ag.edge[link[0]][ link[1]]['MappedTasks'][edge] del ag.node[ link[0]]['Router'].mapped_tasks[edge] # logging.info("\t\t\t\tRemoving Packet "+str(edge)+" To Router:"+str(link[0])) for BatchAndLink in tg.edge[edge[0]][ edge[1]]['Link']: if BatchAndLink[1] == link: tg.edge[edge[0]][edge[1]][ 'Link'].remove(BatchAndLink) del ag.node[path[len(path) - 1] [1]]['Router'].mapped_tasks[edge] # logging.info("\t\t\t\tRemoving Packet "+str(edge)+" To Router:"+str(path[len(path)-1][1])) else: logging.warning("\tNOTHING TO BE REMOVED...") tg.node[task]['task'].node = None ag.node[node]['PE'].mapped_tasks.remove(task) ag.node[node]['PE'].utilization -= tg.node[task]['task'].wcet return True
def apply_fault_event(ag, shmu, noc_rg, fault_location, fault_type): SHMU_Reports.report_the_event(fault_location, fault_type) if type(fault_location) is tuple: # its a Link fault if fault_type == 'T': # Transient Fault if shmu.SHM.edges[fault_location]['LinkHealth']: shmu.break_link(fault_location, True) shmu.restore_broken_link(fault_location, True) else: print("\033[33mSHM:: NOTE:\033[0mLINK ALREADY BROKEN") elif fault_type == 'P': # Permanent Fault port = ag.edges[fault_location]['Port'] from_port = str(fault_location[0]) + str(port[0]) + str('O') to_port = str(fault_location[1]) + str(port[1]) + str('I') shmu.break_link(fault_location, True) Routing.update_noc_route_graph(noc_rg, from_port, to_port, 'REMOVE') elif type(fault_location) is dict: # its a Turn fault current_node = fault_location.keys()[0] current_turn = fault_location[current_node] if fault_type == 'T': # Transient Fault if shmu.SHM.node[current_node]['TurnsHealth'][ current_turn]: # check if the turn is actually working shmu.break_turn(current_node, current_turn, True) shmu.restore_broken_turn(current_node, current_turn, True) else: print("\033[33mSHM:: NOTE:\033[0mTURN ALREADY BROKEN") elif fault_type == 'P': # Permanent Fault from_port = str(current_node) + str(current_turn[0]) + str('I') to_port = str(current_node) + str(current_turn[2]) + str('O') Routing.update_noc_route_graph(noc_rg, from_port, to_port, 'REMOVE') shmu.break_turn(current_node, current_turn, True) else: # its a Node fault if fault_type == 'T': # Transient Fault if shmu.SHM.node[fault_location]['NodeHealth']: shmu.break_node(fault_location, True) shmu.restore_broken_node(fault_location, True) else: print("\033[33mSHM:: NOTE:\033[0m NODE ALREADY BROKEN") elif fault_type == 'P': # Permanent Fault shmu.break_node(fault_location, True) return None
def clean_rg_from_odd_even(ag, turn_model_odd, turn_model_even, shmu, noc_rg): """ gets a turn model for odd and even columns, along with an noc_rg and a SHMU and removes added connections in the SHMU and noc_rg based on the turn models """ 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') return
def apply_fault_event(AG, SHMU, NoCRG, FaultLocation, FaultType): SHMU_Reports.ReportTheEvent(FaultLocation, FaultType) if type(FaultLocation) is tuple: # its a Link fault if FaultType == 'T': # Transient Fault if SHMU.SHM.edge[FaultLocation[0]][FaultLocation[1]]['LinkHealth']: SHMU.break_link(FaultLocation, True) SHMU.restore_broken_link(FaultLocation, True) else: print("\033[33mSHM:: NOTE:\033[0mLINK ALREADY BROKEN") elif FaultType == 'P': # Permanent Fault Port = AG.edge[FaultLocation[0]][FaultLocation[1]]['Port'] FromPort = str(FaultLocation[0]) + str(Port[0]) + str('O') ToPort = str(FaultLocation[1]) + str(Port[1]) + str('I') Routing.UpdateNoCRouteGraph(NoCRG, FromPort, ToPort, 'REMOVE') SHMU.break_link(FaultLocation, True) elif type(FaultLocation) is dict: # its a Turn fault CurrentNode = FaultLocation.keys()[0] CurrentTurn = FaultLocation[CurrentNode] if FaultType == 'T': # Transient Fault if SHMU.SHM.node[CurrentNode]['TurnsHealth'][ CurrentTurn]: # check if the turn is actually working SHMU.break_turn(CurrentNode, CurrentTurn, True) SHMU.restore_broken_turn(CurrentNode, CurrentTurn, True) else: print("\033[33mSHM:: NOTE:\033[0mTURN ALREADY BROKEN") elif FaultType == 'P': # Permanent Fault FromPort = str(CurrentNode) + str(CurrentTurn[0]) + str('I') ToPort = str(CurrentNode) + str(CurrentTurn[2]) + str('O') Routing.UpdateNoCRouteGraph(NoCRG, FromPort, ToPort, 'REMOVE') SHMU.break_turn(CurrentNode, CurrentTurn, True) else: # its a Node fault if FaultType == 'T': # Transient Fault if SHMU.SHM.node[FaultLocation]['NodeHealth']: SHMU.break_node(FaultLocation, True) SHMU.restore_broken_node(FaultLocation, True) else: print("\033[33mSHM:: NOTE:\033[0m NODE ALREADY BROKEN") elif FaultType == 'P': # Permanent Fault SHMU.break_node(FaultLocation, True) 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 apply_fault_event(ag, shmu, noc_rg, fault_location, fault_type): SHMU_Reports.report_the_event(fault_location, fault_type) if type(fault_location) is tuple: # its a Link fault if fault_type == 'T': # Transient Fault if shmu.SHM.edge[fault_location[0]][fault_location[1]]['LinkHealth']: shmu.break_link(fault_location, True) shmu.restore_broken_link(fault_location, True) else: print ("\033[33mSHM:: NOTE:\033[0mLINK ALREADY BROKEN") elif fault_type == 'P': # Permanent Fault port = ag.edge[fault_location[0]][fault_location[1]]['Port'] from_port = str(fault_location[0])+str(port[0])+str('O') to_port = str(fault_location[1])+str(port[1])+str('I') shmu.break_link(fault_location, True) Routing.update_noc_route_graph(noc_rg, from_port, to_port, 'REMOVE') elif type(fault_location) is dict: # its a Turn fault current_node = fault_location.keys()[0] current_turn = fault_location[current_node] if fault_type == 'T': # Transient Fault if shmu.SHM.node[current_node]['TurnsHealth'][current_turn]: # check if the turn is actually working shmu.break_turn(current_node, current_turn, True) shmu.restore_broken_turn(current_node, current_turn, True) else: print ("\033[33mSHM:: NOTE:\033[0mTURN ALREADY BROKEN") elif fault_type == 'P': # Permanent Fault from_port = str(current_node)+str(current_turn[0])+str('I') to_port = str(current_node)+str(current_turn[2])+str('O') Routing.update_noc_route_graph(noc_rg, from_port, to_port, 'REMOVE') shmu.break_turn(current_node, current_turn, True) else: # its a Node fault if fault_type == 'T': # Transient Fault if shmu.SHM.node[fault_location]['NodeHealth']: shmu.break_node(fault_location, True) shmu.restore_broken_node(fault_location, True) else: print ("\033[33mSHM:: NOTE:\033[0m NODE ALREADY BROKEN") elif fault_type == 'P': # Permanent Fault shmu.break_node(fault_location, True) return None
def clean_rg_from_odd_even(ag, turn_model_odd, turn_model_even, shmu, noc_rg): """ gets a turn model for odd and even columns, along with an noc_rg and a SHMU and removes added connections in the SHMU and noc_rg based on the turn models """ 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') return
def remove_task_from_node(tg, ag, noc_rg, critical_rg, noncritical_rg, task, node, logging): """ Removes a task from TG from a certain Node in AG :param tg: Task Graph :param ag: Architecture Graph :param noc_rg: NoC routing graph :param critical_rg: NoC routing Graph for Critical Section :param noncritical_rg: NoC routing graph for non-Critical Section :param task: Task ID to be removed from Node :param node: Node with Task Mapped on it :param logging: logging File :return: True if it removes task with sucess """ if task not in ag.node[node]['PE'].mapped_tasks: raise ValueError("Trying removing Task from Node which is not the host") logging.info("\tREMOVING TASK:"+str(task)+"FROM NODE:"+str(node)) for edge in tg.edges(): if task in edge: source_node = tg.node[edge[0]]['task'].node destination_node = tg.node[edge[1]]['task'].node if source_node is not None and destination_node is not None: if source_node != destination_node: # Find the links to be used list_of_links, number_of_paths = Routing.find_route_in_route_graph(noc_rg, critical_rg, noncritical_rg, source_node, destination_node, False) if list_of_links is not None: # logging.info("\t\t\tREMOVING PATH FROM NODE:"+str(source_node) + # "TO NODE"+str(destination_node)) # logging.info("\t\t\tLIST OF LINKS:"+str(list_of_links)) for path in list_of_links: for link in path: if edge in ag.edge[link[0]][link[1]]['MappedTasks'].keys(): del ag.edge[link[0]][link[1]]['MappedTasks'][edge] del ag.node[link[0]]['Router'].mapped_tasks[edge] # logging.info("\t\t\t\tRemoving Packet "+str(edge)+" To Router:"+str(link[0])) for BatchAndLink in tg.edge[edge[0]][edge[1]]['Link']: if BatchAndLink[1] == link: tg.edge[edge[0]][edge[1]]['Link'].remove(BatchAndLink) del ag.node[path[len(path)-1][1]]['Router'].mapped_tasks[edge] # logging.info("\t\t\t\tRemoving Packet "+str(edge)+" To Router:"+str(path[len(path)-1][1])) else: logging.warning("\tNOTHING TO BE REMOVED...") tg.node[task]['task'].node = None ag.node[node]['PE'].mapped_tasks.remove(task) ag.node[node]['PE'].utilization -= tg.node[task]['task'].wcet return True
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 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 opt_ag_vertical_link_iterative_local_search(ag, shmu, logging): best_vertical_link_list = [] starting_cost = None for j in range(0, Config.AG_Opt_Iterations_ILS): remove_all_vertical_links(shmu, ag) vertical_link_list_init = copy.deepcopy( find_feasible_ag_vertical_link_placement(ag, shmu)) routing_graph = copy.deepcopy( Routing.GenerateNoCRouteGraph(ag, shmu, Config.UsedTurnModel, False, False)) cost = Calculate_Reachability.ReachabilityMetric( ag, routing_graph, False) current_best_cost = cost if j == 0: print("=====================================") print("STARTING AG VERTICAL LINK PLACEMENT OPTIMIZATION") print("NUMBER OF LINKS: " + str(Config.VerticalLinksNum)) print("NUMBER OF ITERATIONS: " + str(Config.AG_Opt_Iterations_ILS * Config.AG_Opt_Iterations_LS)) print("INITIAL REACHABILITY METRIC: " + str(cost)) starting_cost = cost best_cost = cost best_vertical_link_list = vertical_link_list_init[:] ag_temp = copy.deepcopy(ag) cleanup_ag(ag_temp, shmu) draw_ag(ag_temp, "AG_VLOpt_init") del ag_temp else: print("\033[33m* NOTE::\033[0m STARITNG NEW ROUND: " + str(j + 1) + "\t STARTING COST:" + str(cost)) if cost > best_cost: best_vertical_link_list = vertical_link_list_init[:] best_cost = cost print( "\033[32m* NOTE::\033[0mFOUND BETTER SOLUTION WITH COST:" + str(cost) + "\t ITERATION: " + str(j * Config.AG_Opt_Iterations_LS)) vertical_link_list = vertical_link_list_init[:] for i in range(0, Config.AG_Opt_Iterations_LS): new_vertical_link_list = copy.deepcopy( move_to_new_vertical_link_configuration( ag, shmu, vertical_link_list)) new_routing_graph = Routing.GenerateNoCRouteGraph( ag, shmu, Config.UsedTurnModel, False, False) cost = Calculate_Reachability.ReachabilityMetric( ag, new_routing_graph, False) if cost >= current_best_cost: vertical_link_list = new_vertical_link_list[:] if cost > current_best_cost: current_best_cost = cost print("\t \tMOVED TO SOLUTION WITH COST:" + str(cost) + "\t ITERATION: " + str(j * Config.AG_Opt_Iterations_LS + i)) else: return_to_solution(ag, shmu, vertical_link_list) if cost > best_cost: best_vertical_link_list = vertical_link_list[:] best_cost = cost print( "\033[32m* NOTE::\033[0mFOUND BETTER SOLUTION WITH COST:" + str(cost) + "\t ITERATION: " + str(j * Config.AG_Opt_Iterations_LS + i)) return_to_solution(ag, shmu, best_vertical_link_list) print("-------------------------------------") print("STARTING COST:" + str(starting_cost) + "\tFINAL COST:" + str(best_cost)) print("IMPROVEMENT:" + str("{0:.2f}".format(100 * (best_cost - starting_cost) / starting_cost)) + " %") return shmu
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 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 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 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 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 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 opt_ag_vertical_link_sa(ag, shmu, cost_file_name, logging): """ Optimises the vertical link placement using simulated annealing! :param ag: architecture graph :param shmu: system health monitoring unit :param cost_file_name: name of the file for dumping the cost values during the process :param logging: logging file :return: None """ logging.info("STARTING SA FOR VLP OPT") print "===========================================" print "VL PLACEMENT OPTIMIZATION USING SIMULATED ANNEALING..." print "STARTING TEMPERATURE:", Config.vl_opt.sa_initial_temp print "ANNEALING SCHEDULE: ", Config.vl_opt.sa_annealing_schedule print "TERMINATION CRITERIA: ", Config.vl_opt.termination_criteria if Config.vl_opt.termination_criteria == 'IterationNum': print "NUMBER OF ITERATIONS: ", Config.vl_opt.sa_iteration print "================" if type(cost_file_name) is str: ag_cost_file = open('Generated_Files/Internal/'+cost_file_name+'.txt', 'a') else: raise ValueError("ag_cost_file name is not string: "+str(cost_file_name)) temperature_file = open('Generated_Files/Internal/vlp_sa_temp.txt', 'w') remove_all_vertical_links(shmu, ag) vertical_link_list = find_feasible_ag_vertical_link_placement(ag, shmu) routing_graph = copy.deepcopy(Routing.generate_noc_route_graph(ag, shmu, Config.UsedTurnModel, Config.DebugInfo, Config.DebugDetails)) cost = vl_cost_function(ag, routing_graph) print ("STARTING AG VL PLACEMENT OPTIMIZATION") print ("NUMBER OF AVAILABLE V-LINKS: "+str(Config.vl_opt.vl_num)) print ("INITIAL REACHABILITY METRIC: "+str(cost)) starting_cost = cost current_cost = cost best_cost = cost best_vertical_link_list = vertical_link_list[:] ag_temp = copy.deepcopy(ag) cleanup_ag(ag_temp, shmu) Arch_Graph_Reports.draw_ag(ag_temp, "AG_VLOpt_init") del ag_temp ag_cost_file.write(str(cost)+"\n") temperature = Config.vl_opt.sa_initial_temp initial_temp = temperature iteration_num = Config.vl_opt.sa_iteration temperature_file.write(str(temperature)+"\n") i = 0 while True: i += 1 new_vertical_link_list = copy.deepcopy(move_to_new_vertical_link_configuration(ag, shmu, vertical_link_list)) new_routing_graph = copy.deepcopy(Routing.generate_noc_route_graph(ag, shmu, Config.UsedTurnModel, False, False)) new_cost = vl_cost_function(ag, new_routing_graph) ag_cost_file.write(str(new_cost)+"\n") prob = metropolis(current_cost, new_cost, temperature) if prob > random.random(): # accept the new solution vertical_link_list = new_vertical_link_list[:] current_cost = new_cost if new_cost > best_cost: best_cost = new_cost best_vertical_link_list = new_vertical_link_list[:] print ("\033[32m* NOTE::\033[0mFOUND BETTER SOLUTION WITH COST:" + str(cost) + "\t ITERATION: "+str(i)) else: # move back to initial solution return_to_solution(ag, shmu, vertical_link_list) temperature = next_temp(initial_temp, i, iteration_num, temperature) temperature_file.write(str(temperature)+"\n") if Config.vl_opt.termination_criteria == 'IterationNum': if i == Config.vl_opt.sa_iteration: print ("REACHED MAXIMUM ITERATION NUMBER...") break elif Config.vl_opt.termination_criteria == 'StopTemp': if temperature <= Config.vl_opt.sa_stop_temp: print ("REACHED STOP TEMPERATURE...") break ag_cost_file.close() temperature_file.close() return_to_solution(ag, shmu, best_vertical_link_list) print ("-------------------------------------") print ("STARTING COST:"+str(starting_cost)+"\tFINAL COST:"+str(best_cost)) print ("IMPROVEMENT:"+str("{0:.2f}".format(100*(best_cost-starting_cost)/starting_cost))+" %") logging.info("SA FOR VL PLACEMENT FINISHED...") return None
def add_cluster_to_node(tg, ctg, ag, shm, noc_rg, critical_rg, noncritical_rg, cluster, node, logging): """ Adds a Cluster from CTG and all its Task to a Node from Architecture Graph :param tg: Task Graph :param ctg: Clustered Task Graph :param ag: Architecture Graph :param shm: System Health Map :param noc_rg: NoC Routing Graph :param critical_rg: NoC Routing Graph for Critical region :param noncritical_rg: NoC routing Graph for Non-Critical Region :param cluster: ID Cluster to be mapped :param node: ID of the Node for mapping cluster on :param logging: logging file :return: True if maps the cluster successfully otherwise False """ if not shm.nodes[node]['NodeHealth']: logging.info("CAN NOT MAP ON BROKEN NODE: " + str(node)) return False elif ag.node[node]['PE'].dark: logging.info("CAN NOT MAP ON DARK NODE: " + str(node)) return False # Adding The cluster to Node... logging.info("\tADDING CLUSTER: " + str(cluster) + "TO NODE:" + str(node)) ctg.node[cluster]['Node'] = node for Task in ctg.node[cluster]['TaskList']: tg.node[Task]['task'].node = node ag.node[node]['PE'].mapped_tasks.append(Task) ag.node[node]['PE'].utilization += ctg.node[cluster]['Utilization'] for ctg_edge in ctg.edges(): if cluster in ctg_edge: # find all the edges that are connected to cluster # logging.info("\t\tEDGE:"+str(ctg_edge)+"CONTAINS CLUSTER:"+str(cluster)) source_node = ctg.node[ctg_edge[0]]['Node'] destination_node = ctg.node[ctg_edge[1]]['Node'] if source_node is not None and destination_node is not None: # check if both ends of this edge is mapped if source_node != destination_node: # Find the links to be used list_of_links, number_of_paths = Routing.find_route_in_route_graph( noc_rg, critical_rg, noncritical_rg, source_node, destination_node, False) list_of_edges = [] # print("number_of_paths:", number_of_paths) # print(number_of_paths, list_of_links) if list_of_links is not None: # find all the edges in TaskGraph that contribute to this edge in CTG for tg_edge in tg.edges(): if tg.node[tg_edge[0]]['task'].cluster == ctg_edge[0] and \ tg.node[tg_edge[1]]['task'].cluster == ctg_edge[1]: list_of_edges.append(tg_edge) # print("LIST OF LINKS:", list_of_links) # add edges from list of edges to all links from list of links # todo: I have to think more... this is not enough to add all the links there... if list_of_links is not None and len(list_of_edges) > 0: # logging.info("\t\t\tADDING PATH FROM NODE:"+str(source_node)+"TO NODE"+str(destination_node)) # logging.info("\t\t\tLIST OF LINKS:"+str(list_of_links)) # logging.info("\t\t\tLIST OF EDGES:"+str(list_of_edges)) counter = 0 for path in list_of_links: for link in path: for chosen_edge in list_of_edges: if tg.edges[chosen_edge][ "Criticality"] == 'H': probability = 1 # we reserve the whole bandwidth for critical packets... else: probability = 1.0 / number_of_paths if chosen_edge in ag.edges[link][ 'MappedTasks'].keys(): ag.edges[link]['MappedTasks'][ chosen_edge].append( (counter, probability)) ag.node[ link[0]]['Router'].mapped_tasks[ chosen_edge].append( (counter, probability)) # logging.info("\t\t\t\tAdding Packet "+str(chosen_edge)+" To Router:" + # str(link[0])) else: ag.edges[link]['MappedTasks'][ chosen_edge] = [(counter, probability)] ag.node[ link[0]]['Router'].mapped_tasks[ chosen_edge] = [(counter, probability)] # logging.info("\t\t\t\tAdding Packet "+str(chosen_edge)+" To Router:" + # str(link[0])) edge_list_of_links = list( batch[1] for batch in tg.edges[chosen_edge]['Link']) if link not in edge_list_of_links: tg.edges[chosen_edge]['Link'].append( (counter, link, probability)) for chosen_edge in list_of_edges: if tg.edges[chosen_edge]["Criticality"] == 'H': probability = 1 # we reserve the whole bandwidth for critical packets... else: probability = 1.0 / number_of_paths ag.node[path[len(path)-1][1]]['Router'].mapped_tasks[chosen_edge] = \ [(counter, probability)] # logging.info("\t\t\t\tAdding Packet "+str(chosen_edge)+" To Router:" + # str(path[len(path)-1][1])) counter += 1 else: logging.warning( "\tNO PATH FOUND FROM SOURCE TO DESTINATION...") logging.info( "REMOVING ALL THE MAPPED CONNECTIONS FOR CLUSTER " + str(cluster)) remove_cluster_from_node(tg, ctg, ag, noc_rg, critical_rg, noncritical_rg, cluster, node, logging) return False return True
def remove_cluster_from_node(tg, ctg, ag, noc_rg, critical_rg, noncritical_rg, cluster, node, logging): """ removes a cluster and all its tasks from a certain Node from Architecture Graph(AG) :param tg: Task Graph :param ctg: Clustered task Graph :param ag: Architecture Graph :param noc_rg: NoC Routing Graph :param critical_rg: NoC routing Graph of critical Region :param noncritical_rg: NoC Routing Graph of non-Critical Region :param cluster: ID of The cluster to be mapped :param node: ID of the node for mapping the cluster on :param logging: logging file :return: True if can successfully remove cluster from Node """ logging.info("\tREMOVING CLUSTER:" + str(cluster) + "FROM NODE:" + str(node)) for ctg_edge in ctg.edges(): if cluster in ctg_edge: # find all the edges that are connected to Cluster source_node = ctg.node[ctg_edge[0]]['Node'] destination_node = ctg.node[ctg_edge[1]]['Node'] if source_node is not None and destination_node is not None: # check if both ends of this edge is mapped if source_node != destination_node: # Find the links to be used list_of_links, number_of_paths = Routing.find_route_in_route_graph( noc_rg, critical_rg, noncritical_rg, source_node, destination_node, False) list_of_edges = [] if list_of_links is not None: # find all the edges in TaskGraph that contribute to this edge in CTG for tg_edge in tg.edges(): if tg.node[tg_edge[0]]['task'].cluster == ctg_edge[0] and \ tg.node[tg_edge[1]]['task'].cluster == ctg_edge[1]: list_of_edges.append(tg_edge) # remove edges from list of edges to all links from list of links if list_of_links is not None and len(list_of_edges) > 0: # logging.info("\t\t\tREMOVING PATH FROM NODE:"+str(source_node) + # "TO NODE"+str(destination_node)) # logging.info("\t\t\tLIST OF LINKS:"+str(list_of_links)) # logging.info("\t\t\tLIST OF EDGES:"+str(list_of_edges)) for path in list_of_links: for Link in path: for chosen_edge in list_of_edges: if chosen_edge in ag.edges[Link][ 'MappedTasks'].keys(): del ag.edges[Link]['MappedTasks'][ chosen_edge] if chosen_edge in ag.node[Link[0]][ 'Router'].mapped_tasks.keys(): del ag.node[Link[0]][ 'Router'].mapped_tasks[ chosen_edge] # logging.info("\t\t\t\tRemoving Packet "+str(chosen_edge) + # " To Router:"+str(Link[0])) for LinkAndBatch in tg.edges[ chosen_edge]['Link']: if LinkAndBatch[1] == Link: tg.edges[chosen_edge][ 'Link'].remove( LinkAndBatch) for chosen_edge in list_of_edges: if chosen_edge in ag.node[ path[len(path) - 1][1]]['Router'].mapped_tasks: del ag.node[path[len(path) - 1][1]][ 'Router'].mapped_tasks[chosen_edge] # logging.info("\t\t\t\tRemoving Packet "+str(chosen_edge)+" To Router:" + # str(path[len(path)-1][1])) else: logging.warning("\tNOTHING TO BE REMOVED...") ctg.node[cluster]['Node'] = None for task in ctg.node[cluster]['TaskList']: tg.node[task]['task'].node = None ag.node[node]['PE'].mapped_tasks.remove(task) ag.node[node]['PE'].utilization -= ctg.node[cluster]['Utilization'] return True
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 opt_ag_vertical_link_iterative_local_search(ag, shmu, cost_file_name, logging): """ Runs iterative local search optimization on vertical link placement :param ag: architecture graph :param shmu: system health map :param cost_file_name: file name to dump cost values during the process :param logging: logging file :return: None """ logging.info("STARTING ILS FOR VL PLACEMENT...") if type(cost_file_name) is str: ag_cost_file = open('Generated_Files/Internal/'+cost_file_name+'.txt', 'a') else: raise ValueError("ag_cost_file name is not string: "+str(cost_file_name)) best_vertical_link_list = [] starting_cost = None for j in range(0, Config.vl_opt.ils_iteration): remove_all_vertical_links(shmu, ag) vertical_link_list_init = copy.deepcopy(find_feasible_ag_vertical_link_placement(ag, shmu)) routing_graph = copy.deepcopy(Routing.generate_noc_route_graph(ag, shmu, Config.UsedTurnModel, False, False)) cost = vl_cost_function(ag, routing_graph) ag_cost_file.write(str(cost)+"\n") current_best_cost = cost if j == 0: print ("=====================================") print ("STARTING AG VERTICAL LINK PLACEMENT OPTIMIZATION") print ("NUMBER OF LINKS: "+str(Config.vl_opt.vl_num)) print ("NUMBER OF ITERATIONS: "+str(Config.vl_opt.ils_iteration*Config.vl_opt.ls_iteration)) print ("INITIAL REACHABILITY METRIC: "+str(cost)) starting_cost = cost best_cost = cost best_vertical_link_list = vertical_link_list_init[:] ag_temp = copy.deepcopy(ag) cleanup_ag(ag_temp, shmu) Arch_Graph_Reports.draw_ag(ag_temp, "AG_VLOpt_init") del ag_temp else: print("\033[33m* NOTE::\033[0m STARITNG NEW ROUND: "+str(j+1)+"\t STARTING COST:"+str(cost)) if cost > best_cost: best_vertical_link_list = vertical_link_list_init[:] best_cost = cost print("\033[32m* NOTE::\033[0mFOUND BETTER SOLUTION WITH COST:" + str(cost) + "\t ITERATION: "+str(j*Config.vl_opt.ls_iteration)) vertical_link_list = vertical_link_list_init[:] for i in range(0, Config.vl_opt.ls_iteration): new_vertical_link_list = copy.deepcopy(move_to_new_vertical_link_configuration(ag, shmu, vertical_link_list)) new_routing_graph = Routing.generate_noc_route_graph(ag, shmu, Config.UsedTurnModel, False, False) cost = vl_cost_function(ag, new_routing_graph) ag_cost_file.write(str(cost)+"\n") if cost >= current_best_cost: vertical_link_list = new_vertical_link_list[:] if cost > current_best_cost: current_best_cost = cost print ("\t \tMOVED TO SOLUTION WITH COST:" + str(cost) + "\t ITERATION: "+str(j*Config.vl_opt.ls_iteration+i)) else: return_to_solution(ag, shmu, vertical_link_list) if cost > best_cost: best_vertical_link_list = vertical_link_list[:] best_cost = cost print ("\033[32m* NOTE::\033[0mFOUND BETTER SOLUTION WITH COST:" + str(cost) + "\t ITERATION: "+str(j*Config.vl_opt.ls_iteration+i)) return_to_solution(ag, shmu, best_vertical_link_list) ag_cost_file.close() print("-------------------------------------") print("STARTING COST:"+str(starting_cost)+"\tFINAL COST:"+str(best_cost)) print("IMPROVEMENT:"+str("{0:.2f}".format(100*(best_cost-starting_cost)/starting_cost))+" %") logging.info("ILS FOR VL PLACEMENT FINISHED...") 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: 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 add_cluster_to_node(tg, ctg, ag, shm, noc_rg, critical_rg, noncritical_rg, cluster, node, logging): """ Adds a Cluster from CTG and all its Task to a Node from Architecture Graph :param tg: Task Graph :param ctg: Clustered Task Graph :param ag: Architecture Graph :param shm: System Health Map :param noc_rg: NoC Routing Graph :param critical_rg: NoC Routing Graph for Critical region :param noncritical_rg: NoC routing Graph for Non-Critical Region :param cluster: ID Cluster to be mapped :param node: ID of the Node for mapping cluster on :param logging: logging file :return: True if maps the cluster successfully otherwise False """ if not shm.node[node]['NodeHealth']: logging.info("CAN NOT MAP ON BROKEN NODE: "+str(node)) return False elif ag.node[node]['PE'].dark: logging.info("CAN NOT MAP ON DARK NODE: "+str(node)) return False # Adding The cluster to Node... logging.info("\tADDING CLUSTER: "+str(cluster)+"TO NODE:"+str(node)) ctg.node[cluster]['Node'] = node for Task in ctg.node[cluster]['TaskList']: tg.node[Task]['task'].node = node ag.node[node]['PE'].mapped_tasks.append(Task) ag.node[node]['PE'].utilization += ctg.node[cluster]['Utilization'] for ctg_edge in ctg.edges(): if cluster in ctg_edge: # find all the edges that are connected to cluster # logging.info("\t\tEDGE:"+str(ctg_edge)+"CONTAINS CLUSTER:"+str(cluster)) source_node = ctg.node[ctg_edge[0]]['Node'] destination_node = ctg.node[ctg_edge[1]]['Node'] if source_node is not None and destination_node is not None: # check if both ends of this edge is mapped if source_node != destination_node: # Find the links to be used list_of_links, number_of_paths = Routing.find_route_in_route_graph(noc_rg, critical_rg, noncritical_rg, source_node, destination_node, False) list_of_edges = [] # print ("number_of_paths:", number_of_paths) # print number_of_paths, list_of_links if list_of_links is not None: # find all the edges in TaskGraph that contribute to this edge in CTG for tg_edge in tg.edges(): if tg.node[tg_edge[0]]['task'].cluster == ctg_edge[0] and \ tg.node[tg_edge[1]]['task'].cluster == ctg_edge[1]: list_of_edges.append(tg_edge) # print ("LIST OF LINKS:", list_of_links) # add edges from list of edges to all links from list of links # todo: I have to think more... this is not enough to add all the links there... if list_of_links is not None and len(list_of_edges) > 0: # logging.info("\t\t\tADDING PATH FROM NODE:"+str(source_node)+"TO NODE"+str(destination_node)) # logging.info("\t\t\tLIST OF LINKS:"+str(list_of_links)) # logging.info("\t\t\tLIST OF EDGES:"+str(list_of_edges)) counter = 0 for path in list_of_links: for link in path: for chosen_edge in list_of_edges: if tg.edge[chosen_edge[0]][chosen_edge[1]]["Criticality"] == 'H': probability = 1 # we reserve the whole bandwidth for critical packets... else: probability = 1.0/number_of_paths if chosen_edge in ag.edge[link[0]][link[1]]['MappedTasks'].keys(): ag.edge[link[0]][link[1]]['MappedTasks'][chosen_edge].append((counter, probability)) ag.node[link[0]]['Router'].mapped_tasks[chosen_edge].append((counter, probability)) # logging.info("\t\t\t\tAdding Packet "+str(chosen_edge)+" To Router:" + # str(link[0])) else: ag.edge[link[0]][link[1]]['MappedTasks'][chosen_edge] = [(counter, probability)] ag.node[link[0]]['Router'].mapped_tasks[chosen_edge] = [(counter, probability)] # logging.info("\t\t\t\tAdding Packet "+str(chosen_edge)+" To Router:" + # str(link[0])) edge_list_of_links = list(batch[1] for batch in tg.edge[chosen_edge[0]][chosen_edge[1]]['Link']) if link not in edge_list_of_links: tg.edge[chosen_edge[0]][chosen_edge[1]]['Link'].append((counter, link, probability)) for chosen_edge in list_of_edges: if tg.edge[chosen_edge[0]][chosen_edge[1]]["Criticality"] == 'H': probability = 1 # we reserve the whole bandwidth for critical packets... else: probability = 1.0/number_of_paths ag.node[path[len(path)-1][1]]['Router'].mapped_tasks[chosen_edge] = \ [(counter, probability)] # logging.info("\t\t\t\tAdding Packet "+str(chosen_edge)+" To Router:" + # str(path[len(path)-1][1])) counter += 1 else: logging.warning("\tNO PATH FOUND FROM SOURCE TO DESTINATION...") logging.info("REMOVING ALL THE MAPPED CONNECTIONS FOR CLUSTER "+str(cluster)) remove_cluster_from_node(tg, ctg, ag, noc_rg, critical_rg, noncritical_rg, cluster, node, logging) return False return True
def map_task_to_node(tg, ag, shm, noc_rg, critical_rg, noncritical_rg, task, node, logging): """ Maps a task from Task Graph to a specific Node in Architecture Graph :param tg: Task Graph :param ag: Architecture Graph :param shm: System Health Map :param noc_rg: NoC Routing Graph :param critical_rg: NoC Routing Graph for the Cirtical Section :param noncritical_rg: NoC Routing graph for non-critical section :param task: Task to be Mapped :param node: Chosen Node for mapping :param logging: logging file :return: true if can successfully map task to node else returns fails """ if not shm.node[node]['NodeHealth']: logging.info("CAN NOT MAP ON BROKEN NODE: "+str(node)) return False elif ag.node[node]['PE'].dark: logging.info("CAN NOT MAP ON DARK NODE: "+str(node)) return False logging.info("\tADDING TASK: "+str(task)+"TO NODE:"+str(node)) tg.node[task]['task'].node = node ag.node[node]['PE'].mapped_tasks.append(task) ag.node[node]['PE'].utilization += tg.node[task]['task'].wcet for edge in tg.edges(): if task in edge: # find all the edges that are connected to Task # logging.info("\t\tEDGE:"+str(edge)+"CONTAINS Task:"+str(task)) source_node = tg.node[edge[0]]['task'].node destination_node = tg.node[edge[1]]['task'].node if source_node is not None and destination_node is not None: # check if both ends of this edge is mapped if source_node != destination_node: # Find the links to be used list_of_links, number_of_paths = Routing.find_route_in_route_graph(noc_rg, critical_rg, noncritical_rg, source_node, destination_node, False) # print number_of_paths, list_of_links if list_of_links is not None: # logging.info("\t\t\tADDING PATH FROM NODE:"+str(source_node)+"TO NODE"+str(destination_node)) # logging.info("\t\t\tLIST OF LINKS:"+str(list_of_links)) counter = 0 if tg.edge[edge[0]][edge[1]]["Criticality"] == 'H': probability = 1 # we reserve the whole bandwidth for critical packets... else: probability = 1.0/number_of_paths for path in list_of_links: for link in path: if edge in ag.edge[link[0]][link[1]]['MappedTasks'].keys(): ag.edge[link[0]][link[1]]['MappedTasks'][edge].append((counter, probability)) ag.node[link[0]]['Router'].mapped_tasks[edge].append((counter, probability)) # logging.info("\t\t\t\tAdding Packet "+str(edge)+" To Router:"+str(link[0])) else: ag.edge[link[0]][link[1]]['MappedTasks'][edge] = [(counter, probability)] ag.node[link[0]]['Router'].mapped_tasks[edge] = [(counter, probability)] # logging.info("\t\t\t\tAdding Packet "+str(edge)+" To Router:"+str(link[0])) ag.node[path[len(path)-1][1]]['Router'].mapped_tasks[edge] = [(counter, probability)] # logging.info("\t\t\t\tAdding Packet "+str(edge) + # " To Router:"+str(path[len(path)-1][1])) edge_list_of_links = list(batch[1] for batch in tg.edge[edge[0]][edge[1]]['Link']) if link not in edge_list_of_links: tg.edge[edge[0]][edge[1]]['Link'].append((counter, link, probability)) counter += 1 else: remove_task_from_node(tg, ag, noc_rg, critical_rg, noncritical_rg, task, node, logging) logging.warning("\tNO PATH FOUND FROM "+str(source_node)+" TO "+str(destination_node)+"...") print ("NO PATH FOUND FROM "+str(source_node)+" TO "+str(destination_node)+" ...") return False return True
def opt_ag_vertical_link_iterative_local_search(ag, shmu, cost_file_name, logging): """ Runs iterative local search optimization on vertical link placement :param ag: architecture graph :param shmu: system health map :param cost_file_name: file name to dump cost values during the process :param logging: logging file :return: None """ logging.info("STARTING ILS FOR VL PLACEMENT...") if type(cost_file_name) is str: ag_cost_file = open( 'Generated_Files/Internal/' + cost_file_name + '.txt', 'a') else: raise ValueError("ag_cost_file name is not string: " + str(cost_file_name)) best_vertical_link_list = [] starting_cost = None for j in range(0, Config.vl_opt.ils_iteration): remove_all_vertical_links(shmu, ag) vertical_link_list_init = copy.deepcopy( find_feasible_ag_vertical_link_placement(ag, shmu)) routing_graph = copy.deepcopy( Routing.generate_noc_route_graph(ag, shmu, Config.UsedTurnModel, False, False)) cost = vl_cost_function(ag, routing_graph) ag_cost_file.write(str(cost) + "\n") current_best_cost = cost if j == 0: print("=====================================") print("STARTING AG VERTICAL LINK PLACEMENT OPTIMIZATION") print("NUMBER OF LINKS: " + str(Config.vl_opt.vl_num)) print("NUMBER OF ITERATIONS: " + str(Config.vl_opt.ils_iteration * Config.vl_opt.ls_iteration)) print("INITIAL REACHABILITY METRIC: " + str(cost)) starting_cost = cost best_cost = cost best_vertical_link_list = vertical_link_list_init[:] ag_temp = copy.deepcopy(ag) cleanup_ag(ag_temp, shmu) Arch_Graph_Reports.draw_ag(ag_temp, "AG_VLOpt_init") del ag_temp else: print("\033[33m* NOTE::\033[0m STARITNG NEW ROUND: " + str(j + 1) + "\t STARTING COST:" + str(cost)) if cost > best_cost: best_vertical_link_list = vertical_link_list_init[:] best_cost = cost print( "\033[32m* NOTE::\033[0mFOUND BETTER SOLUTION WITH COST:" + str(cost) + "\t ITERATION: " + str(j * Config.vl_opt.ls_iteration)) vertical_link_list = vertical_link_list_init[:] for i in range(0, Config.vl_opt.ls_iteration): new_vertical_link_list = copy.deepcopy( move_to_new_vertical_link_configuration( ag, shmu, vertical_link_list)) new_routing_graph = Routing.generate_noc_route_graph( ag, shmu, Config.UsedTurnModel, False, False) cost = vl_cost_function(ag, new_routing_graph) ag_cost_file.write(str(cost) + "\n") if cost >= current_best_cost: vertical_link_list = new_vertical_link_list[:] if cost > current_best_cost: current_best_cost = cost print("\t \tMOVED TO SOLUTION WITH COST:" + str(cost) + "\t ITERATION: " + str(j * Config.vl_opt.ls_iteration + i)) else: return_to_solution(ag, shmu, vertical_link_list) if cost > best_cost: best_vertical_link_list = vertical_link_list[:] best_cost = cost print( "\033[32m* NOTE::\033[0mFOUND BETTER SOLUTION WITH COST:" + str(cost) + "\t ITERATION: " + str(j * Config.vl_opt.ls_iteration + i)) return_to_solution(ag, shmu, best_vertical_link_list) ag_cost_file.close() print("-------------------------------------") print("STARTING COST:" + str(starting_cost) + "\tFINAL COST:" + str(best_cost)) print("IMPROVEMENT:" + str("{0:.2f}".format(100 * (best_cost - starting_cost) / starting_cost)) + " %") logging.info("ILS FOR VL PLACEMENT FINISHED...") 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 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 opt_ag_vertical_link_sa(ag, shmu, cost_file_name, logging): """ Optimises the vertical link placement using simulated annealing! :param ag: architecture graph :param shmu: system health monitoring unit :param cost_file_name: name of the file for dumping the cost values during the process :param logging: logging file :return: None """ logging.info("STARTING SA FOR VLP OPT") print "===========================================" print "VL PLACEMENT OPTIMIZATION USING SIMULATED ANNEALING..." print "STARTING TEMPERATURE:", Config.vl_opt.sa_initial_temp print "ANNEALING SCHEDULE: ", Config.vl_opt.sa_annealing_schedule print "TERMINATION CRITERIA: ", Config.vl_opt.termination_criteria if Config.vl_opt.termination_criteria == 'IterationNum': print "NUMBER OF ITERATIONS: ", Config.vl_opt.sa_iteration print "================" if type(cost_file_name) is str: ag_cost_file = open( 'Generated_Files/Internal/' + cost_file_name + '.txt', 'a') else: raise ValueError("ag_cost_file name is not string: " + str(cost_file_name)) temperature_file = open('Generated_Files/Internal/vlp_sa_temp.txt', 'w') remove_all_vertical_links(shmu, ag) vertical_link_list = find_feasible_ag_vertical_link_placement(ag, shmu) routing_graph = copy.deepcopy( Routing.generate_noc_route_graph(ag, shmu, Config.UsedTurnModel, Config.DebugInfo, Config.DebugDetails)) cost = vl_cost_function(ag, routing_graph) print("STARTING AG VL PLACEMENT OPTIMIZATION") print("NUMBER OF AVAILABLE V-LINKS: " + str(Config.vl_opt.vl_num)) print("INITIAL REACHABILITY METRIC: " + str(cost)) starting_cost = cost current_cost = cost best_cost = cost best_vertical_link_list = vertical_link_list[:] ag_temp = copy.deepcopy(ag) cleanup_ag(ag_temp, shmu) Arch_Graph_Reports.draw_ag(ag_temp, "AG_VLOpt_init") del ag_temp ag_cost_file.write(str(cost) + "\n") temperature = Config.vl_opt.sa_initial_temp initial_temp = temperature iteration_num = Config.vl_opt.sa_iteration temperature_file.write(str(temperature) + "\n") i = 0 while True: i += 1 new_vertical_link_list = copy.deepcopy( move_to_new_vertical_link_configuration(ag, shmu, vertical_link_list)) new_routing_graph = copy.deepcopy( Routing.generate_noc_route_graph(ag, shmu, Config.UsedTurnModel, False, False)) new_cost = vl_cost_function(ag, new_routing_graph) ag_cost_file.write(str(new_cost) + "\n") prob = metropolis(current_cost, new_cost, temperature) if prob > random.random(): # accept the new solution vertical_link_list = new_vertical_link_list[:] current_cost = new_cost if new_cost > best_cost: best_cost = new_cost best_vertical_link_list = new_vertical_link_list[:] print( "\033[32m* NOTE::\033[0mFOUND BETTER SOLUTION WITH COST:" + str(cost) + "\t ITERATION: " + str(i)) else: # move back to initial solution return_to_solution(ag, shmu, vertical_link_list) temperature = next_temp(initial_temp, i, iteration_num, temperature) temperature_file.write(str(temperature) + "\n") if Config.vl_opt.termination_criteria == 'IterationNum': if i == Config.vl_opt.sa_iteration: print("REACHED MAXIMUM ITERATION NUMBER...") break elif Config.vl_opt.termination_criteria == 'StopTemp': if temperature <= Config.vl_opt.sa_stop_temp: print("REACHED STOP TEMPERATURE...") break ag_cost_file.close() temperature_file.close() return_to_solution(ag, shmu, best_vertical_link_list) print("-------------------------------------") print("STARTING COST:" + str(starting_cost) + "\tFINAL COST:" + str(best_cost)) print( "IMPROVEMENT:" + str("{0:.2f}".format(100 * (best_cost - starting_cost) / starting_cost)) + " %") logging.info("SA FOR VL PLACEMENT FINISHED...") return None
def remove_cluster_from_node(tg, ctg, ag, noc_rg, critical_rg, noncritical_rg, cluster, node, logging): """ removes a cluster and all its tasks from a certain Node from Architecture Graph(AG) :param tg: Task Graph :param ctg: Clustered task Graph :param ag: Architecture Graph :param noc_rg: NoC Routing Graph :param critical_rg: NoC routing Graph of critical Region :param noncritical_rg: NoC Routing Graph of non-Critical Region :param cluster: ID of The cluster to be mapped :param node: ID of the node for mapping the cluster on :param logging: logging file :return: True if can successfully remove cluster from Node """ logging.info("\tREMOVING CLUSTER:"+str(cluster)+"FROM NODE:"+str(node)) for ctg_edge in ctg.edges(): if cluster in ctg_edge: # find all the edges that are connected to Cluster source_node = ctg.node[ctg_edge[0]]['Node'] destination_node = ctg.node[ctg_edge[1]]['Node'] if source_node is not None and destination_node is not None: # check if both ends of this edge is mapped if source_node != destination_node: # Find the links to be used list_of_links, number_of_paths = Routing.find_route_in_route_graph(noc_rg, critical_rg, noncritical_rg, source_node, destination_node, False) list_of_edges = [] if list_of_links is not None: # find all the edges in TaskGraph that contribute to this edge in CTG for tg_edge in tg.edges(): if tg.node[tg_edge[0]]['task'].cluster == ctg_edge[0] and \ tg.node[tg_edge[1]]['task'].cluster == ctg_edge[1]: list_of_edges.append(tg_edge) # remove edges from list of edges to all links from list of links if list_of_links is not None and len(list_of_edges) > 0: # logging.info("\t\t\tREMOVING PATH FROM NODE:"+str(source_node) + # "TO NODE"+str(destination_node)) # logging.info("\t\t\tLIST OF LINKS:"+str(list_of_links)) # logging.info("\t\t\tLIST OF EDGES:"+str(list_of_edges)) for path in list_of_links: for Link in path: for chosen_edge in list_of_edges: if chosen_edge in ag.edge[Link[0]][Link[1]]['MappedTasks'].keys(): del ag.edge[Link[0]][Link[1]]['MappedTasks'][chosen_edge] if chosen_edge in ag.node[Link[0]]['Router'].mapped_tasks.keys(): del ag.node[Link[0]]['Router'].mapped_tasks[chosen_edge] # logging.info("\t\t\t\tRemoving Packet "+str(chosen_edge) + # " To Router:"+str(Link[0])) for LinkAndBatch in tg.edge[chosen_edge[0]][chosen_edge[1]]['Link']: if LinkAndBatch[1] == Link: tg.edge[chosen_edge[0]][chosen_edge[1]]['Link'].remove(LinkAndBatch) for chosen_edge in list_of_edges: if chosen_edge in ag.node[path[len(path)-1][1]]['Router'].mapped_tasks: del ag.node[path[len(path)-1][1]]['Router'].mapped_tasks[chosen_edge] # logging.info("\t\t\t\tRemoving Packet "+str(chosen_edge)+" To Router:" + # str(path[len(path)-1][1])) else: logging.warning("\tNOTHING TO BE REMOVED...") ctg.node[cluster]['Node'] = None for task in ctg.node[cluster]['TaskList']: tg.node[task]['task'].node = None ag.node[node]['PE'].mapped_tasks.remove(task) ag.node[node]['PE'].utilization -= ctg.node[cluster]['Utilization'] return True
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 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_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 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 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 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 map_task_to_node(tg, ag, shm, noc_rg, critical_rg, noncritical_rg, task, node, logging): """ Maps a task from Task Graph to a specific Node in Architecture Graph :param tg: Task Graph :param ag: Architecture Graph :param shm: System Health Map :param noc_rg: NoC Routing Graph :param critical_rg: NoC Routing Graph for the Cirtical Section :param noncritical_rg: NoC Routing graph for non-critical section :param task: Task to be Mapped :param node: Chosen Node for mapping :param logging: logging file :return: true if can successfully map task to node else returns fails """ if not shm.node[node]['NodeHealth']: logging.info("CAN NOT MAP ON BROKEN NODE: " + str(node)) return False elif ag.node[node]['PE'].dark: logging.info("CAN NOT MAP ON DARK NODE: " + str(node)) return False logging.info("\tADDING TASK: " + str(task) + "TO NODE:" + str(node)) tg.node[task]['task'].node = node ag.node[node]['PE'].mapped_tasks.append(task) ag.node[node]['PE'].utilization += tg.node[task]['task'].wcet for edge in tg.edges(): if task in edge: # find all the edges that are connected to Task # logging.info("\t\tEDGE:"+str(edge)+"CONTAINS Task:"+str(task)) source_node = tg.node[edge[0]]['task'].node destination_node = tg.node[edge[1]]['task'].node if source_node is not None and destination_node is not None: # check if both ends of this edge is mapped if source_node != destination_node: # Find the links to be used list_of_links, number_of_paths = Routing.find_route_in_route_graph( noc_rg, critical_rg, noncritical_rg, source_node, destination_node, False) # print(number_of_paths, list_of_links) if list_of_links is not None: # logging.info("\t\t\tADDING PATH FROM NODE:"+str(source_node)+"TO NODE"+str(destination_node)) # logging.info("\t\t\tLIST OF LINKS:"+str(list_of_links)) counter = 0 if tg.edges[edge]["Criticality"] == 'H': probability = 1 # we reserve the whole bandwidth for critical packets... else: probability = 1.0 / number_of_paths for path in list_of_links: for link in path: if edge in ag.edges[link]['MappedTasks'].keys( ): ag.edges[link]['MappedTasks'][edge].append( (counter, probability)) ag.node[link[0]]['Router'].mapped_tasks[ edge].append((counter, probability)) # logging.info("\t\t\t\tAdding Packet "+str(edge)+" To Router:"+str(link[0])) else: ag.edges[link]['MappedTasks'][edge] = [ (counter, probability) ] ag.node[link[0]]['Router'].mapped_tasks[ edge] = [(counter, probability)] # logging.info("\t\t\t\tAdding Packet "+str(edge)+" To Router:"+str(link[0])) ag.node[path[len(path) - 1] [1]]['Router'].mapped_tasks[edge] = [ (counter, probability) ] # logging.info("\t\t\t\tAdding Packet "+str(edge) + # " To Router:"+str(path[len(path)-1][1])) edge_list_of_links = list( batch[1] for batch in tg.edges[edge]['Link']) if link not in edge_list_of_links: tg.edges[edge]['Link'].append( (counter, link, probability)) counter += 1 else: remove_task_from_node(tg, ag, noc_rg, critical_rg, noncritical_rg, task, node, logging) logging.warning("\tNO PATH FOUND FROM " + str(source_node) + " TO " + str(destination_node) + "...") print("NO PATH FOUND FROM " + str(source_node) + " TO " + str(destination_node) + " ...") return False return True
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