diff --git a/src/finn/core/remote_exec.py b/src/finn/core/remote_exec.py index b15d59f10822b8a6753a4021673c7b348d037982..e8f535b3e144a282ea47c8da4c0b3390374b87fc 100644 --- a/src/finn/core/remote_exec.py +++ b/src/finn/core/remote_exec.py @@ -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() diff --git a/src/finn/core/throughput_test.py b/src/finn/core/throughput_test.py index 078764a42ffcdf25774eebe20874aca025376107..69aba1c38c8a21d508e8ac13742c9856ea94a955 100644 --- a/src/finn/core/throughput_test.py +++ b/src/finn/core/throughput_test.py @@ -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() diff --git a/src/finn/transformation/fpgadataflow/make_deployment.py b/src/finn/transformation/fpgadataflow/make_deployment.py index 051e75cda6179d92c333626f1ae708076a93c29e..3850b496aeb1d163c0d81072a3623579efa5fd96 100644 --- a/src/finn/transformation/fpgadataflow/make_deployment.py +++ b/src/finn/transformation/fpgadataflow/make_deployment.py @@ -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) diff --git a/src/finn/transformation/fpgadataflow/templates.py b/src/finn/transformation/fpgadataflow/templates.py index 3bd74ec6a2071db820a35a9440eedd74092354e1..0559d4926ffe6d8b9a2e35c8eb845d53e177f3ae 100644 --- a/src/finn/transformation/fpgadataflow/templates.py +++ b/src/finn/transformation/fpgadataflow/templates.py @@ -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 +"""