Can't build darknet (CNN) with CUDNN support

asked 2019-05-20 13:40:22 -0600

vfbsilva gravatar image

Iḿ trying to build darknet with cudnn support but it does not complete under manjaro. It reports the following error:

g++  -DOPENCV -I/usr/include/opencv4/opencv2/ `pkg-config --cflags opencv`  -DGPU -I/usr/local/cuda/include/ 
-DCUDNN -Wall -Wfatal-errors -Wno-unused-result -Wno-unknown-pragmas -Ofast -DOPENCV -DGPU -DCUDNN -I/usr/local/cudnn/include -c ./src/http_stream.cpp -o obj/http_stream.o
Package opencv was not found in the pkg-config search path.
Perhaps you should add the directory containing `opencv.pc'
to the PKG_CONFIG_PATH environment variable
Package 'opencv', required by 'virtual:world', not found
./src/http_stream.cpp:46:10: fatal error: opencv2/opencv.hpp: Arquivo ou diretório inexistente
 #include "opencv2/opencv.hpp"
          ^~~~~~~~~~~~~~~~~~~~

Here is my make file:

GPU=1
CUDNN=1
CUDNN_HALF=0
OPENCV=1
AVX=0
OPENMP=0
LIBSO=0

# set GPU=1 and CUDNN=1 to speedup on GPU
# set CUDNN_HALF=1 to further speedup 3 x times (Mixed-precision using Tensor Cores) on GPU Tesla V100, Titan V, DGX-2
# set AVX=1 and OPENMP=1 to speedup on CPU (if error occurs then set AVX=0)

DEBUG=0

ARCH= -gencode arch=compute_30,code=sm_30 \
      -gencode arch=compute_35,code=sm_35 \
      -gencode arch=compute_50,code=[sm_50,compute_50] \
      -gencode arch=compute_52,code=[sm_52,compute_52] \
          -gencode arch=compute_61,code=[sm_61,compute_61]

OS := $(shell uname)

# Tesla V100
# ARCH= -gencode arch=compute_70,code=[sm_70,compute_70]

# GTX 1080, GTX 1070, GTX 1060, GTX 1050, GTX 1030, Titan Xp, Tesla P40, Tesla P4
ARCH= -gencode arch=compute_61,code=sm_61 -gencode arch=compute_61,code=compute_61

# GP100/Tesla P100 � DGX-1
# ARCH= -gencode arch=compute_60,code=sm_60

# For Jetson TX1, Tegra X1, DRIVE CX, DRIVE PX - uncomment:
# ARCH= -gencode arch=compute_53,code=[sm_53,compute_53]

# For Jetson Tx2 or Drive-PX2 uncomment:
# ARCH= -gencode arch=compute_62,code=[sm_62,compute_62]


VPATH=./src/
EXEC=darknet
OBJDIR=./obj/

ifeq ($(LIBSO), 1)
LIBNAMESO=darknet.so
APPNAMESO=uselib
endif

CC=gcc
CPP=g++
NVCC=nvcc 
OPTS=-Ofast
LDFLAGS= -lm -pthread 
COMMON= 
CFLAGS=-Wall -Wfatal-errors -Wno-unused-result -Wno-unknown-pragmas

ifeq ($(DEBUG), 1) 
OPTS= -O0 -g
else
ifeq ($(AVX), 1) 
CFLAGS+= -ffp-contract=fast -mavx -msse4.1 -msse4a
endif
endif

CFLAGS+=$(OPTS)

ifeq ($(OPENCV), 1) 
COMMON+= -DOPENCV -I/usr/include/opencv4/opencv2/
CFLAGS+= -DOPENCV
LDFLAGS+= `pkg-config --libs opencv` 
COMMON+= `pkg-config --cflags opencv` 
endif

ifeq ($(OPENMP), 1)
CFLAGS+= -fopenmp
LDFLAGS+= -lgomp
endif

ifeq ($(GPU), 1)
COMMON+= -DGPU -I/usr/local/cuda/include/
CFLAGS+= -DGPU
ifeq ($(OS),Darwin) #MAC
LDFLAGS+= -L/usr/local/cuda/lib -lcuda -lcudart -lcublas -lcurand
else
LDFLAGS+= -L/usr/local/cuda/lib64 -lcuda -lcudart -lcublas -lcurand
endif
endif

ifeq ($(CUDNN), 1)
COMMON+= -DCUDNN
ifeq ($(OS),Darwin) #MAC
CFLAGS+= -DCUDNN -I/usr/local/cuda/include
LDFLAGS+= -L/usr/local/cuda/lib -lcudnn
else
CFLAGS+= -DCUDNN -I/usr/local/cudnn/include
LDFLAGS+= -L/usr/local/cudnn/lib64 -lcudnn
endif
endif

ifeq ($(CUDNN_HALF), 1)
COMMON+= -DCUDNN_HALF
CFLAGS+= -DCUDNN_HALF
ARCH+= -gencode arch=compute_70,code=[sm_70,compute_70]
endif

OBJ=http_stream.o gemm.o utils.o cuda.o convolutional_layer.o list.o image.o activations.o im2col.o col2im.o blas.o crop_layer.o dropout_layer.o maxpool_layer.o softmax_layer.o data.o matrix.o network.o connected_layer.o cost_layer ...
(more)
edit retag flag offensive close merge delete

Comments

  • title of your question does not match the problem ?
  • is there anything under /usr/include/opencv4/opencv2/ ?
  • DID you build the opencv libraries before ?

  • do you absolutely NEED opencv support for this ? try -DOPENCV=OFF first. (libdarknet compiles fine without, you justwon't be able to run some demos, that need video)

  • try NOT to rely on pkg-config (there's not much love from the devs for that), but explicitly specify required libs
berak gravatar imageberak ( 2019-05-21 00:57:37 -0600 )edit

Hello berak thanks for the reply. Well Iḿ open to new title suggestions. Contents under /usr/include/opencv4/opencv2/

aruco freetype.hpp opencv_modules.hpp superres aruco.hpp fuzzy optflow superres.hpp bgsegm.hpp fuzzy.hpp optflow.hpp surface_matching bioinspired gapi phase_unwrapping surface_matching.hpp bioinspired.hpp gapi.hpp phase_unwrapping.hpp text calib3d hdf photo text.hpp calib3d.hpp hdf.hpp photo.hpp tracking ccalib hfs.hpp plot.hpp tracking.hpp ccalib.hpp highgui quality video core highgui.hpp quality.hpp video.hpp core_detect.hpp

vfbsilva gravatar imagevfbsilva ( 2019-05-21 01:15:06 -0600 )edit

and I do absolutely beed it. I did work in some older ubuntu version

vfbsilva gravatar imagevfbsilva ( 2019-05-21 01:15:31 -0600 )edit

try:

-I/usr/include/opencv4          # w/o the "opencv2", that's already part of the include.

explicitly linking opencv libraries (get rid of all pkg-config cruft)

-lopencv_videoio  -lopencv_imgcodecs -lopencv_imgproc -lopencv_core -lopencv_highgui
berak gravatar imageberak ( 2019-05-21 01:24:00 -0600 )edit

Same issue. Here is my current makefile.

vfbsilva gravatar imagevfbsilva ( 2019-05-21 13:21:42 -0600 )edit

@berak About -I/usr/include/opencv4: shouldn't the pkg-config file have this solved for the user? After `pkg-config --cflags opencv` the user shouldn't have to deal with all these problems.

alcoan gravatar imagealcoan ( 2019-09-14 05:18:20 -0600 )edit

@berak Oh, I just noticed that the pkg-config file is named opencv4 now instead of opencv. I don't think it's a good idea. Version control should be done inside the file, and not by using a different file. It broke my compilation, and didn't have any informative message.

alcoan gravatar imagealcoan ( 2019-09-14 05:24:56 -0600 )edit