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

1 次查看(过去 30 天)
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 个)

类别

Help CenterFile Exchange 中查找有关 GPU Computing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by