GPU搭載ノートPCで、Ubuntu 16.04 LTS, CUDA-8.0RC インストール備忘録

# 前提の環境

- PC : MSI WT72S 6QN 
- CPU: Intel Core-i7 6920HQ
- GPU: NVIDIA QUADRO M5500

# 手順

## Ubuntu インストール

- ノートPCについている標準のSSD（M.2ソケット）やは2.5インチHDDは取り外し、SSDのみを入れる
- BIOSでSATAコントローラをRAIDモードからAHCIモードに変更
- BIOSでブート順序をUSBストレージのほうがSSDより高くなるように設定
- USBメモリから16.04 をインストール
- パスワードなしでログインするように設定

## 前準備

```bash
$ sudo apt-get install openssh-server
nvtest@WT72:~$ sudo add-apt-repository ppa:graphics-drivers/ppa
 Fresh drivers from upstream, currently shipping Nvidia.

## Current Status

We currently recommend: `nvidia-367`, Nvidia's current long lived branch.
For GeForce 8 and 9 series GPUs use `nvidia-340`
For GeForce 6 and 7 series GPUs use `nvidia-304`

nvidia-370 is the current BETA release!

## What we're working on right now:

- Normal driver updates
- Investigating how to bring this goodness to distro on a cadence.

## WARNINGS:

This PPA is currently in testing, you should be experienced with packaging before you dive in here. Give us a few days to sort out the kinks.

Volunteers welcome! See also: https://github.com/mamarley/nvidia-graphics-drivers/

### How you can help:

## Install PTS and benchmark your gear:

    sudo apt-get install phoronix-test-suite

Run the benchmark:

    phoronix-test-suite default-benchmark openarena xonotic tesseract gputest unigine-valley

and then say yes when it asks you to submit your results to openbechmarking.org. Then grab a cup of coffee, it takes a bit for the benchmarks to run. Depending on the version of Ubuntu you're using it might preferable for you to grabs PTS from upstream directly: http://www.phoronix-test-suite.com/?k=downloads

## Share your results with the community:

Post a link to your results (or any other feedback to): https://launchpad.net/~graphics-drivers-testers

Remember to rerun and resubmit the benchmarks after driver upgrades, this will allow us to gather a bunch of data on performance that we can share with everybody.

If you run into old documentation referring to other PPAs, you can help us by consolidating references to this PPA.

If someone wants to go ahead and start prototyping on `software-properties-gtk` on what the GUI should look like, please start hacking!

## Help us Help You!

We use the donation funds to get the developers hardware to test and upload these drivers, please consider donating to the "community" slider on the donation page if you're loving this PPA:

http://www.ubuntu.com/download/desktop/contribute
 More info: https://launchpad.net/~graphics-drivers/+archive/ubuntu/ppa
Press [ENTER] to continue or ctrl-c to cancel adding it

gpg: keyring `/tmp/tmpntgccytq/secring.gpg' created
gpg: keyring `/tmp/tmpntgccytq/pubring.gpg' created
gpg: requesting key 1118213C from hkp server keyserver.ubuntu.com
gpg: /tmp/tmpntgccytq/trustdb.gpg: trustdb created
gpg: key 1118213C: public key "Launchpad PPA for Graphics Drivers Team" imported
gpg: Total number processed: 1
gpg:               imported: 1  (RSA: 1)
OK
nvtest@WT72:~$ sudo apt-get update
Hit:1 http://security.ubuntu.com/ubuntu xenial-security InRelease                                        
Get:2 http://ppa.launchpad.net/graphics-drivers/ppa/ubuntu xenial InRelease [18.1 kB]                    
Hit:3 http://jp.archive.ubuntu.com/ubuntu xenial InRelease                           
Hit:4 http://jp.archive.ubuntu.com/ubuntu xenial-updates InRelease                  
Hit:5 http://jp.archive.ubuntu.com/ubuntu xenial-backports InRelease                 
Get:6 http://ppa.launchpad.net/graphics-drivers/ppa/ubuntu xenial/main amd64 Packages [13.2 kB]
Get:7 http://ppa.launchpad.net/graphics-drivers/ppa/ubuntu xenial/main i386 Packages [13.2 kB]
Get:8 http://ppa.launchpad.net/graphics-drivers/ppa/ubuntu xenial/main Translation-en [4,420 B]
Fetched 49.0 kB in 2s (21.2 kB/s)           
Reading package lists... Done
nvtest@WT72:~$ 

```

## CUDA インストール

[NVIDIA CUDA INSTALLATION GUIDE FOR LINUX](http://developer.download.nvidia.com/compute/cuda/8.0/secure/rc1/docs/sidebar/CUDA_Installation_Guide_Linux.pdf) を参照

### Chapter 2. PRE-INSTALLATION ACTIONS

```bash
nvtest@WT72:~$ lspci | grep -i nvidia
01:00.0 VGA compatible controller: NVIDIA Corporation Device 13fb (rev a1)
01:00.1 Audio device: NVIDIA Corporation GM204 High Definition Audio Controller (rev a1)
nvtest@WT72:~$ 
nvtest@WT72:~$ uname -m && cat /etc/*release
x86_64
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=16.04
DISTRIB_CODENAME=xenial
DISTRIB_DESCRIPTION="Ubuntu 16.04.1 LTS"
NAME="Ubuntu"
VERSION="16.04.1 LTS (Xenial Xerus)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 16.04.1 LTS"
VERSION_ID="16.04"
HOME_URL="http://www.ubuntu.com/"
SUPPORT_URL="http://help.ubuntu.com/"
BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/"
UBUNTU_CODENAME=xenial
nvtest@WT72:~$ 
nvtest@WT72:~$ gcc --version
gcc (Ubuntu 5.4.0-6ubuntu1~16.04.1) 5.4.0 20160609
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

nvtest@WT72:~$ uname -r
4.4.0-31-generic
nvtest@WT72:~$ 
nvtest@WT72:~$ sudo apt-get install linux-headers-$(uname -r)
Reading package lists... Done
Building dependency tree       
Reading state information... Done
linux-headers-4.4.0-31-generic is already the newest version (4.4.0-31.50).
linux-headers-4.4.0-31-generic set to manually installed.
0 upgraded, 0 newly installed, 0 to remove and 152 not upgraded.
nvtest@WT72:~$ 
nvtest@WT72:~$ md5sum ~/Downloads/*
8010947dddf9573782acc54e0b060445  /home/nvtest/Downloads/cuda_8.0.27.1_linux.run
5639ffeb939ee58a81554d06bd084e15  /home/nvtest/Downloads/cuda_8.0.27_linux.run
1e4e0091e89ad0c637fb2fc0aa4d3c4b  /home/nvtest/Downloads/cuda-misc-headers-8-0_8.0.27.1-1_amd64.deb
a565be8ec22a62dcee75809f92b9cc76  /home/nvtest/Downloads/cuda-repo-ubuntu1404-8-0-rc_8.0.27-1_amd64.deb

```

### Chapter 4. RUNFILE INSTALLATION

```bash
nvtest@WT72:~$ sudo sh -c 'echo "blacklist nouveau\noptions nouveau modeset=0" > /etc/modprobe.d/blacklist-nouveau.conf'
nvtest@WT72:~$
nvtest@WT72:~$ cat /etc/modprobe.d/blacklist-nouveau.conf
blacklist nouveau
options nouveau modeset=0
nvtest@WT72:~$
```

### Chapter 4.2.3 Reboot into text mode (runlevel 3).

#### nvidia-367 pakcage インストール

```bash
nvtest@WT72:~$ sudo apt-get install nvidia-367
nvtest@WT72:~$ lsmod | grep nouveau
nvtest@WT72:~$ lspci -nnk | grep -iA2 vga
01:00.0 VGA compatible controller [0300]: NVIDIA Corporation Device [10de:13fb] (rev a1)
	Subsystem: Micro-Star International Co., Ltd. [MSI] Device [1462:11b0]
	Kernel driver in use: nvidia
nvtest@WT72:~$ nvidia-smi
Sun Sep 18 00:15:29 2016       
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 367.44                 Driver Version: 367.44                    |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|===============================+======================+======================|
|   0  Quadro M5500        Off  | 0000:01:00.0      On |                  N/A |
| N/A   49C    P8    12W /  N/A |    509MiB /  8120MiB |      0%      Default |
+-------------------------------+----------------------+----------------------+
                                                                               
+-----------------------------------------------------------------------------+
| Processes:                                                       GPU Memory |
|  GPU       PID  Type  Process name                               Usage      |
|=============================================================================|
|    0      3333    G   /usr/lib/xorg/Xorg                             394MiB |
|    0      3642    G   compiz                                         113MiB |
+-----------------------------------------------------------------------------+

```

#### CUDA Toolkit インストール

実機上で`CTRL+ALT+F1`を押して黒画面へ。

ログイン後、もしくはリモートログイン後、
`sudo init 3` を実行して、非X環境してから、先ほどダウンロードしたインストーラを実行。

```bash
nvtest@WT72:~$ sudo service lightdm stop
nvtest@WT72:~$ sudo init 3
nvtest@WT72:~$ cd ~/Downloads/
nvtest@WT72:~/Downloads$ chmod +x cuda_8.0.27_linux.run --override
nvtest@WT72:~/Downloads$ chmod +x cuda_8.0.27.1_linux.run 
nvtest@WT72:~/Downloads$ ll
total 3199528
drwxr-xr-x  2 nvtest nvtest       4096  9月 17 23:09 ./
drwxr-xr-x 16 nvtest nvtest       4096  9月 17 23:14 ../
-rwxrwxr-x  1 nvtest nvtest      42622  9月 17 22:32 cuda_8.0.27.1_linux.run*
-rwxrwxrwx  1 nvtest nvtest 1381136356  9月  5 21:48 cuda_8.0.27_linux.run*
-rw-rw-r--  1 nvtest nvtest    1067836  9月 17 22:35 cuda-misc-headers-8-0_8.0.27.1-1_amd64.deb
-rwxrwxrwx  1 nvtest nvtest 1819010702  9月 16 19:00 cuda-repo-ubuntu1404-8-0-rc_8.0.27-1_amd64.deb*
-rw-rw-r--  1 nvtest nvtest   75032664  9月 17 23:06 NVIDIA-Linux-x86_64-367.44.run
nvtest@WT72:~/Downloads$ sudo ./cuda_8.0.27_linux.run
...(略)...
-------------------------------------------------------------
Do you accept the previously read EULA?
accept/decline/quit: accept

Install NVIDIA Accelerated Graphics Driver for Linux-x86_64 361.77?
(y)es/(n)o/(q)uit: n

Install the CUDA 8.0 Toolkit?
(y)es/(n)o/(q)uit: yes

Enter Toolkit Location
 [ default is /usr/local/cuda-8.0 ]: 

Do you want to install a symbolic link at /usr/local/cuda?
(y)es/(n)o/(q)uit: y

Install the CUDA 8.0 Samples?
(y)es/(n)o/(q)uit: y

Enter CUDA Samples Location
 [ default is /home/nvtest ]: 

Installing the CUDA Toolkit in /usr/local/cuda-8.0 ...
Missing recommended library: libGLU.so
Missing recommended library: libX11.so
Missing recommended library: libXi.so
Missing recommended library: libXmu.so

Installing the CUDA Samples in /home/nvtest ...
Copying samples to /home/nvtest/NVIDIA_CUDA-8.0_Samples now...
Finished copying samples.

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

Driver:   Not Selected
Toolkit:  Installed in /usr/local/cuda-8.0
Samples:  Installed in /home/nvtest, but missing recommended libraries

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 <CudaInstaller> with the name of this run file:
    sudo <CudaInstaller>.run -silent -driver

Logfile is /tmp/cuda_install_4482.log
nvtest@WT72:~/Downloads$
nvtest@WT72:~/Downloads$ sudo ./cuda_8.0.27.1_linux.run
...(略)...
-------------------------------------------------------------
Do you accept the previously read EULA?
accept/decline/quit: accept

Enter CUDA Toolkit installation directory
 [ default is /usr/local/cuda-8.0 ]: 

Installation complete!
Installation directory: /usr/local/cuda-8.0

nvtest@WT72:~/Downloads$ 
nvtest@WT72:~/Downloads$ sudo reboot
```

## サンプルのビルド

# ポイント