Skip to content

Commit

Permalink
Merge pull request #868 from fpjentzsch/feature/apptainer
Browse files Browse the repository at this point in the history
Singularity container support for run script
  • Loading branch information
auphelia authored Feb 9, 2024
2 parents f2424e7 + 94f2001 commit 04b9c9d
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 12 deletions.
47 changes: 47 additions & 0 deletions .github/workflows/singularity-quicktest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: SingularityQuicktest

on:
pull_request:
branches: [ dev ]
push:
branches: [ dev ]

jobs:
build_quicktest_singularity:
name: Build and quicktest Singularity container
runs-on: ubuntu-22.04
steps:
- name: Reclaim storage
run: |
docker image prune -a -f
sudo rm -rf /usr/share/dotnet
sudo rm -rf /usr/local/lib/android
- name: Checkout
uses: actions/checkout@v3
- name: Set up Docker
uses: docker/setup-buildx-action@v2
with:
driver: docker
- name: Set up Singularity
run: |
sudo add-apt-repository -y ppa:apptainer/ppa
sudo apt update
sudo apt install -y apptainer
alias singularity="apptainer"
- name: Build Docker image
uses: docker/build-push-action@v4
with:
file: docker/Dockerfile.finn
context: .
load: true
no-cache: true
tags: finn_docker_export:latest
- name: Build Singularity image
run: |
mkdir $GITHUB_WORKSPACE/singularity_tmp
export APPTAINER_TMPDIR=$GITHUB_WORKSPACE/singularity_tmp
singularity build --disable-cache finn_singularity_image.sif docker-daemon://finn_docker_export:latest
- name: Run quicktest
run: |
export FINN_SINGULARITY=finn_singularity_image.sif
./run-docker.sh quicktest
4 changes: 3 additions & 1 deletion docker/Dockerfile.finn
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ RUN apt-get update && \
lsb-core \
python3 \
python-is-python3 \
python3-pip
python3-pip \
python3-setuptools-scm \
python3-venv
RUN echo "StrictHostKeyChecking no" >> /etc/ssh/ssh_config
RUN locale-gen "en_US.UTF-8"

Expand Down
4 changes: 3 additions & 1 deletion docker/finn_entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ recho () {

# qonnx (using workaround for https://github.com/pypa/pip/issues/7953)
# to be fixed in future Ubuntu versions (https://bugs.launchpad.net/ubuntu/+source/setuptools/+bug/1994016)
pip install --no-build-isolation --no-warn-script-location -e ${FINN_ROOT}/deps/qonnx
mv ${FINN_ROOT}/deps/qonnx/pyproject.toml ${FINN_ROOT}/deps/qonnx/pyproject.tmp
pip install --user -e ${FINN_ROOT}/deps/qonnx
mv ${FINN_ROOT}/deps/qonnx/pyproject.tmp ${FINN_ROOT}/deps/qonnx/pyproject.toml
# finn-experimental
pip install --user -e ${FINN_ROOT}/deps/finn-experimental
# brevitas
Expand Down
1 change: 1 addition & 0 deletions docs/finn/getting_started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ These are summarized below:
* (optional) ``FINN_SKIP_DEP_REPOS`` (default "0") skips the download of FINN dependency repos (uses the ones already downloaded under deps/.
* (optional) ``NVIDIA_VISIBLE_DEVICES`` (default "") specifies specific Nvidia GPUs to use in Docker container. Possible values are a comma-separated list of GPU UUID(s) or index(es) e.g. ``0,1,2``, ``all``, ``none``, or void/empty/unset.
* (optional) ``DOCKER_BUILDKIT`` (default "1") enables `Docker BuildKit <https://docs.docker.com/develop/develop-images/build_enhancements/>`_ for faster Docker image rebuilding (recommended).
* (optional) ``FINN_SINGULARITY`` (default "") points to a pre-built Singularity image to use instead of the Docker image. Singularity support is experimental and intended only for systems where Docker is unavailable. Does not support GPUs.

General FINN Docker tips
************************
Expand Down
33 changes: 23 additions & 10 deletions run-docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ SCRIPTPATH=$(dirname "$SCRIPT")
: ${OHMYXILINX="${SCRIPTPATH}/deps/oh-my-xilinx"}
: ${NVIDIA_VISIBLE_DEVICES=""}
: ${DOCKER_BUILDKIT="1"}
: ${FINN_SINGULARITY=""}

DOCKER_INTERACTIVE=""

Expand All @@ -121,8 +122,10 @@ elif [ "$1" = "notebook" ]; then
DOCKER_CMD="jupyter notebook --allow-root --no-browser --ip=0.0.0.0 --port $JUPYTER_PORT $JUPYTER_PASSWD_ARG notebooks"
FINN_DOCKER_EXTRA+="-e JUPYTER_PORT=$JUPYTER_PORT "
FINN_DOCKER_EXTRA+="-e NETRON_PORT=$NETRON_PORT "
FINN_DOCKER_EXTRA+="-p $JUPYTER_PORT:$JUPYTER_PORT "
FINN_DOCKER_EXTRA+="-p $NETRON_PORT:$NETRON_PORT "
if [ -z "$FINN_SINGULARITY" ]; then
FINN_DOCKER_EXTRA+="-p $JUPYTER_PORT:$JUPYTER_PORT "
FINN_DOCKER_EXTRA+="-p $NETRON_PORT:$NETRON_PORT "
fi
elif [ "$1" = "build_dataflow" ]; then
BUILD_DATAFLOW_DIR=$(readlink -f "$2")
FINN_DOCKER_EXTRA+="-v $BUILD_DATAFLOW_DIR:$BUILD_DATAFLOW_DIR "
Expand All @@ -148,7 +151,7 @@ else
fi


if [ "$FINN_DOCKER_GPU" != 0 ];then
if [ "$FINN_DOCKER_GPU" != 0 ] && [ -z "$FINN_SINGULARITY" ];then
gecho "nvidia-docker detected, enabling GPUs"
if [ ! -z "$NVIDIA_VISIBLE_DEVICES" ];then
FINN_DOCKER_EXTRA+="--runtime nvidia -e NVIDIA_VISIBLE_DEVICES=$NVIDIA_VISIBLE_DEVICES "
Expand Down Expand Up @@ -179,7 +182,7 @@ if [ "$FINN_SKIP_DEP_REPOS" = "0" ]; then
fi

# Build the FINN Docker image
if [ "$FINN_DOCKER_PREBUILT" = "0" ]; then
if [ "$FINN_DOCKER_PREBUILT" = "0" ] && [ -z "$FINN_SINGULARITY" ]; then
# Need to ensure this is done within the finn/ root folder:
OLD_PWD=$(pwd)
cd $SCRIPTPATH
Expand All @@ -189,9 +192,8 @@ fi
# Launch container with current directory mounted
# important to pass the --init flag here for correct Vivado operation, see:
# https://stackoverflow.com/questions/55733058/vivado-synthesis-hangs-in-docker-container-spawned-by-jenkins
DOCKER_EXEC="docker run -t --rm $DOCKER_INTERACTIVE --tty --init "
DOCKER_EXEC+="--hostname $DOCKER_INST_NAME "
DOCKER_EXEC+="-e SHELL=/bin/bash "
DOCKER_BASE="docker run -t --rm $DOCKER_INTERACTIVE --tty --init --hostname $DOCKER_INST_NAME "
DOCKER_EXEC="-e SHELL=/bin/bash "
DOCKER_EXEC+="-w $SCRIPTPATH "
DOCKER_EXEC+="-v $SCRIPTPATH:$SCRIPTPATH "
DOCKER_EXEC+="-v $FINN_HOST_BUILD_DIR:$FINN_HOST_BUILD_DIR "
Expand All @@ -209,7 +211,7 @@ DOCKER_EXEC+="-e NUM_DEFAULT_WORKERS=$NUM_DEFAULT_WORKERS "
# Workaround for FlexLM issue, see:
# https://community.flexera.com/t5/InstallAnywhere-Forum/Issues-when-running-Xilinx-tools-or-Other-vendor-tools-in-docker/m-p/245820#M10647
DOCKER_EXEC+="-e LD_PRELOAD=/lib/x86_64-linux-gnu/libudev.so.1 "
if [ "$FINN_DOCKER_RUN_AS_ROOT" = "0" ];then
if [ "$FINN_DOCKER_RUN_AS_ROOT" = "0" ] && [ -z "$FINN_SINGULARITY" ];then
DOCKER_EXEC+="-v /etc/group:/etc/group:ro "
DOCKER_EXEC+="-v /etc/passwd:/etc/passwd:ro "
DOCKER_EXEC+="-v /etc/shadow:/etc/shadow:ro "
Expand Down Expand Up @@ -249,6 +251,17 @@ if [ ! -z "$FINN_XILINX_PATH" ];then
fi
fi
DOCKER_EXEC+="$FINN_DOCKER_EXTRA "
DOCKER_EXEC+="$FINN_DOCKER_TAG $DOCKER_CMD"

$DOCKER_EXEC
if [ -z "$FINN_SINGULARITY" ];then
CMD_TO_RUN="$DOCKER_BASE $DOCKER_EXEC $FINN_DOCKER_TAG $DOCKER_CMD"
else
SINGULARITY_BASE="singularity exec"
# Replace command options for Singularity
SINGULARITY_EXEC="${DOCKER_EXEC//"-e "/"--env "}"
SINGULARITY_EXEC="${SINGULARITY_EXEC//"-v "/"-B "}"
SINGULARITY_EXEC="${SINGULARITY_EXEC//"-w "/"--pwd "}"
CMD_TO_RUN="$SINGULARITY_BASE $SINGULARITY_EXEC $FINN_SINGULARITY /usr/local/bin/finn_entrypoint.sh $DOCKER_CMD"
gecho "FINN_SINGULARITY is set, launching Singularity container instead of Docker"
fi

$CMD_TO_RUN

0 comments on commit 04b9c9d

Please sign in to comment.