参考了文章 https://blog.csdn.net/xueshengke/article/details/78134991
写的很好,但是我的环境跟他写的还是差别很大,折腾了很久,几乎快崩溃的额时候终于迎来了曙光,耗费了4个小时时间。人生苦短啊。

硬件环境:
NVIDIA Grid K2 显卡

centos7 1805

1.先确认你是否安装了NVIDIA显卡,如果没有,则不用继续,本文章专门给CUDA开发,必须用NVIDIA显卡。

2.先安装好 Linux CentOS 7.5操作系统,我安装的有图形界面的。因为者台是类似工作站的高性能服务器,平时开发测试用的。

3.查看系统内核版本

uname -r

3.10.0-957.1.3.el7.x86_64
#不同操作系统的内核版本会不一样,最好记住它

df ; 确认 boot 目录的空间不少于 300 MB

  1. 屏蔽 nouveau 驱动 同时 关闭 teamviewer, vnc 等会用到图形资源的程序。
    nouveau 是系统自带的一个显示驱动程序,需要先将其禁用,然后再进行下一步操作,否则在安装显卡驱动时,会提示:You appear to be running an X server …,然后安装失败。分别打开如下两个文件(如果没有就创建一个),并在其中输入如下两句,然后保存。

vi /etc/modprobe.d/nvidia-installer-disable-nouveau.conf

添加内容:
blacklist nouveau
options nouveau modeset=0

vi /lib/modprobe.d/nvidia-installer-disable-nouveau.conf

添加内容
blacklist nouveau
options nouveau modeset=0

重做 initramfs 镜像
这一步需要确保 boot 文件目录的空间足够,否则会失败。建议大于 400 MB

mv /boot/initramfs-(unamer).img/boot/initramfs(uname -r).img /boot/initramfs-(uname -r).img.bak

dracut /boot/initramfs-$(uname -r).img $(uname -r)

重启
如果之前在图形界面操作,需要改为终端模式,runlevel 改为 3

systemctl set-default multi-user.target

init 3

reboot

下载驱动:

CUDA在Centos7.5上的成功安装经历

点击Search

CUDA在Centos7.5上的成功安装经历

点击download 下载,
放到/root/目录下
NVIDIA-Linux-x86_64-367.128.run

执行安装
从命令行以root用户执行
./NVIDIA-Linux-x86_64-367.128.run
CUDA在Centos7.5上的成功安装经历

CUDA在Centos7.5上的成功安装经历

CUDA在Centos7.5上的成功安装经历

6 预安装组件
预安装一些必需的组件,需要联网

yum install gcc kernel-devel kernel-headers

CUDA在Centos7.5上的成功安装经历
./NVIDIA-Linux-x86_64-367.128.run --kernel-source-path=/usr/src/kernels/$(uname -r) -k $(uname -r)

检查驱动安装情况
执行如下两条语句,如果出现显卡的型号信息,说明驱动已经安装成功。

lspci |grep NVIDIA

CUDA在Centos7.5上的成功安装经历
CUDA在Centos7.5上的成功安装经历

查找对应的CUDA版本,这个必须准确,不符合的肯定用不了.
https://docs.nvidia.com/cuda/cuda-toolkit-release-notes/index.html
CUDA在Centos7.5上的成功安装经历

打开这个链接,找到对应的下载。

https://developer.nvidia.com/cuda-toolkit-archive
CUDA在Centos7.5上的成功安装经历
CUDA在Centos7.5上的成功安装经历

同样拷贝到/root/目录下,执行 rpm -i /root/cuda-repo-rhel7-8-0-local-8.0.44-1.x86_64.rpm
发现这个并没有安装,只是解开了而已,放在了cd /var/cuda-repo-8-0-local 目录下,
CUDA在Centos7.5上的成功安装经历
cd /var/cuda-repo-8-0-local; yum localinstall *.rpm -y

配置环境:

export PATH=/usr/local/cuda/binKaTeX parse error: Expected '}', got 'EOF' at end of input: {PATH:+:{PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda/lib64KaTeX parse error: Expected '}', got 'EOF' at end of input: …LIBRARY_PATH:+:{LD_LIBRARY_PATH}}

安装样本:
mkdir /root/cuda
cuda-install-samples-8.0.sh /root/cuda

测试:cd /root/cuda/NVIDIA_CUDA-8.0_Samples/1_Utilities/deviceQuery

make;
./deviceQuery

CUDA在Centos7.5上的成功安装经历

至此测试成功。

写个HelloWorld 测试验证一下.
编写应用验证:

[[email protected] t]# pwd
/root/t
[[email protected] t]# more helloworld2.cu
#include
#include <stdio.h>
global void myfirstkernel(void)
{
//blockIdx.x gives the block number of current kernel
printf(“Hello!!!I’m thread in block: %d\n”, blockIdx.x);
}

int main(void)
{
//A kernel call with 16 blocks and 1 thread per block
myfirstkernel << <64,1>> >();
//Function used for waiting for all kernels to finish
cudaDeviceSynchronize();
printf(“All threads are finished!\n”);
return 0;
}

nvcc helloworld2.cu -o helloworld2
./helloworld2

CUDA在Centos7.5上的成功安装经历

相关文章:

  • 2022-12-23
  • 2021-12-24
  • 2021-08-28
  • 2022-12-23
  • 2022-02-11
  • 2022-12-23
  • 2021-08-15
  • 2021-08-06
猜你喜欢
  • 2021-06-27
  • 2021-12-22
  • 2022-12-23
  • 2022-01-26
  • 2022-12-23
  • 2021-10-03
  • 2022-01-07
相关资源
相似解决方案