blob: af93e6425887acc6faa505ef835fb12599129ae3 [file]
# 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
X = 12
N = 60
root = sys.argv[2]
def random_vector(size):
return "{%s}" % ", ".join(["d[%d]" % np.random.randint(40) for k in range(size)])
for x in range(X):
with open(root + "/uram/uram%d.v" % x, "w") as f:
print("module top(input [7:0] clk, cen, rst, input [39:0] d, input [7:0] sel, output [63:0] q);", file=f)
print(" wire [8:0] r = {1'b0, rst}, e = {1'b1, cen};", file=f)
print(" wire [63:0] int_q[0:%d];" % (N-1), file=f)
for i in range(N):
print(" (* KEEP, DONT_TOUCH *)", file=f)
print(" URAM288 #(", file=f)
print(" .AUTO_SLEEP_LATENCY(%d)," % np.random.randint(3, 16), file=f)
print(" .BWE_MODE_A(\"%s\")," % np.random.choice(["PARITY_INTERLEAVED", "PARITY_INDEPENDENT"]), file=f)
print(" .BWE_MODE_B(\"%s\")," % np.random.choice(["PARITY_INTERLEAVED", "PARITY_INDEPENDENT"]), file=f)
print(" .EN_AUTO_SLEEP_MODE(\"%s\")," % np.random.choice(["FALSE", "TRUE"]), file=f)
print(" .EN_ECC_RD_A(\"%s\")," % np.random.choice(["FALSE", "TRUE"]), file=f)
print(" .EN_ECC_RD_B(\"%s\")," % np.random.choice(["FALSE", "TRUE"]), file=f)
print(" .EN_ECC_WR_A(\"%s\")," % np.random.choice(["FALSE", "TRUE"]), file=f)
print(" .EN_ECC_WR_B(\"%s\")," % np.random.choice(["FALSE", "TRUE"]), file=f)
print(" .IREG_PRE_A(\"%s\")," % np.random.choice(["FALSE", "TRUE"]), file=f)
print(" .IREG_PRE_B(\"%s\")," % np.random.choice(["FALSE", "TRUE"]), file=f)
print(" .IS_CLK_INVERTED(%d)," % np.random.randint(2), file=f)
print(" .IS_EN_A_INVERTED(%d)," % np.random.randint(2), file=f)
print(" .IS_EN_B_INVERTED(%d)," % np.random.randint(2), file=f)
print(" .IS_RDB_WR_A_INVERTED(%d)," % np.random.randint(2), file=f)
print(" .IS_RDB_WR_B_INVERTED(%d)," % np.random.randint(2), file=f)
print(" .IS_RST_A_INVERTED(%d)," % np.random.randint(2), file=f)
print(" .IS_RST_B_INVERTED(%d)," % np.random.randint(2), file=f)
print(" .OREG_A(\"%s\")," % np.random.choice(["FALSE", "TRUE"]), file=f)
print(" .OREG_B(\"%s\")," % np.random.choice(["FALSE", "TRUE"]), file=f)
print(" .OREG_ECC_A(\"%s\")," % np.random.choice(["FALSE", "TRUE"]), file=f)
print(" .OREG_ECC_B(\"%s\")," % np.random.choice(["FALSE", "TRUE"]), file=f)
print(" .REG_CAS_A(\"%s\")," % np.random.choice(["FALSE", "TRUE"]), file=f)
print(" .REG_CAS_B(\"%s\")," % np.random.choice(["FALSE", "TRUE"]), file=f)
print(" .RST_MODE_A(\"%s\")," % np.random.choice(["SYNC", "ASYNC"]), file=f)
print(" .RST_MODE_B(\"%s\")," % np.random.choice(["SYNC", "ASYNC"]), file=f)
print(" .SELF_ADDR_A(11'd%d)," % np.random.randint(2**11), file=f)
print(" .SELF_ADDR_B(11'd%d)," % np.random.randint(2**11), file=f)
print(" .SELF_MASK_A(11'd%d)," % np.random.randint(2**11), file=f)
print(" .SELF_MASK_B(11'd%d)," % np.random.randint(2**11), file=f)
print(" .USE_EXT_CE_A(\"%s\")," % np.random.choice(["FALSE", "TRUE"]), file=f)
print(" .USE_EXT_CE_B(\"%s\")" % np.random.choice(["FALSE", "TRUE"]), file=f)
print(" ) uram_%d (" % i, file=f)
print(" .ADDR_A(%s)," % random_vector(23), file=f)
print(" .ADDR_B(%s)," % random_vector(23), file=f)
print(" .BWE_A(%s)," % random_vector(9), file=f)
print(" .BWE_B(%s)," % random_vector(9), file=f)
print(" .CLK(clk[%d])," % np.random.randint(8), file=f)
print(" .DIN_A(%s)," % random_vector(72), file=f)
print(" .DIN_B(%s)," % random_vector(72), file=f)
print(" .EN_A(e[%d])," % np.random.randint(9), file=f)
print(" .EN_B(e[%d])," % np.random.randint(9), file=f)
print(" .INJECT_DBITERR_A(%s)," % random_vector(1), file=f)
print(" .INJECT_DBITERR_B(%s)," % random_vector(1), file=f)
print(" .INJECT_SBITERR_A(%s)," % random_vector(1), file=f)
print(" .INJECT_SBITERR_B(%s)," % random_vector(1), file=f)
print(" .OREG_CE_A(e[%d])," % np.random.randint(9), file=f)
print(" .OREG_CE_B(e[%d])," % np.random.randint(9), file=f)
print(" .OREG_ECC_CE_A(e[%d])," % np.random.randint(9), file=f)
print(" .OREG_ECC_CE_B(e[%d])," % np.random.randint(9), file=f)
print(" .RDB_WR_A(%s)," % random_vector(1), file=f)
print(" .RDB_WR_B(%s)," % random_vector(1), file=f)
print(" .RST_A(r[%d])," % np.random.randint(9), file=f)
print(" .RST_B(r[%d])," % np.random.randint(9), file=f)
o_bit = np.random.randint(-1, 150)
if o_bit < 72:
print(" .DOUT_A({int_q[%d][0]%s})," % (i, ", {%d{1'bx}}" % o_bit if o_bit > 0 else ""), file=f)
elif o_bit < 144:
print(" .DOUT_A({int_q[%d][0]%s})," % (i, ", {%d{1'bx}}" % (o_bit-72) if o_bit > 72 else ""), file=f)
elif o_bit == 144:
print(" .RDACCESS_A(int_q[%d][0])," % i, file=f)
elif o_bit == 145:
print(" .RDACCESS_B(int_q[%d][0])," % i, file=f)
elif o_bit == 146:
print(" .DBITERR_A(int_q[%d][0])," % i, file=f)
elif o_bit == 147:
print(" .DBITERR_B(int_q[%d][0])," % i, file=f)
elif o_bit == 148:
print(" .SBITERR_A(int_q[%d][0])," % i, file=f)
elif o_bit == 149:
print(" .SBITERR_B(int_q[%d][0])," % i, file=f)
print(" .SLEEP(%s)" % random_vector(1), file=f)
print(");", file=f)
print(" assign q = int_q[sel];", file=f)
print("endmodule", file=f)
with open(root + "/uram/uram%d.tcl" % x, "w") as f:
print("add_files %s" % (root + ("/uram/uram%d.v" % x)), file=f)
print("synth_design -top top -part xczu7ev-ffvc1156-2-e", 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 SEVERITY {Warning} [get_drc_checks AVAL-*]", file=f)
print("set_property SEVERITY {Warning} [get_drc_checks REQP-*]", file=f)
print("set_property BITSTREAM.GENERAL.PERFRAMECRC YES [current_design]", file=f)
print("write_checkpoint -force %s/specimen_bram/uram%d.dcp" % (root, x), file=f)
print("write_edif -force %s/specimen_bram/uram%d.edf" % (root, x), file=f)
print("write_bitstream -force %s/specimen_bram/uram%d.bit" % (root, x), file=f)
with open(root + "/uram/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 uram%d.tcl" % x, file=f)
print("if [ $? -eq 0 ]; then", file=f)
print(" ../../ultra/tools/dump_bitstream %s/specimen_bram/uram%d.bit %s/frames.txt > %s/specimen_bram/uram%d.dump" % (root, x, root, root, x), file=f)
print(" python3 ../../ultra/tools/bits_to_tiles.py %s/tilebits.json %s/specimen_bram/uram%d.dump > %s/specimen_bram/uram%d.tbits" % (root, root, x, root, x), file=f)
print("else", file=f)
print(" rm %s/specimen_bram/uram%d.dump" % (root, x), file=f)
print(" rm %s/specimen_bram/uram%d.tbits" % (root, x), file=f)
print(" rm %s/specimen_bram/uram%d.dcp" % (root, x), file=f)
print(" rm %s/specimen_bram/uram%d.bit" % (root, x), file=f)
print(" rm %s/specimen_bram/uram%d.features" % (root, x), file=f)
print("fi", file=f)