Ubuntu14.04に、Cuda8.0をインストールでハマる

GTX1070が付いているマシンにUbuntuを入れて、Cuda8.0をインストールしようとしたんだけど、ハマった。色々やっているうちに、Nvidiaのドライバがうまくインストールできなくて、

$ pgaccelinfo

としても、CUDA Driver VersionとNVRM versionの2行くらいしか表示されなかったり、

# modprobe nvidia

として普通にmoduleを読み込めても、それでもpgaccelinfoでは2行しか表示されなかったり。もう訳が分からなくなったので、Cudaのアンインストールと、nvidiaのアンインストールをして、まっさらな状態から入れなおしたら動きました。具体的には、

1.nvidiaのアンインストール

# nvidia-uninstall
# apt-get remove nvidia*

2.Cudaのアンインストール

# /usr/local/cuda/bin/uninstall_cuda_8.0.pl

としてきれいにしてから、とりあえず再起動。

# reboot

3.Nvidiaドライバのインストール

# ./NVIDIA-Linux-x86_64-384.59.run --disable-nouveau

途中で英語で色々聞かれますが、基本そのままでした。

4.Cuda8.0のインストール

./cuda_8.0.61_375.26_linux.run

ここでインストールの際に、NVIDIAのドライバはスキップします。すると最終的に、

Installing the CUDA Toolkit in /usr/local/cuda-8.0 ...

===========
= Summary =
===========

Driver:   Not Selected
Toolkit:  Installed in /usr/local/cuda-8.0
Samples:  Not Selected

Please make sure that
 -   PATH includes /usr/local/cuda-8.0/bin
 -   LD_LIBRARY_PATH includes /usr/local/cuda-8.0/lib64, or, add /usr/local/cuda-8.0/lib64 to /etc/ld.so.conf and run ldconfig as root

To uninstall the CUDA Toolkit, run the uninstall script in /usr/local/cuda-8.0/bin

Please see CUDA_Installation_Guide_Linux.pdf in /usr/local/cuda-8.0/doc/pdf for detailed information on setting up CUDA.

WARNING: Incomplete installation! This installation did not install the CUDA Driver. A driver of version at least 361.00 is required for CUDA 8.0 functionality to work.
To install the driver using this installer, run the following command, replacing with the name of this run file: sudo .run -silent -driver Logfile is /tmp/cuda_install_5632.log
とWARNINGが出ますが、先に新しいNVIDIAドライバを入れてあるので、
# pgaccelinfo

CUDA Driver Version:           9000
NVRM version:                  NVIDIA UNIX x86_64 Kernel Module  384.59  Wed Jul 19 23:53:34 PDT 2017

Device Number:                 0
Device Name:                   GeForce GTX 1070
Device Revision Number:        6.1
Global Memory Size:            8506769408
Number of Multiprocessors:     15
Concurrent Copy and Execution: Yes
Total Constant Memory:         65536
Total Shared Memory per Block: 49152
Registers per Block:           65536
Warp Size:                     32
Maximum Threads per Block:     1024
Maximum Block Dimensions:      1024, 1024, 64
Maximum Grid Dimensions:       2147483647 x 65535 x 65535
Maximum Memory Pitch:          2147483647B
Texture Alignment:             512B
Clock Rate:                    1746 MHz
Execution Timeout:             No
Integrated Device:             No
Can Map Host Memory:           Yes
Compute Mode:                  default
Concurrent Kernels:            Yes
ECC Enabled:                   No
Memory Clock Rate:             4004 MHz
Memory Bus Width:              256 bits
L2 Cache Size:                 2097152 bytes
Max Threads Per SMP:           2048
Async Engines:                 2
Unified Addressing:            Yes
Managed Memory:                Yes
PGI Compiler Option:           -ta=tesla:cc60
となり、ちゃんと動くことがわかります。再起動しても、そのままでした。めでたしめでたし。