| # Copyright 2020 Project U-Ray Authors |
| # |
| # Licensed under the Apache License, Version 2.0 (the "License"); |
| # you may not use this file except in compliance with the License. |
| # You may obtain a copy of the License at |
| # |
| # http://www.apache.org/licenses/LICENSE-2.0 |
| # |
| # Unless required by applicable law or agreed to in writing, software |
| # distributed under the License is distributed on an "AS IS" BASIS, |
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| # See the License for the specific language governing permissions and |
| # limitations under the License. |
| |
| import numpy as np |
| import sys |
| |
| bufgctrls_by_tile = {} |
| with open(sys.argv[1], "r") as tf: |
| for line in tf: |
| sl = line.strip().split(",") |
| if len(sl) < 4: |
| continue |
| for site in sl[4:]: |
| if ("BUFGCTRL" in site) and "HDIO" not in site: |
| if sl[2] not in bufgctrls_by_tile: |
| bufgctrls_by_tile[sl[2]] = [] |
| bufgctrls_by_tile[sl[2]].append(site.split(":")[0]) |
| |
| X = 10 |
| |
| root = sys.argv[2] |
| |
| for x in range(X): |
| buffers = [] |
| |
| tiles = list(sorted(bufgctrls_by_tile.keys())) |
| np.random.shuffle(tiles) |
| |
| def random_inversion(pins): |
| return ", ".join([".IS_%s_INVERTED(%d)" % (p, np.random.randint(2)) for p in pins]) |
| |
| def random_control(pins): |
| return ", ".join([".%s(aux[%d])" % (p, np.random.randint(10)) for p in pins]) |
| |
| with open(root + "/clkroute7/gclk_casc_%d.v" % x, "w") as f: |
| print("module top(input [9:0] aux, output o);", file=f) |
| |
| for tile in tiles: |
| print("", file=f) |
| if np.random.randint(0, 3) == 0: |
| continue |
| sorted_bufgs = list(sorted(bufgctrls_by_tile[tile], key=lambda x: int(x[x.rfind('Y')+1:]))) |
| bufg_used = [np.random.choice([True, True, False]) for i in range(8)] |
| print("(* KEEP, DONT_TOUCH *) wire [7:0] %s_o;" % tile, file=f) |
| for i, loc in enumerate(sorted_bufgs): |
| if not bufg_used[i]: |
| continue |
| def get_inp(d): |
| if d == 0: |
| return "" |
| elif d == -1: |
| x = 7 if i == 0 else (i-1) |
| elif d == 1: |
| x = 0 if i == 7 else (i+1) |
| if bufg_used[x]: |
| return "%s_o[%d]" % (tile, x) |
| else: |
| return "" |
| i0 = get_inp(np.random.choice([-1, 0, +1])) |
| i1 = get_inp(np.random.choice([-1, 0, +1])) |
| print(" (* KEEP, DONT_TOUCH, LOC=\"%s\" *)" % loc, file=f) |
| print(" BUFGCTRL #(", file=f) |
| print(" %s," % random_inversion(["I0", "I1", "S0", "S1", "CE0", "CE1", "IGNORE0", "IGNORE1"]), file=f) |
| print(" .INIT_OUT(0), .PRESELECT_I0(\"TRUE\"), .PRESELECT_I1(\"FALSE\")", file=f) |
| print(" ) bufgctrl_%s_%d (" % (tile, i), file=f) |
| print(" .I0(%s), .I1(%s), " % (i0, i1), file=f) |
| print(" %s," % random_control(["S0", "S1", "CE0", "CE1", "IGNORE0", "IGNORE1"]), file=f) |
| print(" .O(%s_o[%d])" % (tile, i), file=f) |
| print(" );", file=f) |
| print("endmodule", file=f) |
| with open(root + "/clkroute7/gclk_casc_%d.tcl" % x, "w") as f: |
| print("add_files %s" % (root + ("/clkroute7/gclk_casc_%d.v" % x)), file=f) |
| #print("read_xdc %s" % (root + ("/clkroute7/gclk_casc_%d.xdc" % x)), file=f) |
| print("synth_design -top top -part xczu7ev-ffvc1156-2-e", file=f) |
| print("# set_property CLOCK_DEDICATED_ROUTE FALSE [get_nets]", file=f) |
| print("opt_design", file=f) |
| print("place_design", file=f) |
| print("route_design", file=f) |
| print("set_property SEVERITY {Warning} [get_drc_checks NSTD-1]", file=f) |
| print("set_property SEVERITY {Warning} [get_drc_checks UCIO-1]", file=f) |
| print("set_property BITSTREAM.GENERAL.PERFRAMECRC YES [current_design]", file=f) |
| print("write_checkpoint -force %s/specimen_clk/gclk_casc_%d.dcp" % (root, x), file=f) |
| print("write_edif -force %s/specimen_clk/gclk_casc_%d.edf" % (root, x), file=f) |
| print("write_bitstream -force %s/specimen_clk/gclk_casc_%d.bit" % (root, x), file=f) |
| with open(root + "/clkroute7/run.sh", "w") as f: |
| print("#/usr/bin/env bash", file=f) |
| #print("set -ex", file=f) |
| for x in range(X): |
| print("vivado -mode batch -nolog -nojournal -source gclk_casc_%d.tcl" % x, file=f) |
| print("if [ $? -eq 0 ]; then", file=f) |
| print(" ../../ultra/tools/dump_bitstream %s/specimen_clk/gclk_casc_%d.bit %s/frames.txt > %s/specimen_clk/gclk_casc_%d.dump" % (root, x, root, root, x), file=f) |
| print(" python3 ../../ultra/tools/bits_to_tiles.py %s/tilebits.json %s/specimen_clk/gclk_casc_%d.dump > %s/specimen_clk/gclk_casc_%d.tbits" % (root, root, x, root, x), file=f) |
| print("else", file=f) |
| print(" rm %s/specimen_clk/gclk_casc_%d.dump" % (root, x), file=f) |
| print(" rm %s/specimen_clk/gclk_casc_%d.tbits" % (root, x), file=f) |
| print(" rm %s/specimen_clk/gclk_casc_%d.dcp" % (root, x), file=f) |
| print(" rm %s/specimen_clk/gclk_casc_%d.bit" % (root, x), file=f) |
| print(" rm %s/specimen_clk/gclk_casc_%d.features" % (root, x), file=f) |
| print("fi", file=f) |