Reputation: 13614
I am writing mex code and the cuda code. I am wonder about having two object files of each code and calling cuda kernel from mex file as I am getting an executable by combination of their object files. Therefore I need to know that (if it is possible) how could I call one object file's function from other object file. Does it working to compile mex and cuda with their separate compilers and combine them in that way?
Upvotes: 1
Views: 168
Reputation: 2835
It's completely possible. I played with this a while back. The currently supported ways to do this use the MATLAB parallel computing toolbox. There are instructions to do so here.
To expand a little bit, compiled mex files are really just dynamic libraries with a compiled mex gateway. So long as you have the gateway, appropriately link your files, and give the appropriate mex extension to the resulting compiled file (like mexa64, mexmaci64, etc.) the file will work.
It's important to note, you need not use the mex function from within MATLAB to compile your file. This allows for some unsupported ways in which you can compile outside of MATLAB. This might be useful if you don't have the parallel toolbox, if you need more subtle control over what's going on, or prefer to use make in your workflow. The instructions for how to get started with this are here.
Upvotes: 1