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

[Deploy] add helper script for Alveo deployment

parent 72b96fab
No related branches found
No related tags found
No related merge requests found
......@@ -57,8 +57,8 @@ def remote_exec(model, execution_context):
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; "
# Alveo can run without sudo
remote_prefix = ""
elif "zynq" in platform:
# PYNQ Zynq boards need to execute with sudo
remote_prefix = "echo %s | sudo -S " % pynq_password
......@@ -66,7 +66,7 @@ def remote_exec(model, execution_context):
inp = execution_context[model.graph.input[0].name]
# make copy of array before saving it
inp = inp.copy()
bsize = inp.shape[0]
batchsize = inp.shape[0]
np.save(os.path.join(deployment_dir, "input.npy"), inp)
# extracting last folder of absolute path (deployment_dir)
deployment_folder = os.path.basename(os.path.normpath(deployment_dir))
......@@ -82,24 +82,23 @@ def remote_exec(model, execution_context):
bash_command = ["/bin/bash", "-c", cmd]
process_scp_in = subprocess.Popen(bash_command, stdout=subprocess.PIPE)
process_scp_in.communicate()
# use platform attribute for correct remote execution
if platform == "alveo":
remote_cmd = "bash -i %s/%s/run.sh execute %d" % (
pynq_target_dir,
deployment_folder,
batchsize,
)
else:
remote_cmd = (
"python3.6 driver.py --exec_mode=execute --batchsize={} "
"--bitfile={} --inputfile=input.npy --outputfile=output.npy "
'--platform={} "'
).format(batchsize, bitfile, platform)
cmd = (
local_prefix + "ssh {}@{} -p {} "
'"cd {}/{}; '
+ remote_prefix
+ "python3.6 driver.py --exec_mode=execute --batchsize={} "
"--bitfile={} --inputfile=input.npy --outputfile=output.npy "
'--platform={} "'
).format(
pynq_username,
pynq_ip,
pynq_port,
pynq_target_dir,
deployment_folder,
bsize,
bitfile,
platform,
)
local_prefix + "ssh {}@{} -p {} " '"cd {}/{}; ' + remote_prefix + remote_cmd
).format(pynq_username, pynq_ip, pynq_port, pynq_target_dir, deployment_folder)
bash_command = ["/bin/bash", "-c", cmd]
process_exec_accel = subprocess.Popen(bash_command, stdout=subprocess.PIPE)
process_exec_accel.communicate()
......
......@@ -68,21 +68,22 @@ def throughput_test_remote(model, batchsize=1000):
# PYNQ Zynq boards need to execute with sudo
remote_prefix = "echo %s | sudo -S " % pynq_password
# use platform attribute for correct remote execution
if platform == "alveo":
remote_cmd = "bash -i %s/%s/run.sh throughput_test %d" % (
pynq_target_dir,
deployment_folder,
batchsize,
)
else:
remote_cmd = (
"python3.6 driver.py --exec_mode=throughput_test --batchsize={} "
"--bitfile={} --inputfile=input.npy --outputfile=output.npy "
'--platform={} "'
).format(batchsize, bitfile, platform)
cmd = (
local_prefix + "ssh {}@{} -p {} "
'"cd {}/{}; '
+ remote_prefix
+ 'python3.6 driver.py --exec_mode="throughput_test" --batchsize=%d '
'--bitfile={} --platform={} "' % batchsize
).format(
pynq_username,
pynq_ip,
pynq_port,
pynq_target_dir,
deployment_folder,
bitfile,
platform,
)
local_prefix + "ssh {}@{} -p {} " '"cd {}/{}; ' + remote_prefix + remote_cmd
).format(pynq_username, pynq_ip, pynq_port, pynq_target_dir, deployment_folder)
bash_command = ["/bin/bash", "-c", cmd]
process_throughput_test = subprocess.Popen(bash_command, stdout=subprocess.PIPE)
process_throughput_test.communicate()
......
......@@ -34,6 +34,7 @@ from shutil import copy
from finn.transformation import Transformation
from finn.util.basic import make_build_dir
import finn.transformation.fpgadataflow.templates as templates
class DeployToPYNQ(Transformation):
......@@ -73,13 +74,32 @@ class DeployToPYNQ(Transformation):
if dfile is not None:
copy(dfile, deployment_dir)
# helper script for Alveo
platform = model.get_metadata_prop("platform")
if platform == "alveo":
alveo_run_sh = templates.alveo_run_sh_template
fill_dict = {
"$REMOTE_DEPLOY_DIR$": self.target_dir
+ "/"
+ os.path.basename(deployment_dir),
"$CONDA_ENV_NAME$": "finn-pynq-alveo",
"$REMOTE_XRT$": os.environ["VITIS_XRT"],
"$REMOTE_PLATFORM_REPO_PATHS$": os.environ["PLATFORM_REPO_PATHS"],
"$BITFILE$": os.path.basename(bitfile),
}
for key, value in fill_dict.items():
alveo_run_sh = alveo_run_sh.replace(key, value)
alveo_run_sh_path = deployment_dir + "/alveo_run.sh"
with open(alveo_run_sh_path, "w") as f:
f.write(alveo_run_sh)
# driver.py and python libraries
pynq_driver_dir = model.get_metadata_prop("pynq_driver_dir")
copy_tree(pynq_driver_dir, deployment_dir)
model.set_metadata_prop("pynq_deploy_dir", deployment_dir)
model.set_metadata_prop("exec_mode", "remote_pynq")
if self.password == "":
prefix = "" # assume we are using an ssh key
prefix = "" # assume we are using an ssh key
warnings.warn("Empty password, make sure you've set up an ssh key")
else:
prefix = "sshpass -p %s " % self.password
......@@ -93,11 +113,7 @@ class DeployToPYNQ(Transformation):
process_compile.communicate()
# copy directory to PYNQ board using scp and sshpass
cmd = prefix + "scp -P{} -r {} {}@{}:{}".format(
self.port,
deployment_dir,
self.username,
self.ip,
self.target_dir,
self.port, deployment_dir, self.username, self.ip, self.target_dir,
)
bash_command = ["/bin/bash", "-c", cmd]
process_compile = subprocess.Popen(bash_command, stdout=subprocess.PIPE)
......
......@@ -422,3 +422,14 @@ wait_on_run [get_runs impl_1]
open_run synth_1 -name synth_1
report_utilization -hierarchical -hierarchical_depth 4 -file synth_report.xml -format xml
"""
alveo_run_sh_template = """
#!/bin/bash
cd $REMOTE_DEPLOY_DIR$
conda activate $CONDA_ENV_NAME$
source $REMOTE_XRT$/packages/setenv.sh
export PLATFORM_REPO_PATHS=$REMOTE_PLATFORM_REPO_PATHS$
python3.6 driver.py --exec_mode=$1 --batchsize=$2 --bitfile=$BITFILE$ \
--inputfile=input.npy --outputfile=output.npy --platform=alveo
"""
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