Skip to content

Commit

Permalink
Upgrade to CUDA 11.2 and improve GPU support (opendr-eu#215)
Browse files Browse the repository at this point in the history
* Updated to CUDA11.2

* Switch to devel image

* Update install.sh

* Update dependencies.ini

* Updated pytorch

* DCNv2 update

* Detectron update

* Update installation.md

* More strict stable-baselines3 ver

* Updated dep version

* Update CHANGELOG.md

* Small consistent fix

* Minor typo fix

* Updated CPU/GPU support for pip

* Updated numba version

* Removed OPENDR_DEVICE

* Added support for changing inference device during testing

* Style fixes

* Separate tests for face detection

* Updated testing pipeline for face detection 2d

* Update installation.md

* Fixed weight placement

* Fixed cuda placement check

* Fixed mxnet installation

* Updated base image

* Separate object detection 2d tests

* Upgraded to pytorch 1.9.0

* Changed default constant folding setting

* Updated EfficientPS

* Apply suggestions from code review

Co-authored-by: ad-daniel <44834743+ad-daniel@users.noreply.github.com>

* Bugfixes

* Increase tollerance in test_cox3d_learner

* Test dockerfile with correct branch

* Removed comment

* remove branch from docker files

Co-authored-by: ad-daniel <daniel.dias@epfl.ch>
Co-authored-by: ad-daniel <44834743+ad-daniel@users.noreply.github.com>
Co-authored-by: LukasHedegaard <lh@eng.au.dk>
  • Loading branch information
4 people committed Mar 22, 2022
1 parent b35b483 commit f63cd7c
Show file tree
Hide file tree
Showing 79 changed files with 454 additions and 311 deletions.
14 changes: 12 additions & 2 deletions .github/workflows/test_packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,12 @@ jobs:
- perception/speech_recognition
- perception/skeleton_based_action_recognition
- perception/semantic_segmentation
- perception/object_detection_2d
- perception/object_detection_2d/centernet
- perception/object_detection_2d/detr
- perception/object_detection_2d/gem
- perception/object_detection_2d/ssd
- perception/object_detection_2d/yolov3
- perception/object_detection_2d/retinaface
- perception/facial_expression_recognition
# - perception/object_detection_3d
# - control/mobile_manipulation
Expand Down Expand Up @@ -82,7 +87,12 @@ jobs:
- perception/speech_recognition
- perception/skeleton_based_action_recognition
- perception/semantic_segmentation
- perception/object_detection_2d
- perception/object_detection_2d/centernet
- perception/object_detection_2d/detr
- perception/object_detection_2d/gem
- perception/object_detection_2d/ssd
- perception/object_detection_2d/yolov3
- perception/object_detection_2d/retinaface
- perception/facial_expression_recognition
- perception/object_detection_3d
- control/mobile_manipulation
Expand Down
30 changes: 25 additions & 5 deletions .github/workflows/tests_suite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,12 @@ jobs:
- perception/skeleton_based_action_recognition
- perception/semantic_segmentation
- control/mobile_manipulation
- perception/object_detection_2d
- perception/object_detection_2d/centernet
- perception/object_detection_2d/detr
- perception/object_detection_2d/gem
- perception/object_detection_2d/ssd
- perception/object_detection_2d/yolov3
- perception/object_detection_2d/retinaface
- simulation/human_model_generation
- perception/facial_expression_recognition
- control/single_demo_grasp
Expand Down Expand Up @@ -168,7 +173,12 @@ jobs:
- perception/speech_recognition
- perception/skeleton_based_action_recognition
- perception/semantic_segmentation
- perception/object_detection_2d
- perception/object_detection_2d/centernet
- perception/object_detection_2d/detr
- perception/object_detection_2d/gem
- perception/object_detection_2d/ssd
- perception/object_detection_2d/yolov3
- perception/object_detection_2d/retinaface
- perception/facial_expression_recognition
# - perception/object_detection_3d
# - control/mobile_manipulation
Expand All @@ -194,7 +204,7 @@ jobs:
- name: Test Wheel
run: |
export DISABLE_BCOLZ_AVX2=true
sudo apt -y install python3.8-venv libfreetype6-dev git build-essential cmake python3-dev wget libopenblas-dev libsndfile1 libboost-dev libeigen3-dev
sudo apt -y install python3.8-venv libfreetype6-dev git build-essential cmake python3-dev wget libopenblas-dev libsndfile1 libboost-dev python3-dev
python3 -m venv venv
source venv/bin/activate
pip install wheel
Expand Down Expand Up @@ -232,7 +242,12 @@ jobs:
- perception/speech_recognition
- perception/skeleton_based_action_recognition
- perception/semantic_segmentation
- perception/object_detection_2d
- perception/object_detection_2d/centernet
- perception/object_detection_2d/detr
- perception/object_detection_2d/gem
- perception/object_detection_2d/ssd
- perception/object_detection_2d/yolov3
- perception/object_detection_2d/retinaface
- perception/facial_expression_recognition
# - perception/object_detection_3d
# - control/mobile_manipulation
Expand Down Expand Up @@ -302,7 +317,12 @@ jobs:
- perception/speech_recognition
- perception/skeleton_based_action_recognition
- perception/semantic_segmentation
- perception/object_detection_2d
- perception/object_detection_2d/centernet
- perception/object_detection_2d/detr
- perception/object_detection_2d/gem
- perception/object_detection_2d/ssd
- perception/object_detection_2d/yolov3
- perception/object_detection_2d/retinaface
- perception/facial_expression_recognition
- perception/object_detection_3d
- control/mobile_manipulation
Expand Down
28 changes: 24 additions & 4 deletions .github/workflows/tests_suite_develop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,12 @@ jobs:
- perception/skeleton_based_action_recognition
- perception/semantic_segmentation
- control/mobile_manipulation
- perception/object_detection_2d
- perception/object_detection_2d/centernet
- perception/object_detection_2d/detr
- perception/object_detection_2d/gem
- perception/object_detection_2d/ssd
- perception/object_detection_2d/yolov3
- perception/object_detection_2d/retinaface
- simulation/human_model_generation
- perception/facial_expression_recognition
- control/single_demo_grasp
Expand Down Expand Up @@ -168,7 +173,12 @@ jobs:
- perception/speech_recognition
- perception/skeleton_based_action_recognition
- perception/semantic_segmentation
- perception/object_detection_2d
- perception/object_detection_2d/centernet
- perception/object_detection_2d/detr
- perception/object_detection_2d/gem
- perception/object_detection_2d/ssd
- perception/object_detection_2d/yolov3
- perception/object_detection_2d/retinaface
- perception/facial_expression_recognition
# - perception/object_detection_3d
# - control/mobile_manipulation
Expand Down Expand Up @@ -233,7 +243,12 @@ jobs:
- perception/speech_recognition
- perception/skeleton_based_action_recognition
- perception/semantic_segmentation
- perception/object_detection_2d
- perception/object_detection_2d/centernet
- perception/object_detection_2d/detr
- perception/object_detection_2d/gem
- perception/object_detection_2d/ssd
- perception/object_detection_2d/yolov3
- perception/object_detection_2d/retinaface
- perception/facial_expression_recognition
# - perception/object_detection_3d
# - control/mobile_manipulation
Expand Down Expand Up @@ -304,7 +319,12 @@ jobs:
- perception/speech_recognition
- perception/skeleton_based_action_recognition
- perception/semantic_segmentation
- perception/object_detection_2d
- perception/object_detection_2d/centernet
- perception/object_detection_2d/detr
- perception/object_detection_2d/gem
- perception/object_detection_2d/ssd
- perception/object_detection_2d/yolov3
- perception/object_detection_2d/retinaface
- perception/facial_expression_recognition
- perception/object_detection_3d
- control/mobile_manipulation
Expand Down
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ Released on XX, XXth, 2022.
- Added support for modular pip packages allowing tools to be installed separately ([#201](https://github.com/opendr-eu/opendr/pull/201)).
- Simplified the installation process for pip by including the appropriate post-installation scripts ([#201](https://github.com/opendr-eu/opendr/pull/201)).
- Improved the structure of the toolkit by moving `io` from `utils` to `engine.helper` ([#201](https://github.com/opendr-eu/opendr/pull/201)).
- Added support for `post-install` scripts and `opendr` dependencies in `.ini` files ([#201](https://github.com/opendr-eu/opendr/pull/201)).
- Added support for `post-install` scripts and `opendr` dependencies in `.ini` files ([#201](https://github.com/opendr-eu/opendr/pull/201)).
- Updated toolkit to support CUDA 11.2 and improved GPU support ([#215](https://github.com/opendr-eu/opendr/pull/215)).
- Bug Fixes:
- Updated wheel building pipeline to include missing files and removed unnecessary dependencies ([#200](https://github.com/opendr-eu/opendr/pull/200)).
- `panoptic_segmentation/efficient_ps`: updated dataset preparation scripts to create correct validation ground truth ([#221](https://github.com/opendr-eu/opendr/pull/221)).
Expand Down
32 changes: 2 additions & 30 deletions Dockerfile-cuda
Original file line number Diff line number Diff line change
@@ -1,45 +1,17 @@
FROM nvidia/cuda:11.0-base
FROM nvidia/cuda:11.2.0-cudnn8-devel-ubuntu20.04

# Install dependencies
RUN apt-get update && \
apt-get --yes install git sudo apt-utils
RUN DEBIAN_FRONTEND="noninteractive" apt-get -y install tzdata

# Install CUDA 10.2
RUN apt-get --yes install gcc-8 g++-8 wget && \
update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-8 100 --slave /usr/bin/g++ g++ /usr/bin/g++-8 && \
update-alternatives --auto gcc && \
apt-get --yes install zlib1g-dev libbz2-dev libreadline-dev libssl-dev libsqlite3-dev libffi-dev && \
wget https://developer.download.nvidia.com/compute/cuda/10.2/Prod/local_installers/cuda_10.2.89_440.33.01_linux.run && \
wget http://people.cs.uchicago.edu/~kauffman/nvidia/cudnn/cudnn-10.2-linux-x64-v8.2.0.53.tgz

RUN sudo apt-get --yes install libxml2 && \
sh cuda_10.2.89_440.33.01_linux.run --silent --toolkit --override --librarypath=/usr/local/cuda-10.2 && \
ln -s /usr/local/cuda-10.2/ /usr/local/cuda && \
tar -xzvf cudnn-10.2-linux-x64-v8.2.0.53.tgz && \
cp cuda/include/cudnn.h /usr/local/cuda/include && \
cp cuda/lib64/libcudnn* /usr/local/cuda/lib64 && \
chmod a+r /usr/local/cuda/include/cudnn.h /usr/local/cuda/lib64/libcudnn* && \
bash -c 'echo "/usr/local/cuda-10.2/lib64" > /etc/ld.so.conf.d/nvidia.conf' && \
ln -sf /usr/local/cuda-10.2/targets/x86_64-linux/lib/libcudnn_adv_train.so.8.2.0 /usr/local/cuda-10.2/targets/x86_64-linux/lib/libcudnn_adv_train.so.8 && \
ln -sf /usr/local/cuda-10.2/targets/x86_64-linux/lib/libcudnn_ops_infer.so.8.2.0 /usr/local/cuda-10.2/targets/x86_64-linux/lib/libcudnn_ops_infer.so.8 && \
ln -sf /usr/local/cuda-10.2/targets/x86_64-linux/lib/libcudnn_cnn_train.so.8.0.0 /usr/local/cuda-10.2/targets/x86_64-linux/lib/libcudnn_cnn_train.so.8 && \
ln -sf /usr/local/cuda-10.2/targets/x86_64-linux/lib/libcudnn_adv_infer.so.8.2.0 /usr/local/cuda-10.2/targets/x86_64-linux/lib/libcudnn_adv_infer.so.8 && \
ln -sf /usr/local/cuda-10.2/targets/x86_64-linux/lib/libcudnn_ops_train.so.8.2.0 /usr/local/cuda-10.2/targets/x86_64-linux/lib/libcudnn_ops_train.so.8 && \
ln -sf /usr/local/cuda-10.2/targets/x86_64-linux/lib/libcudnn_cnn_infer.so.8.2.0 /usr/local/cuda-10.2/targets/x86_64-linux/lib/libcudnn_cnn_infer.so.8 && \
ln -sf /usr/local/cuda-10.2/targets/x86_64-linux/lib/libcudnn.so.8.2.0 /usr/local/cuda-10.2/targets/x86_64-linux/lib/libcudnn.so.8 && \
ldconfig

# Add Tini
ENV TINI_VERSION v0.19.0
ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini /tini
RUN chmod +x /tini
ENTRYPOINT ["/tini", "--"]

# Avoid switching back to gcc9 when install build-essential
RUN sudo apt-get --yes install build-essential && \
update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-8 100 --slave /usr/bin/g++ g++ /usr/bin/g++-8 && \
update-alternatives --auto gcc
RUN sudo apt-get --yes install build-essential

# Clone the repo and install the toolkit
ENV OPENDR_DEVICE gpu
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ OpenDR aims to develop, train, deploy and evaluate deep learning models that imp

OpenDR can be installed in the following ways:
1. By *cloning* this repository (CPU/GPU support)
2. Using *pip* (CPU only)
2. Using *pip* (CPU/GPU support only)
3. Using *docker* (CPU/GPU support)

You can find detailed installation instruction in the [documentation](docs/reference/installation.md).
Expand Down
5 changes: 0 additions & 5 deletions bin/activate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,4 @@ export PYTHONPATH=$OPENDR_HOME/src:$PYTHONPATH
export PYTHON=python3
export LD_LIBRARY_PATH=$OPENDR_HOME/lib:$LD_LIBRARY_PATH

if [[ -z "${OPENDR_DEVICE}" ]]; then
echo "[INFO] Set available device to CPU. You can manually change this by running 'export OPENDR_DEVICE=gpu'."
export OPENDR_DEVICE=cpu
fi

source venv/bin/activate
14 changes: 10 additions & 4 deletions bin/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,19 @@ sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main
# Build OpenDR
make install_compilation_dependencies
make install_runtime_dependencies
make libopendr

# If working on GPU install GPU dependencies as needed
if [[ "${OPENDR_DEVICE}" == "gpu" ]]; then
echo "[INFO] Installing mxnet-cu102==1.8.0. You can override this later if you are using a different CUDA version."
pip3 install mxnet-cu102==1.8.0
pip3 uninstall -y mxnet
pip3 uninstall -y torch
echo "[INFO] Replacing mxnet-cu112==1.8.0post0 to enable CUDA acceleration."
pip3 install mxnet-cu112==1.8.0post0
echo "[INFO] Replacing torch==1.9.0+cu111 to enable CUDA acceleration."
pip3 install torch==1.9.0+cu111 torchvision==0.10.0+cu111 torchaudio==0.9.0 -f https://download.pytorch.org/whl/torch_stable.html
echo "[INFO] Reinstalling detectronv2."
pip3 install 'git+https://github.com/facebookresearch/detectron2.git'
fi

deactivate
make libopendr

deactivate
2 changes: 1 addition & 1 deletion dependencies/dependencies.ini
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[runtime]
# 'python' and 'python-dependencies' keys expect a value in the Python requirements file format
# https://pip.pypa.io/en/stable/reference/pip_install/#requirements-file-format
python=torch==1.7.1
python=torch==1.9.0
wheel

[device]
Expand Down
31 changes: 14 additions & 17 deletions docs/reference/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ Using dockerfiles is strongly advised (please see below), unless you know what y
Please also make sure that you have enough RAM available for the installation (about 4GB of free RAM is needed for the full installation/compilation).


You can set the inference/training device using the `OPENDR_DEVICE` variable.
If you want to install GPU-related dependencies, then you can appropriately set the `OPENDR_DEVICE` variable.
The toolkit defaults to using CPU.
If you want to use GPU, please set this variable accordingly:
Therefore, if you want to use GPU, please set this variable accordingly *before* running the installation script:
```bash
export OPENDR_DEVICE=gpu
```
Expand All @@ -49,24 +49,20 @@ source ./bin/activate.sh
```
Then, you are ready to use the toolkit!

**NOTE:** `OPENDR_DEVICE` does not alter the inference/training device at *runtime*.
It only affects the dependency installation.
You can use OpenDR API to change the inference device.

You can also verify the installation by using the supplied Python and C unit tests:
```bash
make unittest
make ctests
```

If you plan to use GPU-enabled functionalities, then you are advised to install [CUDA 10.2](https://developer.nvidia.com/cuda-10.2-download-archive).
To do so, you can follow these steps:
```bash
sudo apt install gcc-8 g++-8 gcc-9 g++-9
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-8 8 --slave /usr/bin/g++ g++ /usr/bin/g++-8
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-9 9 --slave /usr/bin/g++ g++ /usr/bin/g++-9
echo "Please switch to GCC 8"
sudo update-alternatives --config gcc
```
Then, you can install CUDA, along CuDNN.
You can also refer to this [dockerfile](https://github.com/opendr-eu/opendr/blob/master/Dockerfile-cuda) for installation instructions.
Note that NVIDIA 30xx GPUs may not be fully supported, due to CUDA limitations.
If you plan to use GPU-enabled functionalities, then you are advised to install [CUDA 11.2](https://developer.nvidia.com/cuda-11.2.0-download-archive), along with [CuDNN](https://developer.nvidia.com/cudnn).

**HINT:** All tests probe for the `TEST_DEVICE` enviromental variable when running.
If this enviromental variable is set during testing, it allows for easily running all tests on a different device (e.g., setting `TEST_DEVICE=cuda:0` runs all tests on the first GPU of the system).

# Installing using *pip*

Expand Down Expand Up @@ -95,14 +91,15 @@ This is not needed for newer CPUs.
The same OpenDR package is used for both CPU and GPU systems.
However, you need to have the appropriate GPU-enabled dependencies installed to use a GPU with OpenDR.
If you plan to use GPU, then you should first install [mxnet-cuda](https://mxnet.apache.org/versions/1.4.1/install/index.html?platform=Linux&language=Python&processor=CPU) and [detectron2](https://detectron2.readthedocs.io/en/latest/tutorials/install.html).
For example, if you stick with the default PyTorch version (1.7) and use CUDA10.2, then you can simply follow:
For example, if you stick with the default PyTorch version (1.8) and use CUDA11.2, then you can simply follow:
```bash
sudo apt install python3.8-venv libfreetype6-dev git build-essential cmake python3-dev wget libopenblas-dev libsndfile1 libboost-dev libeigen3-dev
python3 -m venv venv
source venv/bin/activate
pip install wheel
pip install detectron2==0.5 -f https://dl.fbaipublicfiles.com/detectron2/wheels/cu102/torch1.7/index.html
pip install mxnet-cu102==1.8.0
pip install torch==1.9.0+cu111 torchvision==0.10.0+cu111 torchaudio==0.9.0 -f https://download.pytorch.org/whl/torch_stable.html
pip install 'git+https://github.com/facebookresearch/detectron2.git'
pip install mxnet-cu112==1.8.0post0
pip install opendr-toolkit-engine
pip install opendr-toolkit
```
Expand Down
2 changes: 1 addition & 1 deletion docs/reference/object-detection-2d-yolov3.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ The *yolov3* module contains the *YOLOv3DetectorLearner* class, which inherits f
### Class YOLOv3DetectorLearner
Bases: `engine.learners.Learner`

The *YOLOv3DetectorLearner* class is a wrapper of the SSD detector[[1]](#yolo-1)
The *YOLOv3DetectorLearner* class is a wrapper of the YOLO detector[[1]](#yolo-1)
[GluonCV implementation](https://github.com/dmlc/gluon-cv/blob/master/gluoncv/model_zoo/yolo/yolo3.py).
It can be used to perform object detection on images (inference) as well as train new object detection models.

Expand Down
6 changes: 2 additions & 4 deletions src/opendr/control/mobile_manipulation/dependencies.ini
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,16 @@ python=vcstool
[runtime]
# 'python' key expects a value using the Python requirements file format
# https://pip.pypa.io/en/stable/reference/pip_install/#requirements-file-format
python=torch==1.7.1
python=torch==1.9.0
tensorboard
numpy
pyyaml
matplotlib
pyparsing
pillow>=8.3.2
scipy
stable-baselines3>=0.10.0
gym>=0.19.0
stable-baselines3==1.1.0
cloudpickle>=1.5.0
defusedxml
netifaces

opendr=opendr-toolkit-engine
8 changes: 1 addition & 7 deletions src/opendr/control/single_demo_grasp/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,6 @@ ifeq ($(MAKECMDGOALS),)
MAKECMDGOALS = release
endif

ifeq ($(OPENDR_DEVICE),gpu)
DETECTRON_WHEEL=https://dl.fbaipublicfiles.com/detectron2/wheels/cu102/torch1.7/index.html
else
DETECTRON_WHEEL=https://dl.fbaipublicfiles.com/detectron2/wheels/cpu/torch1.7/index.html
endif

.PHONY: release install_compilation_dependencies install_runtime_dependencies

release: install_compilation_dependencies
Expand All @@ -31,7 +25,7 @@ install_runtime_dependencies:

install_compilation_dependencies:
@+echo "#"; echo "# * Install Compilation Dependencies for single demonstration grasping *"; echo "#"
@+python3 -m pip install detectron2==0.5 -f \$(DETECTRON_WHEEL)
@+python3 -m pip install 'git+https://github.com/facebookresearch/detectron2.git'
@./install_single_demo_grasp.sh

help:
Expand Down
10 changes: 7 additions & 3 deletions src/opendr/control/single_demo_grasp/dependencies.ini
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
[compilation]
python=torch==1.9.0
torchvision==0.10.0

[runtime]
# 'python' key expects a value using the Python requirements file format
# https://pip.pypa.io/en/stable/reference/pip_install/#requirements-file-format
python=torch==1.7.1
torchvision==0.8.2
python=torch==1.9.0
torchvision==0.10.0
matplotlib>=2.2.2
imgaug==0.4.0
pillow>=8.3.2

opendr=opendr-toolkit-engine

post-install=python3 -m pip install detectron2==0.5 -f https://dl.fbaipublicfiles.com/detectron2/wheels/cpu/torch1.7/index.html
post-install=python3 -m pip install 'git+https://github.com/facebookresearch/detectron2.git'
Loading

0 comments on commit f63cd7c

Please sign in to comment.