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

조회 수: 14 (최근 30일)
Tom Gade
Tom Gade 2020년 12월 11일
편집: Tom Gade 2020년 12월 17일
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
Joss Knight
Joss Knight 2020년 12월 16일
Try launching MATLAB with -softwareopengl and see whether there's some sort of graphics issue here.
Tom Gade
Tom Gade 2020년 12월 17일
편집: Tom Gade 2020년 12월 17일
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.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Get Started with GPU Coder에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by