Cell arrays and multiple GPUs computing

10 Ansichten (letzte 30 Tage)
Mehdi Ravanbakhsh
Mehdi Ravanbakhsh am 16 Okt. 2015
Hi,
I have a cell array of matrices and I have two GPUs, each can process matrices memory-wise.
I want to be able to simultaneously process all mat_list elements on two GPUs. I am wondering if SPMD is suitable for this task? If yes, how can I pass on cell arrays into SPMD in such a way that 2 GPUs process all arrays?
Thank you.

Antworten (1)

Edric Ellis
Edric Ellis am 19 Okt. 2015
You could use spmd or parfor for this, but beware that this will involve making copies of the data onto the GPUs used by the workers. For example, you could do something like this:
matrices = {rand(1000, 'gpuArray'), rand(2000, 'gpuArray')};
spmd
if labindex <= numel(matrices)
myMatrix = matrices{labindex};
myResult = max(myMatrix(:));
else
myResult = NaN;
end
end
The downside of this approach is that all elements of the cell array matrices are copied to each GPU on the workers. For this particular sort of case, parfor would involve fewer copies of data:
matrices = {rand(1000, 'gpuArray'), rand(2000, 'gpuArray')};
parfor idx = 1:numel(matrices)
matrix = matrices{idx};
result(idx) = max(matrix(:));
end
If possible, it's best to build the gpuArray in the body of your spmd or parfor block to avoid making too many copies on the GPU.
  1 Kommentar
Mehdi Ravanbakhsh
Mehdi Ravanbakhsh am 20 Okt. 2015
Thanks Edric. I tested the second approach and it worked well. In your first approach, you used labindex to interate but what if my cell array has more than 20 elements? Matlab help is saying that labindex represents the number for workers. I have 2 GPUs and each has 6 workers so it can handle at max 12 cell elements. Is there any way around this?

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Parallel Computing finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by