GPU Ant1裸金属服务器NVIDIA525+CUDA12.0装机和NCCL验证
【摘要】 GPU Ant1裸金属服务器NVIDIA525+CUDA12.0装机和NCCL验证
1. 替换apt源
sudo sed -i "s@http://.*archive.ubuntu.com@http://repo.huaweicloud.com@g" /etc/apt/sources.list
sudo sed -i "s@http://.*security.ubuntu.com@http://repo.huaweicloud.com@g" /etc/apt/sources.list
sudo apt update
2. 安装NVIDIA驱动
wget https://us.download.nvidia.com/tesla/525.105.17/NVIDIA-Linux-x86_64-525.105.17.run
chmod +x NVIDIA-Linux-x86_64-525.105.17.run
./NVIDIA-Linux-x86_64-525.105.17.run
3. 安装CUDA
wget https://developer.download.nvidia.com/compute/cuda/12.0.0/local_installers/cuda_12.0.0_525.60.13_linux.run
sudo sh cuda_12.0.0_525.60.13_linux.run
执行安装cuda时,弹出选择界面,要取消选择安装驱动,再执行安装
4.安装nvidia-fabricmanager(必须和驱动版本保持一致)
wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/nvidia-fabricmanager-525_525.105.17-1_amd64.deb
sudo dpkg -i ./nvidia-fabricmanager-525_525.105.17-1_amd64.deb
systemctl start nvidia-fabricmanager.service
5. 安装OFED驱动(镜像版本内核较低,只能使用4.9版本驱动)
ofed老版本卸载
cd /usr/sbin
./ofed_uninstall.sh
ofed驱动下载地址:https://network.nvidia.com/products/infiniband-drivers/linux/mlnx_ofed/
wget https://content.mellanox.com/ofed/MLNX_OFED-4.9-7.1.0.0/MLNX_OFED_LINUX-4.9-7.1.0.0-ubuntu20.04-x86_64.tgz
tar -zxvf MLNX_OFED_LINUX-4.9-7.1.0.0-ubuntu20.04-x86_64.tgz
cd MLNX_OFED_LINUX-4.9-7.1.0.0-ubuntu20.04-x86_64
apt-get install -y python3 gcc quilt build-essential bzip2 dh-python pkg-config dh-autoreconf python3-distutils debhelper make
./mlnxofedinstall --add-kernel-support --force
6. 安装nv-peer-memory
由于OFED驱动版本为4.9,因此只能安装1.1版本nv-peer-memory
下载 https://github.com/Mellanox/nv_peer_memory/tree/1.1-0 压缩包,上传至制作镜像服务器,并解压,执行下面命令进行安装
cd nv_peer_memory-1.1-0/
./build_module.sh
cd /tmp
tar xzf /tmp/nvidia-peer-memory_1.1.orig.tar.gz
cd nvidia-peer-memory-1.1
dpkg-buildpackage -us -uc
dpkg -i ../nvidia-peer-memory-dkms_1.1-0_all.deb
安装完成拷贝配置文件到系统路径中
cp /tmp/nvidia-peer-memory-1.1/nv_peer_mem.conf /etc/infiniband/
cp /tmp/nvidia-peer-memory-1.1/debian/tmp/etc/init.d/nv_peer_mem /etc/init.d/
查看nv-peer-memory状态
/etc/init.d/nv_peer_mem/ status
7. 设置openmpi环境变量至bashrc中
先使用如下命令查询openmpi版本号
ls /usr/mpi/gcc/
然后编辑~/.bashrc文件,在末尾行加入如下命令,版本号替换为上述命令查询的版本号
# 加入到~/.bashrc
export LD_LIBRARY_PATH=/usr/local/cuda/lib:usr/local/cuda/lib64:/usr/include/nccl.h:/usr/mpi/gcc/openmpi-4.0.3rc4/lib:$LD_LIBRARY_PATH
export PATH=$PATH:/usr/local/cuda/bin:/usr/mpi/gcc/openmpi-4.0.3rc4/bin
8. 安装docker
curl https://get.docker.com | sh && sudo systemctl --now enable docker
9. 安装nvidia-container-toolkit
配置nvidia-container-toolkit
distribution=$(. /etc/os-release;echo $ID$VERSION_ID) && curl -fsSL https://nvidia.github.io/libnvidia-container/gpgkey | sudo gpg --dearmor -o /usr/share/keyrings/nvidia-container-toolkit-keyring.gpg && curl -s -L https://nvidia.github.io/libnvidia-container/$distribution/libnvidia-container.list | sed 's#deb https://#deb [signed-by=/usr/share/keyrings/nvidia-container-toolkit-keyring.gpg] https://#g' | sudo tee /etc/apt/sources.list.d/nvidia-container-toolkit.list
安装nvidia-container-toolkit
apt-get update
apt-get install -y nvidia-container-toolkit
nvidia-ctk runtime configure --runtime=docker
systemctl restart docker
10. 安装nccl
wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/cuda-keyring_1.0-1_all.deb
sudo dpkg -i cuda-keyring_1.0-1_all.deb
sudo apt update
sudo apt install libnccl2=2.16.2-1+cuda12.0 libnccl-dev=2.16.2-1+cuda12.0
11. 安装nccl-test
通过 ls /usr/mpi/gcc/ 查看openmpi的具体版本
cd /root
git clone https://github.com/NVIDIA/nccl-tests.git
cd ./nccl-tests
make MPI=1 MPI_HOME=/usr/mpi/gcc/openmpi-4.0.3rc4 -j 8
12. 测试验证
a. 验证docker内使用gpu和cuda
拉取pytorch官方镜像
docker run -ti --runtime=nvidia --gpus all pytorch/pytorch:latest bash
在容器中执行nvidia-smi验证gpu
在python中执行如下命令验证cuda
python
import torch
torch.cuda.is_available()
b. nccl测试
单机测试:
/root/nccl-tests/build/all_reduce_perf -b 8 -e 1024M -f 2 -g 8
多机测试:
mpirun --allow-run-as-root --hostfile hostfile -mca btl_tcp_if_include eth0 -mca btl_openib_allow_ib true -x NCCL_DEBUG=INFO -x NCCL_IB_GID_INDEX=3 -x NCCL_IB_TC=128 -x NCCL_ALGO=RING -x NCCL_IB_HCA=^mlx5_bond_0 -x LD_LIBRARY_PATH -x NCCl_IB_QPS_PER_CONNECTION=4 /root/nccl-tests/build/all_reduce_perf -b 8 -e 11g -f 2 -g 8
配置hostfile
#主机私有Ip 单节点进程数
192.168.20.1 slots=1
192.168.20.2 slots=1
配置免密登录:
#一直yes,生成公钥和私钥
ssh-keygen
#输入另一台机器ip地址及密码,配置免密
ssh-copy-id -i ~/.ssh/id_rsa.pub root@192.168.1.1
#测试免密
ssh root@192.168.1.1
【版权声明】本文为华为云社区用户原创内容,转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息, 否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)