Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions openpose/CMakeLists.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 0e269073..d0d4265d 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -220,6 +220,8 @@ if (${GPU_MODE} MATCHES "OPENCL")
find_package(OpenCL)
endif (${GPU_MODE} MATCHES "OPENCL")

+find_package(Boost COMPONENTS system filesystem REQUIRED)
+
# Code to avoid crash at compiling time if OpenCL is not found
if (NOT OpenCL_FOUND)
set(OpenCL_LIBRARIES "")
@@ -786,6 +788,7 @@ if (UNIX OR APPLE)
PREFIX ${CAFFE_PREFIX}
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>
-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}
+ -DCMAKE_CXX_FLAGS="-w"
-DMKLDNN_INSTALL_DIR:PATH=<INSTALL_DIR>
-DUSE_MKL2017_AS_DEFAULT_ENGINE=${CAFFE_CPU_ONLY}
-DUSE_CUDNN=${USE_CUDNN}
@@ -807,6 +810,7 @@ if (UNIX OR APPLE)
PREFIX ${CAFFE_PREFIX}
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>
-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}
+ -DCMAKE_CXX_FLAGS="-w"
-DUSE_CUDNN=${USE_CUDNN}
-DCUDA_ARCH_NAME=${CUDA_ARCH}
-DCUDA_ARCH_BIN=${CUDA_ARCH_BIN}
145 changes: 145 additions & 0 deletions openpose/Singularity.openpose-multi
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
Bootstrap: docker
From: nvcr.io/nvidia/caffe:20.03-py3

%files
CMakeLists.patch
cudacap.cxx

%post
# Packages
export LC_ALL=C
apt-get -y --no-install-recommends update && \
apt-get -y --no-install-recommends upgrade

apt-get install -y --no-install-recommends \
build-essential \
git \
wget \
nano \
dialog \
software-properties-common \
libatlas-base-dev \
libleveldb-dev \
libsnappy-dev \
libhdf5-serial-dev \
libboost-all-dev \
libgflags-dev \
libgoogle-glog-dev \
liblmdb-dev \
pciutils \
python3-setuptools \
python3-dev \
python3-pip \
opencl-headers \
ocl-icd-opencl-dev \
libviennacl-dev \
libavcodec-dev \
libavformat-dev \
libswscale-dev \
libv4l-dev \
libxvidcore-dev \
libx264-dev \
libgtk-3-dev \
gfortran \
pkg-config \
libssl-dev \
libcanberra-gtk-module && \
python3 -m pip install \
numpy \
opencv-python

# Up to date ffmpeg
add-apt-repository -y ppa:jonathonf/ffmpeg-4 && \
apt-get -y --no-install-recommends update && \
apt-get -y --no-install-recommends install ffmpeg \

# Up to date CMake (Ubuntu 18.04 includes 3.10 which is too old)
wget -O - \
https://apt.kitware.com/keys/kitware-archive-latest.asc | \
gpg --dearmor - | \
tee /etc/apt/trusted.gpg.d/kitware.gpg && \
apt-add-repository -y 'deb https://apt.kitware.com/ubuntu/ bionic main' && \
apt-get update && \
apt-get -y --no-install-recommends install cmake

# Get OpenPose
cd /opt && \
git clone --depth 1 https://github.com/CMU-Perceptual-Computing-Lab/openpose.git --branch v1.6.0 --single-branch && \
cp -R openpose openpose_cpu && \
cp -R openpose openpose_legacy_gpu

# Fix up stubs
ln -s /usr/local/cuda/lib64/stubs/libnvidia-ml.so /usr/local/cuda/lib64/stubs/libnvidia-ml.so.1

# Build GPU + NVCaffe OpenPose
mkdir -p /opt/openpose/build && \
cd /opt/openpose/ && git apply /CMakeLists.patch
cd build && \
cmake \
-DGPU_MODE=CUDA \
-DBUILD_PYTHON=ON \
-DCMAKE_EXE_LINKER_FLAGS="-Wl,-rpath-link=/usr/local/cuda/lib64/stubs" \
-DDL_FRAMEWORK=NV_CAFFE \
-DCaffe_INCLUDE_DIRS=/usr/local/include/caffe \
-DCaffe_LIBS_RELEASE=/usr/local/lib/libcaffe-nv.so \
-DCaffe_LIBS=/usr/local/lib/libcaffe-nv.so \
-DBUILD_CAFFE=OFF \
-DCUDA_ARCH=All \
.. && \
make -j`nproc`

# Build CPU OpenPose
mkdir -p /opt/openpose_cpu/build && \
cd /opt/openpose_cpu/ && git apply /CMakeLists.patch &&
cd build &&
cmake \
-DGPU_MODE=CPU_ONLY \
-DBUILD_PYTHON=ON \
.. && \
make -j`nproc`

# Build legacy GPU OpenPose
mkdir -p /opt/openpose_legacy_gpu/build && \
cd /opt/openpose_legacy_gpu/ && git apply /CMakeLists.patch &&
cd build &&
cmake \
-DGPU_MODE=CUDA \
-DBUILD_PYTHON=ON \
-DCMAKE_EXE_LINKER_FLAGS="-Wl,-rpath-link=/usr/local/cuda/lib64/stubs" \
-DCUDA_ARCH=All \
.. && \
make -j`nproc`

# Build CUDA capability checker
g++ /cudacap.cxx -I/usr/local/cuda/include -o /cudacap /usr/local/cuda/lib64/libcudart.so


%environment
if [ -z "$LD_LIBRARY_PATH" ]; then
LD_LIBRARY_PATH="/.singularity.d/libs"
else
LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/.singularity.d/libs"
fi

if nvidia-smi; then
if [ "$(/cudacap)" -ge "50" ]; then
echo "#### USING GPU with NVCaffe ####"
export OPENPOSE_SRC=/opt/openpose
export OPENPOSE_VAR=gpu
else
echo "#### USING Legacy GPU with Custom Caffe ####"
export OPENPOSE_SRC=/opt/openpose_legacy_gpu
export OPENPOSE_VAR=legacy_gpu
fi
else
echo "#### USING CPU ####"
export OPENPOSE_SRC=/opt/openpose_cpu
export OPENPOSE_VAR=cpu
fi
export OPENPOSE=$OPENPOSE_SRC/build
export OPENPOSE_BIN=$OPENPOSE/examples/openpose/openpose.bin
export PYTHONPATH="$OPENPOSE/python:$PYTHONPATH"


%runscript
cd $OPENPOSE_SRC && exec $OPENPOSE_BIN "$@"
31 changes: 31 additions & 0 deletions openpose/cudacap.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include <cstdio>
#include <cstdlib>
#include <cuda_runtime_api.h>

int main(int argc, char *argv[])
{
cudaDeviceProp prop;
cudaError_t status;
int device_count;
int device_index = 0;
if (argc > 1) {
device_index = atoi(argv[1]);
}

status = cudaGetDeviceCount(&device_count);
if (status != cudaSuccess) {
fprintf(stderr,"cudaGetDeviceCount() failed: %s\n", cudaGetErrorString(status));
return -1;
}
if (device_index >= device_count) {
fprintf(stderr, "Specified device index %d exceeds the maximum (the device count on this system is %d)\n", device_index, device_count);
return -1;
}
status = cudaGetDeviceProperties(&prop, device_index);
if (status != cudaSuccess) {
fprintf(stderr,"cudaGetDeviceProperties() for device device_index failed: %s\n", cudaGetErrorString(status));
return -1;
}
int v = prop.major * 10 + prop.minor;
printf("%d\n", v);
}