在GPU之间开启P2P通信功能后,就可以进行拷贝数据了
for (int i=0; i<100; i++)
{
// With UVA we don't need to specify source and target devices, the
// runtime figures this out by itself from the pointers
// Ping-pong copy between GPUs
if (i % 2 == 0)
{
checkCudaErrors(cudaMemcpy(g1, g0, buf_size, cudaMemcpyDefault));
}else{
checkCudaErrors(cudaMemcpy(g0, g1, buf_size, cudaMemcpyDefault));
}
}
注意 P2P通信是单向的