Parfor on GPU

조회 수: 53 (최근 30일)
Sampath reddy
Sampath reddy 2012년 4월 23일
편집: Walter Roberson 2022년 8월 15일
I want to run two functions in parallel on a GPU. For this i want to use pafor(eg: for ii=1 fun1 and ii=2 fun2).
Can variables on GPU be used for parfor operations on GPU?

채택된 답변

Edric Ellis
Edric Ellis 2012년 4월 23일
Yes, you can do this. Whether you get much benefit depends on whether you have multiple GPUs in your system (under some circumstances, a single GPU might actually suffice if you have enough CPU work to keep things busy).
You might wish to do something like
spmd
gpuDevice( 1 + mod( labindex - 1, gpuDeviceCount ) )
end
before you go any further (if you have multiple supported GPUs)
After that, gpuArrays can be passed into and out from PARFOR loops with no further modification. The following example shows this - but note that this is a proof of concept - it performs very badly because you're operating on scalar elements of the gpuArray.
g = gpuArray(1:10);
parfor ii=1:numel(g)
x(ii) = 1/g(ii);
end

추가 답변 (1개)

Titus Edelhofer
Titus Edelhofer 2012년 4월 23일
Hi Sampath,
probably not. I guess it would make not much sense anyway, because the two functions would share the same computational power of the GPU (like running parfor on a single core machine).
If you happen to have to GPUs you could use parfor/spmd to split the functions onto the two GPUs ...
Titus
  댓글 수: 2
Pavel Sinha
Pavel Sinha 2018년 9월 11일
But the GPUs are milti-core computation engine. If a GPU has enough resources, can Matlab run two functions in parallel on the same GPU?
Walter Roberson
Walter Roberson 2018년 9월 11일
편집: Walter Roberson 2022년 8월 15일
Nvidia gpu cores are restricted to running the same instruction as the other cores in the same SM. My reading of the linked article is that different SM could be running unrelated tasks efficiently. However, the end of task processing of bringing back results and status looks like it would potentially be inefficient.

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

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by