def main(): if len(sys.argv) != 4: print("Usage:", sys.argv[0], "<cgra_info.txt>", "<netlist.json>", "<netlist.route>", file=sys.stderr) exit(1) cgra_file = sys.argv[1] netlist = sys.argv[2] route_file = sys.argv[3] packed_file = route_file.replace(".route", ".packed") placement_file = route_file.replace(".route", ".place") board_layout = parse_cgra(cgra_file)["CGRA"] routing_result = parse_routing(route_file) placement, _ = parse_placement(placement_file) if hasattr(sys.stdout, 'isatty') and sys.stdout.isatty(): meta = os.popen('stty size', 'r').read().split() cols = int(meta[-1]) cols = int(cols) scale = cols - 15 else: scale = 68 cols = 80 print("-" * cols) print("Area Usage:") usage = compute_area_usage(placement, board_layout) for entry in usage: percentage = usage[entry][0] / usage[entry][1] * 100 num_bar = max(int(percentage / 100 * scale) - 2, 1) print("{0:4s} {1} {2} {3:.2f}%".format(entry.upper(), num_bar * '█', ' ' * (scale - num_bar - 2), percentage)) print("-" * cols) net_wire = compute_total_wire(routing_result) total_wire = sum([net_wire[x] for x in net_wire]) print("Total wire:", total_wire) # timing removed for future development print("-" * cols) r = parse_routing_resource(cgra_file) routing_resource = build_routing_resource(r) resource_usage = compute_routing_usage(routing_result, routing_resource) for bus in resource_usage: print("BUS:", bus) for track in resource_usage[bus]: total, left = resource_usage[bus][track] percentage = (total - left) / total * 100 num_bar = int(percentage / 100 * scale) print("TRACK {0} {1} {2} {3:.2f}%".format( track, num_bar * '█', ' ' * (scale - num_bar - 5), percentage))
def __init__(self, cgra_filename, board_meta, packed_filename, placement_filename, use_tie_breaker=False, fold_reg=True, channel_width=None): self.board_meta = board_meta self.layout_board = board_meta[0] netlists, _, id_to_name, _, track_mode = load_packed_file( packed_filename, load_track_mode=True) self.id_to_name = id_to_name self.netlists = netlists self.track_mode = track_mode placement, _ = parse_placement(placement_filename) self.placement = placement board_info = board_meta[-1] width = board_info["width"] height = board_info["height"] self.margin = board_info["margin"] # NOTE: it's width x height self.board_size = (width, height) # whether to fold registers when do routing self.fold_reg = fold_reg # result self.route_result = {} print("Building routing resurce") r = parse_routing_resource(cgra_filename) self.routing_resource = build_routing_resource(r) self.use_tie_breaker = use_tie_breaker base_filename = os.path.basename(packed_filename) design_name, _ = os.path.splitext(base_filename) self.design_name = design_name if channel_width is not None: self.channel_width = channel_width else: # loop through the routing resource to figure out the channel width # automatically channel_set = set() for pos in self.routing_resource: chans = self.routing_resource[pos]["route_resource"] for entry in chans: channel_set.add(entry[0][-1]) self.channel_width = len(channel_set) print("Using", self.channel_width, "channels to route")
def main(): parser = ArgumentParser("CGRA graph creation") parser.add_argument("-i", "--input", help="CGRA info file", required=True, action="store", dest="cgra_filename") parser.add_argument("-o", "--output", help="Graph output folder for " "cyclone router", required=True, action="store", dest="graph_dirname") parser.add_argument("-O", "--override", help="Override the existing one " "if the output file exists", required=False, default=False, action="store_true", dest="override_graph") args = parser.parse_args() cgra_filename = args.cgra_filename graph_dirname = args.graph_dirname override_graph = args.override_graph # if the directory doesn't exit, create one if not os.path.isdir(graph_dirname): print("creating folder", graph_dirname) os.mkdir(graph_dirname) g_16_filename = os.path.join(graph_dirname, GRAPH_16) g_1_filename = os.path.join(graph_dirname, GRAPH_1) if os.path.isfile(g_16_filename) and not override_graph: print("found existing", g_16_filename, "skipped.") exit(0) elif os.path.isfile(g_16_filename): print("override existing graph file") layout = parse_cgra(cgra_filename)["CGRA"] raw_routing_resource = parse_routing_resource(cgra_filename) routing_resource = build_routing_resource(raw_routing_resource) g_1, g_16 = build_routing_graph(routing_resource, layout) pycyclone.io.dump_routing_graph(g_16, g_16_filename) pycyclone.io.dump_routing_graph(g_1, g_1_filename) print("graph saved to", g_1_filename, g_16_filename)
def main(): if len(sys.argv) != 4: print("Usage:", sys.argv[0], "<cgra_info.txt>", "<netlist.json>", "<netlist.route>", file=sys.stderr) exit(1) cgra_file = sys.argv[1] netlist = sys.argv[2] route_file = sys.argv[3] packed_file = route_file.replace(".route", ".packed") placement_file = route_file.replace(".route", ".place") board_meta = parse_cgra(cgra_file)["CGRA"] routing_result = parse_routing_result(route_file) placement, _ = parse_placement(placement_file) if hasattr(sys.stdout, 'isatty') and sys.stdout.isatty(): meta = os.popen('stty size', 'r').read().split() cols = int(meta[-1]) cols = int(cols) scale = cols - 15 else: scale = 68 cols = 80 # print("Latency:") # print("Total:", total_time) # latency_info = compute_latency(net_path, routing_result, placement) # total_time = sum([latency_info[key] for key in latency_info]) # for entry in latency_info: # time = latency_info[entry] # percentage = int(time / total_time * 100) # num_bar = int(percentage / (100 / scale)) # s = "{0:4s} {1} {2} {3}".format(entry.upper(), # num_bar * '█', ' ' * (scale - num_bar), # time) # print(s) print("-" * cols) print("Area Usage:") usage = compute_area_usage(placement, board_meta[0]) for entry in usage: percentage = usage[entry][0] / usage[entry][1] * 100 num_bar = int(percentage / 100 * scale) print("{0:4s} {1} {2} {3:.2f}%".format(entry.upper(), num_bar * '█', ' ' * (scale - num_bar - 2), percentage)) print("-" * cols) net_wire = compute_total_wire(routing_result) total_wire = sum([net_wire[x] for x in net_wire]) print("Total wire:", total_wire) print("-" * cols) total_delay, detailed_delay = find_critical_path_delay(netlist, packed_file, routing_result, placement) print("Critical Path:") clock_speed = 1e6 / total_delay total_delay_formatted = "{:.2f} ns".format(total_delay / 1000) print("Delay:", total_delay_formatted, "Max Clock Speed:", "{0:.2f} MHz".format(clock_speed)) delay_keys = list(detailed_delay.keys()) delay_keys.sort(key=lambda x: detailed_delay[x], reverse=True) for entry in delay_keys: percentage = detailed_delay[entry] / total_delay * 100 num_bar = int(percentage / 100 * scale) print("{0:4s} {1} {2} {3:.2f}%".format(entry.upper(), num_bar * '█', ' ' * (scale - num_bar - 2), percentage)) print("-" * cols) r = parse_routing_resource(cgra_file) routing_resource = build_routing_resource(r) resource_usage = compute_routing_usage(routing_result, routing_resource, board_meta[0]) for bus in resource_usage: print("BUS:", bus) for track in resource_usage[bus]: left = 0 total = 0 for _, l, t in resource_usage[bus][track]: left += l total += t percentage = (total - left) / total * 100 num_bar = int(percentage / 100 * scale) print("TRACK {0} {1} {2} {3:.2f}%".format(track, num_bar * '█', ' ' * (scale - num_bar - 5), percentage))