0 前言
教程以Ubuntu系统,显卡为GTX960为例。仅供参考。
1 CUDA安装教程
1.1 安装前的操作
1.1.1 验证是否具有支持CUDA的GPU
lspci | grep -i nvidia
# result :
01:00.0 VGA compatible controller: NVIDIA Corporation GM206 [GeForce GTX 960] (rev a1)
01:00.1 Audio device: NVIDIA Corporation Device 0fba (rev a1)
1.1.2 验证是否具有受支持的Linux版本
uname -m && cat /etc/*release
# result :
x86_64
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=16.04
DISTRIB_CODENAME=xenial
DISTRIB_DESCRIPTION="Ubuntu 16.04.6 LTS"
NAME="Ubuntu"
VERSION="16.04.6 LTS (Xenial Xerus)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 16.04.6 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/"
VERSION_CODENAME=xenial
UBUNTU_CODENAME=xenial
1.1.3 验证系统是否已安装gcc
gcc --version
# result :
gcc (Ubuntu 5.4.0-6ubuntu1~16.04.12) 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.
1.1.4 验证系统是否安装了正确的内核头文件和开发包
sudo apt-get install linux-headers-$(uname -r)
# result :
Reading package lists... Done
Building dependency tree
Reading state information... Done
linux-headers-4.4.0-142-generic is already the newest version (4.4.0-142.168).
linux-headers-4.4.0-142-generic set to manually installed.
0 upgraded, 0 newly installed, 0 to remove and 191 not upgraded.
1.2 安装CUDA
1.2.1 关闭nouveau

# 关闭nouveau后需要重启
sudo reboot
# 检查确保nouveau没有被加载
lsmod | grep nouveau
1.2.2 安装NVIDIA驱动

sudo sh NVIDIA-Linux-x86_64-450.80.02.run
# 查看驱动号
nvidia-smi

1.2.3 安装CUDA
根据本机配置选择对应的CUDA工具包

# 下载CUDA工具包
wget https://developer.download.nvidia.com/compute/cuda/11.1.0/local_installers/cuda_11.1.0_455.23.05_linux.run
# 安装CUDA
sudo sh cuda_11.1.0_455.23.05_linux.run
1.3 环境变量设置
export PATH=/usr/local/cuda-11.1/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda-11.2/lib\
${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
# 检查激活状态
systemctl status nvidia-persistenced
# 激活
sudo systemctl enable nvidia-persistenced
1.4 CUDA测试
cd /usr/local/cuda/samples/1_Utilities/deviceQuery
make
./deviceQuery

2 PGI安装
2.1 安装PGI
tar -xzcf pgixxx.tar.gz
sudo ./install

2.2 环境变量设置
export PGI=/opt/pgi
MANPATH=$MANPATH:$PGI/linux86-64/13.3/man
export PATH=$PGI/linux86-64/13.3/bin:$PATH
export LD_LIBRARY_PATH=/usr/lib:$PGI/linux86-64/13.3/lib:$LD_LIBRARY_PATH
2.3 PGI测试
测试Fortran代码:
b.f90
module b_m
integer , device :: b_d
end module b_m
a.f90
module a_m
integer,device :: a_d
contains
attributes(global) subroutine aPlusB()
use b_m
implicit none
a_d=a_d+b_d
end subroutine aPlusB
end module a_m
aPlusB.f90
program twoPlusThree
use a_m
use b_m
implicit none
integer :: a
a_d=2
b_d=3
call aPlusB <<<1,1>>>()
a=a_d
write(*,"('2+3=',i0)") a
end program twoPlusThree
编译:
pgf90 -Mcuda -c b.f90
pgf90 -Mcuda -c a.f90
pgf90 -Mcuda aPlusB.f90 a.o b.o
./a.out
#or
#pgf90 -c b.cuf
#pgf90 -c a.cuf
#pgf90 aPlusB.cuf a.o b.o
#./a.out

2.4 可能遇到的问题
2.4.1 gcc版本过高

# 增加gcc4.4版本的选择
update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.4 50
# 切换到4.4版本
update-alternatives --config gcc
# 确认当前版本
gcc --version

网友评论