Windows側にCUDA Toolkit 11.6をインストール済み
$ nvcc --version nvcc: NVIDIA (R) Cuda compiler driver Copyright (c) 2005-2021 NVIDIA Corporation Built on Fri_Dec_17_18:28:54_Pacific_Standard_Time_2021 Cuda compilation tools, release 11.6, V11.6.55 Build cuda_11.6.r11.6/compiler.30794723_0
ストアで Windows Terminal をインストールする
再起動後、自動でUbuntuのインストールが開始された。
$ uname -r 5.10.16.3-microsoft-standard-WSL2 $ cat /etc/lsb-release DISTRIB_ID=Ubuntu DISTRIB_RELEASE=20.04 DISTRIB_CODENAME=focal DISTRIB_DESCRIPTION="Ubuntu 20.04.5 LTS"
$ sudo apt update $ sudo apt upgrade
python3.8がインストールされていた。pythonにシンボリックリンクを貼った。あとpipとvenvを使えるようにした。
$ python --version python: command not found $ python3 --version Python 3.8.10 $ sudo ln /usr/bin/python3 /usr/bin/python $ sudo apt install python3-pip $ sudo apt install python3.8-venv
cuda toolkit と cuda のインストール
# この辺を参考にした。 # https://learn.microsoft.com/ja-jp/windows/wsl/tutorials/gpu-compute # https://qiita.com/ksasaki/items/ee864abd74f95fea1efa#cuda-toolkit-%E3%81%AE%E3%82%A4%E3%83%B3%E3%82%B9%E3%83%88%E3%83%BC%E3%83%AB $ wget https://developer.download.nvidia.com/compute/cuda/repos/wsl-ubuntu/x86_64/cuda-wsl-ubuntu.pin $ sudo mv cuda-wsl-ubuntu.pin /etc/apt/preferences.d/cuda-repository-pin-600 $ curl -s -L https://developer.download.nvidia.com/compute/cuda/repos/wsl-ubuntu/x86_64/cuda-wsl-ubuntu-keyring.gpg | sudo apt-key add - $ sudo add-apt-repository "deb https://developer.download.nvidia.com/compute/cuda/repos/wsl-ubuntu/x86_64/ /" $ sudo apt update # apt search cuda でインストールするバージョンを確認しておく $ sudo apt install cuda-toolkit-11-6 # sudo apt install cuda=11.6.2-1
$ git clone https://github.com/NVIDIA/cuda-samples.git $ cd cuda-samples/Samples/1_Utilities/deviceQueryDrv/ $ make && make run ./deviceQueryDrv Starting... CUDA Device Query (Driver API) statically linked version Detected 1 CUDA Capable device(s) Device 0: "NVIDIA GeForce GTX 1650" CUDA Driver Version: 11.6 CUDA Capability Major/Minor version number: 7.5 Total amount of global memory: 4096 MBytes (4294508544 bytes) (14) Multiprocessors, ( 64) CUDA Cores/MP: 896 CUDA Cores GPU Max Clock rate: 1725 MHz (1.73 GHz) Memory Clock rate: 6001 Mhz Memory Bus Width: 128-bit L2 Cache Size: 1048576 bytes Max Texture Dimension Sizes 1D=(131072) 2D=(131072, 65536) 3D=(16384, 16384, 16384) Maximum Layered 1D Texture Size, (num) layers 1D=(32768), 2048 layers Maximum Layered 2D Texture Size, (num) layers 2D=(32768, 32768), 2048 layers Total amount of constant memory: 65536 bytes Total amount of shared memory per block: 49152 bytes Total number of registers available per block: 65536 Warp size: 32 Maximum number of threads per multiprocessor: 1024 Maximum number of threads per block: 1024 Max dimension size of a thread block (x,y,z): (1024, 1024, 64) Max dimension size of a grid size (x,y,z): (2147483647, 65535, 65535) Texture alignment: 512 bytes Maximum memory pitch: 2147483647 bytes Concurrent copy and kernel execution: Yes with 6 copy engine(s) Run time limit on kernels: Yes Integrated GPU sharing Host Memory: No Support host page-locked memory mapping: Yes Concurrent kernel execution: Yes Alignment requirement for Surfaces: Yes Device has ECC support: Disabled Device supports Unified Addressing (UVA): Yes Device supports Managed Memory: Yes Device supports Compute Preemption: Yes Supports Cooperative Kernel Launch: Yes Supports MultiDevice Co-op Kernel Launch: No Device PCI Domain ID / Bus ID / location ID: 0 / 1 / 0 Compute Mode: < Default (multiple host threads can use ::cudaSetDevice() with device simultaneously) > Result = PASS
# Ubuntu用のを使うことにする。 $ curl -s -L https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/cuda-ubuntu2004-keyring.gpg | sudo apt-key add - $ sudo add-apt-repository "deb https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/ /" $ sudo apt update # apt search cudnn でインストールするバージョンを確認しておく $ sudo apt install libcudnn8 # sudo apt install libcudnn8-dev
$ sudo apt install libnvinfer8 $ sudo apt install libnvinfer-plugin8 $ sudo ln /usr/lib/x86_64-linux-gnu/libnvinfer.so.8.4.3 /usr/lib/x86_64-linux-gnu/libnvinfer.so.7 $ sudo ln /usr/lib/x86_64-linux-gnu/libnvinfer_plugin.so.8.4.3 /usr/lib/x86_64-linux-gnu/libnvinfer_plugin.so.7 # こんなことしていいのかは分からない。 # ダメなら https://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1804/x86_64/ にあるのを使う。
tensorflow で GPU が使えているか確認
$ mkdir test && cd test $ python -m venv test $ source test/bin/activate (test) $ pip install tensorflow (test) $ python -c 'from tensorflow.python.client import device_lib; device_lib.list_local_devices()' ...snip... 2022-09-23 00:01:43.008146: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1616] Created device /device:GPU:0 with 2101 MB memory: -> device: 0, name: NVIDIA GeForce GTX 1650, pci bus id: 0000:01:00.0, compute capability: 7.5 (test) $ deactivate
echo 'alias clip=clip.exe' >>.bashrc