Unreliable results from calling CUDA kernel

4 vues (au cours des 30 derniers jours)
Nathan
Nathan le 13 Mai 2012
As part of my undergraduate senior project, I have coded up a common astrodynamics problem to run on the GPU, where each solution to the problem is executed on a different thread.
I have gotten the same algorithm to work in MATLAB on the CPU (in a for loop), in MATLAB on the GPU (using gpuArray and arrayfun), and in CUDA (compiling with nvcc and running the .exe created). All of these work perfectly and give the same results for a variety of test inputs. However, when I try to call the CUDA kernel from within MATLAB, I run into some issues.
When calling the CUDA kernel, MATLAB is not always returning values correctly. What I mean is, for some inputs MATLAB will return all the outputs correctly; for others, all the outputs will be NaN's; and for other inputs, one output will be correct and the rest will be NaN. The perplexing case is when only one output is correct because it is impossible in the CUDA code for only one output to be good. To explain, here is a code snippet:
f = 1.0 - y_num/r1;
g = A*sqrt(y_num/mu2);
v1_1[tid] = 1.0/g*(r2_1[tid] - f*r1_1[tid]);
v1_2[tid] = 1.0/g*(r2_2[tid] - f*r1_2[tid]);
v1_3[tid] = 1.0/g*(r2_3[tid] - f*r1_3[tid]);
r1_1, r1_2, etc... are the inputs, v1_1,v1_2, etc... are the outputs. v1_1 is returning correctly, while the others are coming back as NaN's. This doesn't make sense to me because I have verified that r1_1,r1_2... are being passed in correctly, and the only way that v1_1 can be calculated is if "f" and "g" are both calculated correctly.
Something worth noting is that the algorithm can sometimes have complex numbers in the intermediate calculations. I don't think that is happening for my test cases, however (I have stepped through the test case in the MATLAB version of the code, and I don't see any complex numbers).
Sorry for rambling, just trying to be complete. Any help would be much appreciated!
  1 commentaire
Jill Reese
Jill Reese le 17 Mai 2012
Are you trying to run your kernel via the CUDAKernel interface or using a mex wrapper? Also, are you using any special CUDA functionality in your kernel?

Connectez-vous pour commenter.

Réponses (1)

Denis Riedijk
Denis Riedijk le 14 Mai 2012
Mathworks support is in general very good. I would just email them. I have never experienced a problem like this yet when calling ptx code from Matlab (I assume that is what you are trying, and you did not write a mex file yourself). I have however mostly used CUDA with a custom mex wrapper.

Catégories

En savoir plus sur GPU Computing dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by