Skip to content
Snippets Groups Projects
Commit 8d382b76 authored by auphelia's avatar auphelia
Browse files

[Trafo-templates] Add input arguments for driver.py to select between...

[Trafo-templates] Add input arguments for driver.py to select between functional verification and throughput test on pynq board
parent 6ca5763e
No related branches found
No related tags found
No related merge requests found
...@@ -85,6 +85,8 @@ cd %s ...@@ -85,6 +85,8 @@ cd %s
""" """
pynq_driver_template = """ pynq_driver_template = """
import argparse
from pynq import Overlay from pynq import Overlay
import numpy as np import numpy as np
from pynq import allocate from pynq import allocate
...@@ -131,48 +133,70 @@ def save_output(obuf_folded, N): ...@@ -131,48 +133,70 @@ def save_output(obuf_folded, N):
obuf_normal = obuf_folded.reshape(oshape_normal) obuf_normal = obuf_folded.reshape(oshape_normal)
np.save("output.npy", obuf_normal) np.save("output.npy", obuf_normal)
if __name__ == "__main__":
bitfile_path = "resizer.bit" parser = argparse.ArgumentParser(description='Please select functional verification ("remote_pynq") or throughput test ("throughput_test")')
ol = Overlay(bitfile_path) parser.add_argument('exec_mode', help='metadata prop exec_mode as string')
dma=ol.axi_dma_0 args = parser.parse_args()
ctrl_regs=ol.resize_accel_0 exec_mode = args.exec_mode
# AXI lite register offset for number of iterations
# used by TLastMarker to signal end of transmission for AXI CDMA bitfile_path = "resizer.bit"
REG_OFFSET_NUM_ITERS = 0x10 ol = Overlay(bitfile_path)
dma=ol.axi_dma_0
# number of samples for inference ctrl_regs=ol.resize_accel_0
N = 1 # AXI lite register offset for number of iterations
# used by TLastMarker to signal end of transmission for AXI CDMA
# declare input/output types and shapes for the accelerator REG_OFFSET_NUM_ITERS = 0x10
ishape_packed = $INPUT_SHAPE_PACKED$
oshape_packed = $OUTPUT_SHAPE_PACKED$ # number of samples for inference
if exec_mode == "remote_pynq":
# set up TLastMarker with correct num. samples N = 1
ctrl_regs.write(REG_OFFSET_NUM_ITERS, N) elif exec_mode == "throughput_test":
N = 1000
else:
# allocate a PYNQ buffer for the packed input buffer raise Exception("Exec mode has to be set to remote_pynq or throughput_test")
ibuf_packed_device = allocate(shape=ishape_packed, dtype=np.uint8)
# copy the packed data into the PYNQ buffer # declare input/output types and shapes for the accelerator
# TODO optimization: pack directly into the PYNQ buffer? ishape_packed = $INPUT_SHAPE_PACKED$
np.copyto(ibuf_packed_device, ibuf_packed) oshape_packed = $OUTPUT_SHAPE_PACKED$
# allocate a PYNQ buffer for the returned packed output buffer if exec_mode == "remote_pynq":
obuf_packed = allocate(shape=oshape_packed, dtype=np.uint8) ibuf_normal = load_input(N)
ibuf_packed = pack_input(ibuf_normal, N)
# measure runtime of network elif exec_mode == "throughput_test":
start = time.time() ibuf_packed = np.asarray(np.random.uniform(low=0, high=1, size=tuple(ishape_packed)), dtype=np.uint8)
# set up the DMA and wait until all transfers complete # set up TLastMarker with correct num. samples
dma.sendchannel.transfer(ibuf_packed_device) ctrl_regs.write(REG_OFFSET_NUM_ITERS, N)
dma.recvchannel.transfer(obuf_packed)
dma.sendchannel.wait() # allocate a PYNQ buffer for the packed input buffer
dma.recvchannel.wait() ibuf_packed_device = allocate(shape=ishape_packed, dtype=np.uint8)
# copy the packed data into the PYNQ buffer
end = time.time() # TODO optimization: pack directly into the PYNQ buffer?
runtime = end - start np.copyto(ibuf_packed_device, ibuf_packed)
file = open("nw_runtime.txt", "w")
file.write(str(runtime)) # allocate a PYNQ buffer for the returned packed output buffer
file.close() obuf_packed = allocate(shape=oshape_packed, dtype=np.uint8)
if exec_mode == "throughput_test":
# measure runtime of network
start = time.time()
# set up the DMA and wait until all transfers complete
dma.sendchannel.transfer(ibuf_packed_device)
dma.recvchannel.transfer(obuf_packed)
dma.sendchannel.wait()
dma.recvchannel.wait()
if exec_mode == "throughput_test":
end = time.time()
runtime = end - start
file = open("nw_runtime.txt", "w")
file.write(str(runtime))
file.close()
else:
obuf_folded = unpack_output(obuf_packed, N)
save_output(obuf_folded, N)
""" """
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment