Docker Desktop 中的 GPU 支援
目錄
注意
目前 Docker Desktop 中的 GPU 支援僅適用於使用 WSL2 後端的 Windows。
將 NVIDIA GPU 與 WSL2 搭配使用
適用於 Windows 的 Docker Desktop 支援 NVIDIA GPU 上的 WSL 2 GPU 半虛擬化 (GPU-PV)。要啟用 WSL 2 GPU 半虛擬化,您需要
- 搭載 NVIDIA GPU 的機器
- 最新的 Windows 10 或 Windows 11 安裝
- 來自 NVIDIA 的最新驅動程式
要驗證一切是否按預期運作,請使用 --gpus=all
旗標執行 docker run
命令。例如,以下將在您的 GPU 上執行簡短的基準測試
$ docker run --rm -it --gpus=all nvcr.io/nvidia/k8s/cuda-sample:nbody nbody -gpu -benchmark
輸出將類似於
Run "nbody -benchmark [-numbodies=<numBodies>]" to measure performance.
-fullscreen (run n-body simulation in fullscreen mode)
-fp64 (use double precision floating point values for simulation)
-hostmem (stores simulation data in host memory)
-benchmark (run benchmark to measure performance)
-numbodies=<N> (number of bodies (>= 1) to run in simulation)
-device=<d> (where d=0,1,2.... for the CUDA device to use)
-numdevices=<i> (where i=(number of CUDA devices > 0) to use for simulation)
-compare (compares simulation results running once on the default GPU and once on the CPU)
-cpu (run n-body simulation on the CPU)
-tipsy=<file.bin> (load a tipsy model file for simulation)
> NOTE: The CUDA Samples are not meant for performance measurements. Results may vary when GPU Boost is enabled.
> Windowed mode
> Simulation data stored in video memory
> Single precision floating point simulation
> 1 Devices used for simulation
MapSMtoCores for SM 7.5 is undefined. Default to use 64 Cores/SM
GPU Device 0: "GeForce RTX 2060 with Max-Q Design" with compute capability 7.5
> Compute 7.5 CUDA device: [GeForce RTX 2060 with Max-Q Design]
30720 bodies, total time for 10 iterations: 69.280 ms
= 136.219 billion interactions per second
= 2724.379 single-precision GFLOP/s at 20 flops per interaction
或者,如果您想嘗試更有用的東西,您可以使用官方的 Ollama 映像檔 來執行 Llama2 大型語言模型。
$ docker run --gpus=all -d -v ollama:/root/.ollama -p 11434:11434 --name ollama ollama/ollama
$ docker exec -it ollama ollama run llama2