2018年2月9日 星期五

Ubuntu 16.04上安裝CUDA 9.1 Toolkit

Ubuntu 16.04會自動更新,之前安裝的Nvidia驅動與CUDA工具包不能使用:
Ubuntu 16.04更新完的驅動是384,在安裝CUDA Toolkit 9.1的時候,安裝程式會自動把Nvidia驅動更新成387版本。安裝過程如下

CUDA Toolkit 9.1 Download下載deb (local)檔案,再依序執行:
  1. sudo dpkg -i cuda-repo-ubuntu1604-9-1-local_9.1.85-1_amd64.deb
  2. sudo apt-key add /var/cuda-repo-9-1-local/7fa2af80.pub
  3. sudo apt-get update
  4. export LD_PRELOAD=/usr/lib/nvidia-387/libnvidia-ml.so
  5. apt-get install cuda
上述指令的意思:
  1. 把工具包的東西解開到系統硬碟上
    這步驟好像會加入Nvidia驅動387版本的library到/usr/lib/nvidia-387上面
  2. 加入工具包的PGP public key,這樣apt-get就可以用了
  3. 更新APT(Advanced Package Tool)
  4. 由於我的系統一直抱怨找不到正確的版本libnvidia-ml.so,錯誤訊息如下
    ERROR: ld.so: object '/usr/lib/nvidia-384/libnvidia-ml.so' from LD_PRELOAD cannot be preloaded (cannot open shared object file): ignored.
    需要這行指令,下面的安裝指令才能順利執行
  5. 安裝CUDA 9.1 Toolkit
第5步會更新nvidia_387, nvidia_387_modeset.ko, nvidia_387_drm.ko, nvidia_387_uvm.ko這些modules到/lib/modules/4.10.0-42-generic/updates/dkms/,最後還會更新initrd。安裝順利的訊息如下:

  DKMS: install completed.
  Module build for the currently running kernel was skipped since the
  kernel source for this kernel does not seem to be installed.
  Setting up nvidia-387-dev (387.26-0ubuntu1) ...
  Setting up libcuda1-387 (387.26-0ubuntu1) ...
  Setting up nvidia-opencl-icd-387 (387.26-0ubuntu1) ...
  Setting up cuda-drivers (387.26-1) ...
  Setting up cuda-runtime-9-1 (9.1.85-1) ...
  Setting up cuda-demo-suite-9-1 (9.1.85-1) ...
  Setting up cuda-9-1 (9.1.85-1) ...
  Setting up cuda (9.1.85-1) ...
  Processing triggers for initramfs-tools (0.122ubuntu8.10) ...
  update-initramfs: Generating /boot/initrd.img-4.13.0-32-generic

最後一步則是更新 /etc/profile.d/cuda.sh,讓使用者開機就有CUDA環境,cuda.sh內容如下:
  export PATH=/usr/local/cuda-9.1/bin${PATH:+:${PATH}}
  export LD_LIBRARY_PATH=/usr/local/cuda-9.1/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
  export LD_PRELOAD=/usr/lib/nvidia-387/libnvidia-ml.so

如果都沒有問題,那麼就重新開機~再用下面指令檢查成果:
_EOF_

沒有留言:

張貼留言