I found the CUDA kernel calling function of the PCT very useful. But the calling competition may exist. When I have a .cu file with a kernel "add1", I can firstly get the .ptx file of the kernel, and compile it in matlab, and a matlab function "add1" is built up. And the code "o=feval(add1,arg1,arg2…)" is legal. If I want to update existing variables, "[arg1,arg2]=feval(add1,arg1,arg2…)" is legal. If I have another kernel "add2", then "[arg1,arg2]=feval(add2,arg1,arg2…)" is legal. For a serial code, we may have step1.m doing add1, and step2.m doing add2. And we may have the Forward.m like "for clock =1:tend step1; step2; end" This code may not implement as what we think. Sometimes we get the right answer, but most time, especially when "tend" is larger, the result is wrong. I guess the reason is: when CPU calls step1, GPU runs the kernel, without knowing whether kernel"add1" is finished, the CPU begins to call step2 directly. This would not happen in CUDA C, because in CUDA C, CPU holds when calling a kernel unless GPU returns a signal that no program is in running. So how to solve this problem in matlab?
MATLAB: Calling competition when calling CUDA kernels using PCT
calling competitioncudagpukernelpct
Best Answer