How to pass a user-defined function as a argument to mex file?
2 ビュー (過去 30 日間)
古いコメントを表示
I am building a GUI for simulation of a control system. Users input a model in GUI, and I can obtain it as string type and then convert it into a function by str2fun. I am thinking about accelerating my control algorithm by cuda programming. As far as I know, GPU programming can be integrated with Matlab via cuda kernal which is a mex file(.cu). Since the mex file have only one entrance for passing arguments, i.e.
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Thus I think it is hard to pass a function within the mexFunction. I was wondering if I can pass the function within the main function of cuda kernal, which begins with
__global__ void functionname(.....){
}
or if I can use head file (.h) to pass the function handle. Any suggestion is welcome. Thank you in advance.
Qun(a newbie of GPU programming)
0 件のコメント
採用された回答
Joss Knight
2017 年 7 月 26 日
Simple advice for a newbie to GPU programming - don't write a custom MEX function or CUDAKernel until you've tried using the GPU via gpuArray and simple vectorization of your code. It sounds to me like you are unfamiliar with some basics like the difference between MEX and CUDAKernel, and the sorts of things a CUDAKernel can do, so you shouldn't leap straight to the advanced programming until you've tried the simple stuff that MATLAB goes to a lot of effort to make easy for you.
So I suggest you read the doc and get started trying to convert your code to use the GPU, and leave CUDA programming to another day!
2 件のコメント
Joss Knight
2017 年 7 月 28 日
You need to show me what your user-defined ODE model looks like so we can discuss how to make it GPU-compatible. ODEs are not parallel algorithms because each iteration must run serially. So we need to look at what your model is and whether it's processing enough data to be able to make good use of the GPU during each iteration.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で GPU Computing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!