// Set device 0 as currentcudaSetDevice(0); float* p0;size_t size = 1024 * sizeof(float);// Allocate memory on device 0cudaMalloc(&p0, size); // Set device 1 as currentcudaSetDevice(1); float* p1;// Allocate memory on device 1cudaMalloc(&p1, size); // Set device 0 as currentcudaSetDevice(0);// Launch kernel on device 0MyKernel<<<1000, 128>>>(p0); // Set device 1 as currentcudaSetDevice(1); // Copy p0 to p1cudaMemcpyPeer(p1, 1, p0, 0, size); // Launch kernel on device 1MyKernel<<<1000, 128>>>(p1);
想在两张3080上进行数据传输,目前没有nvlink,使用官方测试样例代码得到的结果如附件图片中所示,信息提示是不支持peer access,我在我的项目中使用的是这个帖子里面的without uva的函数代码https://stackoverflow.com/questions/22694518/what-is-the-difference-between-cudamemcpy-and-cudamemcpypeer-for-p2p-copy,程序代码: [选择]// Set device 0 as currentcudaSetDevice(0); float* p0;size_t size = 1024 * sizeof(float);// Allocate memory on device 0cudaMalloc(&p0, size); // Set device 1 as currentcudaSetDevice(1); float* p1;// Allocate memory on device 1cudaMalloc(&p1, size); // Set device 0 as currentcudaSetDevice(0);// Launch kernel on device 0MyKernel<<<1000, 128>>>(p0); // Set device 1 as currentcudaSetDevice(1); // Copy p0 to p1cudaMemcpyPeer(p1, 1, p0, 0, size); // Launch kernel on device 1MyKernel<<<1000, 128>>>(p1);结果也发现是会先拷贝到内存中,然后再拷贝到另一张卡上。但是我在群里提问,群里有[名词6]回复说是如果没有nvlink会走PCIE直接进行两张卡之间的通信,如果[名词6]的回答是正确的,那么是哪里出了问题呢?我该怎么实现P2P?
你好,从20系列的卡开始,您必须购买一块NVLink桥,才能实现直接卡到卡的P2P Access和Copy。而以前的老版本中,却是可以通过走PCI-E的(虽然慢点,但双向也有20多GB/s了)。现在不买桥是不能用的。请尽快买桥(不到1000元一个)。
我司之前的Sisiy妹子,曾经单独测试过这个问题,并且发过公众号,可能她会稍后回复你相应的公众号文章的地址。