「外付け GPU」の版間の差分

提供: ArchWiki
ナビゲーションに移動 検索に移動
(新規作成(英語版より転載))
 
(同期)
 
(2人の利用者による、間の7版が非表示)
1行目: 1行目:
[[Category:Graphics]]
+
[[Category:グラフィック]]
[[Category:X server]]
+
[[Category:X サーバー]]
  +
[[en:External GPU]]
 
{{Related articles start}}
 
{{Related articles start}}
 
{{Related|Xorg}}
 
{{Related|Xorg}}
 
{{Related|PRIME}}
 
{{Related|PRIME}}
 
{{Related|Thunderbolt}}
 
{{Related|Thunderbolt}}
{{Related|NVIDIA_Optimus}}
+
{{Related|NVIDIA Optimus}}
{{Related|NVIDIA/Tips_and_tricks}}
+
{{Related|NVIDIA/ヒントとテクニック}}
  +
{{Related|ドック}}
 
{{Related articles end}}
 
{{Related articles end}}
  +
[[Wikipedia:ja:Thunderbolt#Thunderbolt_3|Thunderbolt 3 以上]]または [[Wikipedia:ja:USB4|USB4]] を搭載したコンピュータは、GPU エンクロージャを使用して、デスクトップグレードの外付けグラフィックカード (eGPU) を接続できます。[https://egpu.io/ eGPU.io] は購入者ガイドとコミュニティフォーラムのある優れたリソースです。ほとんどの動作モードでは、いくつかの手動設定 (以下に記載) が必要ですが、eGPU の Linux サポートは一般的に良好です。
On computers equipped with [[Wikipedia:Thunderbolt_(interface)#Thunderbolt_3|Thunderbolt 3+]], it is possible to attach a desktop-grade external graphics card (eGPU) using a GPU enclosure. [https://egpu.io/ eGPU.io] is a good resource with buyer's guide and a community forum. While some manual configuration (shown below) is needed for most modes of operation, Linux support for eGPUs is generally good.
 
   
  +
{{Note|USB4 のノート PC に関しては、データの転送速度が最低 20 Gbit/s、オプションでより高く (40、80、またはそれ以上) なるように規定されています。Thunderbolt エンクロージャを使用する場合、ノート PC の USB4 実装が Thunderbolt と同じ転送速度をサポートしているか確認しておくと良いでしょう。}}
== Installation ==
 
  +
  +
== インストール ==
   
 
=== Thunderbolt ===
 
=== Thunderbolt ===
   
  +
eGPU エンクロージャの Thunderbolt デバイスは、挿入した後にまず (BIOS/UEFI のファームウェア設定に基づいて) 認証する必要があるかもしれません。[[Thunderbolt#ユーザーデバイス認証]] の指示に従ってください。それができたら、外付け GPU が {{ic|lspci}} に表示されるはずです:
The eGPU enclosure Thunderbolt device may need to be authorized first after plugging in (based on your BIOS/UEFI Firmware configuration). Follow [[Thunderbolt#User device authorization]]. If successful, the external graphics card should show up in {{ic|lspci}}:
 
   
 
{{hc|$ lspci {{!}} grep -E 'VGA{{!}}3D'|
 
{{hc|$ lspci {{!}} grep -E 'VGA{{!}}3D'|
00:02.0 VGA compatible controller: Intel Corporation UHD Graphics 620 (rev 07) # internal GPU
+
00:02.0 VGA compatible controller: Intel Corporation UHD Graphics 620 (rev 07) # 内部 GPU
1a:10.3 VGA compatible controller: NVIDIA Corporation GP107 [GeForce GTX 1050] (rev a1) # external GPU
+
1a:10.3 VGA compatible controller: NVIDIA Corporation GP107 [GeForce GTX 1050] (rev a1) # 外付け GPU
 
}}
 
}}
   
  +
あなたのコンピュータ、コンピュータのファームウェア、そしてエンクロージャのファームウェアによっては、[https://egpu.io/best-laptops-external-gpu/#pcie PCIe のレーン数と OPI のモード]により、Thunderbolt によってホスト <-> eGPU 間の帯域幅がある程度制限されます:
Depending on your computer, its firmware and enclosure firmware, Thunderbolt will limit host <-> eGPU bandwidth to some extent due to [https://egpu.io/best-laptops-external-gpu/#pcie the number of PCIe lanes and OPI Mode]:
 
   
 
{{hc|# dmesg {{!}} grep PCIe|
 
{{hc|# dmesg {{!}} grep PCIe|
27行目: 31行目:
 
}}
 
}}
   
=== Drivers ===
+
=== ドライバ ===
   
  +
GPU モデルと互換性のあるドライバをインストールする必要があります:
A driver compatible with your GPU model should be installed:
 
   
 
* [[AMDGPU]]
 
* [[AMDGPU]]
* [[NVIDIA]] proprietary Nvidia drivers
+
* [[NVIDIA]] プロプライエタリな Nvidia ドライバ
* [[Nouveau]] open-source Nvidia drivers
+
* [[Nouveau]] オープンソースな Nvidia ドライバ
   
  +
インストールに成功しているならば、{{ic|lspci -k}} の出力でドライバとカードが関連付けられているはずです:
If installed successfully, {{ic|lspci -k}} should show that a driver has been associated with your card:
 
   
  +
{{hc|$ lspci -k|
{{bc|
 
 
1a:10.3 VGA compatible controller: NVIDIA Corporation GP107 [GeForce GTX 1050] (rev a1)
 
1a:10.3 VGA compatible controller: NVIDIA Corporation GP107 [GeForce GTX 1050] (rev a1)
 
Subsystem: NVIDIA Corporation GP107 [GeForce GTX 1050]
 
Subsystem: NVIDIA Corporation GP107 [GeForce GTX 1050]
44行目: 48行目:
 
}}
 
}}
   
  +
AMDGPU ドライバは、(Thunderbolt か USB4 のどちらか一方を使用している場合に) ''pcie_gen_cap'' オプションに間違った値を設定してしまい、その結果 PCIe gen 1.1 の速度にフォールバックしてパフォーマンスに大きな問題が発生する場合があることに注意してください。
== Compute-only workloads ==
 
  +
この場合、適切な値をモジュールオプション ([[カーネルモジュール#/etc/modprobe.d/ 内のファイルを使う]] を参照) として、または[[カーネルパラメータ]]から設定することができます:
   
  +
{{hc|/etc/modprobe.d/amd-egpu-pcie-speed.conf|2=
Right after completing [[#Installation|installation steps]], compute-only workloads like [[GPGPU#CUDA]] that do not need to display anything should work without any extra configuration. {{ic|nvidia-smi}} utility should work with the proprietary NVIDIA driver. Proprietary [[Wikipedia:Nvidia_NVENC|Nvidia NVENC/NVDEC]] should work (without OpenGL interop).
 
  +
options amdgpu pcie_gen_cap=0x40000
  +
}}
  +
  +
この例では、PCIe gen 3 の速度を設定します。利用可能なオプションの完全なリストは [https://github.com/torvalds/linux/blob/master/drivers/gpu/drm/amd/include/amd_pcie.h#L26 amd_pcie.h] で確認できます。
  +
  +
== コンピューティングのみのワークロード ==
  +
  +
[[#インストール|インストール作業]]を完了したら、何も描画する必要のない [[GPGPU#CUDA]] のようなコンピューティングのみのワークロードは追加の設定無しで機能するはずです。''nvidia-smi'' ユーティリティ ({{Pkg|nvidia-utils}} パッケージにあり) はプロプライエタリな NVIDIA ドライバで動作するはずです。プロプライエタリな [[Wikipedia:Nvidia_NVENC|Nvidia NVENC/NVDEC]] も動作するはずです (OpenGL interop 無しで)。
   
  +
このようなユースケースではホットプラグも完全にサポートされているはずです。また、ホットアンプラグも可能なはずです (おそらく、使用するドライバに依ります)。Nvidia では、{{ic|nvidia-persistenced}} をアクティブ化していると、クリーンなホットアンプラグが妨害されると予想されます。
This use-case should also support full hotplug. Hot-unplug should be also possible (probably depending on drivers used). On Nvidia, active {{ic|nvidia-persistenced}} is expected to prevent clean hot-unplug.
 
   
 
== Xorg ==
 
== Xorg ==
   
  +
内部 カード (iGPU) と外付けカード (eGPU) を組み合わせたセットアップには複数のバリエーションがあり、それぞれに長所と短所があります。
Multiple setups combining internal (iGPU) and external (eGPU) cards are possible, each with own advantages and disadvantages.
 
   
=== Xorg rendered on eGPU, PRIME display offload to iGPU ===
+
=== eGPU で Xorg を描画し、iGPU PRIME ディスプレイオフロード ===
   
* Most programs that make use of GPU run out-of-the-box on eGPU: {{ic|glxinfo}}/{{ic|glxgears}}, {{ic|eglinfo}}/{{ic|eglgears_x11}}, {{ic|NVENC}}/{{ic|NVDEC}} (including OpenGL interop).
+
* GPU を使用するプログラムのほとんどは設定せずとも eGPU 上で動作します: {{ic|glxinfo}}/{{ic|glxgears}}{{ic|eglinfo}}/{{ic|eglgears_x11}}{{ic|NVENC}}/{{ic|NVDEC}} (OpenGL interop を含む)
  +
* Xorg は、eGPU が挿入された状態でのみ起動します。
* Xorg only starts with the eGPU plugged in.
 
  +
* eGPU に接続されているモニターは設定せずとも動作します。iGPU に接続されているモニター (つまり、ノート PC の画面) に対しては PRIME ''ディスプレイ''オフロードを使用できます。
* Monitors attached to eGPU work out-of-the-box, PRIME ''display'' offload can be used for monitors attached to iGPU (i.e. internal laptop screen).
 
   
Main articles are [[PRIME#Discrete card as primary GPU]] and [[PRIME#Reverse PRIME]]. Also documented in NVIDIA driver docs [http://us.download.nvidia.com/XFree86/Linux-x86_64/465.27/README/randr14.html Chapter 33. Offloading Graphics Display with RandR 1.4].
+
主な記事は [[PRIME#ディスクリートカードをプライマリ GPU にする]] [[PRIME#Reverse PRIME]] です。また、NVIDIA ドライバのドキュメントの [http://us.download.nvidia.com/XFree86/Linux-x86_64/465.27/README/randr14.html Chapter 33. Offloading Graphics Display with RandR 1.4] でも文書化されています。
   
  +
以下のような Xorg の設定スニペットを使ってください:
Use Xorg config snippet like this one:
 
   
 
{{hc|/etc/X11/xorg.conf.d/80-egpu-primary-igpu-offload.conf|
 
{{hc|/etc/X11/xorg.conf.d/80-egpu-primary-igpu-offload.conf|
68行目: 81行目:
 
Identifier "Device0"
 
Identifier "Device0"
 
Driver "nvidia"
 
Driver "nvidia"
BusID "PCI:26:16:3" # Edit according to lspci, translate from hex to decimal.
+
BusID "PCI:26:16:3" # lspci の出力に応じて書き換えてください。また、16進数から10進数に変換してください。
Option "AllowExternalGpus" "True" # Required for proprietary NVIDIA driver.
+
Option "AllowExternalGpus" "True" # プロプライエタリな NVIDIA ドライバで必要です。
 
EndSection
 
EndSection
   
 
Section "Module"
 
Section "Module"
  +
# iGPU 用の modesetting モジュールをロードします。modesetting は XrandR 1.4 でプロバイダとして表示されるはずです。
# Load modesetting module for the iGPU, which should show up in XrandR 1.4 as a provider.
 
 
Load "modesetting"
 
Load "modesetting"
 
EndSection
 
EndSection
 
}}
 
}}
   
  +
{{Note|Xorg は10進数のバス ID を使用しますが、他のほとんどのツールは16進数を使用します。なので、{{ic|xorg.conf}} スニペットでは {{ic|1a:10.3}} を {{ic|26:16:3}} に変換しなければならなかったのです。}}
{{Note|Xorg uses decimal bus IDs, while most other tools use hexadecimal. We had to convert {{ic|1a:10.3}} to {{ic|26:16:3}} for {{ic|xorg.conf}} snippet.}}
 
   
{{Tip|With modern Xorg, it is not needed to specify {{ic|ServerLayout}} and {{ic|Screen}} sections, as these are inferred automatically. First {{ic|Device}} defined will be considered primary.}}
+
{{Tip|最近の Xorg では、{{ic|ServerLayout}} セクションと {{ic|Screen}} セクションを指定する必要はもうありません。これらは自動的に推測されます。最初に定義された {{ic|Device}} がプライマリとみなされます。}}
   
To '''validate''' this setup, use {{ic|xrandr --listproviders}}, which should display
+
このセットアップを'''検証'''するには、{{ic|xrandr --listproviders}} を使ってください。以下のように表示されるはずです:
   
 
{{bc|
 
{{bc|
90行目: 103行目:
 
}}
 
}}
   
  +
RandR 1.4 PRIME ''ディスプレイ''オフロードを使用することにより、'''iGPU に接続されているノート PC の内蔵ディスプレイと、同じく iGPU に接続されている他のモニタの一方/両方に出力する'''ことができます。上記の {{ic|xrandr --listproviders}} で出力されている名前を使用して、以下のようなコマンドを実行してください:
To '''output to internal laptop screen and/or other monitors attached to iGPU''', RandR 1.4 PRIME ''display'' offload can be used, using names from above {{ic|xrandr --listproviders}} output:
 
   
 
{{bc|xrandr --setprovideroutputsource modesetting NVIDIA-0 && xrandr --auto}}
 
{{bc|xrandr --setprovideroutputsource modesetting NVIDIA-0 && xrandr --auto}}
   
  +
{{Note|{{ic|xrandr --auto}} は任意であり、他の RandR ベースのディスプレイ設定ツールに置き換えても良いです。このコマンドがあることにより、全ての画面が真っ暗になってしまう状況を回避できます。}}
{{Note|The {{ic|xrandr --auto}} is optional and may be substituted by any RandR-based display configuration tool. Its presence prevents all-screens-black situation.}}
 
   
  +
ディスプレイマネージャがログインプロンプトを表示する前や、デスクトップ環境が開始する前にこのコマンドを実行したい場合があるでしょう。これに関しては [[Xrandr#設定]] と [[Xinit]] を見てください。
You may want to run this command before a display manager shows login propmt or before desktop environment starts, see [[Xrandr#Configuration]] and [[Xinit]].
 
   
[[Vulkan]] may enumerate GPUs independently of Xorg, so in order to run for example {{ic|vkcube}} in this setup, one may need to pass {{ic|--gpu_number 1}} option. Alternatively, a layer to reorder GPUs during enumeration can be activated with the same effect: {{ic|1=__NV_PRIME_RENDER_OFFLOAD=1 vkcube}} or equivalently {{ic|prime-run vkcube}}.
+
[[Vulkan]] Xorg とは独立して GPU を列挙する場合があります。なので、この環境で {{ic|vkcube}} などを実行するには、{{ic|--gpu_number 1}} オプションを渡す必要があるかもしれません。または、{{ic|1=__NV_PRIME_RENDER_OFFLOAD=1 vkcube}} かそれと等価な {{ic|prime-run vkcube}} を使って、列挙中に GPU を並べ替えるレイヤーをアクティブ化しても、同じ効果があります。
   
  +
{{Tip|ノート PC 上で ''optimus-manager'' を使っている場合、モードとグラフィックスカードに対応する {{ic|/etc/optimus-manager/xorg/}} 内の適切なファイルに eGPU の {{ic|BusId}} を追加することで、eGPU でレンダリングすることができます。}}
=== Xorg rendered on iGPU, PRIME render offload to eGPU ===
 
   
  +
=== iGPU で Xorg を描画し、eGPU に PRIME レンダーオフロード ===
* Programs are rendered on iGPU by default, but PRIME ''render'' offload can be used to render them on eGPU.
 
* Xorg starts even with eGPU disconnected, but render/display offload will not work until it is restarted.
 
* Monitors attached to iGPU (i.e. internal laptop screen) work out-of-the-box, PRIME ''display'' offload can be used for monitors attached to eGPU.
 
   
  +
* プログラムはデフォルトで iGPU 上で描画されますが、PRIME ''レンダー''オフロードを使って eGPU 上で描画することもできます。
Main article is [[PRIME#PRIME GPU offloading]]. Also documented in NVIDIA driver docs [http://us.download.nvidia.com/XFree86/Linux-x86_64/465.27/README/primerenderoffload.html Chapter 34. PRIME Render Offload].
 
  +
* Xorg は eGPU が接続されていなくても開始しますが、再起動しない限りレンダー/ディスプレイオフロードは機能しません。
  +
* iGPU に接続されているモニタ (つまり、ノート PC の内蔵ディスプレイ) は設定せずとも動作します。eGPU に接続されているモニタに対しては PRIME ''ディスプレイ''オフロードを使用できます。
   
  +
主な記事は [[PRIME#PRIME GPU オフロード]] です。また、NVIDIA ドライバのドキュメントの [http://us.download.nvidia.com/XFree86/Linux-x86_64/465.27/README/primerenderoffload.html Chapter 34. PRIME Render Offload] でも文書化されています。
With many discrete GPU drivers, this mode should be the default without any manual Xorg configuration. If that does not work, or if you use proprietary NVIDIA drivers, use Xorg config snippet like this one:
 
  +
  +
多くのディスクリート GPU ドライバで、Xorg が手動で設定されていない場合はこのモードがデフォルトになっているはずです。動作しない場合や、プロプライエタリな NVIDIA ドライバを使用している場合は、以下の設定を使用してください:
   
 
{{hc|/etc/X11/xorg.conf.d/80-igpu-primary-egpu-offload.conf|
 
{{hc|/etc/X11/xorg.conf.d/80-igpu-primary-egpu-offload.conf|
119行目: 134行目:
 
Identifier "Device1"
 
Identifier "Device1"
 
Driver "nvidia"
 
Driver "nvidia"
BusID "PCI:26:16:3" # Edit according to lspci, translate from hex to decimal.
+
BusID "PCI:26:16:3" # lspci の出力に応じて書き換えてください。また、16進数から10進数に変換してください。
Option "AllowExternalGpus" "True" # Required for proprietary NVIDIA driver.
+
Option "AllowExternalGpus" "True" # プロプライエタリな NVIDIA ドライバで必要です。
 
EndSection
 
EndSection
 
}}
 
}}
   
To '''validate''' this setup, use {{ic|xrandr --listproviders}}, which should display
+
このセットアップを'''検証'''するには、{{ic|xrandr --listproviders}} を使ってください。以下のように表示されるはずです:
   
  +
{{hc|$ xrandr --listproviders|
{{bc|
 
 
Providers: number : 2
 
Providers: number : 2
 
Provider 0: id: 0x47 cap: 0xf, Source Output, Sink Output, Source Offload, Sink Offload crtcs: 3 outputs: 5 associated providers: 0 name:modesetting
 
Provider 0: id: 0x47 cap: 0xf, Source Output, Sink Output, Source Offload, Sink Offload crtcs: 3 outputs: 5 associated providers: 0 name:modesetting
132行目: 147行目:
 
}}
 
}}
   
  +
PRIME ''レンダー''オフロードを使えば、{{ic|''some_program''}} を '''eGPU 上'''で'''レンダリング'''することができます:
To '''render {{ic|someprogram}} on the eGPU''', PRIME ''render'' offload can be used:
 
   
* for proprietary NVIDIA drivers: {{bc|1=__NV_PRIME_RENDER_OFFLOAD=1 __VK_LAYER_NV_optimus=NVIDIA_only __GLX_VENDOR_LIBRARY_NAME=nvidia someprogram}}
+
* プロプライエタリな NVIDIA ドライバの場合: {{bc|1=$ __NV_PRIME_RENDER_OFFLOAD=1 __VK_LAYER_NV_optimus=NVIDIA_only __GLX_VENDOR_LIBRARY_NAME=nvidia ''some_program''}}
* for proprietary NVIDIA drivers (convenience wrapper): {{bc|1=prime-run someprogram}}
+
* プロプライエタリな NVIDIA ドライバの場合 (便利なラッパー): {{bc|1=$ prime-run ''some_program''}}
* for open-source drivers: {{bc|1=DRI_PRIME=1 someprogram}}
+
* オープンソースなドライバの場合: {{bc|1=$ DRI_PRIME=1 ''some_program''}}
   
  +
RandR 1.4 PRIME ''ディスプレイ''オフロードを使えば、'''eGPU に接続されたモニタに出力する'''ことができます:
To '''output to monitors connected to eGPU''', RandR 1.4 PRIME ''display'' offload can be again used:
 
   
{{bc|xrandr --setprovideroutputsource NVIDIA-G0 modesetting && xrandr --auto}}
+
$ xrandr --setprovideroutputsource NVIDIA-G0 modesetting && xrandr --auto
   
  +
{{Tip|この場合、プロバイダの順番が異なり、Nvidia の名前も若干異なります。}}
{{Tip|The order of providers is different, and the Nvidia the has a slightly different name this time.}}
 
   
  +
NVIDIA drivers 460.27.04+ では、[https://forums.developer.nvidia.com/t/linux-solaris-and-freebsd-driver-460-27-04-beta/163730 レンダーオフロードとディスプレイオフロードを組み合わせた特殊なケースにおける最適化が実装されています]:
NVIDIA drivers 460.27.04+ [https://forums.developer.nvidia.com/t/linux-solaris-and-freebsd-driver-460-27-04-beta/163730 implement an optimization for a special case of combined render and display offloads]: ''Added support for “Reverse PRIME Bypass”, an optimization that bypasses the bandwidth overhead of PRIME Render Offload and PRIME Display Offload in conditions where a render offload application is fullscreen, unredirected, and visible only on a given NVIDIA-driven PRIME Display Offload output. Use of the optimization is reported in the X log when verbose logging is enabled in the X server.''
 
   
  +
: “Reverse PRIME Bypass” のサポートを追加しました。これは、レンダーオフロードされたアプリケーションがフルスクリーンで、リダイレクトされておらず、NVIDIA 駆動の PRIME ディスプレイオフロードされた出力でしか表示されない条件で発生する、PRIME レンダーオフロードと PRIME ディスプレイオフロードの帯域幅のオーバーヘッドを回避する最適化です。この最適化が使用されていることは、X サーバの verbose ログが有効化されている場合に X のログで報告されます。
=== Separate Xorg instance for eGPU ===
 
   
  +
=== eGPU に対しては別の Xorg インスタンスを使う ===
Main article is [[Nvidia-xrun#eGPU setup]].
 
   
  +
主な記事は [[Nvidia-xrun#External GPU setup]]{{Broken section link}} です。
=== Known issues with eGPUs on Xorg ===
 
   
  +
=== Xorg 上での eGPU の既知の問題 ===
* hotplug is not supported with most discrete GPU Xorg drivers: the eGPU needs to be plugged in when Xorg starts. Logging out and in again should suffice to restart Xorg.
 
  +
* hot-unplug is not supported at all: doing so leads to system instability or outright freezes (as acknowledged in [http://us.download.nvidia.com/XFree86/Linux-x86_64/465.27/README/egpu.html Nvidia docs]).
 
  +
* ホットプラグは、ほとんどのディスクリート GPU Xorg ドライバでサポートされていません: eGPU は Xorg の開始時に挿入されている必要があります。Xorg を再起動するには、一旦ログアウトして、再びログインし直すだけで十分なはずです。
  +
* ホットアンプラグは全くサポートされていません: 動作中に外付け GPU を抜くとシステムが不安定になったり、完全にフリーズしたりします ([https://us.download.nvidia.com/XFree86/Linux-x86_64/465.27/README/egpu.html Nvidia のドキュメント]で確認されています)。
   
 
== Wayland ==
 
== Wayland ==
   
  +
eGPU (一般には複数 GPU) に対する Wayland のサポートはあまりテストされていませんが、少ない手動設定で動作するはずです。
Wayland support for eGPUs (or multiple GPUs in general) is much less tested now, but should work in theory and with less manual configuration. Note that there needs to be explicit support by particular Wayland compositor.
 
  +
  +
注意点として、Wayland コンポジタによる明示的な GPU ホットプラグのサポートが必要です。しかし、ほとんどのコンポジタには既にある程度のサポートがあります:
  +
  +
* KDE の kwin: https://invent.kde.org/plasma/kwin/-/merge_requests/811
  +
* GNOME の Mutter: https://gitlab.gnome.org/GNOME/mutter/-/issues/17 、https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1562
  +
* wl-roots: https://gitlab.freedesktop.org/wlroots/wlroots/-/issues/1278
  +
  +
オープンソースなドライバの場合は、DRI オフロードが動作するはずです:
  +
  +
$ DRI_PRIME=1 ''some_program''
  +
  +
一部のプロジェクト ([https://github.com/ewagner12/all-ways-egpu/wiki all-ways-egpu] など) では、Wayland で GPU を選択するためのより効率的な方法を提供する試みが進んでいます。
  +
  +
=== Nvidia eGPU をホットプラグ化する ===
  +
  +
Wayland を使用している場合は eGPU をホットプラグ化し、PRIME の機能を使用することができます。Nvidia には既に dGPU に対する良質な PRIME 実装があり、eGPU と同じように機能します。
  +
  +
まず、どのプログラムも Nvidia のモジュール群を使用していないことを確認する必要があります。EGL のプログラムは、たとえ iGPU で動作していても、1MB の dGPU メモリを使用する傾向にあります (このことは {{ic|nvidia-smi}} で確認できます)。dGPU メモリの使用を防ぐには、[[環境変数]] {{ic|1=__EGL_VENDOR_LIBRARY_FILENAMES=/usr/share/glvnd/egl_vendor.d/50_mesa.json}} を使用してください。環境変数の設定場所として最適なのは {{ic|/etc/environment.d/50_mesa.conf}} です。
  +
  +
次に、Nvidia モジュールをアンロードしてください:
  +
  +
# rmmod nvidia_uvm
  +
# rmmod nvidia_drm
  +
# rmmod nvidia_modeset
  +
# rmmod nvidia
  +
  +
Nvidia モジュールがロードされていない状態であれば、外付け GPU を接続することができます。GPU が初期化されたら、{{ic|modprobe nvidia-drm}} コマンドまたは {{ic|modprobe nvidia-current-drm}} コマンドで Nvidia のモジュール群を再びロードしてください。モジュール名はモジュールの入手元 (Nvidia のウェブサイトかパッケージマネージャか) によります。一部ケースで (例えば GIGABYTE AORUS GAMING BOX の場合)、eGPU がプロプライエタリなモジュールで動作しないことがあります。なので、その場合、オープンソースのドライバ ({{ic|modprobe nvidia-current-open-drm}}) を使用する必要があるかもしれません。
  +
  +
モジュールのロードに成功したら、PRIME 機能が利用できるようになっています。しかし、MESA を使うために {{ic|__EGL_VENDOR_LIBRARY_FILENAMES}} 変数を設定しているので、プログラムの開始前に {{ic|1=__EGL_VENDOR_LIBRARY_FILENAMES=/usr/share/glvnd/egl_vendor.d/10_nvidia.json}} を設定しておく必要があります。プログラムの起動手順は以下のようになります:
  +
  +
__GLX_VENDOR_LIBRARY_NAME=nvidia __NV_PRIME_RENDER_OFFLOAD=1 __VK_LAYER_NV_optimus=NVIDIA_only __EGL_VENDOR_LIBRARY_FILENAMES=/usr/share/glvnd/egl_vendor.d/10_nvidia.json %command%
  +
  +
Gnome を使用している場合は、{{ic|__EGL_VENDOR_LIBRARY_FILENAMES}} を環境変数リストに追加するために {{Pkg|switcheroo-control}} にパッチを当てる必要があるかもしれません。こうすることで、右クリックのコンテキストメニューで "Launch using Dedicated Graphics Card" を選択することでプログラムを eGPU 上で実行できるようになります。しかし、これは記事で扱う事柄の範囲外です。
  +
  +
=== Nvidia eGPU をホットプラグ化し、Nvidia dGPU を一時的に無効化する ===
  +
  +
<!-- 原文に問題があるため翻訳保留 -->
  +
  +
In case you have iGPU, Nvidia dGPU and want to connect Nvidia eGPU, you will encounter a conflict, where graphics renders only on dGPU, no matter what you do. To solve this, you need to temporarily disable dGPU, so Nvidia driver will not notice it. Best way to do that is to override its driver.
  +
  +
First, you need to unload Nvidia driver:
  +
  +
# rmmod nvidia_uvm
  +
# rmmod nvidia_drm
  +
# rmmod nvidia_modeset
  +
# rmmod nvidia
  +
  +
Then, you need to override dGPU driver with {{AUR|driverctl}} utility. In this example, 0000:01:00.0 is address of dGPU. It can be found with {{ic|lspci}} utility.
  +
  +
# driverctl --nosave set-override 0000:01:00.0 vfio-pci
  +
  +
It is important to use {{ic|--nosave}} parameter, to prevent driverctl to override driver on boot. It is useful in case something goes wrong, simple reboot cleans everything.
  +
  +
When dGPU is disabled, you can load kernel modules with {{ic|modprobe nvidia-drm}} and then check if {{ic|nvidia-smi}} shows 1 or 2 GPUs.
  +
  +
Bringing dGPU back is tricky, because it is unintuitive. First, unload Nvidia modules, unplug eGPU and then run this series of commands:
  +
  +
# modprobe nvidia-current
  +
# driverctl --nosave unset-override 0000:01:00.0
  +
# modprobe nvidia-current
  +
# driverctl --nosave unset-override 0000:01:00.0
  +
# modprobe nvidia-current-modeset
  +
# modprobe nvidia-current-drm
   
  +
It is strange that we need to run first 2 commands twice, but otherwise it will not bring back dGPU. Command will error once, but it is not critical.
There seems to be also preliminary support for GPU hotplug in some compositors:
 
   
  +
{{TranslationStatus|External GPU|2024-04-19|806415}}
* KDE's kwin: https://invent.kde.org/plasma/kwin/-/merge_requests/811
 
* GNOME's Mutter: https://gitlab.gnome.org/GNOME/mutter/-/issues/17, https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1562
 

2024年4月22日 (月) 22:40時点における最新版

関連記事

Thunderbolt 3 以上または USB4 を搭載したコンピュータは、GPU エンクロージャを使用して、デスクトップグレードの外付けグラフィックカード (eGPU) を接続できます。eGPU.io は購入者ガイドとコミュニティフォーラムのある優れたリソースです。ほとんどの動作モードでは、いくつかの手動設定 (以下に記載) が必要ですが、eGPU の Linux サポートは一般的に良好です。

ノート: USB4 のノート PC に関しては、データの転送速度が最低 20 Gbit/s、オプションでより高く (40、80、またはそれ以上) なるように規定されています。Thunderbolt エンクロージャを使用する場合、ノート PC の USB4 実装が Thunderbolt と同じ転送速度をサポートしているか確認しておくと良いでしょう。

インストール

Thunderbolt

eGPU エンクロージャの Thunderbolt デバイスは、挿入した後にまず (BIOS/UEFI のファームウェア設定に基づいて) 認証する必要があるかもしれません。Thunderbolt#ユーザーデバイス認証 の指示に従ってください。それができたら、外付け GPU が lspci に表示されるはずです:

$ lspci | grep -E 'VGA|3D'
00:02.0 VGA compatible controller: Intel Corporation UHD Graphics 620 (rev 07)             # 内部 GPU
1a:10.3 VGA compatible controller: NVIDIA Corporation GP107 [GeForce GTX 1050] (rev a1)    # 外付け GPU

あなたのコンピュータ、コンピュータのファームウェア、そしてエンクロージャのファームウェアによっては、PCIe のレーン数と OPI のモードにより、Thunderbolt によってホスト <-> eGPU 間の帯域幅がある程度制限されます:

# dmesg | grep PCIe
[19888.928225] pci 0000:1a:10.3: 8.000 Gb/s available PCIe bandwidth, limited by 2.5 GT/s PCIe x4 link at 0000:05:01.0 (capable of 126.016 Gb/s with 8.0 GT/s PCIe x16 link)

ドライバ

GPU モデルと互換性のあるドライバをインストールする必要があります:

  • AMDGPU
  • NVIDIA プロプライエタリな Nvidia ドライバ
  • Nouveau オープンソースな Nvidia ドライバ

インストールに成功しているならば、lspci -k の出力でドライバとカードが関連付けられているはずです:

$ lspci -k
1a:10.3 VGA compatible controller: NVIDIA Corporation GP107 [GeForce GTX 1050] (rev a1)
        Subsystem: NVIDIA Corporation GP107 [GeForce GTX 1050]
        Kernel driver in use: nvidia
        Kernel modules: nouveau, nvidia_drm, nvidia

AMDGPU ドライバは、(Thunderbolt か USB4 のどちらか一方を使用している場合に) pcie_gen_cap オプションに間違った値を設定してしまい、その結果 PCIe gen 1.1 の速度にフォールバックしてパフォーマンスに大きな問題が発生する場合があることに注意してください。 この場合、適切な値をモジュールオプション (カーネルモジュール#/etc/modprobe.d/ 内のファイルを使う を参照) として、またはカーネルパラメータから設定することができます:

/etc/modprobe.d/amd-egpu-pcie-speed.conf
options amdgpu pcie_gen_cap=0x40000

この例では、PCIe gen 3 の速度を設定します。利用可能なオプションの完全なリストは amd_pcie.h で確認できます。

コンピューティングのみのワークロード

インストール作業を完了したら、何も描画する必要のない GPGPU#CUDA のようなコンピューティングのみのワークロードは追加の設定無しで機能するはずです。nvidia-smi ユーティリティ (nvidia-utils パッケージにあり) はプロプライエタリな NVIDIA ドライバで動作するはずです。プロプライエタリな Nvidia NVENC/NVDEC も動作するはずです (OpenGL interop 無しで)。

このようなユースケースではホットプラグも完全にサポートされているはずです。また、ホットアンプラグも可能なはずです (おそらく、使用するドライバに依ります)。Nvidia では、nvidia-persistenced をアクティブ化していると、クリーンなホットアンプラグが妨害されると予想されます。

Xorg

内部 カード (iGPU) と外付けカード (eGPU) を組み合わせたセットアップには複数のバリエーションがあり、それぞれに長所と短所があります。

eGPU で Xorg を描画し、iGPU に PRIME ディスプレイオフロード

  • GPU を使用するプログラムのほとんどは設定せずとも eGPU 上で動作します: glxinfo/glxgearseglinfo/eglgears_x11NVENC/NVDEC (OpenGL interop を含む)。
  • Xorg は、eGPU が挿入された状態でのみ起動します。
  • eGPU に接続されているモニターは設定せずとも動作します。iGPU に接続されているモニター (つまり、ノート PC の画面) に対しては PRIME ディスプレイオフロードを使用できます。

主な記事は PRIME#ディスクリートカードをプライマリ GPU にするPRIME#Reverse PRIME です。また、NVIDIA ドライバのドキュメントの Chapter 33. Offloading Graphics Display with RandR 1.4 でも文書化されています。

以下のような Xorg の設定スニペットを使ってください:

/etc/X11/xorg.conf.d/80-egpu-primary-igpu-offload.conf
Section "Device"
    Identifier "Device0"
    Driver     "nvidia"
    BusID      "PCI:26:16:3"                 # lspci の出力に応じて書き換えてください。また、16進数から10進数に変換してください。
    Option     "AllowExternalGpus" "True"    # プロプライエタリな NVIDIA ドライバで必要です。
EndSection

Section "Module"
    # iGPU 用の modesetting モジュールをロードします。modesetting は XrandR 1.4 でプロバイダとして表示されるはずです。
    Load "modesetting"
EndSection
ノート: Xorg は10進数のバス ID を使用しますが、他のほとんどのツールは16進数を使用します。なので、xorg.conf スニペットでは 1a:10.326:16:3 に変換しなければならなかったのです。
ヒント: 最近の Xorg では、ServerLayout セクションと Screen セクションを指定する必要はもうありません。これらは自動的に推測されます。最初に定義された Device がプライマリとみなされます。

このセットアップを検証するには、xrandr --listproviders を使ってください。以下のように表示されるはずです:

Providers: number : 2
Provider 0: id: 0x1b8 cap: 0x1, Source Output crtcs: 4 outputs: 4 associated providers: 0 name:NVIDIA-0
Provider 1: id: 0x1f3 cap: 0xf, Source Output, Sink Output, Source Offload, Sink Offload crtcs: 3 outputs: 5 associated providers: 0 name:modesetting

RandR 1.4 PRIME ディスプレイオフロードを使用することにより、iGPU に接続されているノート PC の内蔵ディスプレイと、同じく iGPU に接続されている他のモニタの一方/両方に出力することができます。上記の xrandr --listproviders で出力されている名前を使用して、以下のようなコマンドを実行してください:

xrandr --setprovideroutputsource modesetting NVIDIA-0 && xrandr --auto
ノート: xrandr --auto は任意であり、他の RandR ベースのディスプレイ設定ツールに置き換えても良いです。このコマンドがあることにより、全ての画面が真っ暗になってしまう状況を回避できます。

ディスプレイマネージャがログインプロンプトを表示する前や、デスクトップ環境が開始する前にこのコマンドを実行したい場合があるでしょう。これに関しては Xrandr#設定Xinit を見てください。

Vulkan は Xorg とは独立して GPU を列挙する場合があります。なので、この環境で vkcube などを実行するには、--gpu_number 1 オプションを渡す必要があるかもしれません。または、__NV_PRIME_RENDER_OFFLOAD=1 vkcube かそれと等価な prime-run vkcube を使って、列挙中に GPU を並べ替えるレイヤーをアクティブ化しても、同じ効果があります。

ヒント: ノート PC 上で optimus-manager を使っている場合、モードとグラフィックスカードに対応する /etc/optimus-manager/xorg/ 内の適切なファイルに eGPU の BusId を追加することで、eGPU でレンダリングすることができます。

iGPU で Xorg を描画し、eGPU に PRIME レンダーオフロード

  • プログラムはデフォルトで iGPU 上で描画されますが、PRIME レンダーオフロードを使って eGPU 上で描画することもできます。
  • Xorg は eGPU が接続されていなくても開始しますが、再起動しない限りレンダー/ディスプレイオフロードは機能しません。
  • iGPU に接続されているモニタ (つまり、ノート PC の内蔵ディスプレイ) は設定せずとも動作します。eGPU に接続されているモニタに対しては PRIME ディスプレイオフロードを使用できます。

主な記事は PRIME#PRIME GPU オフロード です。また、NVIDIA ドライバのドキュメントの Chapter 34. PRIME Render Offload でも文書化されています。

多くのディスクリート GPU ドライバで、Xorg が手動で設定されていない場合はこのモードがデフォルトになっているはずです。動作しない場合や、プロプライエタリな NVIDIA ドライバを使用している場合は、以下の設定を使用してください:

/etc/X11/xorg.conf.d/80-igpu-primary-egpu-offload.conf
Section "Device"
    Identifier "Device0"
    Driver     "modesetting"
EndSection

Section "Device"
    Identifier "Device1"
    Driver     "nvidia"
    BusID      "PCI:26:16:3"                 # lspci の出力に応じて書き換えてください。また、16進数から10進数に変換してください。
    Option     "AllowExternalGpus" "True"    # プロプライエタリな NVIDIA ドライバで必要です。
EndSection

このセットアップを検証するには、xrandr --listproviders を使ってください。以下のように表示されるはずです:

$ xrandr --listproviders
Providers: number : 2
Provider 0: id: 0x47 cap: 0xf, Source Output, Sink Output, Source Offload, Sink Offload crtcs: 3 outputs: 5 associated providers: 0 name:modesetting
Provider 1: id: 0x24a cap: 0x2, Sink Output crtcs: 4 outputs: 4 associated providers: 0 name:NVIDIA-G0

PRIME レンダーオフロードを使えば、some_programeGPU 上レンダリングすることができます:

  • プロプライエタリな NVIDIA ドライバの場合:
    $ __NV_PRIME_RENDER_OFFLOAD=1 __VK_LAYER_NV_optimus=NVIDIA_only __GLX_VENDOR_LIBRARY_NAME=nvidia some_program
  • プロプライエタリな NVIDIA ドライバの場合 (便利なラッパー):
    $ prime-run some_program
  • オープンソースなドライバの場合:
    $ DRI_PRIME=1 some_program

RandR 1.4 PRIME ディスプレイオフロードを使えば、eGPU に接続されたモニタに出力することができます:

$ xrandr --setprovideroutputsource NVIDIA-G0 modesetting && xrandr --auto
ヒント: この場合、プロバイダの順番が異なり、Nvidia の名前も若干異なります。

NVIDIA drivers 460.27.04+ では、レンダーオフロードとディスプレイオフロードを組み合わせた特殊なケースにおける最適化が実装されています:

“Reverse PRIME Bypass” のサポートを追加しました。これは、レンダーオフロードされたアプリケーションがフルスクリーンで、リダイレクトされておらず、NVIDIA 駆動の PRIME ディスプレイオフロードされた出力でしか表示されない条件で発生する、PRIME レンダーオフロードと PRIME ディスプレイオフロードの帯域幅のオーバーヘッドを回避する最適化です。この最適化が使用されていることは、X サーバの verbose ログが有効化されている場合に X のログで報告されます。

eGPU に対しては別の Xorg インスタンスを使う

主な記事は Nvidia-xrun#External GPU setup[リンク切れ: セクションが存在しません] です。

Xorg 上での eGPU の既知の問題

  • ホットプラグは、ほとんどのディスクリート GPU Xorg ドライバでサポートされていません: eGPU は Xorg の開始時に挿入されている必要があります。Xorg を再起動するには、一旦ログアウトして、再びログインし直すだけで十分なはずです。
  • ホットアンプラグは全くサポートされていません: 動作中に外付け GPU を抜くとシステムが不安定になったり、完全にフリーズしたりします (Nvidia のドキュメントで確認されています)。

Wayland

eGPU (一般には複数 GPU) に対する Wayland のサポートはあまりテストされていませんが、少ない手動設定で動作するはずです。

注意点として、Wayland コンポジタによる明示的な GPU ホットプラグのサポートが必要です。しかし、ほとんどのコンポジタには既にある程度のサポートがあります:

オープンソースなドライバの場合は、DRI オフロードが動作するはずです:

$ DRI_PRIME=1 some_program

一部のプロジェクト (all-ways-egpu など) では、Wayland で GPU を選択するためのより効率的な方法を提供する試みが進んでいます。

Nvidia eGPU をホットプラグ化する

Wayland を使用している場合は eGPU をホットプラグ化し、PRIME の機能を使用することができます。Nvidia には既に dGPU に対する良質な PRIME 実装があり、eGPU と同じように機能します。

まず、どのプログラムも Nvidia のモジュール群を使用していないことを確認する必要があります。EGL のプログラムは、たとえ iGPU で動作していても、1MB の dGPU メモリを使用する傾向にあります (このことは nvidia-smi で確認できます)。dGPU メモリの使用を防ぐには、環境変数 __EGL_VENDOR_LIBRARY_FILENAMES=/usr/share/glvnd/egl_vendor.d/50_mesa.json を使用してください。環境変数の設定場所として最適なのは /etc/environment.d/50_mesa.conf です。

次に、Nvidia モジュールをアンロードしてください:

# rmmod nvidia_uvm
# rmmod nvidia_drm
# rmmod nvidia_modeset
# rmmod nvidia

Nvidia モジュールがロードされていない状態であれば、外付け GPU を接続することができます。GPU が初期化されたら、modprobe nvidia-drm コマンドまたは modprobe nvidia-current-drm コマンドで Nvidia のモジュール群を再びロードしてください。モジュール名はモジュールの入手元 (Nvidia のウェブサイトかパッケージマネージャか) によります。一部ケースで (例えば GIGABYTE AORUS GAMING BOX の場合)、eGPU がプロプライエタリなモジュールで動作しないことがあります。なので、その場合、オープンソースのドライバ (modprobe nvidia-current-open-drm) を使用する必要があるかもしれません。

モジュールのロードに成功したら、PRIME 機能が利用できるようになっています。しかし、MESA を使うために __EGL_VENDOR_LIBRARY_FILENAMES 変数を設定しているので、プログラムの開始前に __EGL_VENDOR_LIBRARY_FILENAMES=/usr/share/glvnd/egl_vendor.d/10_nvidia.json を設定しておく必要があります。プログラムの起動手順は以下のようになります:

__GLX_VENDOR_LIBRARY_NAME=nvidia __NV_PRIME_RENDER_OFFLOAD=1 __VK_LAYER_NV_optimus=NVIDIA_only __EGL_VENDOR_LIBRARY_FILENAMES=/usr/share/glvnd/egl_vendor.d/10_nvidia.json %command%

Gnome を使用している場合は、__EGL_VENDOR_LIBRARY_FILENAMES を環境変数リストに追加するために switcheroo-control にパッチを当てる必要があるかもしれません。こうすることで、右クリックのコンテキストメニューで "Launch using Dedicated Graphics Card" を選択することでプログラムを eGPU 上で実行できるようになります。しかし、これは記事で扱う事柄の範囲外です。

Nvidia eGPU をホットプラグ化し、Nvidia dGPU を一時的に無効化する

In case you have iGPU, Nvidia dGPU and want to connect Nvidia eGPU, you will encounter a conflict, where graphics renders only on dGPU, no matter what you do. To solve this, you need to temporarily disable dGPU, so Nvidia driver will not notice it. Best way to do that is to override its driver.

First, you need to unload Nvidia driver:

# rmmod nvidia_uvm
# rmmod nvidia_drm
# rmmod nvidia_modeset
# rmmod nvidia

Then, you need to override dGPU driver with driverctlAUR utility. In this example, 0000:01:00.0 is address of dGPU. It can be found with lspci utility.

# driverctl --nosave set-override 0000:01:00.0 vfio-pci

It is important to use --nosave parameter, to prevent driverctl to override driver on boot. It is useful in case something goes wrong, simple reboot cleans everything.

When dGPU is disabled, you can load kernel modules with modprobe nvidia-drm and then check if nvidia-smi shows 1 or 2 GPUs.

Bringing dGPU back is tricky, because it is unintuitive. First, unload Nvidia modules, unplug eGPU and then run this series of commands:

# modprobe nvidia-current
# driverctl --nosave unset-override 0000:01:00.0
# modprobe nvidia-current
# driverctl --nosave unset-override 0000:01:00.0
# modprobe nvidia-current-modeset
# modprobe nvidia-current-drm

It is strange that we need to run first 2 commands twice, but otherwise it will not bring back dGPU. Command will error once, but it is not critical.

翻訳ステータス: このページは en:External GPU の翻訳バージョンです。最後の翻訳日は 2024-04-19 です。もし英語版に 変更 があれば、翻訳の同期を手伝うことができます。