Update: it also appears to work if I ‘ clear all ’ every time between runs. Manually clearing every single variable in my Matlab workspace however, like: ‘ clear A U S Vt ’, does not work…
MEX function with CUDA code works once. Then I need to restart Matlab or recompile it!?
1 次查看(过去 30 天)
显示 更早的评论
I’ve written a MEX file that uses the CUDA solver, specifically the cusolverDnDgesvd function, to compute the equivalent of Matlabs SVD calculation: [U, S, Vt] = svd(A)
I can compile it using mexcuda like this:
mexcuda CUDA_SVD.cu -lcublas -lcusolver -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v7.5\include" -L"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v7.5\lib\x64"
and it compiles without any errors and when I run it, it seems to produce the same singular value as the Matlab version does when running it on the CPU. Which is great. However. The second time I run it, with the exact same input, the output is 0! Example:
A = rand(500,1);
[U, S, Vt] = CUDA_SVD(A);
S =
12.7203
[U, S, Vt] = CUDA_SVD(A);
S =
0
[U, S, Vt] = CUDA_SVD(A);
S =
0
It’s like the function is ruined after one call to it. And it doesn’t stop producing 0 as output until I either recompile the .cu file or restart Matlab. If I do that it works one time again before going back to producing zeros. Do I need to reset/clear something inside the MEX file that I have missed or why in the name of all that is holy does it behave like this? Anyone who has any ideas?
I have attached the file here as a .zip if someone would be kind enough to look at it. The CUDA code is largely based on the SVD example from NVIDIA’s webpage:
回答(2 个)
T Mullai
2018-7-10
Hi Petter, I am looking for a MEX file that uses CUDA solver to compute SVD of a matrix. Iam able to download CUDA_SVD.zip file you have shared here. However, an error occurs when I try to unzip. Can you please reload the zip file again?I would like to explore in fixing the problem of zero coming for the second time.
Thanks.
0 个评论
Guillaume GODEFROY
2020-2-26
Hi Peter,
I have a similar problem, the code works the first time but the second time it give me always the same result even if I change the input data, did you find a way to manage it?
Thanks
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Encryption / Cryptography 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!