Add gpu dockerfile

pull/1239/head
Piero Toffanin 2021-02-09 12:14:05 -05:00
rodzic 029ced4fd9
commit 3b2a60737c
6 zmienionych plików z 82 dodań i 3 usunięć

Wyświetl plik

@ -9,7 +9,7 @@ ExternalProject_Add(${_proj_name}
#--Download step--------------
DOWNLOAD_DIR ${SB_DOWNLOAD_DIR}
GIT_REPOSITORY https://github.com/OpenDroneMap/OpenSfM/
GIT_TAG 241
GIT_TAG gpu
#--Update/Patch step----------
UPDATE_COMMAND git submodule update --init --recursive
#--Configure step-------------

46
gpu.Dockerfile 100644
Wyświetl plik

@ -0,0 +1,46 @@
FROM nvidia/cuda:11.2.0-runtime-ubuntu20.04 AS builder
# Env variables
ENV DEBIAN_FRONTEND=noninteractive \
PYTHONPATH="$PYTHONPATH:/code/SuperBuild/install/lib/python3.8/dist-packages:/code/SuperBuild/src/opensfm" \
LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/code/SuperBuild/install/lib"
# Prepare directories
WORKDIR /code
# Copy everything
COPY . ./
# Run the build
RUN bash configure.sh install
# Clean Superbuild
RUN bash configure.sh clean
### END Builder
### Use a second image for the final asset to reduce the number and
# size of the layers.
FROM nvidia/cuda:11.2.0-runtime-ubuntu20.04
# Env variables
ENV DEBIAN_FRONTEND=noninteractive \
PYTHONPATH="$PYTHONPATH:/code/SuperBuild/install/lib/python3.8/dist-packages:/code/SuperBuild/src/opensfm" \
LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/code/SuperBuild/install/lib"
WORKDIR /code
# Copy everything we built from the builder
COPY --from=builder /code /code
# Copy the Python libraries installed via pip from the builder
COPY --from=builder /usr/local /usr/local
# Install shared libraries that we depend on via APT, but *not*
# the -dev packages to save space!
RUN bash configure.sh installruntimedepsonly \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
# Entry point
ENTRYPOINT ["python3", "/code/run.py"]

15
opendm/gpu.py 100644
Wyświetl plik

@ -0,0 +1,15 @@
import os, subprocess
from opendm import log
from repoze.lru import lru_cache
@lru_cache(maxsize=None)
def has_gpus():
import pyopencl
try:
platforms = pyopencl.get_platforms()
print(platforms)
exit(1)
except Exception as e:
print(e)
return False

Wyświetl plik

@ -17,7 +17,7 @@ from opensfm.actions import undistort
from opensfm.dataset import DataSet
from opensfm import report
from opendm.multispectral import get_photos_by_band
from opendm.gpu import has_gpus
class OSFMContext:
def __init__(self, opensfm_project_path):
@ -214,6 +214,14 @@ class OSFMContext:
log.ODM_WARNING("Using BOW matching, will use HAHOG feature type, not SIFT")
feature_type = "HAHOG"
# GPU acceleration?
if has_gpus() and feature_type == "SIFT":
log.ODM_INFO("Using GPU for extracting SIFT features")
feature_type = "SIFT_GPU"
# TODO: REMOVE
config.append("matcher_type: SIFT_GPU")
config.append("feature_type: %s" % feature_type)
if has_alt:

Wyświetl plik

@ -27,3 +27,5 @@ scikit-image==0.17.2
scipy==1.5.4
xmltodict==0.12.0
fpdf2==2.2.0rc2
silx>=0.12.0
pyopencl==2021.1.1

Wyświetl plik

@ -90,6 +90,7 @@ fi
export PORT="${PORT:=3000}"
export QTC="${QTC:=NO}"
export IMAGE="${IMAGE:=opendronemap/nodeodm}"
export GPU="${GPU:=NO}"
if [ -z "$DATA" ]; then
echo "Usage: DATA=/path/to/datasets [VARS] $0"
@ -98,6 +99,7 @@ if [ -z "$DATA" ]; then
echo " DATA Path to directory that contains datasets for testing. The directory will be mounted in /datasets. If you don't have any, simply set it to a folder outside the ODM repository."
echo " PORT Port to expose for NodeODM (default: $PORT)"
echo " IMAGE Docker image to use (default: $IMAGE)"
echo " GPU Enable GPU support (default: $GPU)"
echo " QTC When set to YES, installs QT Creator for C++ development (default: $QTC)"
exit 1
fi
@ -108,6 +110,7 @@ echo "Datasets path: $DATA"
echo "Expose port: $PORT"
echo "QT Creator: $QTC"
echo "Image: $IMAGE"
echo "GPU: $GPU"
if [ ! -e "$HOME"/.odm-dev-home ]; then
mkdir -p "$HOME"/.odm-dev-home
@ -116,6 +119,11 @@ fi
USER_ID=$(id -u)
GROUP_ID=$(id -g)
USER=$(id -un)
GPU_FLAG=""
if [[ "$GPU" != "NO" ]]; then
GPU_FLAG="--gpus all"
fi
xhost + || true
docker run -ti --entrypoint bash --name odmdev -v $(pwd):/code -v "$DATA":/datasets -p $PORT:3000 --privileged -e DISPLAY -e LANG=C.UTF-8 -e LC_ALL=C.UTF-8 -v="/tmp/.X11-unix:/tmp/.X11-unix:rw" -v="$HOME/.odm-dev-home:/home/$USER" $IMAGE -c "/code/start-dev-env.sh --setup $USER $USER_ID $GROUP_ID $QTC"
docker run -ti --entrypoint bash --name odmdev -v $(pwd):/code -v "$DATA":/datasets -p $PORT:3000 $GPU_FLAG --privileged -e DISPLAY -e LANG=C.UTF-8 -e LC_ALL=C.UTF-8 -v="/tmp/.X11-unix:/tmp/.X11-unix:rw" -v="$HOME/.odm-dev-home:/home/$USER" $IMAGE -c "/code/start-dev-env.sh --setup $USER $USER_ID $GROUP_ID $QTC"
exit 0