Cell arrays and multiple GPUs computing
조회 수: 11 (최근 30일)
이전 댓글 표시
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.
댓글 수: 0
답변 (1개)
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.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!