gpuDeviceCount
存在する GPU デバイスの数
説明
は、GPU デバイス ドライバーによって報告された、ローカル マシンに存在する GPU デバイスの数を返します。MATLAB® でサポートされていないデバイスや、現在の MATLAB セッションで使用できないデバイスも含めて、ドライバーによって報告されたすべてのデバイスがカウントされます。 n
= gpuDeviceCount
例
GPU デバイスのカウントとクエリ
コンピューター内の使用可能な GPU デバイスの数と、それらのインデックスを特定します。
[n,indx] = gpuDeviceCount
n = 2 indx = 1 2
gpuDeviceTable
を使用して GPU のプロパティをクエリします。
gpuDeviceTable
ans = Index Name ComputeCapability DeviceAvailable DeviceSelected _____ __________________ _________________ _______________ ______________ 1 "TITAN RTX" "7.5" true false 2 "GeForce GTX 1080" "5.0" true true
並列プールにおける複数の GPU の使用
複数の GPU にアクセスできる場合、並列プールを使用して複数の GPU で並列計算を実行することができます。
MATLAB で使用可能な GPU の数を特定するには、関数gpuDeviceCount
を使用します。
availableGPUs = gpuDeviceCount("available")
availableGPUs = 3
使用可能な GPU と同数のワーカーをもつ並列プールを起動します。最良のパフォーマンスを得るために、MATLAB は既定でワーカーごとに別々の GPU を割り当てます。
parpool('Processes',availableGPUs);
Starting parallel pool (parpool) using the 'Processes' profile ... Connected to the parallel pool (number of workers: 3).
各ワーカーが使用している GPU を識別するために、spmd
ブロック内で gpuDevice
を呼び出します。spmd
ブロックは各ワーカーで gpuDevice
を実行します。
spmd gpuDevice end
parfor
やparfeval
などの並列言語機能を使用して、並列プールのワーカーに計算を分散します。計算にgpuArray
対応関数を使用すると、これらの関数はワーカーの GPU で実行されます。詳細については、GPU での MATLAB 関数の実行を参照してください。例は、複数の GPU での MATLAB 関数の実行を参照してください。
計算が完了したら、並列プールをシャットダウンします。関数gcp
を使用して、現在の並列プールを取得できます。
delete(gcp('nocreate'));
他の GPU を選択して使用する場合は、gpuDevice
で GPU デバイス インデックスを使用して、各ワーカーで特定の GPU を選択できます。関数 gpuDeviceCount
を使用すると、システム内の各 GPU デバイスのインデックスを取得できます。
システム内に使用可能な GPU が 3 つあり、その中の 2 つだけを計算に使用するとします。デバイスのインデックスを取得します。
[availableGPUs,gpuIndx] = gpuDeviceCount("available")
availableGPUs = 3
gpuIndx = 1×3
1 2 3
使用するデバイスのインデックスを定義します。
useGPUs = [1 3];
並列プールを起動します。spmd
ブロックと gpuDevice
を使用して、各ワーカーと使用する GPU のいずれかをデバイス インデックスにより関連付けます。関数 spmdIndex
は各ワーカーのインデックスを識別します。
parpool('Processes',numel(useGPUs));
Starting parallel pool (parpool) using the 'Processes' profile ... Connected to the parallel pool (number of workers: 2).
spmd gpuDevice(useGPUs(spmdIndex)); end
ベスト プラクティスとして、また最良のパフォーマンスを得るには、各ワーカーに異なる GPU を割り当てます。
計算が完了したら、並列プールをシャットダウンします。
delete(gcp('nocreate'));
入力引数
countMode
— デバイスのカウント モード
"all"
(既定値) | "supported"
| "available"
デバイスのカウント モード。次のいずれかとして指定します。
"all"
— GPU デバイス ドライバーによって報告された、すべての GPU デバイスをカウントします。このカウントには、MATLAB でサポートされていないデバイスや、現在の MATLAB セッションで使用できないデバイスも含まれます。"supported"
— 現在の MATLAB のバージョンでサポートされている GPU デバイスのみをカウントします。"available"
— 現在の MATLAB セッションで使用可能な GPU デバイスのみをカウントします。
例: "available"
データ型: char
| string
出力引数
バージョン履歴
R2010b で導入
MATLAB コマンド
次の MATLAB コマンドに対応するリンクがクリックされました。
コマンドを MATLAB コマンド ウィンドウに入力して実行してください。Web ブラウザーは MATLAB コマンドをサポートしていません。
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)