M.K*_*isu 3 c multithreading cuda multi-gpu
我目前将算法移植到两个GPU.硬件具有以下设置:
我在主机上创建了两个线程来控制GPU.线程每个都绑定到NUMA节点,即两个线程中的每一个都在一个CPU插槽上运行.如何确定GPU的数量,以便我可以使用cudaSetDevice()
?选择直接连接的GPU ?
正如我在评论中提到的,这是一种CPU GPU亲和力.这是我一起攻击的bash脚本.我相信它会在RHEL/CentOS 6.x操作系统上提供有用的结果.它可能无法在许多旧的或其他Linux发行版上正常工作.您可以像这样运行脚本:
./gpuaffinity > out.txt
Run Code Online (Sandbox Code Playgroud)
然后out.txt
,您可以读入程序以确定哪些逻辑CPU核心对应于哪些GPU.例如,在具有两个6核处理器和4个GPU的NUMA Sandy Bridge系统上,示例输出可能如下所示:
0 03f
1 03f
2 fc0
3 fc0
Run Code Online (Sandbox Code Playgroud)
该系统有4个GPU,编号从0到3.每个GPU编号后跟一个"核心掩码".核心掩码对应于与该特定GPU"接近"的核心,表示为二进制掩码.因此对于GPU 0和1,系统中的前6个逻辑核(03f二进制掩码)最接近.对于GPU 2和3,系统中的第二个6个逻辑核心(fc0二进制掩码)最接近.
您可以在程序中读取文件,也可以使用脚本中说明的逻辑在程序中执行相同的功能.
您也可以像这样调用脚本:
./gpuaffinity -v
Run Code Online (Sandbox Code Playgroud)
这会产生稍微冗长的输出.
这是bash脚本:
#!/bin/bash
#this script will output a listing of each GPU and it's CPU core affinity mask
file="/proc/driver/nvidia/gpus/0/information"
if [ ! -e $file ]; then
echo "Unable to locate any GPUs!"
else
gpu_num=0
file="/proc/driver/nvidia/gpus/$gpu_num/information"
if [ "-v" == "$1" ]; then echo "GPU: CPU CORE AFFINITY MASK: PCI:"; fi
while [ -e $file ]
do
line=`grep "Bus Location" $file | { read line; echo $line; }`
pcibdf=${line:14}
pcibd=${line:14:7}
file2="/sys/class/pci_bus/$pcibd/cpuaffinity"
read line2 < $file2
if [ "-v" == "$1" ]; then
echo " $gpu_num $line2 $pcibdf"
else
echo " $gpu_num $line2 "
fi
gpu_num=`expr $gpu_num + 1`
file="/proc/driver/nvidia/gpus/$gpu_num/information"
done
fi
Run Code Online (Sandbox Code Playgroud)
nvidia-smi 工具可以告诉 NUMA 机器上的拓扑。
% nvidia-smi topo -m
GPU0 GPU1 GPU2 GPU3 CPU Affinity
GPU0 X PHB SOC SOC 0-5
GPU1 PHB X SOC SOC 0-5
GPU2 SOC SOC X PHB 6-11
GPU3 SOC SOC PHB X 6-11
Legend:
X = Self
SOC = Connection traversing PCIe as well as the SMP link between CPU sockets(e.g. QPI)
PHB = Connection traversing PCIe as well as a PCIe Host Bridge (typically the CPU)
PXB = Connection traversing multiple PCIe switches (without traversing the PCIe Host Bridge)
PIX = Connection traversing a single PCIe switch
NV# = Connection traversing a bonded set of # NVLinks
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
2528 次 |
最近记录: |