Are gpuArray supported within parfor?

2 vues (au cours des 30 derniers jours)
Bharath Lohray
Bharath Lohray le 24 Oct 2018
Hi,
I am running the following code and receive an error
Error using gpuArrayTest (line 16)
The following error occurred converting from gpuArray to double:
Conversion to double from gpuArray is not possible.
Line 16 is
parfor i = 1:numel(x_c)
My Code is as follows
%Window Size
W=20;
num_files=3;
% My Code: Read template image from disk - imread > imcrop
im1 = gpuArray(rand(150));
% Actual Code: S = size(template image | im1)
S=[65,62];
[x_c,y_c]=meshgrid(W+1:S(2)-W, W+1:S(1)-W);
max_xcorr_1=zeros(size(x_c),'gpuArray');
% store xcorr results from all filse
max_xcorr_arr=zeros([size(x_c),num_files]);
Loop over a file list.
for j=1:num_files
% My Code: Read image from disk - imread > imcrop
im2 = gpuArray(rand(150));
tic;
parfor i = 1:numel(x_c)
x=x_c(i);
y=y_c(i);
% Check to see if all pixels in template is not 0 (same).
if (~max(im1(x-W:x+W,y-W:y+W),[],'all')==0)
nxc = normxcorr2(im1(x-W:x+W-1, y-W:y+W-1), im2(x-W:x+W-1, y-W:y+W-1));
% Commenting the line below avoids the gpuArray > double coversion error.
max_xcorr_1(i)=max(nxc,[],'all');
end
end
max_xcorr_arr(:,:,j)=gather(max_xcorr_1);
toc
end
However, I do not receive the error if I do one of the following -
  1. I comment out the line `max_xcorr_1(i)=max(nxc,[],'all');`
  2. Reduce the size of the meshgrid to `S=[40, 40]`. The smallest number that I can use without getting the error varies from time to time.
  3. I replace `parfor` with `for`.
I have 8 local MATLAB Workers running. My GPU is an NVIDIA GeForce GTX860M with 4GB of dedicated RAM. My questions are -
  1. Is gpuArray supported within a `parfor`?
  2. Irrespective of the meshgrid size defined by S, The `normxorr2` operation runs on a 2W x 2W sized matrix. So, why does the size S affect the code?
  3. How can I get around this?

Réponses (0)

Catégories

En savoir plus sur GPU Computing dans Help Center et File Exchange

Produits


Version

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by