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
Petter Stefansson
Petter Stefansson 2017년 1월 19일
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…

댓글을 달려면 로그인하십시오.

답변 (2개)

T Mullai
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.

Guillaume GODEFROY
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

카테고리

Help CenterFile Exchange에서 Encryption / Cryptography에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by