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

[Util] provide own util fxn to create tmp dirs, mount on host

parent e000330b
No related branches found
No related tags found
No related merge requests found
......@@ -30,6 +30,7 @@ CNPY_LOCAL=$SCRIPTPATH/cnpy
FINN_HLS_LOCAL=$SCRIPTPATH/finn-hlslib
PYVERILATOR_LOCAL=$SCRIPTPATH/pyverilator
PYNQSHELL_LOCAL=$SCRIPTPATH/PYNQ-HelloWorld
BUILD_LOCAL=/tmp/finn
VIVADO_HLS_LOCAL=$VIVADO_PATH
# clone dependency repos
......@@ -40,6 +41,9 @@ git clone $FINN_HLS_REPO $FINN_HLS_LOCAL; git -C "$FINN_HLS_LOCAL" checkout b5dc
git clone $PYVERILATOR_REPO $PYVERILATOR_LOCAL || git -C "$PYVERILATOR_LOCAL" pull
git clone $PYNQSHELL_REPO $PYNQSHELL_LOCAL || git -C "$PYNQSHELL_LOCAL" pull
# ensure build dir exists locally
mkdir -p $BUILD_LOCAL
echo "Mounting $SCRIPTPATH into /workspace/finn"
echo "Mounting $SCRIPTPATH/brevitas into /workspace/brevitas"
echo "Mounting $SCRIPTPATH/brevitas_cnv_lfc into /workspace/brevitas_cnv_lfc"
......@@ -47,6 +51,7 @@ echo "Mounting $SCRIPTPATH/cnpy into /workspace/cnpy"
echo "Mounting $SCRIPTPATH/finn-hlslib into /workspace/finn-hlslib"
echo "Mounting $SCRIPTPATH/pyverilator into /workspace/pyverilator"
echo "Mounting $SCRIPTPATH/PYNQ-HelloWorld into /workspace/PYNQ-HelloWorld"
echo "Mounting $BUILD_LOCAL into $BUILD_LOCAL"
echo "Mounting $VIVADO_PATH into $VIVADO_PATH"
if [ "$1" = "test" ]; then
......@@ -78,6 +83,7 @@ docker run --rm --name finn_dev -it \
-v $SCRIPTPATH/finn-hlslib:/workspace/finn-hlslib \
-v $SCRIPTPATH/pyverilator:/workspace/pyverilator \
-v $SCRIPTPATH/PYNQ-HelloWorld:/workspace/PYNQ-HelloWorld \
-v $BUILD_LOCAL:$BUILD_LOCAL \
-v $VIVADO_PATH:$VIVADO_PATH \
-e VIVADO_PATH=$VIVADO_PATH \
-p 8888:8888 -p 8081:8081 \
......
......@@ -2,13 +2,19 @@ import random
import string
import subprocess
import os
import numpy as np
import onnx
import tempfile
from bitstring import BitArray
from finn.core.datatype import DataType
def make_build_dir(prefix=""):
"""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
will survive on the host after the FINN Docker container exits."""
return tempfile.mkdtemp(prefix="finn/"+prefix)
def valueinfo_to_tensor(vi):
"""Creates an all-zeroes numpy tensor from a ValueInfoProto."""
......@@ -276,4 +282,3 @@ class IPGenBuilder:
bash_command = ["bash", self.ipgen_script]
process_compile = subprocess.Popen(bash_command, stdout=subprocess.PIPE)
process_compile.communicate()
import os
import tempfile as tmp
import finn.custom_op.registry as registry
from finn.core.utils import get_by_name
from finn.core.utils import get_by_name, make_build_dir
from finn.transformation import Transformation
......@@ -17,7 +16,7 @@ def _codegen_single_node(node, model, fpgapart, clk):
code_gen_dir = inst.get_nodeattr("code_gen_dir_ipgen")
# ensure that there is a directory
if code_gen_dir == "" or not os.path.isdir(code_gen_dir):
code_gen_dir = tmp.mkdtemp(
code_gen_dir = make_build_dir(
prefix="code_gen_ipgen_" + str(node.op_type) + "_"
)
inst.set_nodeattr("code_gen_dir_ipgen", code_gen_dir)
......
import os
import subprocess
import tempfile as tmp
from finn.core.utils import get_by_name
from finn.core.utils import get_by_name, make_build_dir
from finn.transformation import Transformation
......@@ -90,7 +89,7 @@ class CodeGen_ipstitch(Transformation):
)
# create a temporary folder for the project
vivado_stitch_proj_dir = tmp.mkdtemp(prefix="vivado_stitch_proj_")
vivado_stitch_proj_dir = make_build_dir(prefix="vivado_stitch_proj_")
model.set_metadata_prop("vivado_stitch_proj", vivado_stitch_proj_dir)
# start building the tcl script
tcl = []
......
import os
import tempfile as tmp
import finn.custom_op.registry as registry
from finn.core.utils import get_by_name
from finn.core.utils import get_by_name, make_build_dir
from finn.transformation import Transformation
......@@ -17,7 +16,7 @@ def _codegen_single_node(node, model):
code_gen_dir = inst.get_nodeattr("code_gen_dir_npysim")
# ensure that there is a directory
if code_gen_dir == "" or not os.path.isdir(code_gen_dir):
code_gen_dir = tmp.mkdtemp(
code_gen_dir = make_build_dir(
prefix="code_gen_npysim_" + str(node.op_type) + "_"
)
inst.set_nodeattr("code_gen_dir_npysim", code_gen_dir)
......
import os
import subprocess
import tempfile as tmp
from finn.core.utils import get_by_name
from finn.core.utils import get_by_name, make_build_dir
from finn.transformation import Transformation
......@@ -58,7 +57,7 @@ class MakePYNQProject(Transformation):
nrst_name = "ap_rst_n_0"
# create a temporary folder for the project
vivado_pynq_proj_dir = tmp.mkdtemp(prefix="vivado_pynq_proj_")
vivado_pynq_proj_dir = make_build_dir(prefix="vivado_pynq_proj_")
model.set_metadata_prop("vivado_pynq_proj", vivado_pynq_proj_dir)
ip_config_tcl = """
......
import shutil
import subprocess
import tempfile as tmp
import numpy as np
......@@ -10,7 +9,7 @@ from finn.core.datatype import DataType
def make_npy2apintstream_testcase(ndarray, dtype):
test_dir = tmp.mkdtemp(prefix="test_npy2apintstream_")
test_dir = make_build_dir(prefix="test_npy2apintstream_")
shape = ndarray.shape
elem_bits = dtype.bitwidth()
packed_bits = shape[-1] * elem_bits
......
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