Fixing Darknet OpenCV3 make error (convolutional_kernels)

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:

  1. 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
  2. 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)
  3. 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
  4. sudo sh Downloads/cuda_8.0.27_linux.run –silent –toolkit –override
  5. 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}}
  6. sudo nvidia-xconfig
  7. 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*
  8. Only AFTER all above steps install the cuda_8.0.27.1_linux.run:
    sudo sh /Downloads/cuda_8.0.27.1_linux.run
  9. 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.

 

 

 

 

  1. saurabh left a comment on May 6, 2017 at 9:08 am

    I have already installed cuda 8.0.61. now I am installing cuDNN from the site https://developer.nvidia.com/rdp/cudnn-download#collapseTwo.
    What version do I need to download.
    v6.0 requires a password for installation. So I am trying v5.1

    • saurabh left a comment on May 6, 2017 at 9:15 am

      ./src/cuda.c:140:5: error: ‘for’ loop initial declarations are only allowed in C99 or C11 mode
      for(int i = 0;i < MAX_CUDNN;i ++)
      ^
      compilation terminated due to -Wfatal-errors.
      make: *** [obj/cuda.o] Error 1

      this is the error i am getting.

      • saurabh left a comment on May 6, 2017 at 9:27 am

        after debugging the above error
        by declaring int i outside the for loop.
        I am getting the following error

        ./src/image.c: At top level:
        ./src/image.c:508:29: error: unknown type name ‘CvCapture’
        image get_image_from_stream(CvCapture *cap)
        ^
        compilation terminated due to -Wfatal-errors.
        make: *** [obj/image.o] Error 1

Leave a Comment

Your email address will not be published. Required fields are marked *