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 write_num_words(self, n, tmin, tmax): # values: list of values to feed # tmin: minimum # of clock cycles to wait between input applications # tmax: maximum # of clock cycles to wait between applications assert self.rst_ni.value == 1, "BPCDecoderDriver Error: rst_ni is not high in write_num_words!" yield wait_cycles(self.clk_i, random.randint(tmin, tmax)) yield self.num_words_drv.write_input(n)
def drive_input(self, values, tmin, tmax): # values: list of values to feed # tmin: minimum # of clock cycles to wait between input applications # tmax: maximum # of clock cycles to wait between applications assert self.rst_ni.value == 1, "BPCDecoderDriver Error: rst_ni is not high in drive_input!" for val in values: yield wait_cycles(self.clk_i, random.randint(tmin,tmax)) yield self.bpc_i_drv.write_input(val)
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 drive_znz(self, values, last, tmin, tmax): # values: list of values to feed # last: list of 'last' bits to feed # tmin: minimum # of clock cycles to wait between input applications # tmax: maximum # of clock cycles to wait between applications assert self.rst_ni.value == 1, "BPCDecoderDriver Error: rst_ni is not high in drive_znz!" for inp in zip(values, last): yield wait_cycles(self.clk_i, random.randint(tmin, tmax)) yield self.znz_i_drv.write_input(inp)
def read_outputs(self, num, tmin, tmax): #num: how many output values to read #tmin: minimum # of clock cycles to wait between reads #tmax: maximum # of clock cycles to wait between reads assert self.rst_ni.value == 1, "BPCEncoderDriver Error: rst_ni is not high in read_outputs!" k = 0 for i in range(num): yield wait_cycles(self.clk_i, random.randint(tmin, tmax)) yield self.out_drv.read_output() k+= 1 return k
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_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_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 clear(self): yield apply_signal(dut.clr_i, 1, TA) yield wait_cycles(dut.clk_i, 1) yield apply_signal(dut.clr_i, 0, TA)