https://github.com/zq2599/blog_demos
内容:所有原创文章分类汇总及配套源码,涉及Java、Docker、Kubernetes、DevOPS等;
按照一般步骤,在安装完Nvidia显卡驱动后,会提示对应的CUDA版本,接下来按照提示的版本安装CUDA,例如我这里提示的是11.2,正常情况下,我应该安装11.2版本的CUDA
但是我选择9.1版本就行安装,因为之前的开发中发现deeplearning4j使用了11.2的SDK后,启动应用会有ClassNotFound的错误,此问题至今未修复(惭愧,欣宸水平如此之低…),因此,我在Nvidia驱动提示11.2版本的情况下,依然安装了9.1版本,后来在此环境运行deeplearning4j应用一切正常
如果您没有我这类问题,完全可以按照驱动指定的版本来安装CUDA,具体的操作步骤稍后会详细说到;
接下来的操作,除了在网页下载,其余都是ssh远程连接到ubuntu机器操作的,ssh登录的帐号为普通帐号,并非root
如果已有驱动,请先删除:
sudo apt-get remove --purge nvidia*
blacklist nouveau blacklist lbm-nouveau options nouveau modeset=0 alias nouveau off alias lbm-nouveau off
echo options nouveau modeset=0 | sudo tee -a /etc/modprobe.d/nouveau-kms.conf
update-initramfs -u
执行reboot重启电脑
重启后,执行以下命令,应该不会有任何输出,证明nouveau已经禁用:
lsmod|grep nouveau
sudo apt-get install linux-source
sudo apt-get install linux-headers-4.4.0-210-generic
下载得到的文件名为NVIDIA-Linux-x86_64-460.84.run
关闭图形页面:
sudo service lightdm stop
sudo chmod a+x NVIDIA-Linux-x86_64-460.84.run
sudo ./NVIDIA-Linux-x86_64-460.84.run -no-x-check -no-nouveau-check -no-opengl-files
遇到下图,直接回车:
恢复图形页面:
sudo service lightdm start
will@lenovo:~/temp/202106/20$ nvidia-smi Sun Jun 20 09:02:11 2021 +-----------------------------------------------------------------------------+ | NVIDIA-SMI 460.84 Driver Version: 460.84 CUDA Version: 11.2 | |-------------------------------+----------------------+----------------------+ | GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC | | Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. | | | | MIG M. | |===============================+======================+======================| | 0 GeForce GTX 950M Off | 00000000:01:00.0 Off | N/A | | N/A 41C P0 N/A / N/A | 0MiB / 4046MiB | 1% Default | | | | N/A | +-------------------------------+----------------------+----------------------+ +-----------------------------------------------------------------------------+ | Processes: | | GPU GI CI PID Type Process name GPU Memory | | ID ID Usage | |=============================================================================| | No running processes found | +-----------------------------------------------------------------------------+
https://developer.download.nvidia.cn/compute/cuda/9.1/secure/Prod/local_installers/cuda_9.1.85_387.26_linux.run?P0Ntu_6NLtuuEMm6fJRk1W5vl4KM7oaT1oFW870zKJ-zDw2ckKntFLOE6klRJfw2CmTa8z3Q390_6urlgc6LqjoqlIFW9gvfvDCusnINYplLaw1u8lRY8R4oVNtpNzaXU4BQcHjvdb6c6rjq20dktCcRd4640woXt1yHmD95v1Du7wdBBXq2eOY https://developer.download.nvidia.cn/compute/cuda/9.1/secure/Prod/patches/1/cuda_9.1.85.1_linux.run?yeXf_7wIGlHAUw--E_YVLQZRgXv0x2i043woJVY-ydXU5Kyhc-eYQf5JmL-4mvYmlvPYCEc5RhT2sDWscX20CJbdOwpkt30kWb9vx8E4oIlajDQ3MVPvXdiKKsIOBUx-h0q0N0jSkNn80VMhW-nk8jwvRY_e6MuFzqWBaPk https://developer.download.nvidia.cn/compute/cuda/9.1/secure/Prod/patches/2/cuda_9.1.85.2_linux.run?5jGZxNigaOJkaaPbMagjhSW7ebQvYGyYoqe2vBxZ1eV8qp2BzXJLxIPgAo11UgWhORirQkdJGq5b8eFh4aShBVUTmuPaasvRiMCKDZw5yjjIobGQrCEyU-LFO59AbrRER57Mxa0T1Sc97fC80IOZq8Ox2repjn7A3oYVgd8 https://developer.download.nvidia.cn/compute/cuda/9.1/secure/Prod/patches/3/cuda_9.1.85.3_linux.run?CxWimJTC-XROYihig-UZmH62odbJInf1fmxTZ_bsW1nQ0Zz5cL5r8qLmlMR_1j2rVhk3j8Z5lS6dpArt8frjGHH2MeVn5TefMoclam8udm-RSMMmqHXYE66hHN2D0drVEdtCwe8ZrEIYb2rpucaz9svCFE8Z319mge4Ju94
下载完毕后,执行命令chmod a+x *.run为上述四个文件增加可执行权限
安装CUDA:
sudo sh cuda_9.1.85_387.26_linux.run
Installing the CUDA Toolkit in /usr/local/cuda-9.1 ... Missing recommended library: libGLU.so Missing recommended library: libX11.so Missing recommended library: libXi.so Missing recommended library: libXmu.so Missing recommended library: libGL.so Installing the CUDA Samples in /home/will ... Copying samples to /home/will/NVIDIA_CUDA-9.1_Samples now... Finished copying samples. =========== = Summary = =========== Driver: Not Selected Toolkit: Installed in /usr/local/cuda-9.1 Samples: Installed in /home/will, but missing recommended libraries Please make sure that - PATH includes /usr/local/cuda-9.1/bin - LD_LIBRARY_PATH includes /usr/local/cuda-9.1/lib64, or, add /usr/local/cuda-9.1/lib64 to /etc/ld.so.conf and run ldconfig as root To uninstall the CUDA Toolkit, run the uninstall script in /usr/local/cuda-9.1/bin Please see CUDA_Installation_Guide_Linux.pdf in /usr/local/cuda-9.1/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 384.00 is required for CUDA 9.1 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_13425.log
export PATH=/usr/local/cuda-9.1/bin:$PATH export LD_LIBRARY_PATH=/usr/local/cuda-9.1/lib64
执行命令source ~/.bashrc使配置生效
执行命令su -切换到root帐号,执行以下命令(不要用sudo,而是切到root帐号):
sudo echo "/usr/local/cuda-9.1/lib64" >> /etc/ld.so.conf
ldconfig
执行命令exit退出root身份,现在又是普通帐号的身份了
执行命令nvcc -V检查CUDA版本,注意参数V是大写:
will@lenovo:~$ nvcc -V nvcc: NVIDIA (R) Cuda compiler driver Copyright (c) 2005-2017 NVIDIA Corporation Built on Fri_Nov__3_21:07:56_CDT_2017 Cuda compilation tools, release 9.1, V9.1.85
sudo sh cuda_9.1.85.1_linux.run
sudo sh cuda_9.1.85_387.26_linux.run
sudo sh cuda_9.1.85_387.26_linux.run
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 sudo chmod a+r /usr/local/cuda/lib64/libcudnn*
#define CUDNN_MAJOR 7 #define CUDNN_MINOR 1 #define CUDNN_PATCHLEVEL 3 -- #define CUDNN_VERSION (CUDNN_MAJOR * 1000 + CUDNN_MINOR * 100 + CUDNN_PATCHLEVEL) #include "driver_types.h"
我是欣宸,期待与您一同畅游Java世界…
https://github.com/zq2599/blog_demos