There a several methods available on the file exchange for compiling CUDA C/C++ code into mex files under Windows, but none that I've come across work for linux. However, I've found a nice, easy way to do it, which I'll share with you, though I must confess I haven't tested it extensively.
The idea is to use Nvidia's nvcc compiler to convert CUDA C/C++ code into standard C++ code, then use mex after that. The first stage looks something like:
system(sprintf('nvcc -I"%s/extern/include" --cuda "mexfun.cu" --output-file "mexfun.cpp"', matlabroot));
Then the second stage is roughly:
mex -I/opt/cuda/include -L/opt/cuda/lib -lcudart mexfun.cpp
Obviously you need to set the various paths and file/function names to suit your needs.
HTH,
Oliver
PS Does anyone think this approach could reduce the efficiency of the resulting machine code? I do wonder if it doesn't limit the level of optimization that can be applied.
Five stars, thanks very much. I was SO close to this solution, but with things still going wrong - your commands below just sorted me right out :)
Re. Performance, I don't think it'll have a detrimental effect. The NVCC compiler will use it's standard options for the device code; and gcc (or whatever c/c++ compiler you use) will use the options that mex passes it to compile the part of the code which runs on the host.
If you were concerned about the host code performance, you can always adjust the mexopts.sh file (in matlabroot/bin/) or the call to mex to pass various performance flags (O3 etc) in to the compiler.
Cheers again!
Tom Clark
"Oliver Woodford" <o.j.woo...@cantab.net> wrote in message <h9shtd$q9g$1...@fred.mathworks.com>...
Thanks!
Best regards, Jorian Seokaner!
http://www.mathworks.com/matlabcentral/newsreader/author/126323