OS: Ubuntu 16.04.4 LTS, 64-bit
CPU: i9-7900X CPU @ 3.30GHz × 20
GPU: GeForce GTX 1060 6GB/PCIe/SSE2
Untuk instalasi CUDA 9.2, baca bagian bawah tulisan ini.
Langkah-langkah instalasi
Jalankan langkah-langkah berikut pada terminal, saya sarankan anda berada di "/tmp".$ wget http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/cuda-repo-ubuntu1604_8.0.61-1_amd64.deb $ wget http://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1604/x86_64/libcudnn6_6.0.21-1%2Bcuda8.0_amd64.deb $ wget http://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1604/x86_64/libcudnn6-dev_6.0.21-1%2Bcuda8.0_amd64.deb $ sudo dpkg -i cuda-repo-ubuntu1604_8.0.61-1_amd64.deb $ sudo dpkg -i libcudnn6_6.0.21-1+cuda8.0_amd64.deb $ sudo dpkg -i libcudnn6-dev_6.0.21-1+cuda8.0_amd64.deb
Kemudian tambahkan path instalasi di ~/.bashrc seperti berikut:
$ vim .bashrcAnda bisa menggunakan Gedit jika tidak ingin menggunakan vim.
# cuda path export PATH="/usr/local/cuda-8.0/bin:$PATH" export LD_LIBRARY_PATH="/usr/local/cuda-8.0/lib64/$LD_LIBRARY_PATH"
Untuk mengeceknya, gunakan perintah `nvcc-version` dan `watch nvidia-smi`:
Output nvcc:
$ nvcc --version nvcc: NVIDIA (R) Cuda compiler driver Copyright (c) 2005-2016 NVIDIA Corporation Built on Tue_Aug_11_14:27:32_CDT_2017 Cuda compilation tools, release 8.0, V8.0.61Ouput watch nvidia-smi:
$ watch nvidia-smi Mon May 21 23:13:17 2018 +-----------------------------------------------------------------------------+ | NVIDIA-SMI 384.111 Driver Version: 384.111 | |-------------------------------+----------------------+----------------------+ | GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC | | Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. | |===============================+======================+======================| | 0 GeForce GTX 106... Off | 00000000:65:00.0 On | N/A | | 24% 41C P8 6W / 120W | 328MiB / 6069MiB | 0% Default | +-------------------------------+----------------------+----------------------+ +-----------------------------------------------------------------------------+ | Processes: GPU Memory | | GPU PID Type Process name Usage | |=============================================================================| | 0 1291 G /usr/lib/xorg/Xorg 169MiB | | 0 1792 G compiz 155MiB | | 0 2171 G /opt/teamviewer/tv_bin/TeamViewer 1MiB | +-----------------------------------------------------------------------------+
Alhamdulillah, jika anda melihat seri dari GPU yang terpasang (misal seperti diatas GTX 1060) beserta penggunaan powernya, berarti driver CUDA telah terinstall dengan proper.
Note:
CUDA 8 bukan merupakan CUDA terbaru, per tulisan ini ditulis, yang versi terbaru adalah CUDA 9.2. Versi 8 saya butuhkan agar "it works" saja di komputer saya. Begitu juga dengan CuDNN 6.
Update 9 Juli 2018: Downgrade ke CUDA 7.5
Karena masalah "low graphic mode", NVIDIA saya upgrade ke versi 396.24.02 via software & updates >> Additional driver (update secara grafis, bukan melalui terminal). Sampai saat ini masih berjalan dengan baik.
Setelah itu, saya menginstall nvcc melalui repository (downgrade CUDA ke versi 7.5),
sudo apt install nvidia-cuda-toolkitUntuk mengeceknya gunakan,
$ nvcc --version nvcc: NVIDIA (R) Cuda compiler driver Copyright (c) 2005-2015 NVIDIA Corporation Built on Tue_Aug_11_14:27:32_CDT_2015 Cuda compilation tools, release 7.5, V7.5.17
Update 1 Agustus 2018: Upgrade ke CUDA 9.2
Langkah-langkah:
- Uninstall nvcc, `sudo apt autoremove nvidia-cuda-toolkit`
- Download deb installer (network), `wget http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/cuda-repo-ubuntu1604_9.2.148-1_amd64.deb`
- `sudo dpkg -i cuda-repo-ubuntu1604_9.2.148-1_amd64.deb`
- `sudo apt-key adv --fetch-keys http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/7fa2af80.pub`
- `sudo apt-get update`
- `sudo apt-get install cuda`
- Tambahkan path berikut di ~/.profile, ` PATH="/usr/local/cuda-9.2/bin:$HOME/bin:$HOME/.local/bin:$PATH" `
Update Oktober 2018: Downgrade ke CUDA 9.0
Karena Ubuntu yang saya install saya upgrade ke versi 18.04 dan Tensorflow-gpu versi 1.12.0 belum support CUDA 9.2, maka saya downgrade ke CUDA 9.0 per instruksi disini.
Cek apakah Python TensorFlow sudah menggunakan GPU:
- Install tensorflow-gpu: pip3 install --user tensorflow gpu
- Cek sbb:
- Jika tf.test menghasilkan output seperti di atas (terlihat GTX1060), maka TF sudah menggunakan GPU.
$ ipython --pylab In [1]: import tensorflow as tf In [2]: tf.test.gpu_device_name() 2018-11-10 11:57:33.627670: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 AVX512F FMA 2018-11-10 11:57:33.870820: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1432] Found device 0 with properties: name: GeForce GTX 1060 6GB major: 6 minor: 1 memoryClockRate(GHz): 1.7085 pciBusID: 0000:65:00.0 totalMemory: 5.93GiB free
Update Juni 2019: Upgrade ke CUDA10.0 [2]
Langkah-langkah (Ubuntu 18.04):
sudo apt-get purge nvidia* sudo apt-get autoremove sudo apt-get autoclean sudo rm -rf /usr/local/cuda* sudo apt-key adv --fetch-keys http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/7fa2af80.pub echo "deb https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64 /" | sudo tee /etc/apt/sources.list.d/cuda.list sudo apt-get update sudo apt-get -o Dpkg::Options::="--force-overwrite" install cuda-10-0 cuda-drivers source ~/.bashrc sudo ldconfig
Re-install libcudnn7:
- Download ini, http://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1804/x86_64/libcudnn7_7.3.0.29-1+cuda10.0_amd64.deb
- Ini juga, http://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1804/x86_64/nvidia-machine-learning-repo-ubuntu1804_1.0.0-1_amd64.deb
sudo dpkg -i *.deb
sudo apt update && sudo apt -y upgrade
Referensi:
- https://yangcha.github.io/Install-CUDA8/
- https://www.pytorials.com/how-to-install-tensorflow-gpu-with-cuda-10-0-for-python-on-ubuntu/