def test_manhattan_distance(self): self.assertEqual(manhattan_distance(0, 0), 0) last_node_number = return_node_number(Config.ag.x_size - 1, Config.ag.y_size - 1, Config.ag.z_size - 1) self.assertEqual( manhattan_distance(0, last_node_number), Config.ag.x_size + Config.ag.y_size + Config.ag.z_size - 3)
def test_manhattan_distance(self): self.assertEqual(manhattan_distance(0, 0), 0) last_node_number = return_node_number(Config.Network_X_Size - 1, Config.Network_Y_Size - 1, Config.Network_Z_Size - 1) self.assertEqual( manhattan_distance(0, last_node_number), Config.Network_X_Size + Config.Network_Y_Size + Config.Network_Z_Size - 3)
def degree_of_adaptiveness(ag, noc_rg, report): """ :param ag: architecture graph :param noc_rg: NoC routing graph :param report: report switch :return: reachability metric """ if report: print("=====================================") print( "CALCULATING REACH-ABILITY METRIC OF THE CURRENT ROUTING ALGORITHM UNDER CURRENT FAULT CONFIG" ) reachability_counter = 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): for path in all_shortest_paths( noc_rg, str(source_node) + str('L') + str('I'), str(destination_node) + str('L') + str('O')): if (len(path) / 2) - 1 <= manhattan_distance( source_node, destination_node): reachability_counter += 1 r_metric = float(reachability_counter) if report: print("REACH-ABILITY METRIC: " + str(r_metric)) return r_metric
def is_destination_reachable_from_source(noc_rg, source_node, destination_node): """ checks if destination is reachable from the local port of the source node the search starts from the local port :param noc_rg: NoC routing graph :param source_node: source node id :param destination_node: destination node id :return: True if there is a path else, False """ # the Source port should be input port since this is input of router # (which will be connected to PE's output port) source = str(source_node) + str('L') + str('I') # the destination port should be output port since this is output of router to PE # (which will be connected to PE's input port) destination = str(destination_node) + str('L') + str('O') if has_path(noc_rg, source, destination): if Config.RotingType == 'MinimalPath': path_length = shortest_path_length(noc_rg, source, destination) - 1 minimal_hop_count = manhattan_distance(source_node, destination_node) if (path_length / 2) == minimal_hop_count: return True else: return True return False
def is_destination_reachable_from_source(noc_rg, source_node, destination_node): """ checks if destination is reachable from the local port of the source node the search starts from the local port :param noc_rg: NoC routing graph :param source_node: source node id :param destination_node: destination node id :return: True if there is a path else, False """ # the Source port should be input port since this is input of router # (which will be connected to PE's output port) source = str(source_node)+str('L')+str('I') # the destination port should be output port since this is output of router to PE # (which will be connected to PE's input port) destination = str(destination_node)+str('L')+str('O') if has_path(noc_rg, source, destination): if Config.RotingType == 'MinimalPath': path_length = shortest_path_length(noc_rg, source, destination) minimal_hop_count = manhattan_distance(source_node, destination_node) if (path_length/2) == minimal_hop_count: return True else: return True else: return False
def return_minimal_paths(current_rg, source_node, destination_node): """ returns all minimal paths from source node to destination node, under current routing graph constraints :param current_rg: current routing graph :param source_node: source node id :param destination_node: destination node id :return: list of all minimal paths """ all_minimal_paths = [] max_hop_count = manhattan_distance(source_node, destination_node) source = str(source_node)+str('L')+str('I') destination = str(destination_node)+str('L')+str('O') all_paths = list(all_shortest_paths(current_rg, source, destination)) for Path in all_paths: if (len(Path)-2)/2 <= max_hop_count: all_minimal_paths.append(Path) return all_minimal_paths
def return_minimal_paths(current_rg, source_node, destination_node): """ returns all minimal paths from source node to destination node, under current routing graph constraints :param current_rg: current routing graph :param source_node: source node id :param destination_node: destination node id :return: list of all minimal paths """ all_minimal_paths = [] max_hop_count = manhattan_distance(source_node, destination_node) source = str(source_node) + str('L') + str('I') destination = str(destination_node) + str('L') + str('O') all_paths = list(all_shortest_paths(current_rg, source, destination)) for Path in all_paths: if (len(Path) - 2) / 2 <= max_hop_count: all_minimal_paths.append(Path) return all_minimal_paths
def degree_of_adaptiveness(ag, noc_rg, report): """ :param ag: architecture graph :param noc_rg: NoC routing graph :param report: report switch :return: reachability metric """ if report: print ("=====================================") print ("CALCULATING REACH-ABILITY METRIC OF THE CURRENT ROUTING ALGORITHM UNDER CURRENT FAULT CONFIG") reachability_counter = 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): for path in all_shortest_paths(noc_rg, str(source_node)+str('L')+str('I'), str(destination_node)+str('L')+str('O')): if (len(path)/2)-1 <= manhattan_distance(source_node, destination_node): reachability_counter += 1 r_metric = float(reachability_counter) if report: print ("REACH-ABILITY METRIC: "+str(r_metric)) return r_metric
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 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 generate_routing_table(size, noc_rg, routing_type): routing_table_file = open("Generated_Files/MC_routing_table.txt", 'a') for current_node in range(0, size**2): routing_table_file.write("-- Node " + str(current_node) + "\n") routing_table_file.write("constant routing_table_bits_" + str(current_node) + ": t_tata_long := (\n") counter = 0 for dir in ["L", "S", "E", "W", "N"]: if dir == "L": routing_table_file.write("\t-- local\n") elif dir == "S": routing_table_file.write("\t-- north\n") elif dir == "E": routing_table_file.write("\t-- east\n") elif dir == "W": routing_table_file.write("\t-- west\n") else: routing_table_file.write("\t-- south\n") for destination_node in range(0, size**2): current_port = str(current_node) + dir + "I" if current_node == destination_node: if counter == size**2 * 5 - 1: routing_table_file.write("\t\t" + str(counter) + " => \"0000\"\n") else: routing_table_file.write("\t\t" + str(counter) + " => \"0000\",\n") else: destination_port = str(destination_node) + "LO" if has_path(noc_rg, current_port, destination_port): all_paths = [] if routing_type == "MinimalPath": max_hop_count = manhattan_distance( current_node, destination_node) all_found_paths = list( all_shortest_paths(noc_rg, current_port, destination_port)) for Path in all_found_paths: if (len(Path) - 2) / 2 <= max_hop_count: all_paths.append(Path) else: all_paths = list( all_simple_paths(noc_rg, current_port, destination_port)) all_ports = [] for path in all_paths: if path[1][-2] not in all_ports: if path[1][-2] == "N": all_ports.append("S") elif path[1][-2] == "S": all_ports.append("N") else: all_ports.append(path[1][-2]) string = "" if "N" in all_ports: string += "1" else: string += "0" if "E" in all_ports: string += "1" else: string += "0" if "W" in all_ports: string += "1" else: string += "0" if "S" in all_ports: string += "1" else: string += "0" if counter == size**2 * 5 - 1: routing_table_file.write("\t\t" + str(counter) + " => \"" + string + "\"\n") else: routing_table_file.write("\t\t" + str(counter) + " => \"" + string + "\",\n") else: if counter == size**2 * 5 - 1: routing_table_file.write("\t\t" + str(counter) + " => \"0000\"\n") else: routing_table_file.write("\t\t" + str(counter) + " => \"0000\",\n") pass counter += 1 routing_table_file.write(" );\n") routing_table_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 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 generate_routing_table(size, noc_rg, routing_type): routing_table_file = open("Generated_Files/MC_routing_table.txt", 'a') for current_node in range(0, size**2): routing_table_file.write("-- Node "+str(current_node)+"\n") routing_table_file.write("constant routing_table_bits_"+str(current_node)+": t_tata_long := (\n") counter = 0 for dir in ["L", "S", "E", "W", "N"]: if dir == "L": routing_table_file.write("\t-- local\n") elif dir == "S": routing_table_file.write("\t-- north\n") elif dir == "E": routing_table_file.write("\t-- east\n") elif dir == "W": routing_table_file.write("\t-- west\n") else: routing_table_file.write("\t-- south\n") for destination_node in range(0, size**2): current_port = str(current_node)+dir+"I" if current_node == destination_node: if counter == size**2*5-1: routing_table_file.write("\t\t"+str(counter)+" => \"0000\"\n") else: routing_table_file.write("\t\t"+str(counter)+" => \"0000\",\n") else: destination_port = str(destination_node)+"LO" if has_path(noc_rg, current_port, destination_port): all_paths = [] if routing_type == "MinimalPath": max_hop_count = manhattan_distance(current_node, destination_node) all_found_paths = list(all_shortest_paths(noc_rg, current_port, destination_port)) for Path in all_found_paths: if (len(Path)-2)/2 <= max_hop_count: all_paths.append(Path) else: all_paths = list(all_simple_paths(noc_rg, current_port, destination_port)) all_ports = [] for path in all_paths: if path[1][-2] not in all_ports: if path[1][-2] == "N": all_ports.append("S") elif path[1][-2] == "S": all_ports.append("N") else: all_ports.append(path[1][-2]) string = "" if "N" in all_ports: string += "1" else: string += "0" if "E" in all_ports: string += "1" else: string += "0" if "W" in all_ports: string += "1" else: string += "0" if "S" in all_ports: string += "1" else: string += "0" if counter == size**2*5-1: routing_table_file.write("\t\t"+str(counter)+" => \""+string+"\"\n") else: routing_table_file.write("\t\t"+str(counter)+" => \""+string+"\",\n") #print '%20s' % string, else: if counter == size**2*5-1: routing_table_file.write("\t\t"+str(counter)+" => \"0000\"\n") else: routing_table_file.write("\t\t"+str(counter)+" => \"0000\",\n") #print '%20s' % "0000", pass counter += 1 #print routing_table_file.write(" );\n") routing_table_file.close() return None
def test(): all_odd_evens_file = open( 'Generated_Files/Turn_Model_Lists/all_odd_evens_doa.txt', 'w') turns_health_2d_network = { "N2W": False, "N2E": False, "S2W": False, "S2E": False, "W2N": False, "W2S": False, "E2N": False, "E2S": False } Config.ag.topology = '2DMesh' Config.ag.x_size = 3 Config.ag.y_size = 3 Config.ag.z_size = 1 Config.RotingType = 'NonMinimalPath' ag = copy.deepcopy(AG_Functions.generate_ag()) number_of_pairs = len(ag.nodes()) * (len(ag.nodes()) - 1) max_ratio = 0 classes_of_doa_ratio = [] turn_model_class_dict = {} for turn_model in all_odd_even_list: #for item in selected_turn_models: #print item #turn_model = all_odd_even_list[item] #print turn_model turn_model_index = all_odd_even_list.index(turn_model) turn_model_odd = turn_model[0] turn_model_even = turn_model[1] turns_health = copy.deepcopy(turns_health_2d_network) shmu = SystemHealthMonitoringUnit.SystemHealthMonitoringUnit() shmu.setup_noc_shm(ag, turns_health, False) noc_rg = copy.deepcopy( Routing.generate_noc_route_graph(ag, shmu, [], False, False)) for node in ag.nodes(): node_x, node_y, node_z = AG_Functions.return_node_location(node) if node_x % 2 == 1: for turn in turn_model_odd: shmu.restore_broken_turn(node, turn, False) from_port = str(node) + str(turn[0]) + "I" to_port = str(node) + str(turn[2]) + "O" Routing.update_noc_route_graph(noc_rg, from_port, to_port, 'ADD') else: for turn in turn_model_even: shmu.restore_broken_turn(node, turn, False) from_port = str(node) + str(turn[0]) + "I" to_port = str(node) + str(turn[2]) + "O" Routing.update_noc_route_graph(noc_rg, from_port, to_port, 'ADD') #draw_rg(noc_rg) number_of_pairs = len(ag.nodes()) * (len(ag.nodes()) - 1) doa_ex = extended_degree_of_adaptiveness( ag, noc_rg, False) / float(number_of_pairs) doa = degree_of_adaptiveness(ag, noc_rg, False) / float(number_of_pairs) sum_of_paths = 0 sum_of_sim_ratio = 0 for source_node in ag.nodes(): for destination_node in ag.nodes(): if source_node != destination_node: if is_destination_reachable_from_source( noc_rg, source_node, destination_node): #print source_node, "--->", destination_node if Config.RotingType == 'MinimalPath': shortest_paths = list( all_shortest_paths( noc_rg, str(source_node) + str('L') + str('I'), str(destination_node) + str('L') + str('O'))) paths = [] for path in shortest_paths: minimal_hop_count = manhattan_distance( source_node, destination_node) if (len(path) / 2) - 1 <= minimal_hop_count: paths.append(path) else: paths = list( all_simple_paths( noc_rg, str(source_node) + str('L') + str('I'), str(destination_node) + str('L') + str('O'))) #for path in paths: # print path local_sim_ratio = 0 counter = 0 if len(paths) > 1: for i in range(0, len(paths)): for j in range(i, len(paths)): if paths[i] != paths[j]: sm = difflib.SequenceMatcher( None, paths[i], paths[j]) counter += 1 local_sim_ratio += sm.ratio() #print float(local_sim_ratio)/counter sum_of_sim_ratio += float( local_sim_ratio) / counter else: sum_of_sim_ratio += 1 if Config.RotingType == 'MinimalPath': print("Turn Model ", '%5s' % turn_model_index, "\tdoa:", "{:3.3f}".format(doa), "\tsimilarity ratio:", "{:3.3f}".format(sum_of_sim_ratio), "\t\tfault tolerance metric:", "{:3.5f}".format(float(doa) / sum_of_sim_ratio)) doa_ratio = float("{:3.5f}".format( float(doa) / sum_of_sim_ratio, 5)) else: print("Turn Model ", '%5s' % turn_model_index, "\tdoa:", "{:3.3f}".format(doa_ex), "\tsimilarity ratio:", "{:3.3f}".format(sum_of_sim_ratio), "\t\tfault tolerance metric:", "{:3.5f}".format(float(doa_ex) / sum_of_sim_ratio)) doa_ratio = float("{:3.5f}".format( float(doa_ex) / sum_of_sim_ratio, 5)) if doa_ratio not in classes_of_doa_ratio: classes_of_doa_ratio.append(doa_ratio) if doa_ratio in list(turn_model_class_dict.keys()): turn_model_class_dict[doa_ratio].append(turn_model_index) else: turn_model_class_dict[doa_ratio] = [turn_model_index] if max_ratio < doa_ratio: max_ratio = doa_ratio #print "--------------------------------------------" del noc_rg print("max doa_ratio", max_ratio) print("classes of doa_ratio", classes_of_doa_ratio) for item in sorted(turn_model_class_dict.keys()): print(item, turn_model_class_dict[item]) return None
def odd_even_fault_tolerance_metric(network_size, routing_type): turns_health_2d_network = {"N2W": False, "N2E": False, "S2W": False, "S2E": False, "W2N": False, "W2S": False, "E2N": False, "E2S": False} Config.ag.topology = '2DMesh' Config.ag.x_size = network_size Config.ag.y_size = network_size Config.ag.z_size = 1 Config.RotingType = routing_type all_odd_evens_file = open('Generated_Files/Turn_Model_Eval/'+str(network_size)+"x"+str(network_size)+ '_OE_metric_'+Config.RotingType+'.txt', 'w') all_odd_evens_file.write("TOPOLOGY::"+str(Config.ag.topology)+"\n") all_odd_evens_file.write("X SIZE:"+str(Config.ag.x_size)+"\n") all_odd_evens_file.write("Y SIZE:"+str(Config.ag.y_size)+"\n") all_odd_evens_file.write("Z SIZE:"+str(Config.ag.z_size)+"\n") ag = copy.deepcopy(AG_Functions.generate_ag()) shmu = SystemHealthMonitoringUnit.SystemHealthMonitoringUnit() turns_health = copy.deepcopy(turns_health_2d_network) shmu.setup_noc_shm(ag, turns_health, False) noc_rg = copy.deepcopy(Routing.generate_noc_route_graph(ag, shmu, [], False, False)) classes_of_doa_ratio = [] turn_model_class_dict = {} tm_counter = 0 for turn_model in all_odd_even_list: sys.stdout.write("\rnumber of processed turn models: %i " % tm_counter) sys.stdout.flush() tm_counter += 1 link_dict = {} turn_model_index = all_odd_even_list.index(turn_model) turn_model_odd = turn_model[0] turn_model_even = turn_model[1] update_rg_odd_even(ag, turn_model_odd, turn_model_even, shmu, noc_rg) number_of_pairs = len(ag.nodes())*(len(ag.nodes())-1) all_paths_in_graph = [] for source_node in ag.nodes(): for destination_node in ag.nodes(): if source_node != destination_node: if is_destination_reachable_from_source(noc_rg, source_node, destination_node): if Config.RotingType == 'MinimalPath': shortest_paths = list(all_shortest_paths(noc_rg, str(source_node)+str('L')+str('I'), str(destination_node)+str('L')+str('O'))) paths = [] for path in shortest_paths: minimal_hop_count = manhattan_distance(source_node, destination_node) if (len(path)/2)-1 <= minimal_hop_count: paths.append(path) all_paths_in_graph.append(path) else: paths = list(all_simple_paths(noc_rg, str(source_node)+str('L')+str('I'), str(destination_node)+str('L')+str('O'))) all_paths_in_graph += paths link_dict = find_similarity_in_paths(link_dict, paths) metric = 0 for item in link_dict.keys(): metric += link_dict[item] if Config.RotingType == 'MinimalPath': doa = degree_of_adaptiveness(ag, noc_rg, False)/float(number_of_pairs) metric = 1/(float(metric)/len(ag.edges())) metric = float("{:3.3f}".format(metric)) else: doa_ex = extended_degree_of_adaptiveness(ag, noc_rg, False)/float(number_of_pairs) metric = 1/(float(metric)/len(ag.edges())) metric = float("{:3.3f}".format(metric)) if metric not in classes_of_doa_ratio: classes_of_doa_ratio.append(metric) if metric in turn_model_class_dict.keys(): turn_model_class_dict[metric].append(turn_model_index) else: turn_model_class_dict[metric] = [turn_model_index] # return SHMU and RG back to default clean_rg_from_odd_even(ag, turn_model_odd, turn_model_even, shmu, noc_rg) all_odd_evens_file.write("classes of metric"+str(classes_of_doa_ratio)+"\n") all_odd_evens_file.write("----------"*3+"\n") all_odd_evens_file.write("turn models of class"+"\n") for item in sorted(turn_model_class_dict.keys()): all_odd_evens_file.write(str(item)+" "+str(turn_model_class_dict[item])+"\n") all_odd_evens_file.write("----------"*3+"\n") all_odd_evens_file.write("distribution of turn models"+"\n") for item in sorted(turn_model_class_dict.keys()): temp_list = [] for tm in turn_model_class_dict[item]: turn_model = all_odd_even_list[tm] number_of_turns = len(turn_model[0])+len(turn_model[1]) temp_list.append(number_of_turns) all_odd_evens_file.write(str(item)+" "+str(temp_list.count(8))+" "+str(temp_list.count(9))+" " + str(temp_list.count(10))+" "+str(temp_list.count(11))+" " + str(temp_list.count(12))+"\n") all_odd_evens_file.close() return turn_model_class_dict
def 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