Development Environment on Ubuntu 20.04 LTS
Introduction
Having proper foundations in software usually translates on having a software project easy to extend and faster to develop. On its core, software engineering provides tools to improve: Business Value, Code Quality, and Process Predictability (Our primary focus).
Our goal is to introduce Software Engineering practices, for the usage of Cloud and Edge Computing for video processing.
Writen by: Santiago Hurtado
Environment
We used a Linux environment tested on a bare-metal machine and also using docker containers. Docker provides good process predictability, and the benchmarks are run on the bare-metal machine for performance reasons.
The specifications used are the following:
- Ubuntu 20.04
- Docker Community Edition(CE)v19
- Nvidia Cuda 10.2
- Nvidia Container Toolkit
- OpenCV 4, CMake 3, C++, Boost 1.7, GTest and Python 3.8, Numpy
- *Nvidia Quadro P400 GPU
*The P400 seems to be an excellent card to learn Cuda since it provides an architecture 6.1 and is not expensive. However, to have higher performance is recommended an Nvidia GeForce RTX 2060 GPU, at the least. https://timdettmers.com/2019/04/03/which-gpu-for-deep-learning/
System Installation
Ubuntu 20.04 LTS
Installing ubuntu 20.04 LTS and Cuda together is very straight forward, go to https://ubuntu.com/download/desktop, there are many resources can be found. Many Linux distros have similar installation steps, for instance, CentOS and Redhat should be pretty much the same.
- Install the Linux distro on your machine, update and upgrade your system and restart,
Cuda
-
The Nvidia drivers should have been already installed, to verify run
nvidia-settings
When installing a new driver on the kernel be aware that new computers might have security for the UEFI boot https://wiki.ubuntu.com/UEFI/SecureBoot/DKMS.
-
Next step is to install the Cuda SDK, for now, we will use the ubuntu 1804 support
wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/cuda-ubuntu1804.pin sudo mv cuda-ubuntu1804.pin /etc/apt/preferences.d/cuda-repository-pin-600 sudo apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/7fa2af80.pub sudo add-apt-repository "deb http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/ /" sudo apt-get update sudo apt-get install cuda
-
Add to your .bashrc
export PATH=/usr/local/cuda-10.2/bin:/usr/local/cuda-10.2/NsightCompute-2019.1${PATH:+:${PATH}} export LD_LIBRARY_PATH=/usr/local/cuda-10.2/lib64 ${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
-
The last step is to restart the system and check that everything works. Run the command and check that you see your card on the screen.
nvidia-smi
There are detailed instructions on the Cuda quick start https://docs.nvidia.com/cuda/cuda-quick-start-guide/index.html
Dockers
If you like, now you can install the docker-ce (community edition) on your system. For ubuntu 20.04 LTS there is already a package on the main package repository so the only step needed is to run the following command.
sudo apt install docker.io
- Afterward, install the repository for the nVidia docker from https://github.com/NVIDIA/nvidia-docker. *Again we will use the ubuntu 18.04 repositories
Instead of “distribution=$(. /etc/os-release;echo $ID$VERSION_ID)” set to ubuntu1804
export distribution=ubuntu18.04
curl -s -L https://nvidia.github.io/nvidia-docker/gpgkey | sudo apt-key add -
curl -s -L https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.list | sudo tee /etc/apt/sources.list.d/nvidia-docker.list
sudo apt-get update && sudo apt-get install -y nvidia-container-toolkit
sudo systemctl restart docker
Development Libraries
Install OpenCV
To install OpenCV we will use the master from the git repository, you can select a specific version if you prefer. Here is the guide we used. Note: At this moment Cuda 10.02 can use only gcc 8, the ubuntu 20.04 default is 9.
#[compiler]
sudo apt-get install -y build-essential
#[required]
sudo apt-get install -y cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
#[optional]
sudo apt-get install -y libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libdc1394-22-dev
#[Cuda support] https://stackoverflow.com/questions/6622454/cuda-incompatible-with-my-gcc-version
sudo apt-get install gcc-8 g++-8
sudo ln -s /usr/bin/gcc-8 gcc
sudo ln -s /usr/bin/g++-8 g++
cd /usr/local/cuda-10.2/bin
sudo rm gcc
sudo rm g++
sudo ln -s /usr/bin/gcc-8 gcc
sudo ln -s /usr/bin/g++-8 g++
cd /opt/libs
git clone https://github.com/opencv/opencv.git
git clone https://github.com/opencv/opencv_contrib.git
mkdir opencv_build
cd opencv_build
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D BUILD_PROTOBUF=OFF -D UPDATE_PROTO_FILES=ON -D BUILD_PNG=ON -D BUILD_JPEG=ON -D INSTALL_C_EXAMPLES=OFF -D WITH_CUDA=ON -DCUDA_HOST_COMPILER=/usr/bin/gcc-8 -D BUILD_EXAMPLES=OFF -D BUILD_PERF_TESTS=ON -D BUILD_opencv_java=OFF -D BUILD_opencv_python2=OFF -D BUILD_opencv_python3=ON -D INSTALL_PYTHON_EXAMPLES=OFF -D WITH_TBB=ON -D WITH_FFMPEG=ON -D OPENCV_EXTRA_MODULES_PATH="../opencv_contrib/modules" ../opencv
make -j 8
Install Boost 1.72
To install boost you will not require many dependencies but if you want Boost.python you will need to have installed Python.
sudo apt install python3-dev python3-numpy
cd ~/Downloads
wget https://dl.bintray.com/boostorg/release/1.72.0/source/boost_1_72_0.tar.gz
tar xvfz boost_1_72_0.tar.gz -C /opt/libs
cd /opt/libs/boost_1_72_0
This step is for Boost.Python, verify that you have all the paths correct and spaces.
./bootstrap.sh --with-libraries=python,thread,log,system,chrono --with-python-version=3.8
echo "using python : 3.8 : /usr/bin/python3.8 : /usr/include/python3.8 : /usr/lib ;" >> project-config.jam
./b2 headers
./b2
sudo ./b2 install
Install Gtest
There are many ways to install gTest, we use the package included in ubuntu.
libgtest-dev
cd /tmp
mkdir build
mkdir /opt/libs/gtest
cd build
cmake /usr/src/googletest
make && sudo make install
cd && rm -rf /tmp/build
Now you have a development system ready and there are plenty of examples out there. You can start with the nVidia Samples https://github.com/NVIDIA/cuda-samples, OpenCV https://docs.opencv.org/master/examples.html, and Boost https://theboostcpplibraries.com/.
Happy coding!
References
List of references presented on this post:
https://timdettmers.com/2019/04/03/which-gpu-for-deep-learning/
https://ubuntu.com/download/desktop
https://wiki.ubuntu.com/UEFI/SecureBoot/DKMS
https://developer.nvidia.com/cuda-toolkit
https://docs.nvidia.com/cuda/cuda-quick-start-guide/index.html
https://docs.docker.com/install/linux/docker-ce/ubuntu/
https://github.com/NVIDIA/nvidia-docker
https://www.packtpub.com/eu/application-development/building-computer-vision-projects-opencv-4-and-c
https://www.packtpub.com/eu/application-development/cmake-cookbook