Linux CUDA-based Shared Library Crashes MATLAB with Segfault on Kernel Call

14 visualizaciones (últimos 30 días)
Hey all,
I'm running into an issue with a CUDA-based shared library I've written to solve a system of PDEs that I load through loadlibrary. I've written this using pretty generic CUDA / no outside libraries, etc. When compiled to the shared library, executing it from MATLAB results in a crash (due to a segfault) once the execution arrives at the kernel calls (there are 5 distinct kernels, each called about twice). I've commented out the kernels one-by-one and they all lead to a segfault, leading me to believe there is some issue with the kernel calling mechanism, maybe?
I believe the kernels to be well functioning - I've written a c++ caller of the .so, and it works fine (passing cuda-memcheck as well). This code also works in Windows just fine, exactly as is (called from MATLAB). Therefore, I believe this to be a specific MATLAB issue or possibly compile flags issue. The odd thing is that writing a quick, trivial kernel appears to work within MATLAB (same flags as below) - the kernel does execute correctly.
So, I understand that you don't have my code...so I'm not asking for code debugging. My questions are moreso related to shared library compiling requirements by MATLAB. I use the following flags to compile through nvcc:
-std=c++14 -shared -x cu -cudart static -O2 -gencode=arch=compute_50,code=\"sm_50,compute_50\" -m64 -Xcompiler "-fPIC -Wno-narrowing" -w -Wno-deprecated-gpu-targets
and the following to link:
-shared -w
Do you see any issues with that? I mark the functions as extern "C" when compiling with g++ and have a clause for when MATLAB compiles the thunk library to simply use extern (due to using gcc).
#ifdef __linux__
#ifdef __cplusplus
#define EXTC extern "C"
#else
#define EXTC extern
#endif
...
Any issues there? I don't think there is - as mentioned, other funciton calls work fine.
I'm at a bit of a loss as to how to move forward here. Does anyone have any insight?
Thanks.
  7 comentarios
Joss Knight
Joss Knight el 16 de Dic. de 2020
Try launching MATLAB with -softwareopengl and see whether there's some sort of graphics issue here.
Tom Gade
Tom Gade el 17 de Dic. de 2020
Editada: Tom Gade el 17 de Dic. de 2020
Thanks. I gave that a shot, and it's still not working. At this point, I think I'll just deal with running it from the command line. It just works form there. I can save the workspace at the end of the sim, and load it from the IDE. I can even have the IDE running in a separate process at the same time. So, I think that will be a good enough solution for me on Linux. Thanks for all your help. I appreciate your diligence in continuing to suggest things to try.

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Get Started with GPU Coder en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by