Out of memory on device using accumarray
1 view (last 30 days)
Show older comments
Hi! I'm trying to speed up the mutual information calculation between two images using GPU, but I get a memory error.
I'm computing the mutual information inside a function that I have created, in which in the very first lines I do:
function nMI = mutualInformation(im1, im2)
% Inputs: im1: first image
% im2: second image
[~,~,indrow] = unique(im1(:));
[~,~,indcol] = unique(im2(:));
jointHistogram = accumarray([indrow indcol], 1);
...
...
...
end
Since it takes so long to calculate it, I stored the input images in GPU with gpuArray function in the main script, before execute the mutualInformation.
I use this function two times: the first time it doesn't give me problems and the execution is really improved compared to the case without GPU, but the second one it returns me this error:
"Error using gpuArray/accumarray
Out of memory on device. To view more detail about available memory on the GPU, use 'gpuDevice()'. If the problem
persists, reset the GPU by calling 'gpuDevice(1)'.
Error in mutualInformation (line 33)
jointHistogram = accumarray([indrow indcol], 1);"
Since the error didn't exist the first time I run the code (even if images' dimensions are bigger here than in the second case), I supposed that the problem was that I had to many variables in the workspace filling the memory. However, the problem persists even if I delete all the variables except the two input images. I also reset the GPU by calling gpuDevice(1), but nothing to do.
Images are double precision (I nees it); my operating system is Windows 10 and this is what gpuDevice() returns:
CUDADevice with properties:
Name: 'GeForce GTX 1050'
Index: 1
ComputeCapability: '6.1'
SupportsDouble: 1
DriverVersion: 11
ToolkitVersion: 10.1000
MaxThreadsPerBlock: 1024
MaxShmemPerBlock: 49152
MaxThreadBlockSize: [1024 1024 64]
MaxGridSize: [2.1475e+09 65535 65535]
SIMDWidth: 32
TotalMemory: 3.2212e+09
AvailableMemory: 2.3286e+09
MultiprocessorCount: 6
ClockRateKHz: 1442000
ComputeMode: 'Default'
GPUOverlapsTransfers: 1
KernelExecutionTimeout: 1
CanMapHostMemory: 1
DeviceSupported: 1
DeviceSelected: 1
Thank you for helping me.
0 Comments
Answers (1)
Srivardhan Gadila
on 18 Jun 2020
Try the following code to verify the usage of reset function:
g = gpuDevice(1)
M = gpuArray(magic(10000));
Check the gpu memory using the Task Manager if you are using Windows.
reset(g)
Check gpu memory again.
0 Comments
See Also
Categories
Find more on GPU Computing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!