Ubuntu18.04上安装cuda10.0

Ubuntu18.04 + cuda (+ Optional Pytorch)

 

Step1: 检查硬件和系统

检查版本和类型:ubuntu-drivers devices
$ sudo ubuntu-drivers list
nvidia-driver-390

$ ubuntu-drivers devices
== /sys/devices/pci0000:00/0000:00:01.0/0000:01:00.0 ==
modalias : pci:v000010DEd00001B06sv00001458sd0000374Cbc03sc00i00
vendor   : NVIDIA Corporation
model    : GP102 [GeForce GTX 1080 Ti]
driver   : nvidia-driver-390 - distro non-free recommended
driver   : xserver-xorg-video-nouveau - distro free builtin

这里显示,390是推荐的版本(recommended)

检查自己的GPU是否是CUDA-capable 
$ lspci | grep -i nvidia
01:00.0 VGA compatible controller: NVIDIA Corporation GP102 [GeForce GTX 1080 Ti] (rev a1)
01:00.1 Audio device: NVIDIA Corporation GP102 HDMI Audio Controller (rev a1)
然后,可去CUDA的官网查看自己的GPU版本是否在CUDA的支持列表中 
https://developer.nvidia.com/cuda-gpus 

 

step.2,安装驱动

选择安装所有推荐的驱动,如下命令
$ sudo ubuntu-drivers autoinstall

也可以选择,只安装其中一个驱动,命令如下
$ sudo apt install nvidia-390
OK 驱动安装完成。

这时候,只需要重新启动一下就可以使用NVIDIA的驱动了!
如何查看到底有没有启动呢?

~$ lsmod | grep nouveau
#(no response, it means nouveau not running)

~$ lsmod | grep nvidia
#(nvidia is running if we get info similar to below)
nvidia_uvm            757760  0
nvidia_drm             40960  1
nvidia_modeset       1110016  9 nvidia_drm
nvidia              14360576  418 nvidia_uvm,nvidia_modeset
drm_kms_helper        172032  1 nvidia_drm
drm                   401408  4 drm_kms_helper,nvidia_drm
ipmi_msghandler        53248  2 ipmi_devintf,nvidia

关于驱动的安装,给个可供参考的贴子:
Linux安装NVIDIA显卡驱动的正确姿势
https://blog.csdn.net/wf19930209/article/details/81877822
 

step.3, 安装CUDA

----使用anaconda----

仅仅是使用cuda和cudnn的话,毫无疑问是anaconda比较省事,只需要一条指令,
conda install cudnn即可大功告成。比如我的机器上,执行完这条指令后,
1。存放目录:
anaconda3/pkgs/cudatoolkit-10.0.130-0.tar.bz2
anaconda3/pkgs/cudnn-7.3.1-cuda10.0_0.tar.bz2
2。下载源地址:
下载源地址最后存放在anaconda3/pkgs/urls.txt中,不过貌似要下载完之后才能看到。https://repo.anaconda.com/pkgs/main/linux-64/cudatoolkit-10.0.130-0.tar.bz2
https://repo.anaconda.com/pkgs/main/linux-64/cudnn-7.3.1-cuda10.0_0.tar.bz2

----手动安装----

如果你想手动安装呢,就到这里去下载相关的版本,安装包
https://developer.nvidia.com/cuda-toolkit
https://developer.nvidia.com/cuda-toolkit-archive
下载完了再输入命令安装
sudo sh cuda_9.2.148_396.37_linux.run
后面还有不少依赖包,一个个装吧!
这样装的好处是文件比较全,比如cudeSample都会有。

 

----sudo apt install nvidia-cuda-toolkit----

这个安装方法和前面的不一样,会自动完成很多包的安装,我列出来在下面,

==>>> 不想一个个装可以使用这个试试看,不过这个方法我不推荐,比如下面我提到的pytorch的编译,这种方法就有报错。不清楚是否是ubuntu没整理完整还是啥冲突的问题。另外一种与此不同的安装方法是后面给出了的参考[1]的安装方式,是依赖于nvidia官网上的包,貌似会好一些,可参考着看。


$ sudo apt install nvidia-cuda-toolkit
正在读取软件包列表... 完成
正在分析软件包的依赖关系树       
正在读取状态信息... 完成       
将会同时安装下列软件:
  ca-certificates-java cpp-6 fonts-dejavu-extra g++-6 gcc-6 gcc-6-base
  java-common libaccinj64-9.1 libasan3 libatk-wrapper-java
  libatk-wrapper-java-jni libcublas9.1 libcudart9.1 libcufft9.1 libcufftw9.1
  libcuinj64-9.1 libcurand9.1 libcusolver9.1 libcusparse9.1 libdrm-dev
  libgcc-6-dev libgl1-mesa-dev libgles1 libglvnd-core-dev libglvnd-dev
  libnppc9.1 libnppial9.1 libnppicc9.1 libnppicom9.1 libnppidei9.1 libnppif9.1
  libnppig9.1 libnppim9.1 libnppist9.1 libnppisu9.1 libnppitc9.1 libnpps9.1
  libnvblas9.1 libnvgraph9.1 libnvrtc9.1 libnvtoolsext1 libnvvm3 libopengl0
  libstdc++-6-dev libthrust-dev libvdpau-dev libx11-xcb-dev libxcb-dri2-0-dev
  libxcb-dri3-dev libxcb-glx0-dev libxcb-present-dev libxcb-randr0-dev
  libxcb-shape0-dev libxcb-sync-dev libxcb-xfixes0-dev libxshmfence-dev
  libxxf86vm-dev mesa-common-dev nvidia-cuda-dev nvidia-cuda-doc
  nvidia-cuda-gdb nvidia-opencl-dev nvidia-profiler nvidia-visual-profiler
  ocl-icd-libopencl1 ocl-icd-opencl-dev opencl-c-headers openjdk-8-jre
  openjdk-8-jre-headless x11proto-dri2-dev x11proto-gl-dev
  x11proto-xf86vidmode-dev
建议安装:
  gcc-6-locales g++-6-multilib gcc-6-doc libstdc++6-6-dbg gcc-6-multilib
  libgcc1-dbg libgomp1-dbg libitm1-dbg libatomic1-dbg libasan3-dbg
  liblsan0-dbg libtsan0-dbg libubsan0-dbg libcilkrts5-dbg libmpx2-dbg
  libquadmath0-dbg default-jre libstdc++-6-doc libvdpau-doc libcupti-dev
  nvidia-driver libpoclu-dev icedtea-8-plugin fonts-ipafont-gothic
  fonts-ipafont-mincho fonts-wqy-microhei fonts-wqy-zenhei
推荐安装:
  libnvcuvid1
下列【新】软件包将被安装:
  ca-certificates-java cpp-6 fonts-dejavu-extra g++-6 gcc-6 gcc-6-base
  java-common libaccinj64-9.1 libasan3 libatk-wrapper-java
  libatk-wrapper-java-jni libcublas9.1 libcudart9.1 libcufft9.1 libcufftw9.1
  libcuinj64-9.1 libcurand9.1 libcusolver9.1 libcusparse9.1 libdrm-dev
  libgcc-6-dev libgl1-mesa-dev libgles1 libglvnd-core-dev libglvnd-dev
  libnppc9.1 libnppial9.1 libnppicc9.1 libnppicom9.1 libnppidei9.1 libnppif9.1
  libnppig9.1 libnppim9.1 libnppist9.1 libnppisu9.1 libnppitc9.1 libnpps9.1
  libnvblas9.1 libnvgraph9.1 libnvrtc9.1 libnvtoolsext1 libnvvm3 libopengl0
  libstdc++-6-dev libthrust-dev libvdpau-dev libx11-xcb-dev libxcb-dri2-0-dev
  libxcb-dri3-dev libxcb-glx0-dev libxcb-present-dev libxcb-randr0-dev
  libxcb-shape0-dev libxcb-sync-dev libxcb-xfixes0-dev libxshmfence-dev
  libxxf86vm-dev mesa-common-dev nvidia-cuda-dev nvidia-cuda-doc
  nvidia-cuda-gdb nvidia-cuda-toolkit nvidia-opencl-dev nvidia-profiler
  nvidia-visual-profiler ocl-icd-libopencl1 ocl-icd-opencl-dev
  opencl-c-headers openjdk-8-jre openjdk-8-jre-headless x11proto-dri2-dev
  x11proto-gl-dev x11proto-xf86vidmode-dev
升级了 0 个软件包,新安装了 73 个软件包,要卸载 0 个软件包,有 305 个软件包未被升级。
需要下载 827 MB 的归档。
解压缩后会消耗 1,990 MB 的额外空间。
获取:1 http://cn.archive.ubuntu.com/ubuntu bionic/main amd64 java-common all 0.63ubuntu1~02 [7,032 B]
获取:2 http://cn.archive.ubuntu.com/ubuntu bionic-updates/universe amd64 openjdk-8-jre-headless amd64 8u191-b12-0ubuntu0.18.04.1 [27.3 MB]
获取:3 http://cn.archive.ubuntu.com/ubuntu bionic-updates/main amd64 ca-certificates-java all 20180516ubuntu1~18.04.1 [12.2 kB]
获取:4 http://cn.archive.ubuntu.com/ubuntu bionic-updates/universe amd64 gcc-6-base amd64 6.5.0-2ubuntu1~18.04 [16.7 kB]
获取:5 http://cn.archive.ubuntu.com/ubuntu bionic-updates/universe amd64 cpp-6 amd64 6.5.0-2ubuntu1~18.04 [6,396 kB]
获取:6 http://cn.archive.ubuntu.com/ubuntu bionic/main amd64 fonts-dejavu-extra all 2.37-1 [1,953 kB]
获取:7 http://cn.archive.ubuntu.com/ubuntu bionic-updates/universe amd64 libasan3 amd64 6.5.0-2ubuntu1~18.04 [313 kB]
获取:8 http://cn.archive.ubuntu.com/ubuntu bionic-updates/universe amd64 libgcc-6-dev amd64 6.5.0-2ubuntu1~18.04 [2,308 kB]
获取:9 http://cn.archive.ubuntu.com/ubuntu bionic-updates/universe amd64 gcc-6 amd64 6.5.0-2ubuntu1~18.04 [7,067 kB]
获取:10 http://cn.archive.ubuntu.com/ubuntu bionic-updates/universe amd64 libstdc++-6-dev amd64 6.5.0-2ubuntu1~18.04 [1,437 kB]
获取:11 http://cn.archive.ubuntu.com/ubuntu bionic-updates/universe amd64 g++-6 amd64 6.5.0-2ubuntu1~18.04 [7,213 kB]
获取:12 http://cn.archive.ubuntu.com/ubuntu bionic/multiverse amd64 libaccinj64-9.1 amd64 9.1.85-3ubuntu1 [1,748 kB]
获取:13 http://cn.archive.ubuntu.com/ubuntu bionic/main amd64 libatk-wrapper-java all 0.33.3-20ubuntu0.1 [34.7 kB]
获取:14 http://cn.archive.ubuntu.com/ubuntu bionic/main amd64 libatk-wrapper-java-jni amd64 0.33.3-20ubuntu0.1 [28.3 kB]
获取:15 http://cn.archive.ubuntu.com/ubuntu bionic/multiverse amd64 libcublas9.1 amd64 9.1.85-3ubuntu1 [25.0 MB]
获取:16 http://cn.archive.ubuntu.com/ubuntu bionic/multiverse amd64 libcudart9.1 amd64 9.1.85-3ubuntu1 [121 kB]
获取:17 http://cn.archive.ubuntu.com/ubuntu bionic/multiverse amd64 libcufft9.1 amd64 9.1.85-3ubuntu1 [76.1 MB]
获取:18 http://cn.archive.ubuntu.com/ubuntu bionic/multiverse amd64 libcufftw9.1 amd64 9.1.85-3ubuntu1 [131 kB]                    
获取:19 http://cn.archive.ubuntu.com/ubuntu bionic/multiverse amd64 libcuinj64-9.1 amd64 9.1.85-3ubuntu1 [1,878 kB]               获取:20 http://cn.archive.ubuntu.com/ubuntu bionic/multiverse amd64 libcurand9.1 amd64 9.1.85-3ubuntu1 [38.9 MB]                 获取:21 http://cn.archive.ubuntu.com/ubuntu bionic/multiverse amd64 libcusolver9.1 amd64 9.1.85-3ubuntu1 [28.2 MB]              获取:22 http://cn.archive.ubuntu.com/ubuntu bionic/multiverse amd64 libcusparse9.1 amd64 9.1.85-3ubuntu1 [25.2 MB]           获取:23 http://cn.archive.ubuntu.com/ubuntu bionic/main amd64 libdrm-dev amd64 2.4.91-2 [238 kB]                                           获取:24 http://cn.archive.ubuntu.com/ubuntu bionic-updates/main amd64 libgles1 amd64 1.0.0-2ubuntu2.2 [11.2 kB]                   获取:25 http://cn.archive.ubuntu.com/ubuntu bionic/multiverse amd64 libnppc9.1 amd64 9.1.85-3ubuntu1 [127 kB]                     获取:26 http://cn.archive.ubuntu.com/ubuntu bionic/multiverse amd64 libnppial9.1 amd64 9.1.85-3ubuntu1 [3,169 kB]                 获取:27 http://cn.archive.ubuntu.com/ubuntu bionic/multiverse amd64 libnppicc9.1 amd64 9.1.85-3ubuntu1 [1,376 kB]               获取:28 http://cn.archive.ubuntu.com/ubuntu bionic/multiverse amd64 libnppicom9.1 amd64 9.1.85-3ubuntu1 [497 kB]                获取:29 http://cn.archive.ubuntu.com/ubuntu bionic/multiverse amd64 libnppidei9.1 amd64 9.1.85-3ubuntu1 [1,673 kB]             获取:30 http://cn.archive.ubuntu.com/ubuntu bionic/multiverse amd64 libnppif9.1 amd64 9.1.85-3ubuntu1 [20.9 MB]                   获取:31 http://cn.archive.ubuntu.com/ubuntu bionic/multiverse amd64 libnppig9.1 amd64 9.1.85-3ubuntu1 [9,960 kB]                 获取:32 http://cn.archive.ubuntu.com/ubuntu bionic/multiverse amd64 libnppim9.1 amd64 9.1.85-3ubuntu1 [2,295 kB]                 获取:33 http://cn.archive.ubuntu.com/ubuntu bionic/multiverse amd64 libnppist9.1 amd64 9.1.85-3ubuntu1 [4,910 kB]                 获取:34 http://cn.archive.ubuntu.com/ubuntu bionic/multiverse amd64 libnppisu9.1 amd64 9.1.85-3ubuntu1 [120 kB]                   获取:35 http://cn.archive.ubuntu.com/ubuntu bionic/multiverse amd64 libnppitc9.1 amd64 9.1.85-3ubuntu1 [714 kB]                   获取:36 http://cn.archive.ubuntu.com/ubuntu bionic/multiverse amd64 libnpps9.1 amd64 9.1.85-3ubuntu1 [2,568 kB]                   获取:37 http://cn.archive.ubuntu.com/ubuntu bionic/multiverse amd64 libnvblas9.1 amd64 9.1.85-3ubuntu1 [132 kB]                   获取:38 http://cn.archive.ubuntu.com/ubuntu bionic/multiverse amd64 libnvgraph9.1 amd64 9.1.85-3ubuntu1 [6,252 kB]             
获取:39 http://cn.archive.ubuntu.com/ubuntu bionic/multiverse amd64 libnvrtc9.1 amd64 9.1.85-3ubuntu1 [6,309 kB]                   
获取:40 http://cn.archive.ubuntu.com/ubuntu bionic/main amd64 libvdpau-dev amd64 1.1.1-3ubuntu1 [35.8 kB]                             获取:41 http://cn.archive.ubuntu.com/ubuntu bionic-updates/main amd64 libx11-xcb-dev amd64 2:1.6.4-3ubuntu0.1 [9,764 B]     获取:42 http://cn.archive.ubuntu.com/ubuntu bionic/main amd64 libxcb-dri2-0-dev amd64 1.13-1 [8,476 B]                                   获取:43 http://cn.archive.ubuntu.com/ubuntu bionic/main amd64 libxcb-dri3-dev amd64 1.13-1 [7,368 B]                                     
获取:44 http://cn.archive.ubuntu.com/ubuntu bionic/main amd64 libxcb-glx0-dev amd64 1.13-1 [27.9 kB]    
获取:45 http://cn.archive.ubuntu.com/ubuntu bionic/main amd64 libxcb-randr0-dev amd64 1.13-1 [20.4 kB]     
获取:46 http://cn.archive.ubuntu.com/ubuntu bionic/main amd64 libxcb-shape0-dev amd64 1.13-1 [7,144 B]   
获取:47 http://cn.archive.ubuntu.com/ubuntu bionic/main amd64 libxcb-xfixes0-dev amd64 1.13-1 [11.7 kB]       
获取:48 http://cn.archive.ubuntu.com/ubuntu bionic/main amd64 libxcb-sync-dev amd64 1.13-1 [10.6 kB]      
获取:49 http://cn.archive.ubuntu.com/ubuntu bionic/main amd64 libxcb-present-dev amd64 1.13-1 [6,968 B]   
获取:50 http://cn.archive.ubuntu.com/ubuntu bionic/main amd64 libxshmfence-dev amd64 1.3-1 [3,692 B]   
获取:51 http://cn.archive.ubuntu.com/ubuntu bionic/main amd64 x11proto-xf86vidmode-dev all 2018.4-4 [2,632 B]  
获取:52 http://cn.archive.ubuntu.com/ubuntu bionic/main amd64 libxxf86vm-dev amd64 1:1.1.4-1 [13.3 kB]               
获取:53 http://cn.archive.ubuntu.com/ubuntu bionic-updates/main amd64 mesa-common-dev amd64 18.0.5-0ubuntu0~18.04.1 [536 kB]
获取:54 http://cn.archive.ubuntu.com/ubuntu bionic-updates/universe amd64 openjdk-8-jre amd64 8u191-b12-0ubuntu0.18.04.1 [69.7 kB]    
获取:55 http://cn.archive.ubuntu.com/ubuntu bionic/main amd64 x11proto-dri2-dev all 2018.4-4 [2,620 B]  
获取:56 http://cn.archive.ubuntu.com/ubuntu bionic/main amd64 x11proto-gl-dev all 2018.4-4 [2,612 B]    
获取:57 http://cn.archive.ubuntu.com/ubuntu bionic-updates/main amd64 libglvnd-core-dev amd64 1.0.0-2ubuntu2.2 [12.9 kB]   
获取:58 http://cn.archive.ubuntu.com/ubuntu bionic-updates/main amd64 libopengl0 amd64 1.0.0-2ubuntu2.2 [31.3 kB]   
获取:59 http://cn.archive.ubuntu.com/ubuntu bionic-updates/main amd64 libglvnd-dev amd64 1.0.0-2ubuntu2.2 [3,408 B]  
获取:60 http://cn.archive.ubuntu.com/ubuntu bionic-updates/main amd64 libgl1-mesa-dev amd64 18.0.5-0ubuntu0~18.04.1 [4,444 B]
获取:61 http://cn.archive.ubuntu.com/ubuntu bionic/multiverse amd64 libnvtoolsext1 amd64 9.1.85-3ubuntu1 [31.3 kB]     
获取:62 http://cn.archive.ubuntu.com/ubuntu bionic/multiverse amd64 libnvvm3 amd64 9.1.85-3ubuntu1 [4,274 kB]   
获取:63 http://cn.archive.ubuntu.com/ubuntu bionic/multiverse amd64 libthrust-dev all 1.9.1~9.1.85-3ubuntu1 [461 kB]  
获取:64 http://cn.archive.ubuntu.com/ubuntu bionic/multiverse amd64 nvidia-cuda-dev amd64 9.1.85-3ubuntu1 [263 MB]   
获取:65 http://cn.archive.ubuntu.com/ubuntu bionic/multiverse amd64 nvidia-cuda-doc all 9.1.85-3ubuntu1 [95.2 MB]    
获取:66 http://cn.archive.ubuntu.com/ubuntu bionic/multiverse amd64 nvidia-cuda-gdb amd64 9.1.85-3ubuntu1 [2,724 kB]  
获取:67 http://cn.archive.ubuntu.com/ubuntu bionic/multiverse amd64 nvidia-profiler amd64 9.1.85-3ubuntu1 [2,672 kB]     
获取:68 http://cn.archive.ubuntu.com/ubuntu bionic/main amd64 opencl-c-headers all 2.2~2018.02.21-gb5c3680-1 [28.5 kB] 
获取:69 http://cn.archive.ubuntu.com/ubuntu bionic/main amd64 ocl-icd-libopencl1 amd64 2.2.11-1ubuntu1 [30.3 kB]   
获取:70 http://cn.archive.ubuntu.com/ubuntu bionic/main amd64 ocl-icd-opencl-dev amd64 2.2.11-1ubuntu1 [2,512 B]    
获取:71 http://cn.archive.ubuntu.com/ubuntu bionic/multiverse amd64 nvidia-opencl-dev amd64 9.1.85-3ubuntu1 [22.6 kB]   
获取:72 http://cn.archive.ubuntu.com/ubuntu bionic/multiverse amd64 nvidia-cuda-toolkit amd64 9.1.85-3ubuntu1 [30.4 MB]  
获取:73 http://cn.archive.ubuntu.com/ubuntu bionic/multiverse amd64 nvidia-visual-profiler amd64 9.1.85-3ubuntu1 [115 MB]  

卸载

卸载过程比较简单,就是一个命令:sudo apt-get --purge remove nvidia-cuda-toolkit
注意执行本语句过程中,有一个提示:'sudo apt autoremove',就是那些不需要再用的依赖也可以删除掉(我一般都保留不删,只要不冲突就行,免得其他程序还得再安装)。

$ sudo apt-get --purge remove nvidia-cuda-toolkit
正在读取软件包列表... 完成
正在分析软件包的依赖关系树       
正在读取状态信息... 完成       
下列软件包是自动安装的并且现在不需要了:
  debugedit g++-6 libaccinj64-9.1 libcublas9.1 libcudart9.1 libcufft9.1 libcufftw9.1 libcuinj64-9.1 libcurand9.1 libcusolver9.1 libcusparse9.1 libdrm-dev libgl1-mesa-dev libgles1 libglvnd-core-dev
  libglvnd-dev libnppc9.1 libnppial9.1 libnppicc9.1 libnppicom9.1 libnppidei9.1 libnppif9.1 libnppig9.1 libnppim9.1 libnppist9.1 libnppisu9.1 libnppitc9.1 libnpps9.1 libnvblas9.1 libnvgraph9.1
  libnvrtc9.1 libnvtoolsext1 libnvvm3 libopengl0 librpmbuild8 librpmsign8 libsqlite0 libthrust-dev libvdpau-dev libx11-xcb-dev libxcb-dri2-0-dev libxcb-dri3-dev libxcb-glx0-dev libxcb-present-dev
  libxcb-randr0-dev libxcb-shape0-dev libxcb-sync-dev libxcb-xfixes0-dev libxshmfence-dev libxxf86vm-dev mesa-common-dev nvidia-cuda-dev nvidia-cuda-doc nvidia-cuda-gdb nvidia-opencl-dev nvidia-profiler
  nvidia-visual-profiler ocl-icd-opencl-dev opencl-c-headers python-libxml2 python-lzma python-pycurl python-rpm python-sqlite python-sqlitecachec python-urlgrabber rpm x11proto-dri2-dev x11proto-gl-dev
  x11proto-xf86vidmode-dev
使用'sudo apt autoremove'来卸载它(它们)。
下列软件包将被【卸载】:
  nvidia-cuda-toolkit*
升级了 0 个软件包,新安装了 0 个软件包,要卸载 1 个软件包,有 14 个软件包未被升级。
解压缩后将会空出 61.0 MB 的空间。
您希望继续执行吗? [Y/n] y
(正在读取数据库 ... 系统当前共安装有 188653 个文件和目录。)
正在卸载 nvidia-cuda-toolkit (9.1.85-3ubuntu1) ...
正在处理用于 man-db (2.8.3-2ubuntu0.1) 的触发器 ...
(正在读取数据库 ... 系统当前共安装有 188613 个文件和目录。)
正在清除 nvidia-cuda-toolkit (9.1.85-3ubuntu1) 的配置文件 ...

 

另外提一下pytorch的编译与安装,

根据https://github.com/pytorch/pytorch的说法,

采用下面这几步就够了,
conda install numpy pyyaml mkl mkl-include setuptools cmake cffi typing

# Add LAPACK support for the GPU if needed
conda install -c pytorch magma-cuda92 # or [magma-cuda80 | magma-cuda91] depending on your cuda version

# Get the PyTorch Source
git clone --recursive https://github.com/pytorch/pytorch
cd pytorch

#Install PyTorch
export CMAKE_PREFIX_PATH=${CONDA_PREFIX:-"$(dirname $(which conda))/../"}
python setup.py install

而实际上,我发现Ubuntu18.04上也有不少冲突,主要是缺少安装包什么的,或者是不兼容,具体报错内容没记住,其中有一个cuda的问题

CMake Error at cmake/public/cuda.cmake:318 (message):
  CUDA 9.1 is not compatible with std::tuple from GCC version >= 6.  Please
  upgrade to CUDA 9.2 or use the following option to use another version (for
  example):
    -DCUDA_HOST_COMPILER=/usr/bin/gcc-5
.....
-- Configuring incomplete, errors occurred!
See also "/home/matthew/dev/pytorch/build/CMakeFiles/CMakeOutput.log".
See also "/home/matthew/dev/pytorch/build/CMakeFiles/CMakeError.log".
Failed to run 'bash ../tools/build_pytorch_libs.sh --use-cuda --use-fbgemm --use-nnpack --use-mkldnn --use-qnnpack caffe2'

网上有不少解决办法,参考:https://github.com/pytorch/pytorch/issues/14152

我的办法是

step1: remove the previous cuda
sudo apt-get --purge remove nvidia-cuda-toolkit
conda remove cudnn (if has installed a different version needed)

step2: install cudnn  (this will install cudnn7_cuda9.2
conda install pybind11
conda install cudnn

$ conda install cudnn
Solving environment: done

## Package Plan ##
  environment location: /home/matthew/anaconda3/envs/torchdev
  added / updated specs: 
    - cudnn

The following packages will be downloaded:
    package                    |            build
    ---------------------------|-----------------
    cudatoolkit-9.2            |                0       351.0 MB
    cudnn-7.2.1                |        cuda9.2_0       322.8 MB
    ------------------------------------------------------------
                                           Total:       673.8 MB

The following NEW packages will be INSTALLED:
    cudatoolkit: 9.2-0          
    cudnn:       7.2.1-cuda9.2_0
Proceed ([y]/n)? y

这一步之后,就可以正常执行python setup.py install了。

 

参考安装方式[1]

https://askubuntu.com/questions/1077061/how-do-i-install-nvidia-and-cuda-drivers-into-ubuntu
本安装方式的缺点是:看运气,网络上有些包比较卡顿!!!

安装过程

Remove any CUDA PPAs that may be setup and also remove the nvidia-cuda-toolkit if installed:

sudo rm /etc/apt/sources.list.d/cuda*
sudo apt remove nvidia-cuda-toolkit

Recommended to also remove all NVIDIA drivers before installing new drivers:

sudo apt remove nvidia-*

Then update the system:

sudo apt update

Install the key:

sudo apt-key adv --fetch-keys  http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/7fa2af80.pub

Add the repo:

sudo bash -c 'echo "deb http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64 /" > /etc/apt/sources.list.d/cuda.list'

Update the system again:

sudo apt update

If you only want the NVIDIA 410 driver run, if not, skip this step:

sudo apt install nvidia-driver-410

Install CUDA 10.0.

sudo apt install cuda-10-0

It should be installing the nvidia-410 drivers with it as those are what are listed in the repo. See:http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/

Add the following lines to your ~/.profile file for CUDA 10.0

# set PATH for cuda 10.0 installation
if [ -d "/usr/local/cuda-10.0/bin/" ]; then
    export PATH=/usr/local/cuda-10.0/bin${PATH:+:${PATH}}
    export LD_LIBRARY_PATH=/usr/local/cuda-10.0/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
fi

Reboot the computer and check your settings when reboot is complete:
Check NVIDIA Cuda Compiler with nvcc --version:
Check NVIDIA driver with nvidia-smi:
...

安装结果(列出全部的安装包)

~$ sudo apt install nvidia-driver-410
正在读取软件包列表... 完成
正在分析软件包的依赖关系树       
正在读取状态信息... 完成       
将会同时安装下列软件:
  libnvidia-cfg1-410 libnvidia-common-410 libnvidia-compute-410
  libnvidia-decode-410 libnvidia-encode-410 libnvidia-fbc1-410
  libnvidia-gl-410 libnvidia-ifr1-410 libopengl0 libxnvctrl0
  nvidia-compute-utils-410 nvidia-dkms-410 nvidia-kernel-common-410
  nvidia-kernel-source-410 nvidia-prime nvidia-settings nvidia-utils-410
  screen-resolution-extra xserver-xorg-video-nvidia-410
推荐安装:
  libnvidia-compute-410:i386 libnvidia-decode-410:i386
  libnvidia-encode-410:i386 libnvidia-ifr1-410:i386 libnvidia-fbc1-410:i386
  libnvidia-gl-410:i386
下列软件包将被【卸载】:
  libnvidia-compute-390 libnvidia-compute-390:i386
下列【新】软件包将被安装:
  libnvidia-cfg1-410 libnvidia-common-410 libnvidia-compute-410
  libnvidia-decode-410 libnvidia-encode-410 libnvidia-fbc1-410
  libnvidia-gl-410 libnvidia-ifr1-410 libopengl0 libxnvctrl0
  nvidia-compute-utils-410 nvidia-dkms-410 nvidia-driver-410
  nvidia-kernel-common-410 nvidia-kernel-source-410 nvidia-prime
  nvidia-settings nvidia-utils-410 screen-resolution-extra
  xserver-xorg-video-nvidia-410
升级了 0 个软件包,新安装了 20 个软件包,要卸载 2 个软件包,有 37 个软件包未被升级。
需要下载 67.1 MB/67.2 MB 的归档。
解压缩后会消耗 130 MB 的额外空间。
您希望继续执行吗? [Y/n] y
获取:2 http://cn.archive.ubuntu.com/ubuntu bionic-updates/main amd64 libopengl0 amd64 1.0.0-2ubuntu2.2 [31.3 kB]
获取:1 https://developer.download.nvidia.cn/compute/cuda/repos/ubuntu1804/x86_64  libnvidia-cfg1-410 410.79-0ubuntu1 [70.2 kB]
获取:3 https://developer.download.nvidia.cn/compute/cuda/repos/ubuntu1804/x86_64  libnvidia-common-410 410.79-0ubuntu1 [9,800 B]
获取:4 https://developer.download.nvidia.cn/compute/cuda/repos/ubuntu1804/x86_64  libnvidia-compute-410 410.79-0ubuntu1 [20.6 MB]
获取:5 https://developer.download.nvidia.cn/compute/cuda/repos/ubuntu1804/x86_64  libnvidia-decode-410 410.79-0ubuntu1 [1,209 kB]
获取:6 https://developer.download.nvidia.cn/compute/cuda/repos/ubuntu1804/x86_64  libnvidia-encode-410 410.79-0ubuntu1 [52.2 kB]
获取:7 https://developer.download.nvidia.cn/compute/cuda/repos/ubuntu1804/x86_64  libnvidia-fbc1-410 410.79-0ubuntu1 [43.6 kB]
获取:8 https://developer.download.nvidia.cn/compute/cuda/repos/ubuntu1804/x86_64  libnvidia-gl-410 410.79-0ubuntu1 [31.4 MB]
获取:9 https://developer.download.nvidia.cn/compute/cuda/repos/ubuntu1804/x86_64  libnvidia-ifr1-410 410.79-0ubuntu1 [68.4 kB]
获取:10 https://developer.download.nvidia.cn/compute/cuda/repos/ubuntu1804/x86_64  libxnvctrl0 410.79-0ubuntu1 [19.3 kB]
获取:11 https://developer.download.nvidia.cn/compute/cuda/repos/ubuntu1804/x86_64  nvidia-compute-utils-410 410.79-0ubuntu1 [72.8 kB]
获取:12 https://developer.download.nvidia.cn/compute/cuda/repos/ubuntu1804/x86_64  nvidia-kernel-source-410 410.79-0ubuntu1 [10.2 MB]
获取:13 https://developer.download.nvidia.cn/compute/cuda/repos/ubuntu1804/x86_64  nvidia-kernel-common-410 410.79-0ubuntu1 [10.3 kB]
获取:14 https://developer.download.nvidia.cn/compute/cuda/repos/ubuntu1804/x86_64  nvidia-dkms-410 410.79-0ubuntu1 [26.0 kB]
获取:15 https://developer.download.nvidia.cn/compute/cuda/repos/ubuntu1804/x86_64  nvidia-utils-410 410.79-0ubuntu1 [333 kB]
获取:16 https://developer.download.nvidia.cn/compute/cuda/repos/ubuntu1804/x86_64  xserver-xorg-video-nvidia-410 410.79-0ubuntu1 [1,652 kB]
获取:17 https://developer.download.nvidia.cn/compute/cuda/repos/ubuntu1804/x86_64  nvidia-driver-410 410.79-0ubuntu1 [395 kB]
获取:18 https://developer.download.nvidia.cn/compute/cuda/repos/ubuntu1804/x86_64  nvidia-settings 410.79-0ubuntu1 [962 kB]
已下载 67.1 MB,耗时 39秒 (1,717 kB/s)                                         
(正在读取数据库 ... 系统当前共安装有 198634 个文件和目录。)
正在卸载 libnvidia-compute-390:amd64 (390.77-0ubuntu0.18.04.1) ...
正在卸载 libnvidia-compute-390:i386 (390.77-0ubuntu0.18.04.1) ...
正在选中未选择的软件包 libnvidia-cfg1-410:amd64。
(正在读取数据库 ... 系统当前共安装有 198606 个文件和目录。)
正准备解包 ...
...
update-initramfs: deferring update (trigger activated)

A modprobe blacklist file has been created at /etc/modprobe.d to prevent Nouveau
from loading. This can be reverted by deleting the following file:
/etc/modprobe.d/nvidia-graphics-drivers.conf

A new initrd image has also been created. To revert, please regenerate your
initrd by running the following command after deleting the modprobe.d file:
`/usr/sbin/initramfs -u`

*****************************************************************************
*** Reboot your computer and verify that the NVIDIA graphics driver can   ***
*** be loaded.                                                            ***
*****************************************************************************

INFO:Enable nvidia
DEBUG:Parsing /usr/share/ubuntu-drivers-common/quirks/put_your_quirks_here
DEBUG:Parsing /usr/share/ubuntu-drivers-common/quirks/dell_latitude
DEBUG:Parsing /usr/share/ubuntu-drivers-common/quirks/lenovo_thinkpad
Loading new nvidia-410.79 DKMS files...
Building for 4.15.0-45-generic
Building for architecture x86_64
Building initial module for 4.15.0-45-generic
Done.

nvidia:
Running module version sanity check.
 - Original module
   - No original module exists within this kernel
 - Installation
   - Installing to /lib/modules/4.15.0-45-generic/updates/dkms/

nvidia-modeset.ko:
Running module version sanity check.
 - Original module
   - No original module exists within this kernel
 - Installation
   - Installing to /lib/modules/4.15.0-45-generic/updates/dkms/

nvidia-drm.ko:
Running module version sanity check.
 - Original module
   - No original module exists within this kernel
 - Installation
   - Installing to /lib/modules/4.15.0-45-generic/updates/dkms/

nvidia-uvm.ko:
Running module version sanity check.
 - Original module
   - No original module exists within this kernel
 - Installation
   - Installing to /lib/modules/4.15.0-45-generic/updates/dkms/

depmod.....

DKMS: install completed.
 ...


============================================================================
~$ sudo apt install cuda-10-0
正在读取软件包列表... 完成
正在分析软件包的依赖关系树       
正在读取状态信息... 完成       
将会同时安装下列软件:
  ca-certificates-java cuda-command-line-tools-10-0 cuda-compiler-10-0 cuda-cublas-10-0 cuda-cublas-dev-10-0 cuda-cudart-10-0 cuda-cudart-dev-10-0 cuda-cufft-10-0 cuda-cufft-dev-10-0 cuda-cuobjdump-10-0
  cuda-cupti-10-0 cuda-curand-10-0 cuda-curand-dev-10-0 cuda-cusolver-10-0 cuda-cusolver-dev-10-0 cuda-cusparse-10-0 cuda-cusparse-dev-10-0 cuda-demo-suite-10-0 cuda-documentation-10-0
  cuda-driver-dev-10-0 cuda-drivers cuda-gdb-10-0 cuda-gpu-library-advisor-10-0 cuda-libraries-10-0 cuda-libraries-dev-10-0 cuda-license-10-0 cuda-memcheck-10-0 cuda-misc-headers-10-0 cuda-npp-10-0
  cuda-npp-dev-10-0 cuda-nsight-10-0 cuda-nsight-compute-10-0 cuda-nvcc-10-0 cuda-nvdisasm-10-0 cuda-nvgraph-10-0 cuda-nvgraph-dev-10-0 cuda-nvjpeg-10-0 cuda-nvjpeg-dev-10-0 cuda-nvml-dev-10-0
  cuda-nvprof-10-0 cuda-nvprune-10-0 cuda-nvrtc-10-0 cuda-nvrtc-dev-10-0 cuda-nvtx-10-0 cuda-nvvp-10-0 cuda-runtime-10-0 cuda-samples-10-0 cuda-toolkit-10-0 cuda-tools-10-0 cuda-visual-tools-10-0
  default-jre default-jre-headless fonts-dejavu-extra freeglut3 freeglut3-dev java-common libatk-wrapper-java libatk-wrapper-java-jni libdrm-dev libgl1-mesa-dev libgles1 libglu1-mesa-dev
  libglvnd-core-dev libglvnd-dev libx11-xcb-dev libxcb-dri2-0-dev libxcb-dri3-dev libxcb-glx0-dev libxcb-present-dev libxcb-randr0-dev libxcb-shape0-dev libxcb-sync-dev libxcb-xfixes0-dev libxmu-dev
  libxmu-headers libxshmfence-dev libxxf86vm-dev mesa-common-dev nvidia-modprobe openjdk-11-jre openjdk-11-jre-headless x11proto-xf86vidmode-dev
建议安装:
  default-java-plugin fonts-ipafont-gothic fonts-ipafont-mincho fonts-wqy-microhei | fonts-wqy-zenhei
下列【新】软件包将被安装:
  ca-certificates-java cuda-10-0 cuda-command-line-tools-10-0 cuda-compiler-10-0 cuda-cublas-10-0 cuda-cublas-dev-10-0 cuda-cudart-10-0 cuda-cudart-dev-10-0 cuda-cufft-10-0 cuda-cufft-dev-10-0
  cuda-cuobjdump-10-0 cuda-cupti-10-0 cuda-curand-10-0 cuda-curand-dev-10-0 cuda-cusolver-10-0 cuda-cusolver-dev-10-0 cuda-cusparse-10-0 cuda-cusparse-dev-10-0 cuda-demo-suite-10-0
  cuda-documentation-10-0 cuda-driver-dev-10-0 cuda-drivers cuda-gdb-10-0 cuda-gpu-library-advisor-10-0 cuda-libraries-10-0 cuda-libraries-dev-10-0 cuda-license-10-0 cuda-memcheck-10-0
  cuda-misc-headers-10-0 cuda-npp-10-0 cuda-npp-dev-10-0 cuda-nsight-10-0 cuda-nsight-compute-10-0 cuda-nvcc-10-0 cuda-nvdisasm-10-0 cuda-nvgraph-10-0 cuda-nvgraph-dev-10-0 cuda-nvjpeg-10-0
  cuda-nvjpeg-dev-10-0 cuda-nvml-dev-10-0 cuda-nvprof-10-0 cuda-nvprune-10-0 cuda-nvrtc-10-0 cuda-nvrtc-dev-10-0 cuda-nvtx-10-0 cuda-nvvp-10-0 cuda-runtime-10-0 cuda-samples-10-0 cuda-toolkit-10-0
  cuda-tools-10-0 cuda-visual-tools-10-0 default-jre default-jre-headless fonts-dejavu-extra freeglut3 freeglut3-dev java-common libatk-wrapper-java libatk-wrapper-java-jni libdrm-dev libgl1-mesa-dev
  libgles1 libglu1-mesa-dev libglvnd-core-dev libglvnd-dev libx11-xcb-dev libxcb-dri2-0-dev libxcb-dri3-dev libxcb-glx0-dev libxcb-present-dev libxcb-randr0-dev libxcb-shape0-dev libxcb-sync-dev
  libxcb-xfixes0-dev libxmu-dev libxmu-headers libxshmfence-dev libxxf86vm-dev mesa-common-dev nvidia-modprobe openjdk-11-jre openjdk-11-jre-headless x11proto-xf86vidmode-dev
升级了 0 个软件包,新安装了 83 个软件包,要卸载 0 个软件包,有 37 个软件包未被升级。
需要下载 1,407 MB 的归档。
解压缩后会消耗 3,336 MB 的额外空间。
您希望继续执行吗? [Y/n] y
获取:1 http://cn.archive.ubuntu.com/ubuntu bionic/main amd64 java-common all 0.63ubuntu1~02 [7,032 B]
获取:2 https://developer.download.nvidia.cn/compute/cuda/repos/ubuntu1804/x86_64  cuda-license-10-0 10.0.130-1 [17.6 kB]
获取:13 http://cn.archive.ubuntu.com/ubuntu bionic-updates/main amd64 openjdk-11-jre-headless amd64 10.0.2+13-1ubuntu0.18.04.4 [39.5 MB]
获取:3 https://developer.download.nvidia.cn/compute/cuda/repos/ubuntu1804/x86_64  cuda-misc-headers-10-0 10.0.130-1 [640 kB]
获取:4 https://developer.download.nvidia.cn/compute/cuda/repos/ubuntu1804/x86_64  cuda-nvcc-10-0 10.0.130-1 [20.0 MB]
获取:5 https://developer.download.nvidia.cn/compute/cuda/repos/ubuntu1804/x86_64  cuda-cuobjdump-10-0 10.0.130-1 [130 kB]
获取:6 https://developer.download.nvidia.cn/compute/cuda/repos/ubuntu1804/x86_64  cuda-nvprune-10-0 10.0.130-1 [36.8 kB]
获取:7 https://developer.download.nvidia.cn/compute/cuda/repos/ubuntu1804/x86_64  cuda-compiler-10-0 10.0.130-1 [2,538 B]
获取:8 https://developer.download.nvidia.cn/compute/cuda/repos/ubuntu1804/x86_64  cuda-nvdisasm-10-0 10.0.130-1 [22.1 MB]
获取:9 https://developer.download.nvidia.cn/compute/cuda/repos/ubuntu1804/x86_64  cuda-gdb-10-0 10.0.130-1 [2,769 kB]                                                                                      
获取:10 https://developer.download.nvidia.cn/compute/cuda/repos/ubuntu1804/x86_64  cuda-nvprof-10-0 10.0.130-1 [5,590 kB]                                                                                  
获取:11 https://developer.download.nvidia.cn/compute/cuda/repos/ubuntu1804/x86_64  cuda-memcheck-10-0 10.0.130-1 [139 kB]                                                                                  
获取:12 https://developer.download.nvidia.cn/compute/cuda/repos/ubuntu1804/x86_64  cuda-cudart-10-0 10.0.130-1 [109 kB]                                                                                    
获取:14 https://developer.download.nvidia.cn/compute/cuda/repos/ubuntu1804/x86_64  cuda-driver-dev-10-0 10.0.130-1 [12.0 kB]                                                                               
获取:15 https://developer.download.nvidia.cn/compute/cuda/repos/ubuntu1804/x86_64  cuda-cudart-dev-10-0 10.0.130-1 [457 kB]                                                                                
获取:16 https://developer.download.nvidia.cn/compute/cuda/repos/ubuntu1804/x86_64  cuda-cupti-10-0 10.0.130-1 [1,564 kB]                                                                                   
获取:17 https://developer.download.nvidia.cn/compute/cuda/repos/ubuntu1804/x86_64  cuda-gpu-library-advisor-10-0 10.0.130-1 [1,003 kB]                                                                     
获取:18 https://developer.download.nvidia.cn/compute/cuda/repos/ubuntu1804/x86_64  cuda-nvtx-10-0 10.0.130-1 [38.9 kB]                                                                                     
获取:19 https://developer.download.nvidia.cn/compute/cuda/repos/ubuntu1804/x86_64  cuda-command-line-tools-10-0 10.0.130-1 [26.9 kB]                                                                       
获取:20 https://developer.download.nvidia.cn/compute/cuda/repos/ubuntu1804/x86_64  cuda-nsight-10-0 10.0.130-1 [2,590 B]                                                                                   
获取:21 https://developer.download.nvidia.cn/compute/cuda/repos/ubuntu1804/x86_64  cuda-nvvp-10-0 10.0.130-1 [2,536 B]                                                                                     
获取:22 https://developer.download.nvidia.cn/compute/cuda/repos/ubuntu1804/x86_64  cuda-nvrtc-10-0 10.0.130-1 [5,925 kB]                                                                                   
获取:23 https://developer.download.nvidia.cn/compute/cuda/repos/ubuntu1804/x86_64  cuda-nvrtc-dev-10-0 10.0.130-1 [9,344 B]                                                                                
获取:24 https://developer.download.nvidia.cn/compute/cuda/repos/ubuntu1804/x86_64  cuda-cusolver-10-0 10.0.130-1 [38.4 MB]                                                                                 
获取:25 https://developer.download.nvidia.cn/compute/cuda/repos/ubuntu1804/x86_64  cuda-cusolver-dev-10-0 10.0.130-1 [13.2 MB]                                                                             
获取:26 https://developer.download.nvidia.cn/compute/cuda/repos/ubuntu1804/x86_64  cuda-cublas-10-0 10.0.130-1 [30.3 MB]                                                                                   
获取:27 https://developer.download.nvidia.cn/compute/cuda/repos/ubuntu1804/x86_64  cuda-cublas-dev-10-0 10.0.130-1 [30.8 MB]                                                                               
获取:28 https://developer.download.nvidia.cn/compute/cuda/repos/ubuntu1804/x86_64  cuda-cufft-10-0 10.0.130-1 [60.7 MB]                                                                                    
获取:29 https://developer.download.nvidia.cn/compute/cuda/repos/ubuntu1804/x86_64  cuda-cufft-dev-10-0 10.0.130-1 [124 MB]                                                                                 
获取:30 https://developer.download.nvidia.cn/compute/cuda/repos/ubuntu1804/x86_64  cuda-curand-10-0 10.0.130-1 [38.9 MB]                                                                                   
获取:31 https://developer.download.nvidia.cn/compute/cuda/repos/ubuntu1804/x86_64  cuda-curand-dev-10-0 10.0.130-1 [58.1 MB]                                                                               
获取:32 https://developer.download.nvidia.cn/compute/cuda/repos/ubuntu1804/x86_64  cuda-cusparse-10-0 10.0.130-1 [27.1 MB]                                                                                 
获取:33 https://developer.download.nvidia.cn/compute/cuda/repos/ubuntu1804/x86_64  cuda-cusparse-dev-10-0 10.0.130-1 [27.2 MB]                                                                             
获取:34 https://developer.download.nvidia.cn/compute/cuda/repos/ubuntu1804/x86_64  cuda-npp-10-0 10.0.130-1 [54.2 MB]                                                                                      
获取:35 https://developer.download.nvidia.cn/compute/cuda/repos/ubuntu1804/x86_64  cuda-npp-dev-10-0 10.0.130-1 [55.0 MB]                                                                                  
获取:36 https://developer.download.nvidia.cn/compute/cuda/repos/ubuntu1804/x86_64  cuda-nvml-dev-10-0 10.0.130-1 [51.6 kB]                                                                                 
获取:37 https://developer.download.nvidia.cn/compute/cuda/repos/ubuntu1804/x86_64  cuda-nvgraph-10-0 10.0.130-1 [12.8 MB]                                                                                  
获取:38 https://developer.download.nvidia.cn/compute/cuda/repos/ubuntu1804/x86_64  cuda-nvgraph-dev-10-0 10.0.130-1 [33.4 MB]                                                                              
获取:39 https://developer.download.nvidia.cn/compute/cuda/repos/ubuntu1804/x86_64  cuda-nvjpeg-10-0 10.0.130-1 [281 kB]                                                                                    
获取:40 https://developer.download.nvidia.cn/compute/cuda/repos/ubuntu1804/x86_64  cuda-nvjpeg-dev-10-0 10.0.130-1 [192 kB]                                                                                
获取:41 https://developer.download.nvidia.cn/compute/cuda/repos/ubuntu1804/x86_64  cuda-nsight-compute-10-0 10.0.130-1 [188 MB]                                                                            
获取:42 https://developer.download.nvidia.cn/compute/cuda/repos/ubuntu1804/x86_64  cuda-visual-tools-10-0 10.0.130-1 [394 MB]                                                                              
获取:43 https://developer.download.nvidia.cn/compute/cuda/repos/ubuntu1804/x86_64  cuda-tools-10-0 10.0.130-1 [2,498 B]                                                                                    
获取:44 https://developer.download.nvidia.cn/compute/cuda/repos/ubuntu1804/x86_64  cuda-samples-10-0 10.0.130-1 [61.5 MB]                                                                                  
获取:45 https://developer.download.nvidia.cn/compute/cuda/repos/ubuntu1804/x86_64  cuda-documentation-10-0 10.0.130-1 [52.0 MB]                                                                            
获取:46 https://developer.download.nvidia.cn/compute/cuda/repos/ubuntu1804/x86_64  cuda-libraries-dev-10-0 10.0.130-1 [2,606 B]                                                                            
获取:47 https://developer.download.nvidia.cn/compute/cuda/repos/ubuntu1804/x86_64  cuda-toolkit-10-0 10.0.130-1 [2,834 B]                                                                                  
获取:48 https://developer.download.nvidia.cn/compute/cuda/repos/ubuntu1804/x86_64  nvidia-modprobe 410.79-0ubuntu1 [19.1 kB]                                                                               
获取:49 https://developer.download.nvidia.cn/compute/cuda/repos/ubuntu1804/x86_64  cuda-drivers 410.79-1 [2,568 B]                                                                                         
获取:50 https://developer.download.nvidia.cn/compute/cuda/repos/ubuntu1804/x86_64  cuda-libraries-10-0 10.0.130-1 [2,586 B]                                                                                
获取:51 https://developer.download.nvidia.cn/compute/cuda/repos/ubuntu1804/x86_64  cuda-runtime-10-0 10.0.130-1 [2,540 B]                                                                                  
获取:52 https://developer.download.nvidia.cn/compute/cuda/repos/ubuntu1804/x86_64  cuda-demo-suite-10-0 10.0.130-1 [3,868 kB]                                                                              
获取:53 https://developer.download.nvidia.cn/compute/cuda/repos/ubuntu1804/x86_64  cuda-10-0 10.0.130-1 [2,562 B]                                                                                          
91% [13 openjdk-11-jre-headless 11.0 MB/39.5 MB 28%]                                                                                                                                  17.8 kB/s 29分 52秒 
获取:54 http://cn.archive.ubuntu.com/ubuntu bionic/main amd64 default-jre-headless amd64 2:1.10-63ubuntu1~02 [3,412 B]                                                                                     
获取:55 http://cn.archive.ubuntu.com/ubuntu bionic-updates/main amd64 ca-certificates-java all 20180516ubuntu1~18.04.1 [12.2 kB]                                                                           
获取:56 http://cn.archive.ubuntu.com/ubuntu bionic-updates/main amd64 openjdk-11-jre amd64 10.0.2+13-1ubuntu0.18.04.4 [53.1 kB]                                                                            
获取:57 http://cn.archive.ubuntu.com/ubuntu bionic/main amd64 default-jre amd64 2:1.10-63ubuntu1~02 [1,092 B]                                                                                              
获取:58 http://cn.archive.ubuntu.com/ubuntu bionic/universe amd64 freeglut3 amd64 2.8.1-3 [73.6 kB]                                                                                                        
获取:59 http://cn.archive.ubuntu.com/ubuntu bionic-updates/main amd64 libdrm-dev amd64 2.4.95-1~18.04.1 [121 kB]                                                                                           
获取:60 http://cn.archive.ubuntu.com/ubuntu bionic-updates/main amd64 mesa-common-dev amd64 18.2.2-0ubuntu1~18.04.1 [551 kB]                                                                               
获取:61 http://cn.archive.ubuntu.com/ubuntu bionic-updates/main amd64 libglvnd-core-dev amd64 1.0.0-2ubuntu2.2 [12.9 kB]                                                                                   
获取:62 http://cn.archive.ubuntu.com/ubuntu bionic-updates/main amd64 libgles1 amd64 1.0.0-2ubuntu2.2 [11.2 kB]                                                                                            
获取:63 http://cn.archive.ubuntu.com/ubuntu bionic-updates/main amd64 libglvnd-dev amd64 1.0.0-2ubuntu2.2 [3,408 B]                                                                                        
获取:64 http://cn.archive.ubuntu.com/ubuntu bionic-updates/main amd64 libx11-xcb-dev amd64 2:1.6.4-3ubuntu0.1 [9,764 B]                                                                                    
获取:65 http://cn.archive.ubuntu.com/ubuntu bionic/main amd64 libxcb-dri3-dev amd64 1.13-1 [7,368 B]                                                                                                       
获取:66 http://cn.archive.ubuntu.com/ubuntu bionic/main amd64 libxcb-randr0-dev amd64 1.13-1 [20.4 kB]                                                                                                     
获取:67 http://cn.archive.ubuntu.com/ubuntu bionic/main amd64 libxcb-shape0-dev amd64 1.13-1 [7,144 B]                                                                                                     
获取:68 http://cn.archive.ubuntu.com/ubuntu bionic/main amd64 libxcb-xfixes0-dev amd64 1.13-1 [11.7 kB]                                                                                                    
获取:69 http://cn.archive.ubuntu.com/ubuntu bionic/main amd64 libxcb-sync-dev amd64 1.13-1 [10.6 kB]                                                                                                       
获取:70 http://cn.archive.ubuntu.com/ubuntu bionic/main amd64 libxcb-present-dev amd64 1.13-1 [6,968 B]                                                                                                    
获取:71 http://cn.archive.ubuntu.com/ubuntu bionic/main amd64 libxshmfence-dev amd64 1.3-1 [3,692 B]                                                                                                       
获取:72 http://cn.archive.ubuntu.com/ubuntu bionic/main amd64 libxcb-dri2-0-dev amd64 1.13-1 [8,476 B]                                                                                                     
获取:73 http://cn.archive.ubuntu.com/ubuntu bionic/main amd64 libxcb-glx0-dev amd64 1.13-1 [27.9 kB]                                                                                                       
获取:74 http://cn.archive.ubuntu.com/ubuntu bionic/main amd64 x11proto-xf86vidmode-dev all 2018.4-4 [2,632 B]                                                                                              
获取:75 http://cn.archive.ubuntu.com/ubuntu bionic/main amd64 libxxf86vm-dev amd64 1:1.1.4-1 [13.3 kB]                                                                                                     
获取:76 http://cn.archive.ubuntu.com/ubuntu bionic-updates/main amd64 libgl1-mesa-dev amd64 18.2.2-0ubuntu1~18.04.1 [4,432 B]                                                                              
获取:77 http://cn.archive.ubuntu.com/ubuntu bionic/main amd64 libglu1-mesa-dev amd64 9.0.0-2.1build1 [206 kB]                                                                                              
获取:78 http://cn.archive.ubuntu.com/ubuntu bionic/universe amd64 freeglut3-dev amd64 2.8.1-3 [124 kB]                                                                                                     
获取:79 http://cn.archive.ubuntu.com/ubuntu bionic/main amd64 libxmu-headers all 2:1.1.2-2 [54.3 kB]                                                                                                       
获取:80 http://cn.archive.ubuntu.com/ubuntu bionic/main amd64 libxmu-dev amd64 2:1.1.2-2 [49.0 kB]                                                                                                         
获取:81 http://cn.archive.ubuntu.com/ubuntu bionic/main amd64 fonts-dejavu-extra all 2.37-1 [1,953 kB]                                                                                                     
获取:82 http://cn.archive.ubuntu.com/ubuntu bionic/main amd64 libatk-wrapper-java all 0.33.3-20ubuntu0.1 [34.7 kB]                                                                                         
获取:83 http://cn.archive.ubuntu.com/ubuntu bionic/main amd64 libatk-wrapper-java-jni amd64 0.33.3-20ubuntu0.1 [28.3 kB]                                                                                   
已下载 1,407 MB,耗时 26分 38秒 (880 kB/s)                                                                                                                                                                 
正在从软件包中解出模板:100%
正在选中未选择的软件包 java-common。
(正在读取数据库 ... 系统当前共安装有 199217 个文件和目录。)
正准备解包 ...

Running hooks in /etc/ca-certificates/update.d...

done.

 

Step.4 检查cuda是否安装成功

检查 CUDA Toolkit是否安装成功 终端输入 :
$ nvcc -V
会输出CUDA的版本信息(V要大写) 
$ nvidia-smi

一般安装完后,cuda还有一些可供测试的samples,位置一般是在/usr/local/cuda-10.0下面,我们可以检测一下效果,如下

~$ cd /usr/local/cuda-10.0/samples/1_Utilities/deviceQuery

==>>>
...deviceQuery$ sudo make
/usr/local/cuda-10.0/bin/nvcc -ccbin g++ -I../../common/inc  -m64    -gencode arch=compute_30,code=sm_30 -gencode arch=compute_35,code=sm_35 -gencode arch=compute_37,code=sm_37 -gencode arch=compute_50,code=sm_50 -gencode arch=compute_52,code=sm_52 -gencode arch=compute_60,code=sm_60 -gencode arch=compute_61,code=sm_61 -gencode arch=compute_70,code=sm_70 -gencode arch=compute_75,code=sm_75 -gencode arch=compute_75,code=compute_75 -o deviceQuery.o -c deviceQuery.cpp
/usr/local/cuda-10.0/bin/nvcc -ccbin g++   -m64      -gencode arch=compute_30,code=sm_30 -gencode arch=compute_35,code=sm_35 -gencode arch=compute_37,code=sm_37 -gencode arch=compute_50,code=sm_50 -gencode arch=compute_52,code=sm_52 -gencode arch=compute_60,code=sm_60 -gencode arch=compute_61,code=sm_61 -gencode arch=compute_70,code=sm_70 -gencode arch=compute_75,code=sm_75 -gencode arch=compute_75,code=compute_75 -o deviceQuery deviceQuery.o 
mkdir -p ../../bin/x86_64/linux/release
cp deviceQuery ../../bin/x86_64/linux/release

==>>>
...deviceQuery$ ls
deviceQuery      deviceQuery.o  NsightEclipse.xml
deviceQuery.cpp  Makefile       readme.txt

==>>>
...deviceQuery$ ./deviceQuery
./deviceQuery Starting...

 CUDA Device Query (Runtime API) version (CUDART static linking)

Detected 1 CUDA Capable device(s)

Device 0: "GeForce GTX 1080 Ti"
  CUDA Driver Version / Runtime Version          10.0 / 10.0
  CUDA Capability Major/Minor version number:    6.1
  Total amount of global memory:                 11177 MBytes (11720130560 bytes)
  (28) Multiprocessors, (128) CUDA Cores/MP:     3584 CUDA Cores
  GPU Max Clock rate:                            1633 MHz (1.63 GHz)
  Memory Clock rate:                             5505 Mhz
  Memory Bus Width:                              352-bit
  L2 Cache Size:                                 2883584 bytes
  Maximum Texture Dimension Size (x,y,z)         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:  2048
  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)
  Maximum memory pitch:                          2147483647 bytes
  Texture alignment:                             512 bytes
  Concurrent copy and kernel execution:          Yes with 2 copy engine(s)
  Run time limit on kernels:                     Yes
  Integrated GPU sharing Host Memory:            No
  Support host page-locked memory mapping:       Yes
  Alignment requirement for Surfaces:            Yes
  Device has ECC support:                        Disabled
  Device supports Unified Addressing (UVA):      Yes
  Device supports Compute Preemption:            Yes
  Supports Cooperative Kernel Launch:            Yes
  Supports MultiDevice Co-op Kernel Launch:      Yes
  Device PCI Domain ID / Bus ID / location ID:   0 / 1 / 0
  Compute Mode:
     < Default (multiple host threads can use ::cudaSetDevice() with device simultaneously) >

deviceQuery, CUDA Driver = CUDART, CUDA Driver Version = 10.0, CUDA Runtime Version = 10.0, NumDevs = 1


 

 

 

你可能感兴趣的:(Linux,Cuda,ubuntu)