Out of memory GPU
1 view (last 30 days)
Show older comments
Hello every one,
when I run my code I have in the output of my code:
Could you help me please ? What should I do ?
my code is :
…
parfor f=1:Nb_images
im = imread(fullfile(fileFolder,char(names(f))));
[ligne, colonne]=size(im);
surface_echantillon=ligne*colonne;
[counts, ~] = imhist(im,16);
t = otsuthresh(counts);
binary = imbinarize(im,t);
bw1 = bwareaopen(binary,97);
bw6=bw1;
CC_tris=bwconncomp(bw6);
stats1=regionprops(CC_tris, 'Area', 'MajorAxisLength');
idx_tris=find ([stats1.MajorAxisLength]<300);
bw6= ismember(labelmatrix(CC_tris),idx_tris);
[L4,num]=bwlabel(bw6,8);
stats4=regionprops('table', L4, 'MajorAxisLength', 'MinorAxisLength','Area', 'Circularity');
rap2=stats4.MajorAxisLength./stats4.MajorAxisLength;
idx_4=find (rap2>5 & rap2<19 & [stats4.Area]<=700 ); % & [stats4.Area]<=600%%100 et bw7= ismember(bw6,idx_4);
bw7=bw6;
D=-bwdist(~bw6);
Ld=watershed(D);
bw2=bw6;
bw2(Ld==0)=0;
mask=imextendedmin(D,2);
D2=imimposemin(D,mask);
Ld2=watershed(D2);
bw3=gpuArray(bw6);
bw3(Ld2==0)=0;
bw4=gpuArray(bw3);
figure, imagesc(bw4),title("watershed");
[L3,num]=bwlabel(bw4,8);
stats=regionprops('table', L3, 'Area','Circularity','MajorAxisLength', 'MinorAxisLength');
elong=(stats.MajorAxisLength-stats.MinorAxisLength)./(stats.MajorAxisLength+stats.MinorAxisLength);
crit=stats.MajorAxisLength./stats.MinorAxisLength;
idx3=find([stats.Area]>=7 & [stats.Area]<550 & [stats.Circularity]>=0.75 & [elong]<0.55 & [stats.MajorAxisLength]<45 & crit<3.5);
binary=ismember(L3,idx3);
[L5,num5]=bwlabel(binary,8);
F=num5;
list_F=[list_F,F];
binary=gpuArray(binary*100);
bw=gpuArray(bw*90);
resu= gpuArray(binary+bw);
exportim=['C:\Users\MATLAB\pour vérif','\',int2str(f),'.tif'];
imwrite(resu,jet,exportim);
end
2 Comments
Raymond Norris
on 4 Apr 2022
As you can see, your GPU device has about 5 GB of total memory. I don't have any specific suggestion, but have a few comments
- I'm assuming you're running a pool of workers; otherwise, why run the parfor loop. Therefore, multiple workers will be accessing this one (?) GPU. Will that create a bottleneck?
- How much data are your gpuArray variables (bw3, bw4, binary, bw, resu)?
- What is the core of what you want to process on the GPU? For instance
Ld=watershed(D);
bw2=bw6;
bw2(Ld==0)=0;
% ...
Ld2=watershed(D2);
bw3=gpuArray(bw6);
bw3(Ld2==0)=0;
Why is bw2 on the CPU but bw3 on the GPU? Next, look how bw4 is assigned
bw4=gpuArray(bw3);
figure, imagesc(bw4),title("watershed");
[L3,num]=bwlabel(bw4,8);
To begin with, since bw3 is an gpuArray, you could assign bw4 as such
bw4 = bw3;
But do you even need to create bw4? Couldn't you use bw3 for imagesc and bwlabel?
- If I'm reading this right, you have a bug in the following line
binary=gpuArray(binary*100);
bw=gpuArray(bw*90);
resu= gpuArray(binary+bw);
I don't see where bw is first initialized. And again, since binary and bw are gpuArray, adding them together will make resu a gpuArray as well.
binary = gpuArray(binary*100);
bw = gpuArray(bw*90);
resu = binary+bw;
I don't know how big binary is, but is it worth mutiplying out binary * 100 on the GPU? Or bw * 90?
Answers (0)
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!