How to specify GPU devices for parallel computing using "parfor"?

7 ビュー (過去 30 日間)
ts
ts 2021 年 12 月 20 日
コメント済み: ts 2021 年 12 月 20 日
I have a workstation with four GPUs, and I want to run a parfor loop using specific two or three GPUs to share the workstation with other users. If you know how to specify gpu devices for parallel computing using "parfor", I would appreciate it if you could let me know.

採用された回答

Edric Ellis
Edric Ellis 2021 年 12 月 20 日
The documentation here describes how you might do this in general. Things get a little more complicated if you want to run more workers than the number of GPUs you're accessing, but the principle is the same - set things up using gpuDevice inside an spmd block. That then sets the GPU in use by the worker process, and parfor loops will continue to use that device.
  1 件のコメント
ts
ts 2021 年 12 月 20 日
Thank you very much! The documentation and your anwer were very helpful. The following code specifies GPUs #2, #3, #4 to workers #1, #2, #3, respectively, and then following parfor loop uses the specified GPUs.
useGPUs = [2 3 4];
spmd
gpuDevice(useGPUs(labindex));
end
parfor
...
end

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeParallel and Cloud についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by