So Darknet is a great open-source framework for deep learning including useful neural network implementations such as YOLO, ImageNet, RNNs etc but we have stumbled upon problems when trying to make it work with our system running CUDA 8.0 and OpenCV 3. It simply wouldn’t make, producing this error instead:
nvcc –gpu-architecture=compute_52 –gpu-code=compute_52 -DGPU -I/usr/local/cuda/include/ -DCUDNN –compiler-options “-Wall -Wfatal-errors -O0 -g -DGPU -DCUDNN” -c ./src/convolutional_kernels.cu -o obj/convolutional_kernels.o
/usr/include/c++/4.8/bits/stl_relops.h(85): error: this declaration may not have extern “C” linkage
Error limit reached.
100 errors detected in the compilation of “/tmp/tmpxft_00007d61_00000000-7_convolutional_kernels.cpp1.ii”.
Compilation terminated.
Makefile:98: recipe for target ‘obj/convolutional_kernels.o’ failed
make: *** [obj/convolutional_kernels.o] Error 4
Apparently this is a known issue when trying to build Darknet with OpenCV3 and is being discussed in Darknet google group: https://groups.google.com/forum/#!topic/darknet/bXDkfGwU3CE. Most people ended up downgrading to OpenCV2 to make it work.
However just recently in October’2016, Prabindh Sundareson has posted his forked version of Darknet that resolves this problem: https://github.com/prabindh/darknet also available as a pull request to original code from PJReddie: https://github.com/pjreddie/darknet/pull/21.
That version actually allows to build Darknet with GPU, cuDNN and full OpenCV3 support and we have tested it on Ubuntu 16.04 xenial.
Still it didn’t work out of the box using Prabindh’s update, for example we had a problem with nvcc resulting in this:
nvcc –gpu-architecture=compute_52 –gpu-code=compute_52 -DGPU -I/usr/local/cuda/include/ -DCUDNN –compiler-options “-Wall -Wfatal-errors -O0 -g -DGPU -DCUDNN” -c ./src/convolutional_kernels.cu -o obj/convolutional_kernels.o
/usr/local/cuda/include/surface_functions.h(134): error: expected a “;”
and other issues to do with environment and versioning so we decided to post the steps here in our blog so that others can benefit from them too:
- Clone the repo from Prabindh Sundareson (as of 13th November 2016 PJReddies hasn’t accepted this pull request into main repo of Darknet yet):
git clone https://github.com/prabindh/darknet.git
- get the RC build from Nvidia (cuda_8.0.27_linux.run). For us this was tricky to find as NVidia search wouldn’t locate the file. Make sure you go into Member area or simply follow this link: https://developer.nvidia.com/cuda-release-candidate-download
sudo sh Downloads/cuda_8.0.27_linux.run —override
(in our case said “no” to driver and “yes” to samples as we had later driver version installed already)
-
download “cuda_8.0.27.1_linux.run” patch from Nvidia as well. This patch fixes the NVCC / GCC versioning compiler issue but don’t install it yet if you’re in same situation like me, below:
so in our case nvcc -V was still returning version “7.5” even after installing the 8.0.27 and 8.0.27.1 above so if you have the same, make sure you set up the environment following instructions from “CUDA quick start guide for Ubuntu” or our steps below
- sudo sh Downloads/cuda_8.0.27_linux.run –silent –toolkit –override
-
export PATH=/usr/local/cuda-8.0/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda-8.0/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
- sudo nvidia-xconfig
- Then install cuDNN (re-install if like us you had it installed before)
do something like:
cd ~/Downloads/
tar xvf cudnn*.tgz
cd cuda
sudo cp */*.h /usr/local/cuda/include/
sudo cp */libcudnn* /usr/local/cuda/lib64/
sudo chmod a+r /usr/local/cuda/lib64/libcudnn*
-
Only AFTER all above steps install the cuda_8.0.27.1_linux.run:
sudo sh /Downloads/cuda_8.0.27.1_linux.run
- Finally, go into darknet folder (Prabindh version you downloaded above) and build it:cd darknet make
Following the steps above allowed us to make and run Darknet with CUDA 8.0 and OpenCV3 installed, these are the parameters from Makefile:
GPU=1
CUDNN=1
OPENCV=1
DEBUG=1
Hope it helps, leave your questions or comments if any.
Best regards,
Covijn team.