the device being used is no longer there (MATLAB + GPU)

hi Folks: This bothers me: I have 2 GPU cards on my machine. I designate the 2nd one to use in my MATLBA code, but I got following error:
The device being used is no longer current.
Error in deriv_optcontMxy_cuda (line 18)
gpuderivMxy.GridSize = [min(1024,tmp.MaxGridSize(1)) 1]; % min(1024, maxblocks)
Error in optcontMxyHBG (line 72)
drfn = deriv_optcontMxy_cuda(rfn,gamgdtn,xx,auxa,auxb,a,b,rfmask);
I am not sure why; Here is my code:
persistent gpuderivMxy
persistent drfrt drfit;
Nt = size(rf,1);
Ns = size(xx,1);
Ndim = size(xx,2);
if isempty(gpuderivMxy)
disp 'Initializing GPU drf calculation...';
gpuderivMxy = parallel.gpu.CUDAKernel('deriv_optcontMxy_cuda.ptx','deriv_optcontMxy_cuda.cu','deriv_optcontMxy_cuda');
tmp = gpuDevice(2);
gpuderivMxy.GridSize = [min(1024,tmp.MaxGridSize(1)) 1]; % min(1024, maxblocks)
gpuderivMxy.ThreadBlockSize = [min(128, tmp.MaxThreadsPerBlock) 1 1]; % min(128, maxthreadsperblock)
drfrt = gpuArray(zeros(Ns, Nt));
drfit = gpuArray(zeros(Ns, Nt));
end;
If I do not use tmp = gpuDevice(2), only tmp = gpuDevice(); it has no mistake like above;
Any one has any idea why this is happening? I appreciate it.

 채택된 답변

Nick Tsui
Nick Tsui 2012년 7월 26일
편집: Nick Tsui 2012년 7월 26일
I think if you put
tmp = gpuDevice(2)
before
gpuderivMxy = parallel.gpu.CUDAKernel('deriv_optcontMxy_cuda.ptx','deriv_optcontMxy_cuda.cu','deriv_optcontMxy_cuda');
thsn you will be fine.
Thank you.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

질문:

2012년 7월 26일

Community Treasure Hunt

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

Start Hunting!

Translated by