Cell arrays and multiple GPUs computing

조회 수: 11 (최근 30일)
Mehdi Ravanbakhsh
Mehdi Ravanbakhsh 2015년 10월 16일
댓글: Mehdi Ravanbakhsh 2015년 10월 20일
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.

답변 (1개)

Edric Ellis
Edric Ellis 2015년 10월 19일
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
Mehdi Ravanbakhsh
Mehdi Ravanbakhsh 2015년 10월 20일
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?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Parallel Computing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by