GPU computing: data no longer available on device??
조회 수: 2 (최근 30일)
이전 댓글 표시
Hi all,
the following code gives me an error sometimes:
if isa(rawData,'gpuArray')
rawData = gather(rawData);
gpuSwitcheroo = 1;
else
gpuSwitcheroo = 0;
end
The error is: Error using gpuArray/gather The data no longer exists on the device.
I really cant make any sense of this, since the if statement should already check whether or not the variable is on the GPU, right?? How could it possibly not be on the GPU anymore if that statement just resulted in the variable being of type 'gpuArray'??
This only occurs on a system with very limited GPU memory, but I checked and during that specific operation the memory is not exceeded! It is however beforehand, and as a result of that, rawData is automatically gathered, hence the usage of that if-statement. But then how can the statement be true, if rawData has already been gathered??
I'm really confused, hopefully someone knows whats going on.
Thanks!
댓글 수: 0
답변 (1개)
Edric Ellis
2019년 11월 28일
That error occurs when MATLAB resets the GPU "context". This generally happens when you either select a different GPU device, or reset the current device. In both cases, the class of your data doesn't change, but the ability to retrieve the contents is lost. You need to use the function existsOnGPU to tell whether or not the data is still accessible, like this:
g = gpuArray(1:10);
isa(g, 'gpuArray') && existsOnGPU(g) % returns true
reset(gpuDevice) % force invalidation of the GPU "context"
isa(g, 'gpuArray') % still true
existsOnGPU(g) % false
참고 항목
카테고리
Help Center 및 File Exchange에서 Get Started with GPU Coder에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!