def is_node_inside_rectangle(rect, node): """ Checks if the node id is inside the rectangle :param rect: rectangle represented by 2 coordinates lower_left, upper_right :param node: node id :return: True if node id is inside rectangle else, False """ r1x, r1y, r1z = return_node_location(rect[0]) r2x, r2y, r2z = return_node_location(rect[1]) node_x, node_y, node_z = return_node_location(node) if r1x <= node_x <= r2x and r1y <= node_y <= r2y and r1z <= node_z <= r2z: return True else: return False
def is_node_inside_rectangle(rect, node): """ Checks if the node id is inside the rectangle :param rect: rectangle represented by 2 coordinates lower_left, upper_right :param node: node id :return: True if node id is inside rectangle else, False """ r1x, r1y, r1z = return_node_location(rect[0]) r2x, r2y, r2z = return_node_location(rect[1]) node_x, node_y, node_z = return_node_location(node) if r1x <= node_x <= r2x and r1y <= node_y <= r2y and r1z <= node_z <= r2z: return True else: return False
def find_all_vertical_links(ag): """ returns a list of all the vertical links possible in AG :param ag: architecture graph :return: list of all vertical links """ vertical_link_list = [] for link in ag.edges(): # if these nodes are on different layers if return_node_location(link[0])[2] != return_node_location( link[1])[2]: if link not in vertical_link_list: vertical_link_list.append(link) return vertical_link_list
def test_return_node_location(self): for k in range(0, Config.Network_Z_Size): for j in range(0, Config.Network_Y_Size): for i in range(0, Config.Network_X_Size): # we have the assumption that return_node_number is fully tested... self.assertEqual( return_node_location(return_node_number(i, j, k)), (i, j, k))
def merge_rectangle_with_node(rect_ll, rect_ur, node): """ Merges a rectangle with a node :param rect_ll: rectangle lower left position :param rect_ur: rectangle upper right position :param node: ID of the node to be merged :return: coordination of final rectangle (rect_ll, rect_ur) """ x1, y1, z1 = return_node_location(rect_ll) x2, y2, z2 = return_node_location(rect_ur) node_x, node_y, node_z = return_node_location(node) merged_x1 = min(x1, node_x) merged_y1 = min(y1, node_y) merged_z1 = min(z1, node_z) merged_x2 = max(x2, node_x) merged_y2 = max(y2, node_y) merged_z2 = max(z2, node_z) location_1 = merged_x1, merged_y1, merged_z1 location_2 = merged_x2, merged_y2, merged_z2 return location_1, location_2
def merge_rectangle_with_node(rect_ll, rect_ur, node): """ Merges a rectangle with a node :param rect_ll: rectangle lower left position :param rect_ur: rectangle upper right position :param node: ID of the node to be merged :return: coordination of final rectangle (rect_ll, rect_ur) """ x1, y1, z1 = return_node_location(rect_ll) x2, y2, z2 = return_node_location(rect_ur) node_x, node_y, node_z = return_node_location(node) merged_x1 = min(x1, node_x) merged_y1 = min(y1, node_y) merged_z1 = min(z1, node_z) merged_x2 = max(x2, node_x) merged_y2 = max(y2, node_y) merged_z2 = max(z2, node_z) location_1 = merged_x1, merged_y1, merged_z1 location_2 = merged_x2, merged_y2, merged_z2 return location_1, location_2
def draw_ag(ag, file_name): """ Generates Visualizations of the Architecture Graph and saves it in "GraphDrawings/FileName.png" :param ag: Architecture Graph :param file_name: Name of the file for saving the graph :return: None """ position = {} color_list = [] number_of_layers = Config.ag.z_size largest_number = Config.ag.x_size*Config.ag.y_size*Config.ag.z_size - 1 node_size = math.log10(largest_number)*60 # print "Node Size", node_size node_distance_x = 0.2 * (number_of_layers+1) node_distance_y = 0.2 * (number_of_layers+1) offset_x = 0.2 offset_y = 0.2 plt.figure(num=None, figsize=(3*Config.ag.x_size, 3*Config.ag.y_size), dpi=350) for Node in ag.nodes(): x, y, z = return_node_location(Node) position[Node] = [(x*node_distance_x)+(z*offset_x), (y*node_distance_y)+(z*offset_y)] # print(x*node_distance_x)+(z*offset_x), (y*node_distance_y)+(z*offset_y) if ag.node[Node]['Region'] == 'H': color_list.append('#FF878B') elif ag.node[Node]['Region'] == 'GH': # gateway to high critical color_list.append('#FFC29C') elif ag.node[Node]['Region'] == 'GNH': # gateway to Non-high critical color_list.append('#928AFF') else: color_list.append('#CFECFF') # POS = networkx.spring_layout(AG) networkx.draw(ag, pos=position, with_labels=True, node_size=node_size, arrows=True, node_color=color_list, font_size=7, linewidths=1) plt.savefig("GraphDrawings/"+file_name+".png") plt.clf() return None
def draw_rg(rg): """ draws routing graph in GraphDrawings/RG.png :param rg: routing graph :return: None """ print ("===========================================") print ("GENERATING ROUTING GRAPH VISUALIZATION...") line_width = 2 pos = {} color_list = [] plt.figure(figsize=(10*Config.ag.x_size, 10*Config.ag.y_size)) distance = 100*Config.ag.z_size step = (distance*0.8)/Config.ag.z_size for node in rg.nodes(): chosen_node = int(search(r'\d+', node).group()) location = return_node_location(chosen_node) circle1 = plt.Circle((location[0]*distance+step*location[2], location[1]*distance+step*location[2]), radius=35, color='#8ABDFF', fill=False, lw=line_width) plt.gca().add_patch(circle1) circle2 = plt.Circle((location[0]*distance+step*location[2]+45, location[1]*distance+step*location[2]-50), radius=10, color='#FF878B', fill=False, lw=line_width) plt.gca().add_patch(circle2) plt.text(location[0]*distance+step*location[2]-30, location[1]*distance+step*location[2]+30, str(chosen_node), fontsize=45) offset_x = 0 offset_y = 0 if 'N' in node: offset_y += 30 if 'I'in node: color_list.append('#CFECFF') offset_x += 12 else: color_list.append('#FF878B') offset_x -= 12 elif 'S' in node: offset_y -= 30 if 'I'in node: color_list.append('#CFECFF') offset_x -= 12 else: color_list.append('#FF878B') offset_x += 12 elif 'W' in node: offset_x -= 30 if 'I'in node: color_list.append('#CFECFF') offset_y += 12 else: color_list.append('#FF878B') offset_y -= 12 elif 'E' in node: offset_x += 30 if 'I'in node: color_list.append('#CFECFF') offset_y -= 12 else: color_list.append('#FF878B') offset_y += 12 if 'L' in node: if 'I'in node: color_list.append('#CFECFF') offset_x += 44 offset_y -= 56 else: color_list.append('#FF878B') offset_x += 48 offset_y -= 48 if 'U' in node: offset_y = 16 if 'I'in node: color_list.append('#CFECFF') offset_x -= 15 else: color_list.append('#FF878B') offset_x += 15 if 'D' in node: offset_y = -16 if 'I'in node: color_list.append('#CFECFF') offset_x -= 15 else: color_list.append('#FF878B') offset_x += 15 pos[node] = [location[0]*distance+offset_x+step*location[2], location[1]*distance+offset_y+step*location[2]] draw(rg, pos, with_labels=False, arrows=False, node_size=140, node_color=color_list, linewidths=line_width, width=line_width) plt.text(0, -100, 'X', fontsize=15) plt.text(-100, 0, 'Y', fontsize=15) plt.text(-45, -45, 'Z', fontsize=15) plt.gca().add_patch(patches.Arrow(-100, -100, 100, 0, width=10)) plt.gca().add_patch(patches.Arrow(-100, -100, 50, 50, width=10)) plt.gca().add_patch(patches.Arrow(-100, -100, 0, 100, width=10)) plt.savefig("GraphDrawings/RG.png", dpi=100) plt.clf() print ("\033[35m* VIZ::\033[0mROUTING GRAPH DRAWING CREATED AT: GraphDrawings/RG.png") return None
def draw_rg(rg): """ draws routing graph in GraphDrawings/RG.png :param rg: routing graph :return: None """ print("===========================================") print("GENERATING ROUTING GRAPH VISUALIZATION...") line_width = 2 pos = {} color_list = [] plt.figure(figsize=(10 * Config.ag.x_size, 10 * Config.ag.y_size)) distance = 100 * Config.ag.z_size step = (distance * 0.8) / Config.ag.z_size for node in rg.nodes(): chosen_node = int(search(r'\d+', node).group()) location = return_node_location(chosen_node) circle1 = plt.Circle((location[0] * distance + step * location[2], location[1] * distance + step * location[2]), radius=35, color='#8ABDFF', fill=False, lw=line_width) plt.gca().add_patch(circle1) circle2 = plt.Circle( (location[0] * distance + step * location[2] + 45, location[1] * distance + step * location[2] - 50), radius=10, color='#FF878B', fill=False, lw=line_width) plt.gca().add_patch(circle2) plt.text(location[0] * distance + step * location[2] - 30, location[1] * distance + step * location[2] + 30, str(chosen_node), fontsize=45) offset_x = 0 offset_y = 0 if 'N' in node: offset_y += 30 if 'I' in node: color_list.append('#CFECFF') offset_x += 12 else: color_list.append('#FF878B') offset_x -= 12 elif 'S' in node: offset_y -= 30 if 'I' in node: color_list.append('#CFECFF') offset_x -= 12 else: color_list.append('#FF878B') offset_x += 12 elif 'W' in node: offset_x -= 30 if 'I' in node: color_list.append('#CFECFF') offset_y += 12 else: color_list.append('#FF878B') offset_y -= 12 elif 'E' in node: offset_x += 30 if 'I' in node: color_list.append('#CFECFF') offset_y -= 12 else: color_list.append('#FF878B') offset_y += 12 if 'L' in node: if 'I' in node: color_list.append('#CFECFF') offset_x += 44 offset_y -= 56 else: color_list.append('#FF878B') offset_x += 48 offset_y -= 48 if 'U' in node: offset_y = 16 if 'I' in node: color_list.append('#CFECFF') offset_x -= 15 else: color_list.append('#FF878B') offset_x += 15 if 'D' in node: offset_y = -16 if 'I' in node: color_list.append('#CFECFF') offset_x -= 15 else: color_list.append('#FF878B') offset_x += 15 pos[node] = [ location[0] * distance + offset_x + step * location[2], location[1] * distance + offset_y + step * location[2] ] draw(rg, pos, with_labels=False, arrows=False, node_size=140, node_color=color_list, linewidths=line_width, width=line_width) plt.text(0, -100, 'X', fontsize=15) plt.text(-100, 0, 'Y', fontsize=15) plt.text(-45, -45, 'Z', fontsize=15) plt.gca().add_patch(patches.Arrow(-100, -100, 100, 0, width=10)) plt.gca().add_patch(patches.Arrow(-100, -100, 50, 50, width=10)) plt.gca().add_patch(patches.Arrow(-100, -100, 0, 100, width=10)) plt.savefig("GraphDrawings/RG.png", dpi=100) plt.clf() print( "\033[35m* VIZ::\033[0mROUTING GRAPH DRAWING CREATED AT: GraphDrawings/RG.png" ) return None
def test_is_destination_reachable_from_source(self): initial_config_ag = deepcopy(Config.ag) initial_turn_model = Config.UsedTurnModel initial_routing_type = Config.RotingType Config.ag.type = "Generic" Config.ag.topology = "2DMesh" Config.ag.x_size = 3 Config.ag.y_size = 3 Config.ag.z_size = 1 for turn_model in PackageFile.routing_alg_list_2d: Config.UsedTurnModel = deepcopy(turn_model) Config.TurnsHealth = deepcopy(Config.setup_turns_health()) ag_4_test = deepcopy(generate_ag(logging=None)) shmu_4_test = SystemHealthMonitoringUnit.SystemHealthMonitoringUnit( ) shmu_4_test.setup_noc_shm(ag_4_test, Config.TurnsHealth, False) noc_rg = generate_noc_route_graph(ag_4_test, shmu_4_test, turn_model, False, False) for source_node in ag_4_test.nodes(): for destination_node in ag_4_test.nodes(): if source_node != destination_node: self.assertEqual( is_destination_reachable_from_source( noc_rg, source_node, destination_node), True) s_x, s_y, s_z = return_node_location(source_node) d_x, d_y, d_z = return_node_location(destination_node) # is_destination_reachable_via_port checks output ports only self.assertEqual( is_destination_reachable_via_port( noc_rg, source_node, 'L', destination_node, False), False) if turn_model == PackageFile.XY_TurnModel: if s_x > d_x: self.assertEqual( is_destination_reachable_via_port( noc_rg, source_node, 'W', destination_node, False), True) if s_x < d_x: self.assertEqual( is_destination_reachable_via_port( noc_rg, source_node, 'E', destination_node, False), True) if s_x == d_x: if s_y < d_y: self.assertEqual( is_destination_reachable_via_port( noc_rg, source_node, 'N', destination_node, False), True) else: self.assertEqual( is_destination_reachable_via_port( noc_rg, source_node, 'S', destination_node, False), True) del ag_4_test del shmu_4_test del noc_rg Config.ag.type = "Generic" Config.ag.topology = "3DMesh" Config.ag.x_size = 3 Config.ag.y_size = 3 Config.ag.z_size = 3 Config.RotingType = "MinimalPath" for turn_model in PackageFile.routing_alg_list_3d: Config.UsedTurnModel = deepcopy(turn_model) Config.TurnsHealth = deepcopy(Config.setup_turns_health()) ag_4_test = deepcopy(generate_ag(logging=None)) shmu_4_test = SystemHealthMonitoringUnit.SystemHealthMonitoringUnit( ) shmu_4_test.setup_noc_shm(ag_4_test, Config.TurnsHealth, False) noc_rg = generate_noc_route_graph(ag_4_test, shmu_4_test, turn_model, False, False) for source_node in ag_4_test.nodes(): for destination_node in ag_4_test.nodes(): if source_node != destination_node: self.assertEqual( is_destination_reachable_from_source( noc_rg, source_node, destination_node), True) # todo: check is_destination_reachable_via_port del ag_4_test del shmu_4_test del noc_rg Config.ag = deepcopy(initial_config_ag) Config.UsedTurnModel = initial_turn_model Config.TurnsHealth = deepcopy(Config.setup_turns_health()) Config.RotingType = initial_routing_type