AlexeyAB / darknet

YOLOv4 / Scaled-YOLOv4 / YOLO - Neural Networks for Object Detection (Windows and Linux version of Darknet )
http://pjreddie.com/darknet/
Other
21.75k stars 7.96k forks source link

exported structs have different fields when building with GPU=... and CUDNN=... #4839

Closed stephanecharette closed 4 years ago

stephanecharette commented 4 years ago

3rd party libraries like DarkHelp that use libdarknet.so must #include <darknet.h>, and also reference the network and layer structures.

The problem is those structures have some optional fields within #ifdef GPU and #ifdef CUDNN blocks. So depending on whether support for GPU/CUDNN was toggled in darknet's makefile, this means the network and layer structures change size!

In my case tonight, I tracked down a segfault that was caused by this issue. A 3rd party lib that didn't define either GPU nor CUDNN before including darknet.h. So the structures were the wrong size, leading to a segfault caused by memcpy() located within network_predict_gpu().

What this means is all my .deb libraries that have code which #include darknet.h need to be published in 3 flavours:

Any chance we can always include those optional GPU and CUDNN fields in the structs defined in darknet.h even when building without full GPU/CUDNN support? It means the structs would be slightly larger on CPU-only, but then there wouldn't be this incompatibility.

stephanecharette commented 4 years ago

Thanks, @AlexeyAB, for looking into this. It certainly will simplify publishing 3rd party libraries and tools that build on libdarknet.so.

AlexeyAB commented 4 years ago

@stephanecharette

I fixed it: https://github.com/AlexeyAB/darknet/commit/ef979a1fd2d14f41c65aa4b15a5f1db390b7bb43

stephanecharette commented 4 years ago

Did a git pull tonight and finally had a chance to try this out. Thanks, @AlexeyAB, the size of the structures are now exactly the same when building the various flavours.