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

[Docker] add random number to inst name, use also in tmpdir name

parent c7ae9cb5
No related branches found
No related tags found
No related merge requests found
...@@ -10,7 +10,11 @@ DOCKER_GNAME=$(id -gn) ...@@ -10,7 +10,11 @@ DOCKER_GNAME=$(id -gn)
DOCKER_UNAME=$(id -un) DOCKER_UNAME=$(id -un)
DOCKER_UID=$(id -u) DOCKER_UID=$(id -u)
DOCKER_PASSWD="finn" DOCKER_PASSWD="finn"
DOCKER_TAG="finn_$DOCKER_UNAME" # generate a random number per-run to allow multiple
# containers from the same user
DOCKER_RND=$(shuf -i0-32768 -n1)
DOCKER_TAG="finn_${DOCKER_UNAME}"
DOCKER_INST_NAME="finn_${DOCKER_UNAME}_${DOCKER_RND}"
: ${JUPYTER_PORT=8888} : ${JUPYTER_PORT=8888}
# Absolute path to this script, e.g. /home/user/bin/foo.sh # Absolute path to this script, e.g. /home/user/bin/foo.sh
...@@ -31,7 +35,7 @@ CNPY_LOCAL=$SCRIPTPATH/cnpy ...@@ -31,7 +35,7 @@ CNPY_LOCAL=$SCRIPTPATH/cnpy
FINN_HLS_LOCAL=$SCRIPTPATH/finn-hlslib FINN_HLS_LOCAL=$SCRIPTPATH/finn-hlslib
PYVERILATOR_LOCAL=$SCRIPTPATH/pyverilator PYVERILATOR_LOCAL=$SCRIPTPATH/pyverilator
PYNQSHELL_LOCAL=$SCRIPTPATH/PYNQ-HelloWorld PYNQSHELL_LOCAL=$SCRIPTPATH/PYNQ-HelloWorld
BUILD_LOCAL=/tmp/finn BUILD_LOCAL=/tmp/$DOCKER_INST_NAME
VIVADO_HLS_LOCAL=$VIVADO_PATH VIVADO_HLS_LOCAL=$VIVADO_PATH
# clone dependency repos # clone dependency repos
...@@ -45,6 +49,7 @@ git clone $PYNQSHELL_REPO $PYNQSHELL_LOCAL || git -C "$PYNQSHELL_LOCAL" pull ...@@ -45,6 +49,7 @@ git clone $PYNQSHELL_REPO $PYNQSHELL_LOCAL || git -C "$PYNQSHELL_LOCAL" pull
# ensure build dir exists locally # ensure build dir exists locally
mkdir -p $BUILD_LOCAL mkdir -p $BUILD_LOCAL
echo "Instance is named as $DOCKER_INST_NAME"
echo "Mounting $SCRIPTPATH into /workspace/finn" echo "Mounting $SCRIPTPATH into /workspace/finn"
echo "Mounting $SCRIPTPATH/brevitas into /workspace/brevitas" echo "Mounting $SCRIPTPATH/brevitas into /workspace/brevitas"
echo "Mounting $SCRIPTPATH/brevitas_cnv_lfc into /workspace/brevitas_cnv_lfc" echo "Mounting $SCRIPTPATH/brevitas_cnv_lfc into /workspace/brevitas_cnv_lfc"
...@@ -77,7 +82,8 @@ docker build --tag=$DOCKER_TAG \ ...@@ -77,7 +82,8 @@ docker build --tag=$DOCKER_TAG \
--build-arg JUPYTER_PORT=$JUPYTER_PORT \ --build-arg JUPYTER_PORT=$JUPYTER_PORT \
. .
# Launch container with current directory mounted # Launch container with current directory mounted
docker run -t --rm --name finn_dev_$DOCKER_UNAME -it \ docker run -t --rm --name $DOCKER_INST_NAME -it \
--hostname $DOCKER_INST_NAME \
-e "XILINX_VIVADO=$VIVADO_PATH" \ -e "XILINX_VIVADO=$VIVADO_PATH" \
-e "SHELL=/bin/bash" \ -e "SHELL=/bin/bash" \
-v $SCRIPTPATH:/workspace/finn \ -v $SCRIPTPATH:/workspace/finn \
...@@ -90,5 +96,6 @@ docker run -t --rm --name finn_dev_$DOCKER_UNAME -it \ ...@@ -90,5 +96,6 @@ docker run -t --rm --name finn_dev_$DOCKER_UNAME -it \
-v $BUILD_LOCAL:$BUILD_LOCAL \ -v $BUILD_LOCAL:$BUILD_LOCAL \
-v $VIVADO_PATH:$VIVADO_PATH \ -v $VIVADO_PATH:$VIVADO_PATH \
-e VIVADO_PATH=$VIVADO_PATH \ -e VIVADO_PATH=$VIVADO_PATH \
-e FINN_INST_NAME=$DOCKER_TAG \
-p $JUPYTER_PORT:$JUPYTER_PORT \ -p $JUPYTER_PORT:$JUPYTER_PORT \
$DOCKER_TAG bash -c "$DOCKER_CMD" $DOCKER_TAG bash -c "$DOCKER_CMD"
...@@ -6,16 +6,23 @@ import tempfile ...@@ -6,16 +6,23 @@ import tempfile
import numpy as np import numpy as np
import onnx import onnx
from bitstring import BitArray
from finn.core.datatype import DataType from finn.core.datatype import DataType
def make_build_dir(prefix=""): def make_build_dir(prefix=""):
"""Creates a temporary folder with given prefix to be used as a build dir. """Creates a temporary folder with given prefix to be used as a build dir.
Use this function instead of tempfile.mkdtemp to ensure any generated files Use this function instead of tempfile.mkdtemp to ensure any generated files
will survive on the host after the FINN Docker container exits.""" will survive on the host after the FINN Docker container exits."""
try:
return tempfile.mkdtemp(prefix="finn/" + prefix) inst_prefix = os.environ["FINN_INST_NAME"] + "/"
return tempfile.mkdtemp(prefix=inst_prefix + prefix)
except KeyError:
raise Exception(
"""Environment variable FINN_INST_NAME must be set
correctly. Please ensure you have launched the Docker contaier correctly.
"""
)
def valueinfo_to_tensor(vi): def valueinfo_to_tensor(vi):
...@@ -49,6 +56,7 @@ def random_string(stringLength=6): ...@@ -49,6 +56,7 @@ def random_string(stringLength=6):
lettersAndDigits = string.ascii_letters + string.digits lettersAndDigits = string.ascii_letters + string.digits
return "".join(random.choice(lettersAndDigits) for i in range(stringLength)) return "".join(random.choice(lettersAndDigits) for i in range(stringLength))
def interleave_matrix_outer_dim_from_partitions(matrix, n_partitions): def interleave_matrix_outer_dim_from_partitions(matrix, n_partitions):
if type(matrix) != np.ndarray or matrix.dtype != np.float32: if type(matrix) != np.ndarray or matrix.dtype != np.float32:
# try to convert to a float numpy array (container dtype is float) # try to convert to a float numpy array (container dtype is float)
......
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