【Azure】 NC系列安装Drive and CUDNN
安装Nvidia Drive
方法一:
CUDA_REPO_PKG=cuda-repo-ubuntu1804_10.1.168-1_amd64.deb
wget -O /tmp/${CUDA_REPO_PKG} http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/${CUDA_REPO_PKG}
sudo dpkg -i /tmp/${CUDA_REPO_PKG}
sudo apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/7fa2af80.pub
rm -f /tmp/${CUDA_REPO_PKG}
sudo apt-get update
sudo apt-get install cuda-drivers
sudo apt-get install cuda
nvidia-smi
方法二:如果方法一安装失败,由于无法加载7fa2af80.pub导致请参考方法二。
wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/7fa2af80.pub
sudo apt-key add 7fa2af80.pub
CUDA_REPO_PKG=cuda-repo-ubuntu1804_10.1.168-1_amd64.deb
wget -O /tmp/${CUDA_REPO_PKG} http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/${CUDA_REPO_PKG}
sudo dpkg -i /tmp/${CUDA_REPO_PKG}
rm -f /tmp/${CUDA_REPO_PKG}
sudo apt-get update
sudo apt-get install cuda-drivers
sudo apt-get install cuda
nvidia-smi
由于cuda已经包含了drivers,所以仅仅安装cuda就可以了。
https://docs.nvidia.com/deeplearning/sdk/cudnn-install/index.html
https://developer.nvidia.com/rdp/cudnn-download
- 下载到本地并上传到VM中。
[jichba.jichba] ➤ scp libcudnn7_7.6.4.38-1+cuda10.1_amd64.deb libcudnn7-dev_7.6.4.38-1+cuda10.1_amd64.deb libcudnn7-doc_7.6.4.38-1+cuda10.1_amd64.deb cudnn-10.1-linux-x64-v7.6.3.30.tgz gpuvm04@139.217.118.15:/home/gpuvm04
Warning: Permanently added '139.217.118.15' (RSA) to the list of known hosts.
gpuvm04@139.217.118.15's password:
libcudnn7_7.6.4.38-1+cuda10.1_amd64.deb 100% 174MB 1.2MB/s 02:31
libcudnn7-dev_7.6.4.38-1+cuda10.1_amd64.deb 99% 153MB 1.0MB/s 02:35
libcudnn7-doc_7.6.4.38-1+cuda10.1_amd64.deb 100% 5424KB 5.3MB/s 00:01
cudnn-10.1-linux-x64-v7.6.3.30.tgz 100% 499MB 787.6KB/s 10:49
- 解压缩
gpuvm04@gpuvm04:~$ ls
7fa2af80.pub libcudnn7-dev_7.6.4.38-1+cuda10.1_amd64.deb libcudnn7_7.6.4.38-1+cuda10.1_amd64.deb
cudnn-10.1-linux-x64-v7.6.3.30.tgz libcudnn7-doc_7.6.4.38-1+cuda10.1_amd64.deb
gpuvm04@gpuvm04:~$ sudo tar -xvzf cudnn-10.1-linux-x64-v7.6.3.30.tgz
cuda/include/cudnn.h
cuda/NVIDIA_SLA_cuDNN_Support.txt
cuda/lib64/libcudnn.so
cuda/lib64/libcudnn.so.7
cuda/lib64/libcudnn.so.7.6.3
cuda/lib64/libcudnn_static.a
- 复制到cuba toolkits目录,并改变权限
sudo cp cuda/include/cudnn.h /usr/local/cuda/include
sudo cp cuda/lib64/libcudnn* /usr/local/cuda/lib64
sudo chmod a+r /usr/local/cuda/include/cudnn.h /usr/local/cuda/lib64/libcudnn*
- Install the runtime library,Install the developer library,Install the code samples and the cuDNN Library User Guide
gpuvm04@gpuvm04:~$ sudo dpkg -i libcudnn7_7.6.4.38-1+cuda10.1_amd64.deb
Selecting previously unselected package libcudnn7.
(Reading database ... 92828 files and directories currently installed.)
Preparing to unpack libcudnn7_7.6.4.38-1+cuda10.1_amd64.deb ...
Unpacking libcudnn7 (7.6.4.38-1+cuda10.1) ...
Setting up libcudnn7 (7.6.4.38-1+cuda10.1) ...
Processing triggers for libc-bin (2.27-3ubuntu1) ...
/sbin/ldconfig.real: /usr/local/cuda-10.1/targets/x86_64-linux/lib/libcudnn.so.7 is not a symbolic link
gpuvm04@gpuvm04:~$ sudo dpkg -i libcudnn7-dev_7.6.4.38-1+cuda10.1_amd64.deb
Selecting previously unselected package libcudnn7-dev.
(Reading database ... 92834 files and directories currently installed.)
Preparing to unpack libcudnn7-dev_7.6.4.38-1+cuda10.1_amd64.deb ...
Unpacking libcudnn7-dev (7.6.4.38-1+cuda10.1) ...
Setting up libcudnn7-dev (7.6.4.38-1+cuda10.1) ...
update-alternatives: using /usr/include/x86_64-linux-gnu/cudnn_v7.h to provide /usr/include/cudnn.h (libcudnn) in auto mode
gpuvm04@gpuvm04:~$ sudo dpkg -i libcudnn7-doc_7.6.4.38-1+cuda10.1_amd64.deb
Selecting previously unselected package libcudnn7-doc.
(Reading database ... 92840 files and directories currently installed.)
Preparing to unpack libcudnn7-doc_7.6.4.38-1+cuda10.1_amd64.deb ...
Unpacking libcudnn7-doc (7.6.4.38-1+cuda10.1) ...
Setting up libcudnn7-doc (7.6.4.38-1+cuda10.1) ...
验证cuDNN
gpuvm04@gpuvm04:~$ cp -r /usr/src/cudnn_samples_v7/ $HOME
gpuvm04@gpuvm04:~$ cd cudnn_samples_v7/
gpuvm04@gpuvm04:~/cudnn_samples_v7$ cd mnistCUDNN/
gpuvm04@gpuvm04:~/cudnn_samples_v7/mnistCUDNN$ ls
FreeImage Makefile data error_util.h fp16_dev.cu fp16_dev.h fp16_emu.cpp fp16_emu.h gemv.h mnistCUDNN.cpp readme.txt
gpuvm04@gpuvm04:~/cudnn_samples_v7/mnistCUDNN$ make clean && make
gpuvm04@gpuvm04:~/cudnn_samples_v7/mnistCUDNN$ ./mnistCUDNN
cudnnGetVersion() : 7603 , CUDNN_VERSION from cudnn.h : 7603 (7.6.3)
Host compiler version : GCC 7.4.0
There are 1 CUDA capable devices on your machine :
device 0 : sms 80 Capabilities 7.0, SmClock 1380.0 Mhz, MemSize (Mb) 16160, MemClock 877.0 Mhz, Ecc=1, boardGroupID=0
Using device 0
Testing single precision
Loading image data/one_28x28.pgm
Performing forward propagation ...
Testing cudnnGetConvolutionForwardAlgorithm ...
Fastest algorithm is Algo 0
Testing cudnnFindConvolutionForwardAlgorithm ...
^^^^ CUDNN_STATUS_SUCCESS for Algo 5: 0.069632 time requiring 203008 memory
^^^^ CUDNN_STATUS_SUCCESS for Algo 2: 0.071712 time requiring 57600 memory
^^^^ CUDNN_STATUS_SUCCESS for Algo 7: 0.077824 time requiring 2057744 memory
^^^^ CUDNN_STATUS_SUCCESS for Algo 4: 0.103424 time requiring 207360 memory
^^^^ CUDNN_STATUS_SUCCESS for Algo 0: 0.159776 time requiring 0 memory
Resulting weights from Softmax:
0.0000000 0.9999399 0.0000000 0.0000000 0.0000561 0.0000000 0.0000012 0.0000017 0.0000010 0.0000000
Loading image data/three_28x28.pgm
Performing forward propagation ...
Resulting weights from Softmax:
0.0000000 0.0000000 0.0000000 0.9999288 0.0000000 0.0000711 0.0000000 0.0000000 0.0000000 0.0000000
Loading image data/five_28x28.pgm
Performing forward propagation ...
Resulting weights from Softmax:
0.0000000 0.0000008 0.0000000 0.0000002 0.0000000 0.9999820 0.0000154 0.0000000 0.0000012 0.0000006
Result of classification: 1 3 5
Test passed!
Testing half precision (math in single precision)
Loading image data/one_28x28.pgm
Performing forward propagation ...
Testing cudnnGetConvolutionForwardAlgorithm ...
Fastest algorithm is Algo 0
Testing cudnnFindConvolutionForwardAlgorithm ...
^^^^ CUDNN_STATUS_SUCCESS for Algo 0: 0.018432 time requiring 0 memory
^^^^ CUDNN_STATUS_SUCCESS for Algo 2: 0.045088 time requiring 28800 memory
^^^^ CUDNN_STATUS_SUCCESS for Algo 5: 0.052224 time requiring 203008 memory
^^^^ CUDNN_STATUS_SUCCESS for Algo 1: 0.055264 time requiring 3464 memory
^^^^ CUDNN_STATUS_SUCCESS for Algo 7: 0.057344 time requiring 2057744 memory
Resulting weights from Softmax:
0.0000001 1.0000000 0.0000001 0.0000000 0.0000563 0.0000001 0.0000012 0.0000017 0.0000010 0.0000001
Loading image data/three_28x28.pgm
Performing forward propagation ...
Resulting weights from Softmax:
0.0000000 0.0000000 0.0000000 1.0000000 0.0000000 0.0000714 0.0000000 0.0000000 0.0000000 0.0000000
Loading image data/five_28x28.pgm
Performing forward propagation ...
Resulting weights from Softmax:
0.0000000 0.0000008 0.0000000 0.0000002 0.0000000 1.0000000 0.0000154 0.0000000 0.0000012 0.0000006
Result of classification: 1 3 5
Test passed!