ganyc717 / Darknet-On-OpenCL

Darknet On OpenCL
MIT License
100 stars 44 forks source link

How to use it as a shared library? #7

Closed Bardo91 closed 6 years ago

Bardo91 commented 6 years ago

I am trying to export is as a shared library by adding add_library(darknet SHARED ${DIR_LIB_SRC})

Everything compile and link but I get weird unexpected results in the detections. Does anyone exported it before? This is what I get using the original executable: predictions

This is what I get using an executable from a different project which links the shared library: predictions

Bardo91 commented 6 years ago

Oh... I am sorry. I followed the code in test_detector and missed the initialization of the gpu device...

Just adding cl_set_device(0); fixed the problem.

pra-dan commented 4 years ago

@Bardo91 Hi, could you help me use this port by sharing your knowledge and experience ? I am new to OpenCL and would like to use it with ARM devices without GPUs... Can you give me some info which may have worked for you ?

Bardo91 commented 4 years ago

Hi @PrashantDandriyal , if it does not have GPU, then you cannot use OpenCL. The ARM needs to have any kind of embedded GPU at least (well, it is possible just with CPU but then... use the original darknet repo, because it will be the same and will be more updated). If that is your case, just compile it using the cmake flag "-DBUILDLIB=ON" and the shared_lib will be produced, so you can reuse it in other projects. What is do you need exactly?

pra-dan commented 4 years ago

@Bardo91 Let me explain:

Actually I need to run the models on either the Beaglebone AI or the Beaglebone x15. Both the boards are almost with same resources. The issue is that they lack any good GPU as the on board sgx is not very powerful. Instead, they have 2 DSPs and 4 EVEs both are co processors running at 700MHz and 1.2 GHz respectively. So, I am compelled yo use them for good performance.

By good performance I mean the FPS of 30 or more on frames of 320x240 (can vary a bit).

Using these co-processors as alternative to the GPGPUs, requires either using the API developed by Texas Instruments (called TIDL), or manually configuring them using OPENCL. But TIDL is poorly tested and somewhat unreliable and I am new to OpenCL and NNPACK. Although I am ready to learn them once I have a plan ! I hope I made sense. what you think.

Bardo91 commented 4 years ago

It looks reasonable. It seems that BeagleBone AI has OpenCL preinstalled (https://beagleboard.org/ai), so the CMakeLists, should find automatically OpenCL and compile the project using the embedded GPU. Have you tried just compiling the project as cloned? GPU is enable by default, so it will generate the "darknet" executable for you automatically. If it does, try downloading some weights wget https://pjreddie.com/media/files/yolov3.weights and run the software ./darknet detect cfg/yolov3.cfg yolov3.weights data/dog.jpg .It will generate an image with the result. If it works as you expect, then what you need is to embed the software in your application.

pra-dan commented 4 years ago

But this means, the GPU leveraging will be done automatically by the OpenCL backend. Right ? Also, what about the devices with no GPUs. Although the other co-processors (the DSPs + EVEs) also use the OpenCL backend, but piplining the workload uses the dedicated API : TIDL for it. I feel that this port can't help me much in this case :(

Bardo91 commented 4 years ago

That is what I understood from the documentation, The custom OpenCL library that is installed by default in the beaglebone OS should handle the GPU resources automatically. In the official documentation (https://github.com/beagleboard/beaglebone-ai/wiki/System-Reference-Manual), it says that all the devices are supported and handle through OpenCL interface. The quickest thing you can do is to give a try and compile it. You should be able to see easily if it is using OpenCL if it compiles and runs at a high speed.

If you want to debug it a bit, another quick&easy thing to check is if the system is able to detect "cl" compatible "gpu" devices in this line https://github.com/ganyc717/Darknet-On-OpenCL/blob/1dd549bb54d3bf1f235904bc09f54a2cc2b42974/darknet_cl/example/darknet.cpp#L421 . If gpu_index is not -1, then it means that it is handling the devices underneath.

Unfortunatelly, I don't have experiende with EVEs, nor beaglebones in general, but with myriads by intel. And in that case, OpenCL and OpenVINO does it automatically.

I hope it helps.