sowson/darknet

OpenCV 4 support

cyro666 opened this issue · 12 comments

Device ID: 0
Device name: gfx803
Device vendor: Advanced Micro Devices, Inc.
Device opencl availability: OpenCL 1.2 
Device opencl used: 2924.0 (HSA1.1,LC)
Device double precision: YES
Device max group size: 256
Device address bits: 64
opencl_load: could not link. error: CL_INVALID_LINKER_OPTIONS
CL_PROGRAM_BUILD_LOG:

That's all the output I get. I'm running on the official AMD ROCm OpenCL implementation on Arch Linux. The card is RX590. I tested OpenCL with hashcat and it worked there.

EDIT: Also, I was trying to run a simple detector: ./darknet detector demo cfg/coco.data cfg/yolov3.cfg yolov3.weights vid1.mp4

I have now also tried with the official AMDGPU-PRO implementation. Not sure what's wrong here.

Removing -cl-kernel-arg-info from clLinkProgram fixes the issue.

On an unrelated note, Yolov3 performance is slower than I expected... 0.7 fps. Is this normal? I looked at GPU utilization and it was jumping between 30% and 65%. Not sure if it is possible to utilize the GPU more under such workloads, however.

Thank you very much for this issue... have you tried to add "-i 0" switch? Please try. Btw, I removed this parameter in latest commit just now. Hope you figured out and share here. Thanks!

Yes, I have tried the -i 0 switch. I have also tried to compile your clBLAS and enable multi-gpu, just to see what would happen (I only have 1 GPU anyways). The GPU utilization was now at 100%, but the performance was even worse. I also tried compiling your version of darknet from 31st August 2018 and the performance was identical to what I get now.

Have no idea then... anyone?

Can you tell me what sort of a Linux system you used to run this (OS and version)? I will try to replicate the setup to see if the issue is maybe in the compiler or library versions.

Also which graphics card are you using?

See my blog comments thread.

It looks like it might be a problem with the OpenCV version I was using. I was using OpenCV 2, because I compiled it for some other project and forgot about it.

Unfortunately, compiling with OpenCV 3 didn't work out well. It crashes because OpenCV 3 is pretty old and was using ffmpeg in "legacy way" and modern ffmpeg doesn't support that. Compiling some old version of ffmpeg wasn't on my bucket list, so...

I was left only left with OpenCV 4. It is available by default from Arch Linux repos, the version is 4.1.1.
After changing pkg-config from opencv to opencv4 in the Makefile it finds all the headers properly, but can't compile. This is the error I get: OpenCV 4.x+ requires enabled C++11 support. I tried adding C++ with CPP=g++ -std=c++11, but to no avail. I tried with cmake by adding set(CMAKE_CXX_STANDARD 11), and many other things. But it just wouldn't set it properly, no matter what.

I tracked down the problems to include/darknet.h, it seems you are doing things a bit differently here from other darknet implementations, with ifndef __cplusplus instead of the other way around ifdef __cplusplus.

Unfortunately I'm not familiar with mixing C++ and C headers/sources, so I don't really know what I'm doing here.

So I guess my question is if you could maybe add support for OpenCV 4.*?

EDIT: The error happens pretty much at the first source file:

gcc -Iinclude/ -Isrc/ -DOPENCV `pkg-config --cflags opencv4`  -DGPU -DOPENCL -DGPU_FAST -Wall -Wno-unknown-pragmas -Wno-unused-variable -Wfatal-errors -fPIC -O2 -DOPENCV -DGPU -DOPENCL -I/usr/include/ -I/usr/local/cuda/include/ -I/usr/include/clBLAS/ -DGPU_FAST -c ./src/gemm.c -o obj/gemm.o
In file included from /usr/include/opencv4/opencv2/core/types_c.h:82,
                 from /usr/include/opencv4/opencv2/core/core_c.h:48,
                 from /usr/include/opencv4/opencv2/highgui/highgui_c.h:45,
                 from include/darknet.h:18,
                 from ./src/utils.h:5,
                 from ./src/gemm.c:2:
/usr/include/opencv4/opencv2/core/cvdef.h:690:4: error: #error "OpenCV 4.x+ requires enabled C++11 support"
  690 | #  error "OpenCV 4.x+ requires enabled C++11 support"
      |    ^~~~~
compilation terminated due to -Wfatal-errors.
make: *** [Makefile:122: obj/gemm.o] Error 1

It looks like someone made a patch for the original darknet implementation. Looks like some more things need to be changed, but as I said, I'm really not familiar with mixing C/C++.
https://github.com/pjreddie/darknet/pull/1348/files/795e5ac1ebee56dac1f792938a9698604e9e4638

I managed to compile this on Ubuntu 18.04 which uses some sort of OpenCV version 3 and the result was the same... about 0.65fps. So OpenCV was not to blame. Would still be nice to have OpenCV 4 support.

There is obviously something wrong since you made it work on RX570, while I have an RX590. But I am all out of ideas. The only thing I could do is learn OpenCL myself and debug, but that would take a long time.

You know if this makes you happy you can do it on your own :D.... I am too lazy to do so :D.

DONE! :D