def asap_scheduling(tg, ag, shm, report, logging=None): """ :param tg: Task Graph :param ag: Architecture Graph :param shm: System Health Map :param report: report Switch :param logging: logging file :return: None """ if logging is not None: logging.info("STARTING ASAP SCHEDULING ...") max_distance = TG_Functions.calculate_max_distance(tg) + 1 for distance in range(0, max_distance): for task in tg.nodes(): if tg.node[task]['task'].type == 'App': if tg.node[task]['task'].distance == distance: node = tg.node[task]['task'].node # logging.info("\tSCHEDULING TASK "+str(task)+" ON NODE:"+str(node)) (start_time, end_time) = find_task_asap_scheduling(tg, ag, shm, task, node, logging) add_tg_task_to_node(tg, ag, task, node, start_time, end_time, None) for edge in tg.edges(): if edge[0] == task: destination_node = tg.node[edge[1]]['task'].node if len(tg.edge[edge[0]][edge[1]]['Link']) > 0: for batch_and_link in tg.edge[edge[0]][edge[1]]['Link']: batch = batch_and_link[0] link = batch_and_link[1] probability = batch_and_link[2] # logging.info("\tSCHEDULING EDGE "+str(edge)+" ON Router: "+str(link) + # " FROM BATCH: "+str(batch)) (start_time, end_time) = find_edge_asap_scheduling_router(tg, ag, edge, link[0], batch, probability, report, logging) add_tg_edge_to_router(ag, edge, link[0], batch, probability, start_time, end_time, logging) # logging.info("\tSCHEDULING EDGE "+str(edge)+" ON LINK: "+str(link) + # " FROM BATCH: "+str(batch)) (start_time, end_time) = find_edge_asap_scheduling_link(tg, ag, edge, link, batch, probability, report, logging) add_tg_edge_to_link(ag, edge, link, batch, probability, start_time, end_time, logging) if destination_node == link[1]: # logging.info("\tSCHEDULING EDGE "+str(edge)+" ON Router: "+str(link) + # " FROM BATCH: "+str(batch)) (start_time, end_time) = find_edge_asap_scheduling_router(tg, ag, edge, link[1], batch, probability, report, logging) add_tg_edge_to_router(ag, edge, link[1], batch, probability, start_time, end_time, logging) if logging is not None: logging.info("DONE ASAP SCHEDULING...") return None
def asap_scheduling(tg, ag, shm, report, logging=None): """ :param tg: Task Graph :param ag: Architecture Graph :param shm: System Health Map :param report: report Switch :param logging: logging file :return: None """ if logging is not None: logging.info("STARTING ASAP SCHEDULING ...") max_distance = TG_Functions.calculate_max_distance(tg) + 1 for distance in range(0, max_distance): for task in tg.nodes(): if tg.node[task]['task'].type == 'App': if tg.node[task]['task'].distance == distance: node = tg.node[task]['task'].node # logging.info("\tSCHEDULING TASK "+str(task)+" ON NODE:"+str(node)) (start_time, end_time) = find_task_asap_scheduling(tg, ag, shm, task, node, logging) add_tg_task_to_node(tg, ag, task, node, start_time, end_time, None) for edge in tg.edges(): if edge[0] == task: destination_node = tg.node[edge[1]]['task'].node if len(tg.edges[edge]['Link']) > 0: for batch_and_link in tg.edges[edge]['Link']: batch = batch_and_link[0] link = batch_and_link[1] probability = batch_and_link[2] # logging.info("\tSCHEDULING EDGE "+str(edge)+" ON Router: "+str(link) + # " FROM BATCH: "+str(batch)) (start_time, end_time) = find_edge_asap_scheduling_router(tg, ag, edge, link[0], batch, probability, report, logging) add_tg_edge_to_router(ag, edge, link[0], batch, probability, start_time, end_time, logging) # logging.info("\tSCHEDULING EDGE "+str(edge)+" ON LINK: "+str(link) + # " FROM BATCH: "+str(batch)) (start_time, end_time) = find_edge_asap_scheduling_link(tg, ag, edge, link, batch, probability, report, logging) add_tg_edge_to_link(ag, edge, link, batch, probability, start_time, end_time, logging) if destination_node == link[1]: # logging.info("\tSCHEDULING EDGE "+str(edge)+" ON Router: "+str(link) + # " FROM BATCH: "+str(batch)) (start_time, end_time) = find_edge_asap_scheduling_router(tg, ag, edge, link[1], batch, probability, report, logging) add_tg_edge_to_router(ag, edge, link[1], batch, probability, start_time, end_time, logging) if logging is not None: logging.info("DONE ASAP SCHEDULING...") return None
def draw_task_graph(tg, ttg=None): print("DRAWING TASK GRAPH...") plt.figure() node_colors = [] for Node in tg.nodes(): if tg.node[Node]['task'].criticality == 'H': node_colors.append('#FF878B') elif tg.node[Node]['task'].criticality == 'GH': node_colors.append('#FFC29C') elif tg.node[Node]['task'].criticality == 'GNH': node_colors.append('#928AFF') else: node_colors.append('#A0CBE2') edge_colors = [] for Edge in tg.edges(): if tg.edges[Edge]['Criticality'] == 'H': edge_colors.append('red') else: edge_colors.append('black') tg_edge_list = [] tg_edge_weight = [] for Edge in tg.edges(): tg_edge_list.append(Edge) tg_edge_weight.append(tg.edges[Edge]['ComWeight']) if Config.tg.type == "RandomIndependent": pos = networkx.shell_layout(tg) else: width = 1000 height = 10000 pos = {} max_distance = TG_Functions.calculate_max_distance(tg) for current_distance in range(0, max_distance + 1): num_tasks_with_same_distance = 0 for node in tg.nodes(): if tg.node[node]['task'].type == 'App': distance = tg.node[node]['task'].distance if current_distance == distance: num_tasks_with_same_distance += 1 counter = 0 for node in tg.nodes(): if tg.node[node]['task'].type == 'App': distance = tg.node[node]['task'].distance if current_distance == distance: counter += 1 pos[node] = (counter * (width / num_tasks_with_same_distance) + width, (max_distance - current_distance) * height / max_distance) if ttg is not None: temp_pos = networkx.shell_layout(ttg) for test_node in tg.nodes(): if tg.node[test_node]['task'].type == 'Test': pos[test_node] = [ temp_pos[test_node][0] * (width / 2) + width / 2, temp_pos[test_node][1] * (height / 2) + height / 2 ] networkx.draw_networkx_nodes(tg, pos, with_labels=True, node_color=node_colors, node_size=50) networkx.draw_networkx_edges(tg, pos, edge_color=tg_edge_weight, edge_cmap=plt.cm.Reds, width=3, arrows=False) networkx.draw_networkx_edges(tg, pos, arrows=False, width=0.5) networkx.draw_networkx_labels(tg, pos, font_size=4) # networkx.draw_networkx_edge_labels(TG, pos, edge_labels=dict(zip(tg_edge_list, tg_edge_weight)), # font_size=10, label_pos=0.7) if ttg is None: plt.savefig("GraphDrawings/TG.png", dpi=200, bbox_inches='tight') else: plt.savefig("GraphDrawings/TG_And_TTG.png", dpi=200, bbox_inches='tight') plt.clf() print( "\033[35m* VIZ::\033[0mTASK GRAPH DRAWINGS CREATED AT: GraphDrawings/TG.png" ) return None