필터 지우기
필터 지우기

How to pass a user-defined function as a argument to mex file?

조회 수: 1 (최근 30일)
Qun Wu
Qun Wu 2017년 7월 26일
댓글: Joss Knight 2017년 7월 28일
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)

채택된 답변

Joss Knight
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
Qun Wu
Qun Wu 2017년 7월 26일
I just checked the available methods for gpuArray in command window typing 'methods gpuArray'. Although there are plenty of methods, I didn't find the one I need, which is ode45. I coded the ode45(RK4) algorithm by myself, but as I mentioned before I need the user-defined ODE model as one argument. Would you give me some advises please? Thank you.
Joss Knight
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 CenterFile Exchange에서 GPU Computing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by