Debian package with GPU support.

pull/1066/head
Branton Davis 2021-09-29 13:58:12 -05:00
rodzic af32e3aa29
commit 6bcec32833
12 zmienionych plików z 593 dodań i 4 usunięć

4
.gitignore vendored
Wyświetl plik

@ -98,3 +98,7 @@ package-lock.json
.cronenv
.initialized
.DS_Store
# Debian builds
dpkg/build
dpkg/deb

30
detect_gpus.sh 100755
Wyświetl plik

@ -0,0 +1,30 @@
#!/usr/bin/env bash
set -uxo
set +e
function detectGPUs() {
lspci | grep 'VGA.*NVIDIA'
if [ "${?}" -eq 0 ]; then
export GPU_NVIDIA=true
return
fi
lspci | grep "VGA.*Intel"
if [ "${?}" -eq 0 ]; then
export GPU_INTEL=true
return
fi
# Total guess. Need to look into AMD.
lspci | grep "VGA.*AMD"
if [ "${?}" -eq 0 ]; then
export GPU_INTEL=true
fi
}
export GPU_AMD=false
export GPU_INTEL=false
export GPU_NVIDIA=false
detectGPUs

Wyświetl plik

@ -0,0 +1,29 @@
# Chaining this file to the main docker-compose file adds
# a default processing node instance. This is best for users
# who are just getting started with WebODM.
version: '2.1'
services:
webapp:
depends_on:
- node-odm
environment:
- PYOPENCL_COMPILER_OUTPUT=1
node-odm:
image: opendronemap/nodeodm:gpu.intel
devices:
- "/dev/dri"
ports:
- "3000"
restart: unless-stopped
oom_score_adj: 500
environment:
- PYOPENCL_COMPILER_OUTPUT=1
deploy:
resources:
limits:
cpus: 3
memory: 6144M
reservations:
cpus: 2
memory: 4096M

Wyświetl plik

@ -0,0 +1,24 @@
# Chaining this file to the main docker-compose file adds
# a default processing node instance. This is best for users
# who are just getting started with WebODM.
version: '2.1'
services:
webapp:
depends_on:
- node-odm
environment:
- WO_DEFAULT_NODES
node-odm:
image: opendronemap/nodeodm:gpu
ports:
- "3000"
restart: unless-stopped
oom_score_adj: 500
deploy:
resources:
reservations:
devices:
- driver: nvidia
count: 1
capabilities: [gpu]

69
dpkg/build.sh 100755
Wyświetl plik

@ -0,0 +1,69 @@
#!/usr/bin/env bash
set -euxo
HERE="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
WEBODM_VERSION=1.9.7
WEBODM_DPKG_VERSION=3
WEBODM_DPKG_NAME="webodm_${WEBODM_VERSION}-${WEBODM_DPKG_VERSION}"
BUILD_DIR="${HERE}/build"
DEB_DIR="${HERE}/deb"
WEBODM_DIR="${HERE}/${WEBODM_DPKG_NAME}/opt/WebODM"
NODEODM_DIR="${HERE}/${WEBODM_DPKG_NAME}/opt/nodeodm"
function moveToBuildDir() {
cd "${BUILD_DIR}/${WEBODM_DPKG_NAME}"
}
function prepareBuildDir() {
if [ -d "${BUILD_DIR}" ]; then
rm -Rf "${BUILD_DIR}"
fi
mkdir -p "${BUILD_DIR}/${WEBODM_DPKG_NAME}"
cp -R "${HERE}/webodm" "${BUILD_DIR}/${WEBODM_DPKG_NAME}/${WEBODM_DPKG_NAME}"
}
function prepareDebDir() {
if [ -d "${DEB_DIR}" ]; then
rm -Rf "${DEB_DIR}"
fi
mkdir -p "${DEB_DIR}"
}
function prepareWebODMDir() {
TMP_DIR="/tmp/WebODM"
if [ -d "${BUILD_DIR}" ]; then
rm -Rf "${TMP_DIR}"
fi
cp -R "${HERE}/.." "${TMP_DIR}"
mv "${TMP_DIR}" "${BUILD_DIR}/${WEBODM_DPKG_NAME}/${WEBODM_DPKG_NAME}/opt/"
}
function prepareNodeODMDir() {
# This can go away when we can pull the image from Docker Hub.
git clone -b bkd/gpu https://github.com/airmap/nodeodm.git "${BUILD_DIR}/${WEBODM_DPKG_NAME}/${WEBODM_DPKG_NAME}/opt/nodeodm"
}
function build() {
dpkg-deb --build "${WEBODM_DPKG_NAME}"
}
function bundle() {
mkdir -p "${DEB_DIR}/${WEBODM_DPKG_NAME}"
cp "${HERE}/install.sh" "${DEB_DIR}/${WEBODM_DPKG_NAME}/"
cp "${BUILD_DIR}/${WEBODM_DPKG_NAME}/${WEBODM_DPKG_NAME}/opt/WebODM/detect_gpus.sh" "${DEB_DIR}/${WEBODM_DPKG_NAME}/"
cp "${WEBODM_DPKG_NAME}.deb" "${DEB_DIR}/${WEBODM_DPKG_NAME}/"
}
prepareBuildDir
prepareDebDir
prepareNodeODMDir
prepareWebODMDir
moveToBuildDir
build
bundle

139
dpkg/install.sh 100755
Wyświetl plik

@ -0,0 +1,139 @@
#!/usr/bin/env bash
set -ux
HERE="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
WEBODM_VERSION=1.9.7
WEBODM_DPKG_VERSION=3
WEBODM_DPKG_NAME="webodm_${WEBODM_VERSION}-${WEBODM_DPKG_VERSION}"
function aptFixInstall() {
echo "aptFixInstall"
sudo apt update
sudo apt --fix-missing --fix-broken install
}
function ensureDocker() {
if ! command -v docker &> /dev/null; then
sudo apt install docker.io
fi
}
function ensureDockerCompose() {
if ! command -v docker-compose &> /dev/null; then
sudo apt install docker-compose
fi
}
function ensureIntelOpenCL() {
if [ "${GPU_INTEL}" = false ]; then
return
fi
INTEL_COMPUTE_RUNTIME_VERSION="21.38.21026"
INTEL_GRAPHICS_COMPILER_VERSION="1.0.8708"
INTEL_COMPUTE_RUNTIME_DOWNLOAD_URL="https://github.com/intel/compute-runtime/releases/download/${INTEL_COMPUTE_RUNTIME_VERSION}"
INTEL_GRAPHICS_COMPILER_DOWNLOAD_URL="https://github.com/intel/intel-graphics-compiler/releases/download/igc-${INTEL_GRAPHICS_COMPILER_VERSION}"
INTEL_GMMLIB_VERSION="21.2.1"
INTEL_LEVEL_ZERO_GPU_VERSION="1.2.21026"
dpkg -l intel-gmmlib | grep "${INTEL_GMMLIB_VERSION}"
INTEL_GMMLIB="${?}"
dpkg -l intel-igc-core | grep "${INTEL_GRAPHICS_COMPILER_VERSION}"
INTEL_IGC_CORE="${?}"
dpkg -l intel-igc-opencl | grep "${INTEL_GRAPHICS_COMPILER_VERSION}"
INTEL_IGC_OPENCL="${?}"
dpkg -l intel-opencl | grep "${INTEL_COMPUTE_RUNTIME_VERSION}"
INTEL_OPENCL="${?}"
dpkg -l intel-ocloc | grep "${INTEL_COMPUTE_RUNTIME_VERSION}"
INTEL_OCLOC="${?}"
dpkg -l intel-level-zero-gpu | grep "${INTEL_LEVEL_ZERO_GPU_VERSION}"
INTEL_LEVEL_ZERO_GPU="${?}"
if [ "${INTEL_GMMLIB}" -ne 0 ] || [ "${INTEL_IGC_CORE}" -ne 0 ] || [ "${INTEL_IGC_OPENCL}" -ne 0 ] || [ "${INTEL_OPENCL}" -ne 0 ] || [ "${INTEL_OCLOC}" -ne 0 ]; then
sudo apt-get update
sudo apt-get install --no-install-recommends ocl-icd-libopencl1 curl
sudo rm -rf /var/lib/apt/lists/*
TEMP_DIR=/tmp/opencl
sudo mkdir -p "${TEMP_DIR}"
if [ "${INTEL_GMMLIB}" -ne 0 ]; then
sudo curl -L "${INTEL_COMPUTE_RUNTIME_DOWNLOAD_URL}/intel-gmmlib_${INTEL_GMMLIB_VERSION}_amd64.deb" --output "${TEMP_DIR}/intel-gmmlib_${INTEL_GMMLIB_VERSION}_amd64.deb"
fi
if [ "${INTEL_IGC_CORE}" -ne 0 ]; then
sudo curl -L "${INTEL_GRAPHICS_COMPILER_DOWNLOAD_URL}/intel-igc-core_${INTEL_GRAPHICS_COMPILER_VERSION}_amd64.deb" --output "${TEMP_DIR}/intel-igc-core${INTEL_GRAPHICS_COMPILER_VERSION}_amd64.deb"
fi
if [ "${INTEL_IGC_OPENCL}" -ne 0 ]; then
sudo curl -L "${INTEL_GRAPHICS_COMPILER_DOWNLOAD_URL}/intel-igc-opencl_${INTEL_GRAPHICS_COMPILER_VERSION}_amd64.deb" --output "${TEMP_DIR}/intel-igc-core${INTEL_GRAPHICS_COMPILER_VERSION}_amd64.deb"
fi
if [ "${INTEL_OPENCL}" -ne 0 ]; then
sudo curl -L "${INTEL_COMPUTE_RUNTIME_DOWNLOAD_URL}/intel-opencl_${INTEL_COMPUTE_RUNTIME_VERSION}_amd64.deb" --output "${TEMP_DIR}/intel-gmmlib_${INTEL_COMPUTE_RUNTIME_VERSION}_amd64.deb"
fi
if [ "${INTEL_OCLOC}" -ne 0 ]; then
sudo curl -L "${INTEL_COMPUTE_RUNTIME_DOWNLOAD_URL}/intel-ocloc_${INTEL_COMPUTE_RUNTIME_VERSION}_amd64.deb" --output "${TEMP_DIR}/intel-ocloc_${INTEL_COMPUTE_RUNTIME_VERSION}_amd64.deb"
fi
if [ "${INTEL_LEVEL_ZERO_GPU}" -ne 0 ]; then
sudo curl -L "${INTEL_COMPUTE_RUNTIME_DOWNLOAD_URL}/intel-level-zero-gpu_${INTEL_LEVEL_ZERO_GPU_VERSION}_amd64.deb" --output "${TEMP_DIR}/intel-level-zero-gpu_${INTEL_LEVEL_ZERO_GPU_VERSION}_amd64.deb"
fi
sudo dpkg -i "${TEMP_DIR}/"*.deb
sudo ldconfig
sudo rm -Rf "${TEMP_DIR}"
sudo apt-get update
sudo apt install clinfo
fi
}
function ensureNVIDIAOpenCL() {
if [ "${GPU_NVIDIA}" = false ]; then
return
fi
RECOMMENDED_DRIVER=$(ubuntu-drivers devices | grep "nvidia.*recommended" | cut -d' ' -f5)
if [ -z "${RECOMMENDED_DRIVER}" ]; then
echo "Unable to find a recommended NVIDIA driver."
exit 1
fi
sudo apt install "${RECOMMENDED_DRIVER}"
}
function ensureOpenCL() {
source "${HERE}/detect_gpus.sh"
if [ "${GPU_INTEL}" = true ]; then
ensureIntelOpenCL
fi
# if [ "${GPU_NVIDIA}" = true ]; then
# ensureNVIDIAOpenCL
# fi
}
function install() {
ensureOpenCL
ensureDocker
ensureDockerCompose
sudo dpkg -i "${HERE}/${WEBODM_DPKG_NAME}.deb"
}
function uninstall() {
sudo dpkg --purge webodm
}
uninstall || echo "Skipping uninstall."
install || aptFixInstall

Wyświetl plik

@ -0,0 +1,17 @@
Package: WebODM
Version: 1.9.7-3
Section: base
Priority: optional
Architecture: all
Depends: docker.io | docker-ce,
docker-compose,
ocl-icd-libopencl1,
clinfo,
python3,
python3-pip,
python3-venv,
screen
Maintainer: Branton Davis <branton@airmap.com>
Description: WebODM
When you need some sunshine, just run this
small program!

Wyświetl plik

@ -0,0 +1,137 @@
#!/usr/bin/env bash
set -euxo
export WEBODM_VERSION=1.9.7
export WEBODM_USER=odm
export WEBODM_USER_HOME="/home/${WEBODM_USER}"
export WEBODM_DIR=/opt/WebODM
export WEBODM_VENV_DIR="${WEBODM_DIR}/python3-venv"
export NODEODM_DIR=/opt/nodeodm
function addNodeODMGPUIntelDockerGroups() {
DOCKER_COMPOSE_FILE="${WEBODM_DIR}/docker-compose.nodeodm.gpu.intel.yml"
for gid in $(id -G "${WEBODM_USER}"); do
echo "Checking gid ${gid}."
SED_SEARCH="/^\s\{4\}group_add/{:start /${gid}$/!"
SED_SEARCH="${SED_SEARCH}{N;b start};/${gid}$/p}"
# SED_OUT=$(sed -n '/^\s\{4\}group_add/{:start /$gid$/!{N;b start};/10/p}' "${DOCKER_COMPOSE_FILE}")
SED_OUT=$(sed -n "${SED_SEARCH}" "${DOCKER_COMPOSE_FILE}")
if [ -z "${SED_OUT}" ]; then
echo "Adding gid ${gid}."
echo "SED_OUT: ${SED_OUT}"
sed -i "/^\s\{4\}image/a \ \ \ \ group_add:\n\ \ \ \ \ \ - ${gid}" "${DOCKER_COMPOSE_FILE}"
fi
done
}
function buildNodeODMGPUIntelDockerImage() {
cd "${NODEODM_DIR}"
# We won't have to do this after the image is on Docker Hub.
docker build -f Dockerfile.gpu -t opendronemap/nodeodm:gpu .
# This will continue to be necessary, since it needs to bake in the actual
# render group id on this system.
RENDER_GROUP_ID=$(getent group render | cut -d":" -f3)
docker build -f Dockerfile.gpu.intel -t opendronemap/nodeodm:gpu.intel --build-arg RENDER_GROUP_ID="${RENDER_GROUP_ID}" .
}
function createGroup() {
if [ "${GPU_INTEL}" = true ]; then
if ! grep -q "^render:" /etc/group; then
groupadd render
fi
fi
}
function createUser() {
if ! grep -q "^${WEBODM_USER}:" /etc/passwd; then
if [ "${GPU_INTEL}" = true ]; then
useradd -m -d "${WEBODM_USER_HOME}" -s /bin/bash -G docker,video,render "${WEBODM_USER}"
else
useradd -m -d "${WEBODM_USER_HOME}" -s /bin/bash -G docker "${WEBODM_USER}"
fi
chown "${WEBODM_USER}":"${WEBODM_USER}" "${WEBODM_USER_HOME}"
fi
PROFILE_PATH="/home/odm/.profile"
if [ ! -f "${PROFILE_PATH}" ]; then
touch "${PROFILE_PATH}"
chmod odm:odm "${PROFILE_PATH}"
fi
if ! grep -q "PATH.*home\/odm\/\.local\/bin" "${PROFILE_PATH}"; then
echo "export PATH=\"/home/odm/.local/bin:${PATH}\"" >> "${PROFILE_PATH}"
fi
}
function createVenv() {
if [ ! -d "${WEBODM_VENV_DIR}" ]; then
mkdir "${WEBODM_VENV_DIR}"
python3 -m venv "${WEBODM_VENV_DIR}"
fi
}
function detectGPUs() {
source "${WEBODM_DIR}/detect_gpus.sh"
}
function enableService() {
systemctl enable "${WEBODM_DIR}/service/webodm-docker.service"
}
function installPythonDockerCompose() {
su "${WEBODM_USER}" -c "python3 -m pip install --upgrade docker-compose"
}
function setFilePermissions() {
chown -R "${WEBODM_USER}:${WEBODM_USER}" "${WEBODM_DIR}"
}
function upgradePythonPip() {
su "${WEBODM_USER}" -c "python3 -m pip install --upgrade pip"
}
####
function startService() {
systemctl daemon-reload
systemctl restart webodm-docker.service
}
function abortRemove() {
echo "Unable to remove webodm."
}
function configure() {
detectGPUs
createGroup
createUser
if [ "${GPU_INTEL}" = true ]; then
buildNodeODMGPUIntelDockerImage
addNodeODMGPUIntelDockerGroups
fi
createVenv
setFilePermissions
upgradePythonPip
installPythonDockerCompose
enableService
startService
}
case $1 in
abort-remove)
abortRemove
;;
configure)
configure
;;
default)
exit 1
;;
esac

Wyświetl plik

@ -0,0 +1,70 @@
#!/usr/bin/env bash
set -euxo
export WEBODM_VERSION=1.9.7
export WEBODM_USER=odm
export WEBODM_USER_HOME="/home/${WEBODM_USER}"
export WEBODM_DIR=/opt/WebODM
export WEBODM_VENV_DIR="${WEBODM_DIR}/python3-venv"
export NODEODM_DIR=/opt/nodeodm
function deleteUser() {
if grep -q "^${WEBODM_USER}:" /etc/passwd; then
userdel "${WEBODM_USER}"
fi
}
function deleteUserHome() {
if [ -d "${WEBODM_USER_HOME}" ]; then
rm -Rf "${WEBODM_USER_HOME}"
fi
}
function deleteVenv() {
if [ -d "${WEBODM_VENV_DIR}" ]; then
rm -Rf "${WEBODM_VENV_DIR}"
fi
}
function stopService() {
UNIT_NAME="webodm-docker.service"
set +e
systemctl is-active -q "${UNIT_NAME}"
if [ "${?}" -eq 0 ]; then
set -e
systemctl stop "${UNIT_NAME}"
else
set -e
fi
systemctl disable "${UNIT_NAME}"
systemctl daemon-reload
/opt/WebODM/webodm.sh down
}
function purge() {
stopService
deleteUser
deleteVenv
deleteUserHome
}
function abortInstall() {
purge
}
case $1 in
abort-install)
abortInstall
;;
remove)
exit 0
;;
purge)
purge
;;
default)
exit 1
;;
esac

Wyświetl plik

@ -0,0 +1,23 @@
#!/usr/bin/env bash
set -euxo
export WEBODM_VERSION=1.9.7
export WEBODM_USER=odm
export WEBODM_USER_HOME="/home/${WEBODM_USER}"
export WEBODM_DIR=/opt/WebODM
export WEBODM_VENV_DIR="${WEBODM_DIR}/python3-venv"
export NODEODM_DIR=/opt/nodeodm
function install() {
echo "preinst install"
}
case $1 in
install)
install
;;
default)
exit 1
;;
esac

Plik binarny nie jest wyświetlany.

Wyświetl plik

@ -220,7 +220,16 @@ start(){
command="docker-compose -f docker-compose.yml"
if [[ $default_nodes > 0 ]]; then
command+=" -f docker-compose.nodeodm.yml"
source "${__dirname}/detect_gpus.sh"
set +ux
if [ "${GPU_NVIDIA}" = true ]; then
command+=" -f docker-compose.nodeodm.gpu.nvidia.yml"
elif [ "${GPU_INTEL}" = true ]; then
command+=" -f docker-compose.nodeodm.gpu.intel.yml"
else
command+=" -f docker-compose.nodeodm.yml"
fi
fi
if [[ $load_micmac_node = true ]]; then
@ -283,7 +292,22 @@ start(){
}
down(){
run "docker-compose -f docker-compose.yml -f docker-compose.nodeodm.yml -f docker-compose.nodemicmac.yml down --remove-orphans"
source "${__dirname}/detect_gpus.sh"
set +ux
command="docker-compose -f docker-compose.yml"
if [ "${GPU_NVIDIA}" = true ]; then
command+=" -f docker-compose.nodeodm.gpu.nvidia.yml"
elif [ "${GPU_INTEL}" = true ]; then
command+=" -f docker-compose.nodeodm.gpu.intel.yml"
else
command+=" -f docker-compose.nodeodm.yml"
fi
command+=" -f docker-compose.nodemicmac.yml down --remove-orphans"
run "${command}"
}
rebuild(){
@ -340,7 +364,21 @@ if [[ $1 = "start" ]]; then
elif [[ $1 = "stop" ]]; then
environment_check
echo "Stopping WebODM..."
run "docker-compose -f docker-compose.yml -f docker-compose.nodeodm.yml -f docker-compose.nodemicmac.yml stop"
source "${__dirname}/detect_gpus.sh"
set +ux
command="docker-compose -f docker-compose.yml"
if [ "${GPU_NVIDIA}" = true ]; then
command+=" -f docker-compose.nodeodm.gpu.nvidia.yml"
elif [ "${GPU_INTEL}" = true ]; then
command+=" -f docker-compose.nodeodm.gpu.intel.yml"
else
command+=" -f docker-compose.nodeodm.yml"
fi
command+=" -f docker-compose.nodemicmac.yml stop"
run "${command}"
elif [[ $1 = "restart" ]]; then
environment_check
echo "Restarting WebODM..."
@ -372,7 +410,16 @@ elif [[ $1 = "update" ]]; then
command="docker-compose -f docker-compose.yml"
if [[ $default_nodes > 0 ]]; then
command+=" -f docker-compose.nodeodm.yml"
source "${__dirname}/detect_gpus.sh"
set +ux
if [ "${GPU_NVIDIA}" = true ]; then
command+=" -f docker-compose.nodeodm.gpu.nvidia.yml"
elif [ "${GPU_INTEL}" = true ]; then
command+=" -f docker-compose.nodeodm.gpu.intel.yml"
else
command+=" -f docker-compose.nodeodm.yml"
fi
fi
if [[ $load_micmac_node = true ]]; then