def test_routing_functions(self): initial_config_ag = deepcopy(Config.ag) initial_turn_model = Config.UsedTurnModel initial_routing_type = Config.RotingType Config.ag.type = "Generic" Config.ag.topology = "2DMesh" Config.ag.x_size = 3 Config.ag.y_size = 3 Config.ag.z_size = 1 for turn_model in PackageFile.routing_alg_list_2d: Config.UsedTurnModel = deepcopy(turn_model) Config.TurnsHealth = deepcopy(Config.setup_turns_health()) ag_4_test = deepcopy(generate_ag(logging=None)) shmu_4_test = SystemHealthMonitoringUnit.SystemHealthMonitoringUnit() shmu_4_test.setup_noc_shm(ag_4_test, Config.TurnsHealth, False) noc_rg = generate_noc_route_graph(ag_4_test, shmu_4_test, turn_model, False, False) self.assertEqual(check_deadlock_freeness(noc_rg), True) if turn_model in [PackageFile.XY_TurnModel, PackageFile.YX_TurnModel]: if turn_model == PackageFile.XY_TurnModel: self.assertEqual(return_turn_model_name(turn_model), '0') else: self.assertEqual(return_turn_model_name(turn_model), '13') self.assertEqual(degree_of_adaptiveness(ag_4_test, noc_rg, False)/72, 1) self.assertEqual(extended_degree_of_adaptiveness(ag_4_test, noc_rg, False)/72, 1) del ag_4_test del shmu_4_test Config.ag.type = "Generic" Config.ag.topology = "3DMesh" Config.ag.x_size = 3 Config.ag.y_size = 3 Config.ag.z_size = 3 Config.RotingType = "NonMinimalPath" for turn_model in PackageFile.routing_alg_list_3d: Config.UsedTurnModel = deepcopy(turn_model) Config.TurnsHealth = deepcopy(Config.setup_turns_health()) ag_4_test = deepcopy(generate_ag(logging=None)) shmu_4_test = SystemHealthMonitoringUnit.SystemHealthMonitoringUnit() shmu_4_test.setup_noc_shm(ag_4_test, Config.TurnsHealth, False) noc_rg = generate_noc_route_graph(ag_4_test, shmu_4_test, turn_model, False, False) self.assertEqual(check_deadlock_freeness(noc_rg), True) if turn_model == PackageFile.XYZ_TurnModel: self.assertEqual(return_turn_model_name(turn_model), "3d_XYZ") self.assertEqual(degree_of_adaptiveness(ag_4_test, noc_rg, False)/702, 1) self.assertEqual(extended_degree_of_adaptiveness(ag_4_test, noc_rg, False)/702, 1) if turn_model == PackageFile.NegativeFirst3D_TurnModel: self.assertEqual(return_turn_model_name(turn_model), "3d_NegFirst") del ag_4_test del shmu_4_test del noc_rg Config.ag = deepcopy(initial_config_ag) Config.UsedTurnModel = initial_turn_model Config.TurnsHealth = deepcopy(Config.setup_turns_health()) Config.RotingType = initial_routing_type
def evaluate_actual_odd_even_turn_model(): """ evaluates the classic odd-even turn model in terms of DoA and DoA_ex :return: None """ turns_health_2d_network = {"N2W": False, "N2E": False, "S2W": False, "S2E": False, "W2N": False, "W2S": False, "E2N": False, "E2S": False} Config.ag.topology = '2DMesh' Config.ag.x_size = 3 Config.ag.y_size = 3 Config.ag.z_size = 1 Config.RotingType = 'MinimalPath' ag = copy.deepcopy(AG_Functions.generate_ag()) number_of_pairs = len(ag.nodes())*(len(ag.nodes())-1) turn_model_odd = ['E2N', 'E2S', 'W2N', 'W2S', 'S2E', 'N2E'] turn_model_even = ['E2N', 'E2S', 'S2W', 'S2E', 'N2W', 'N2E'] if not check_tm_domination(turn_model_odd, turn_model_even): # taking out the domination! turns_health = copy.deepcopy(turns_health_2d_network) shmu = SystemHealthMonitoringUnit.SystemHealthMonitoringUnit() shmu.setup_noc_shm(ag, turns_health, False) noc_rg = copy.deepcopy(Routing.generate_noc_route_graph(ag, shmu, [], False, False)) update_rg_odd_even(ag, turn_model_odd, turn_model_even, shmu, noc_rg) draw_rg(noc_rg) connectivity_metric = reachability_metric(ag, noc_rg, False) print "connectivity_metric:", connectivity_metric if check_deadlock_freeness(noc_rg): print "Deadlock free!" doa = degree_of_adaptiveness(ag, noc_rg, False)/float(number_of_pairs) doa_ex = extended_degree_of_adaptiveness(ag, noc_rg, False)/float(number_of_pairs) print "doa:", doa print "doa_ex", doa_ex return None
def evaluate_actual_odd_even_turn_model(): turns_health_2d_network = { "N2W": False, "N2E": False, "S2W": False, "S2E": False, "W2N": False, "W2S": False, "E2N": False, "E2S": False } Config.ag.topology = '2DMesh' Config.ag.x_size = 3 Config.ag.y_size = 3 Config.ag.z_size = 1 Config.RotingType = 'MinimalPath' ag = copy.deepcopy(AG_Functions.generate_ag()) number_of_pairs = len(ag.nodes()) * (len(ag.nodes()) - 1) turn_model_odd = ['E2N', 'E2S', 'W2N', 'W2S', 'S2E', 'N2E'] turn_model_even = ['E2N', 'E2S', 'S2W', 'S2E', 'N2W', 'N2E'] if not check_tm_domination(turn_model_odd, turn_model_even): # taking out the domination! turns_health = copy.deepcopy(turns_health_2d_network) shmu = SystemHealthMonitoringUnit.SystemHealthMonitoringUnit() shmu.setup_noc_shm(ag, turns_health, False) noc_rg = copy.deepcopy( Routing.generate_noc_route_graph(ag, shmu, [], False, False)) for node in ag.nodes(): node_x, node_y, node_z = AG_Functions.return_node_location(node) if node_x % 2 == 1: for turn in turn_model_odd: shmu.restore_broken_turn(node, turn, False) from_port = str(node) + str(turn[0]) + "I" to_port = str(node) + str(turn[2]) + "O" Routing.update_noc_route_graph(noc_rg, from_port, to_port, 'ADD') else: for turn in turn_model_even: shmu.restore_broken_turn(node, turn, False) from_port = str(node) + str(turn[0]) + "I" to_port = str(node) + str(turn[2]) + "O" Routing.update_noc_route_graph(noc_rg, from_port, to_port, 'ADD') draw_rg(noc_rg) connectivity_metric = reachability_metric(ag, noc_rg, False) print("connectivity_metric:", connectivity_metric) if check_deadlock_freeness(noc_rg): print("Deadlock free!") doa = degree_of_adaptiveness(ag, noc_rg, False) / float(number_of_pairs) doa_ex = extended_degree_of_adaptiveness( ag, noc_rg, False) / float(number_of_pairs) print("doa:", doa) print("doa_ex", doa_ex) sys.stdout.flush()
def enumerate_all_2d_turn_models_based_on_df(combination): """ Lists all 2D deadlock free turn models in "deadlock_free_turns" in "Generated_Files" folder! --------------------- We have 256 turns in 2D Mesh NoC! --------------------- :param combination: number of turns which should be checked for combination! :return: None """ counter = 0 all_turns_file = open('Generated_Files/Turn_Model_Lists/all_2D_turn_models_'+str(combination)+'.txt', 'w') turns_health_2d_network = {"N2W": False, "N2E": False, "S2W": False, "S2E": False, "W2N": False, "W2S": False, "E2N": False, "E2S": False} Config.ag.topology = '2DMesh' Config.ag.x_size = 3 Config.ag.y_size = 3 Config.ag.z_size = 1 Config.RotingType = 'NonMinimalPath' all_turns_file.write("#"+"\t\tDF/D\t"+'%25s' % "turns"+'%20s' % " "+"\t\t"+'%10s' % "c-metric" + "\t\t"+'%10s' % "DoA"+"\t\t"+'%10s' % "DoAx"+"\n") all_turns_file.write("--------------"*8+"\n") ag = copy.deepcopy(AG_Functions.generate_ag()) number_of_pairs = len(ag.nodes())*(len(ag.nodes())-1) turn_model_list = copy.deepcopy(PackageFile.FULL_TurnModel_2D) deadlock_free_counter = 0 deadlock_counter = 0 # print "Number of Turns:", combination for turns in itertools.combinations(turn_model_list, combination): turns_health = copy.deepcopy(turns_health_2d_network) for turn in turns: turns_health[turn] = True counter += 1 shmu = SystemHealthMonitoringUnit.SystemHealthMonitoringUnit() shmu.setup_noc_shm(ag, turns_health, False) noc_rg = copy.deepcopy(Routing.generate_noc_route_graph(ag, shmu, list(turns), False, False)) if check_deadlock_freeness(noc_rg): connectivity_metric = reachability_metric(ag, noc_rg, False) doa = degree_of_adaptiveness(ag, noc_rg, False)/float(number_of_pairs) doa_ex = extended_degree_of_adaptiveness(ag, noc_rg, False)/float(number_of_pairs) deadlock_free_counter += 1 # print counter, "\t \033[92mDF\033[0m \t", list(turns), "\t\t", connectivity_metric all_turns_file.write(str(counter)+"\t\tDF\t"+'%51s' % str(list(turns)) + "\t\t"+'%10s' % str(connectivity_metric) + "\t\t"+'%10s' % str(round(doa, 2))+"\t\t"+'%10s' % str(round(doa_ex, 2))+"\n") else: deadlock_counter += 1 # print counter, "\t \033[31mDL\033[0m \t", list(turns), "\t\t----" all_turns_file.write(str(counter)+"\t\tDL\t"+'%51s' % str(list(turns)) + "\t\t-----"+"\t\t-----"+"\t\t-----"+"\n") del shmu del noc_rg all_turns_file.write("---------------------------"+"\n") all_turns_file.write("Number of turn models with deadlock: "+str(deadlock_counter)+"\n") all_turns_file.write("Number of turn models without deadlock: "+str(deadlock_free_counter)+"\n") all_turns_file.write("=========================================="+"\n") all_turns_file.close() return None
def enumerate_all_3d_turn_models_based_on_df(combination): """ Lists all 3D deadlock free turn models in "deadlock_free_turns" in "Generated_Files" folder! --------------------- We have 16,777,216 turns in 3D Mesh NoC! if it takes one second to calculate deadlock freeness Then it takes almost 194.2 Days (almost 6.4 Months) to check all of them. that is the reason we need to make this parallel! --------------------- :param combination: number of turns which should be checked for combination! :return: None """ counter = 0 all_turns_file = open('Generated_Files/Turn_Model_Lists/all_3D_turn_models_'+str(combination)+'.txt', 'w') turns_health_3d_network = {"N2W": False, "N2E": False, "S2W": False, "S2E": False, "W2N": False, "W2S": False, "E2N": False, "E2S": False, "N2U": False, "N2D": False, "S2U": False, "S2D": False, "W2U": False, "W2D": False, "E2U": False, "E2D": False, "U2W": False, "U2E": False, "U2N": False, "U2S": False, "D2W": False, "D2E": False, "D2N": False, "D2S": False} Config.ag.topology = '3DMesh' Config.ag.x_size = 3 Config.ag.y_size = 3 Config.ag.z_size = 3 ag = copy.deepcopy(AG_Functions.generate_ag()) turn_model_list = copy.deepcopy(PackageFile.FULL_TurnModel_3D) deadlock_free_counter = 0 deadlock_counter = 0 # print "Number of Turns:", combination for turns in itertools.combinations(turn_model_list, combination): turns_health = copy.deepcopy(turns_health_3d_network) for turn in turns: turns_health[turn] = True counter += 1 shmu = SystemHealthMonitoringUnit.SystemHealthMonitoringUnit() shmu.setup_noc_shm(ag, turns_health, False) noc_rg = copy.deepcopy(Routing.generate_noc_route_graph(ag, shmu, list(turns), False, False)) if check_deadlock_freeness(noc_rg): connectivity_metric = reachability_metric(ag, noc_rg, False) doa = degree_of_adaptiveness(ag, noc_rg, False) deadlock_free_counter += 1 # print counter, "\t \033[92mDF\033[0m \t", list(turns), "\t\t", connectivity_metric all_turns_file.write(str(counter)+"\t\tDF\t"+str(list(turns))+"\t\t"+str(connectivity_metric) + "\t\t"+str(doa)+"\n") else: deadlock_counter += 1 # print counter, "\t \033[31mDL\033[0m \t", list(turns), "\t\t----" all_turns_file.write(str(counter)+"\t\tDL\t"+str(list(turns))+"\t\t-----""\n") del shmu del noc_rg all_turns_file.write("---------------------------"+"\n") all_turns_file.write("Number of turn models with deadlock: "+str(deadlock_counter)+"\n") all_turns_file.write("Number of turn models without deadlock: "+str(deadlock_free_counter)+"\n") all_turns_file.write("=========================================="+"\n") all_turns_file.close() return None
def enumerate_all_odd_even_turn_models(network_size, routing_type): all_odd_evens_file = open('Generated_Files/Turn_Model_Lists/'+str(network_size)+"x" +str(network_size)+"_"+str(routing_type)+"_"+'odd_even_tm_list_dl_free.txt', 'w') turns_health_2d_network = {"N2W": False, "N2E": False, "S2W": False, "S2E": False, "W2N": False, "W2S": False, "E2N": False, "E2S": False} Config.ag.topology = '2DMesh' Config.ag.x_size = network_size Config.ag.y_size = network_size Config.ag.z_size = 1 Config.RotingType = routing_type ag = copy.deepcopy(AG_Functions.generate_ag()) number_of_pairs = len(ag.nodes())*(len(ag.nodes())-1) turn_model_list = [] for length in range(0, len(turns_health_2d_network.keys())+1): for item in list(itertools.combinations(turns_health_2d_network.keys(), length)): if len(item) > 0: turn_model_list.append(list(item)) connected_counter = 0 deadlock_free_counter = 0 tm_counter = 0 turns_health = copy.deepcopy(turns_health_2d_network) shmu = SystemHealthMonitoringUnit.SystemHealthMonitoringUnit() shmu.setup_noc_shm(ag, turns_health, False) noc_rg = copy.deepcopy(Routing.generate_noc_route_graph(ag, shmu, [], False, False)) for turn_model_odd in turn_model_list: for turn_model_even in turn_model_list: if not check_tm_domination(turn_model_odd, turn_model_even): # taking out the domination! update_rg_odd_even(ag, turn_model_odd, turn_model_even, shmu, noc_rg) connectivity_metric = reachability_metric(ag, noc_rg, False) if connectivity_metric == number_of_pairs: connected_counter += 1 if check_deadlock_freeness(noc_rg): deadlock_free_counter += 1 all_odd_evens_file.write("["+str(turn_model_odd)+","+str(turn_model_even)+"],\n") tm_counter += 1 sys.stdout.write("\rchecked TM: %i " % tm_counter + " number of fully connected TM: %i" % connected_counter + " number of deadlock free connected TM: %i" % deadlock_free_counter) sys.stdout.flush() clean_rg_from_odd_even(ag, turn_model_odd, turn_model_even, shmu, noc_rg) all_odd_evens_file.write("checked TM: %i " + str(tm_counter) + " number of fully connected TM: %i" +str(connected_counter) + " number of deadlock free connected TM: %i"+str(deadlock_free_counter)) all_odd_evens_file.close() return None
def evaluate_actual_odd_even_turn_model(): """ evaluates the classic odd-even turn model in terms of DoA and DoA_ex :return: None """ turns_health_2d_network = { "N2W": False, "N2E": False, "S2W": False, "S2E": False, "W2N": False, "W2S": False, "E2N": False, "E2S": False } Config.ag.topology = '2DMesh' Config.ag.x_size = 3 Config.ag.y_size = 3 Config.ag.z_size = 1 Config.RotingType = 'MinimalPath' ag = copy.deepcopy(AG_Functions.generate_ag()) number_of_pairs = len(ag.nodes()) * (len(ag.nodes()) - 1) turn_model_odd = ['E2N', 'E2S', 'W2N', 'W2S', 'S2E', 'N2E'] turn_model_even = ['E2N', 'E2S', 'S2W', 'S2E', 'N2W', 'N2E'] if not check_tm_domination(turn_model_odd, turn_model_even): # taking out the domination! turns_health = copy.deepcopy(turns_health_2d_network) shmu = SystemHealthMonitoringUnit.SystemHealthMonitoringUnit() shmu.setup_noc_shm(ag, turns_health, False) noc_rg = copy.deepcopy( Routing.generate_noc_route_graph(ag, shmu, [], False, False)) update_rg_odd_even(ag, turn_model_odd, turn_model_even, shmu, noc_rg) draw_rg(noc_rg) connectivity_metric = reachability_metric(ag, noc_rg, False) print("connectivity_metric:", connectivity_metric) if check_deadlock_freeness(noc_rg): print("Deadlock free!") doa = degree_of_adaptiveness(ag, noc_rg, False) / float(number_of_pairs) doa_ex = extended_degree_of_adaptiveness( ag, noc_rg, False) / float(number_of_pairs) print("doa:", doa) print("doa_ex", doa_ex) return None
def 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 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 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 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 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 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 test_routing_functions(self): initial_config_ag = deepcopy(Config.ag) initial_turn_model = Config.UsedTurnModel initial_routing_type = Config.RotingType Config.ag.type = "Generic" Config.ag.topology = "2DMesh" Config.ag.x_size = 3 Config.ag.y_size = 3 Config.ag.z_size = 1 for turn_model in PackageFile.routing_alg_list_2d: Config.UsedTurnModel = deepcopy(turn_model) Config.TurnsHealth = deepcopy(Config.setup_turns_health()) ag_4_test = deepcopy(generate_ag(logging=None)) shmu_4_test = SystemHealthMonitoringUnit.SystemHealthMonitoringUnit( ) shmu_4_test.setup_noc_shm(ag_4_test, Config.TurnsHealth, False) noc_rg = generate_noc_route_graph(ag_4_test, shmu_4_test, turn_model, False, False) self.assertEqual(check_deadlock_freeness(noc_rg), True) if turn_model in [ PackageFile.XY_TurnModel, PackageFile.YX_TurnModel ]: if turn_model == PackageFile.XY_TurnModel: self.assertEqual(return_turn_model_name(turn_model), '0') else: self.assertEqual(return_turn_model_name(turn_model), '13') self.assertEqual( degree_of_adaptiveness(ag_4_test, noc_rg, False) / 72, 1) self.assertEqual( extended_degree_of_adaptiveness(ag_4_test, noc_rg, False) / 72, 1) del ag_4_test del shmu_4_test Config.ag.type = "Generic" Config.ag.topology = "3DMesh" Config.ag.x_size = 3 Config.ag.y_size = 3 Config.ag.z_size = 3 Config.RotingType = "NonMinimalPath" for turn_model in PackageFile.routing_alg_list_3d: Config.UsedTurnModel = deepcopy(turn_model) Config.TurnsHealth = deepcopy(Config.setup_turns_health()) ag_4_test = deepcopy(generate_ag(logging=None)) shmu_4_test = SystemHealthMonitoringUnit.SystemHealthMonitoringUnit( ) shmu_4_test.setup_noc_shm(ag_4_test, Config.TurnsHealth, False) noc_rg = generate_noc_route_graph(ag_4_test, shmu_4_test, turn_model, False, False) self.assertEqual(check_deadlock_freeness(noc_rg), True) if turn_model == PackageFile.XYZ_TurnModel: self.assertEqual(return_turn_model_name(turn_model), "3d_XYZ") self.assertEqual( degree_of_adaptiveness(ag_4_test, noc_rg, False) / 702, 1) self.assertEqual( extended_degree_of_adaptiveness(ag_4_test, noc_rg, False) / 702, 1) if turn_model == PackageFile.NegativeFirst3D_TurnModel: self.assertEqual(return_turn_model_name(turn_model), "3d_NegFirst") del ag_4_test del shmu_4_test del noc_rg Config.ag = deepcopy(initial_config_ag) Config.UsedTurnModel = initial_turn_model Config.TurnsHealth = deepcopy(Config.setup_turns_health()) Config.RotingType = initial_routing_type
def test_routing_functions(self): # backing up the original config... initial_config_ag = deepcopy(Config.ag) initial_turn_model = Config.UsedTurnModel initial_routing_type = Config.RotingType # ----------------------------------------------------- Config.ag.type = "Generic" Config.ag.topology = "2DMesh" Config.RotingType = "MinimalPath" Config.ag.x_size = 3 Config.ag.y_size = 3 Config.ag.z_size = 1 for turn_model in PackageFile.routing_alg_list_2d: tmName = return_turn_model_name(turn_model) Config.UsedTurnModel = deepcopy(turn_model) Config.TurnsHealth = deepcopy(Config.setup_turns_health()) ag_4_test = deepcopy(generate_ag(logging=None)) shmu_4_test = SystemHealthMonitoringUnit.SystemHealthMonitoringUnit( ) shmu_4_test.setup_noc_shm(ag_4_test, Config.TurnsHealth, False) noc_rg = generate_noc_route_graph(ag_4_test, shmu_4_test, turn_model, False, False) self.assertEqual(check_deadlock_freeness(noc_rg), True, msg=f"TM {tmName} Deadlock freeness failed") if turn_model in [ PackageFile.XY_TurnModel, PackageFile.YX_TurnModel ]: if turn_model == PackageFile.XY_TurnModel: self.assertEqual(tmName, '0', msg=f"TM name {tmName} is not 0") else: self.assertEqual(tmName, '13', msg=f"TM name {tmName} is not 13") self.assertEqual( degree_of_adaptiveness(ag_4_test, noc_rg, report=False) / 72.0, 1.0, msg=f"TM: {tmName} DOA failed") self.assertEqual(extended_degree_of_adaptiveness( ag_4_test, noc_rg, report=False) / 72.0, 1.0, msg=f"TM: {tmName} DOAex failed") del ag_4_test del shmu_4_test # ----------------------------------------------------- Config.ag.type = "Generic" Config.ag.topology = "3DMesh" Config.RotingType = "NonMinimalPath" Config.ag.x_size = 3 Config.ag.y_size = 3 Config.ag.z_size = 3 for turn_model in PackageFile.routing_alg_list_3d: Config.UsedTurnModel = deepcopy(turn_model) Config.TurnsHealth = deepcopy(Config.setup_turns_health()) ag_4_test = deepcopy(generate_ag(logging=None)) shmu_4_test = SystemHealthMonitoringUnit.SystemHealthMonitoringUnit( ) shmu_4_test.setup_noc_shm(ag_4_test, Config.TurnsHealth, False) noc_rg = generate_noc_route_graph(ag_4_test, shmu_4_test, turn_model, False, False) self.assertEqual(check_deadlock_freeness(noc_rg), True, msg=f"TM: {turn_model} deadlock freeness Failed!") if turn_model == PackageFile.XYZ_TurnModel: self.assertEqual(return_turn_model_name(turn_model), "3d_XYZ", msg="Turn Model is not 3d_XYZ") self.assertEqual( degree_of_adaptiveness(ag_4_test, noc_rg, False) / 702, 1, msg="DoA test failed") self.assertEqual( extended_degree_of_adaptiveness(ag_4_test, noc_rg, False) / 702, 1, msg="ExDoA test failed") if turn_model == PackageFile.NegativeFirst3D_TurnModel: self.assertEqual(return_turn_model_name(turn_model), "3d_NegFirst", msg="TM name is not 3d_NegFirst") del ag_4_test del shmu_4_test del noc_rg # ----------------------------------------------------- # going back to original config Config.ag = deepcopy(initial_config_ag) Config.UsedTurnModel = initial_turn_model Config.TurnsHealth = deepcopy(Config.setup_turns_health()) Config.RotingType = initial_routing_type