way to handle to write CUDA+MEX code in linux?

混江龙づ霸主 提交于 2019-12-11 13:09:09

问题


I try to write matlab mex code with Cuda integrated but it is just hard enough to compile and debug all around. Is there any better approach to code and test? I am on Matlab 2012b.

Currently I am writing code in sublime then compile it on matlab but I am also newbie at CUDA as well thus it is just hard to code it without seeing the result instantly.


回答1:


The comment by Robert Crovella is interesting.

I just wanted to mention the way I was used to compile mex file with CUDA instructions (and which works also on different versions of MATLAB).

1) Compile by nvcc and transform the source code in C++ code by the command

 system(sprintf('nvcc -I"%s/extern/include" -cuda "mex-fun.cu" -output-file "mexfun.cpp"', matlabroot));

2) Link it to Matlab by

mex -I/opt/cuda/include -L/opt/cuda/lib -lcudart mex-fun.cpp

This was originally suggested at the MATLAB Newsreader page.




回答2:


I have both a matlab entry point (i.e. a file with the function "mexFunction") and a C++ entry point (a file with "main"), and the rest of my actual CUDA code is independant of what entry point was used. This way, I can debug the code used for my MEX files using the standard set of CUDA tools (i.e. nvprof, cuda-memcheck, etc) without having to deal with the MEX file. Then once I'm sure I have no bugs or memory leaks, I just compile it to a MEX file. Alternately you can always just attach cuda-gdb to your MEX file, although your mileage may vary with this.



来源:https://stackoverflow.com/questions/14404189/way-to-handle-to-write-cudamex-code-in-linux

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!