Skip to content
Snippets Groups Projects
Commit 0c6afb06 authored by Yaman Umuroglu's avatar Yaman Umuroglu
Browse files

[Core] work on making remote exec/thr test on Alveo too

parent 20ff796f
No related branches found
No related tags found
No related merge requests found
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
import os import os
import subprocess import subprocess
import warnings
import numpy as np import numpy as np
...@@ -43,15 +43,35 @@ def remote_exec(model, execution_context): ...@@ -43,15 +43,35 @@ def remote_exec(model, execution_context):
pynq_password = model.get_metadata_prop("pynq_password") pynq_password = model.get_metadata_prop("pynq_password")
pynq_target_dir = model.get_metadata_prop("pynq_target_dir") pynq_target_dir = model.get_metadata_prop("pynq_target_dir")
deployment_dir = model.get_metadata_prop("pynq_deploy_dir") deployment_dir = model.get_metadata_prop("pynq_deploy_dir")
platform = model.get_metadata_prop("platform")
assert platform in ["alveo", "zynq", "zynq-iodma"]
bitfile = model.get_metadata_prop("bitfile")
bitfile = os.path.basename(bitfile)
if pynq_password == "":
if "zynq" in platform:
raise Exception("PYNQ board remote exec needs password for sudo")
else:
local_prefix = "" # assume we are using an ssh key
warnings.warn("Empty password, make sure you've set up an ssh key")
else:
local_prefix = "sshpass -p %s " % pynq_password
if platform == "alveo":
# Alveo can run without sudo but needs correct environment
remote_prefix = "conda activate finn-pynq-alveo; "
elif "zynq" in platform:
# PYNQ Zynq boards need to execute with sudo
remote_prefix = "echo %s | sudo -S " % pynq_password
inp = execution_context[model.graph.input[0].name] inp = execution_context[model.graph.input[0].name]
# make copy of array before saving it # make copy of array before saving it
inp = inp.copy() inp = inp.copy()
bsize = inp.shape[0]
np.save(os.path.join(deployment_dir, "input.npy"), inp) np.save(os.path.join(deployment_dir, "input.npy"), inp)
# extracting last folder of absolute path (deployment_dir) # extracting last folder of absolute path (deployment_dir)
deployment_folder = os.path.basename(os.path.normpath(deployment_dir)) deployment_folder = os.path.basename(os.path.normpath(deployment_dir))
# copy input to PYNQ board # copy input to PYNQ board
cmd = "sshpass -p {} scp -P{} -r {}/input.npy {}@{}:{}/{}".format( cmd = local_prefix + "scp -P{} -r {}/input.npy {}@{}:{}/{}".format(
pynq_password,
pynq_port, pynq_port,
deployment_dir, deployment_dir,
pynq_username, pynq_username,
...@@ -60,38 +80,36 @@ def remote_exec(model, execution_context): ...@@ -60,38 +80,36 @@ def remote_exec(model, execution_context):
deployment_folder, deployment_folder,
) )
bash_command = ["/bin/bash", "-c", cmd] bash_command = ["/bin/bash", "-c", cmd]
process_compile = subprocess.Popen(bash_command, stdout=subprocess.PIPE) process_scp_in = subprocess.Popen(bash_command, stdout=subprocess.PIPE)
process_compile.communicate() process_scp_in.communicate()
# set platform attribute for correct remote execution # use platform attribute for correct remote execution
platform = model.get_metadata_prop("platform")
assert platform in ["alveo", "zynq", "zynq-iodma"]
cmd = ( cmd = (
"sshpass -p {} ssh {}@{} -p {} " local_prefix + "ssh {}@{} -p {} "
'"cd {}/{}; echo "{}" | ' '"cd {}/{}; '
'sudo -S python3.6 driver.py --exec_mode="execute" --batchsize=1" ' + remote_prefix
'--bitfile="resizer.bit" --inputfile="input.npy" --outputfile="output.npy" ' + "python3.6 driver.py --exec_mode=execute --batchsize={} "
'--platform="{}" ' "--bitfile={} --inputfile=input.npy --outputfile=output.npy "
'--platform={} "'
).format( ).format(
pynq_password,
pynq_username, pynq_username,
pynq_ip, pynq_ip,
pynq_port, pynq_port,
pynq_target_dir, pynq_target_dir,
deployment_folder, deployment_folder,
pynq_password, bsize,
bitfile,
platform, platform,
) )
bash_command = ["/bin/bash", "-c", cmd] bash_command = ["/bin/bash", "-c", cmd]
process_compile = subprocess.Popen(bash_command, stdout=subprocess.PIPE) process_exec_accel = subprocess.Popen(bash_command, stdout=subprocess.PIPE)
process_compile.communicate() process_exec_accel.communicate()
# remove stale output file from local dir, if any # remove stale output file from local dir, if any
try: try:
os.remove("{}/output.npy".format(deployment_dir)) os.remove("{}/output.npy".format(deployment_dir))
except FileNotFoundError: except FileNotFoundError:
pass pass
# copy generated output to local # copy generated output to local
cmd = "sshpass -p {} scp -P{} {}@{}:{}/{}/output.npy {}".format( cmd = local_prefix + "scp -P{} {}@{}:{}/{}/output.npy {}".format(
pynq_password,
pynq_port, pynq_port,
pynq_username, pynq_username,
pynq_ip, pynq_ip,
...@@ -100,7 +118,7 @@ def remote_exec(model, execution_context): ...@@ -100,7 +118,7 @@ def remote_exec(model, execution_context):
deployment_dir, deployment_dir,
) )
bash_command = ["/bin/bash", "-c", cmd] bash_command = ["/bin/bash", "-c", cmd]
process_compile = subprocess.Popen(bash_command, stdout=subprocess.PIPE) process_scp_out = subprocess.Popen(bash_command, stdout=subprocess.PIPE)
process_compile.communicate() process_scp_out.communicate()
outp = np.load("{}/output.npy".format(deployment_dir)) outp = np.load("{}/output.npy".format(deployment_dir))
execution_context[model.graph.output[0].name] = outp execution_context[model.graph.output[0].name] = outp
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
import os import os
import subprocess import subprocess
import numpy as np import numpy as np
import warnings
from finn.util.basic import gen_finn_dt_tensor from finn.util.basic import gen_finn_dt_tensor
from finn.core.rtlsim_exec import rtlsim_exec from finn.core.rtlsim_exec import rtlsim_exec
...@@ -48,24 +48,44 @@ def throughput_test(model, batchsize=1000): ...@@ -48,24 +48,44 @@ def throughput_test(model, batchsize=1000):
deployment_dir = model.get_metadata_prop("pynq_deploy_dir") deployment_dir = model.get_metadata_prop("pynq_deploy_dir")
# extracting last folder of absolute path (deployment_dir) # extracting last folder of absolute path (deployment_dir)
deployment_folder = os.path.basename(os.path.normpath(deployment_dir)) deployment_folder = os.path.basename(os.path.normpath(deployment_dir))
platform = model.get_metadata_prop("platform")
assert platform in ["alveo", "zynq", "zynq-iodma"]
bitfile = model.get_metadata_prop("bitfile")
bitfile = os.path.basename(bitfile)
if pynq_password == "":
if "zynq" in platform:
raise Exception("PYNQ board remote exec needs password for sudo")
else:
local_prefix = "" # assume we are using an ssh key
warnings.warn("Empty password, make sure you've set up an ssh key")
else:
local_prefix = "sshpass -p %s " % pynq_password
if platform == "alveo":
# Alveo can run without sudo but needs correct environment
remote_prefix = "conda activate finn-pynq-alveo; "
elif "zynq" in platform:
# PYNQ Zynq boards need to execute with sudo
remote_prefix = "echo %s | sudo -S " % pynq_password
cmd = ( cmd = (
"sshpass -p {} ssh {}@{} -p {} " local_prefix + "ssh {}@{} -p {} "
'"cd {}/{}; echo "{}" | ' '"cd {}/{}; '
'sudo -S python3.6 driver.py --exec_mode="throughput_test" --batchsize=%d"' + remote_prefix
% batchsize + 'python3.6 driver.py --exec_mode="throughput_test" --batchsize=%d '
'--bitfile={} --platform={} "' % batchsize
).format( ).format(
pynq_password,
pynq_username, pynq_username,
pynq_ip, pynq_ip,
pynq_port, pynq_port,
pynq_target_dir, pynq_target_dir,
deployment_folder, deployment_folder,
pynq_password, bitfile,
platform,
) )
bash_command = ["/bin/bash", "-c", cmd] bash_command = ["/bin/bash", "-c", cmd]
process_compile = subprocess.Popen(bash_command, stdout=subprocess.PIPE) process_throughput_test = subprocess.Popen(bash_command, stdout=subprocess.PIPE)
process_compile.communicate() process_throughput_test.communicate()
# remove any pre-existing metrics file # remove any pre-existing metrics file
try: try:
...@@ -73,8 +93,7 @@ def throughput_test(model, batchsize=1000): ...@@ -73,8 +93,7 @@ def throughput_test(model, batchsize=1000):
except FileNotFoundError: except FileNotFoundError:
pass pass
cmd = "sshpass -p {} scp -P{} {}@{}:{}/{}/nw_metrics.txt {}".format( cmd = local_prefix + "scp -P{} {}@{}:{}/{}/nw_metrics.txt {}".format(
pynq_password,
pynq_port, pynq_port,
pynq_username, pynq_username,
pynq_ip, pynq_ip,
......
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