def fmap_inputs(dut): drv = EBPCEncoderDriver(dut, TA, TT) sb = EBPCEncoderScoreboard(dut, BLOCK_SIZE, DATA_W, MAX_ZRLE_LEN) mon = EBPCEncoderMonitor(dut, sb, TA, TT) inputs, bpc_len, znz_len = sb.gen_fmap_stimuli(model=MODEL, dataset_path=IMAGE_LOCATION, num_batches=NUM_BATCHES, batch_size=BATCHSIZE, fmap_frac=FMAP_FRAC) print('Compression Ratio: {}'.format((bpc_len + znz_len) / len(inputs))) drv.apply_defaults() cocotb.fork(Clock(dut.clk_i, CLOCK_PERIOD).start()) yield reset_dut(dut.rst_ni, RESET_TIME) dut._log.info("Reset Done!") yield wait_cycles(dut.clk_i, 4) mon.start() bpc_read_task = cocotb.fork( drv.read_bpc_outputs(len(inputs) * 2, tmin=0, tmax=0)) znz_read_task = cocotb.fork( drv.read_znz_outputs(len(inputs) * 2, tmin=0, tmax=0)) cocotb.fork(drv.drive_input(inputs, tmin=0, tmax=0)) yield mon.wait_done() bpc_read_task.kill() znz_read_task.kill() mon.stop() yield wait_cycles(dut.clk_i, 4) if sb.report(): raise TestFailure("Scoreboard reported problems - check log!")
def random_inputs_only(dut): num_blocks = 200 drv = BPCDecoderDriver(dut, TA, TT) vals = random_vals(num_blocks * BLOCK_SIZE, DATA_W) vals = int_list_to_binval_list(vals, DATA_W, True) cocotb.fork(Clock(dut.clk_i, CLOCK_PERIOD).start()) yield reset_dut(dut.rst_ni, RESET_TIME) yield wait_cycles(dut.clk_i, 4) cocotb.fork(drv.read_outputs(1000000, 0, 5)) yield drv.drive_input(vals, 0, 5) yield Timer(10000) dut._log.info( "The assertion errors are bound to happen, as the inputs do not amount to a sensible encoding! No worries here :^)" )
def random_blocks(dut): drv = BPCDecoderDriver(dut, TA, TT) sb = BPCDecoderScoreboard(dut, BLOCK_SIZE, DATA_W, NUM_BLOCKS, STIM_REPORT_FILE, STIM_DBG_FILE) mon = BPCDecoderMonitor(dut, sb) encoded_vals = sb.gen_rand_stimuli() cocotb.fork(Clock(dut.clk_i, CLOCK_PERIOD).start()) yield reset_dut(dut.rst_ni, RESET_TIME) yield wait_cycles(dut.clk_i, 4) cocotb.fork(drv.drive_input(encoded_vals, 0, 5)) mon.start() yield drv.read_outputs(NUM_BLOCKS * BLOCK_SIZE, 0, 5) yield Timer(1000) yield wait_cycles(dut.clk_i, 1) drv.clear() mon.stop() if sb.report(): raise TestFailure("Scoreboard reported problems - check log!")
def random_inputs(dut): drv = BPCEncoderDriver(dut, TA, TT) sb = BPCEncoderScoreboard(dut, BLOCK_SIZE, DATA_W, stim_report_file=STIM_REPORT_FILE) mon = BPCEncoderMonitor(dut, BLOCK_SIZE, DATA_W, sb) num_input_blocks = 1000 input_vals = [BinaryValue(n_bits=DATA_W, bigEndian=False, value=random.randint(-2**(DATA_W-1), 2**(DATA_W-1)-1), binaryRepresentation=2) for k in range(BLOCK_SIZE*num_input_blocks)] flush = [0] * (len(input_vals)-1) flush.append(1) cocotb.fork(Clock(dut.clk_i, CLOCK_PERIOD).start()) drv.apply_defaults() yield reset_dut(dut.rst_ni, RESET_TIME) dut._log.info("Reset Done!") for k in range(4): yield RisingEdge(dut.clk_i) mon.start() read_task = cocotb.fork(drv.read_outputs(len(input_vals)*2, tmin=0, tmax=0)) yield drv.drive_input(zip(input_vals, flush), tmin=0, tmax=0) yield Timer(4*CLOCK_PERIOD*len(input_vals)) read_task.kill() mon.stop() if sb.report(): raise TestFailure("Scoreboard reported problems - check log!")
def all_zeros(dut): drv = EBPCEncoderDriver(dut, TA, TT) sb = EBPCEncoderScoreboard(dut, BLOCK_SIZE, DATA_W, MAX_ZRLE_LEN) mon = EBPCEncoderMonitor(dut, sb, TA, TT) inputs = sb.gen_zero_stimuli(4000) drv.apply_defaults() cocotb.fork(Clock(dut.clk_i, CLOCK_PERIOD).start()) yield reset_dut(dut.rst_ni, RESET_TIME) dut._log.info("Reset Done!") yield wait_cycles(dut.clk_i, 4) mon.start() bpc_read_task = cocotb.fork( drv.read_bpc_outputs(len(inputs) * 2, tmin=0, tmax=0)) znz_read_task = cocotb.fork( drv.read_znz_outputs(len(inputs) * 2, tmin=0, tmax=0)) cocotb.fork(drv.drive_input(inputs, tmin=0, tmax=0)) yield mon.wait_done() bpc_read_task.kill() znz_read_task.kill() mon.stop() yield wait_cycles(dut.clk_i, 4) if sb.report(): raise TestFailure("Scoreboard reported problems - check log!")
def random_inputs_with_last(dut): drv = EBPCDecoderDriver(dut, TA, TT) sb = EBPCDecoderScoreboard(dut, BLOCK_SIZE, DATA_W, MAX_ZRLE_LEN) mon = EBPCDecoderMonitor(dut, sb) bpc_in, znz_in = sb.gen_rand_stimuli(NUM_WORDS, 10, 0.2) bpc_last_in = [0] * (len(bpc_in) - 1) + [1] znz_last_in = [0] * (len(znz_in) - 1) + [1] drv.apply_defaults() cocotb.fork(Clock(dut.clk_i, CLOCK_PERIOD).start()) yield reset_dut(dut.rst_ni, RESET_TIME) yield wait_cycles(dut.clk_i, 4) mon.start() num_words_feed_task = cocotb.fork(drv.write_num_words( NUM_WORDS - 1, 0, 50)) bpc_feed_task = cocotb.fork(drv.drive_bpc(bpc_in, bpc_last_in, 0, 0)) znz_feed_task = cocotb.fork(drv.drive_znz(znz_in, znz_last_in, 0, 0)) yield drv.read_outputs(100000000, 0, 0) bpc_feed_task.kill() znz_feed_task.kill() num_words_feed_task.kill() mon.stop() if sb.report(): raise TestFailure("Scoreboard reported problems - check log!")
def basic_bringup(dut): cocotb.fork(Clock(dut.clk_i, CLOCK_PERIOD).start()) yield reset_dut(dut.rst_ni, RESET_TIME) yield Timer(10000)