首页 > 解决方案 > 在 cuda 10.0 中的多个 gpus 上运行每个内核函数

问题描述

// Four Kernel Runs Simultaneously
Kernel1 <<< numBlocks, threadPerBlock >>> (args); // GPU 0
Kernel2 <<< numBlocks, threadPerBlock >>> (args); // GPU 1
Kernel3 <<< numBlocks, threadPerBlock >>> (args); // GPU 2
Kernel4 <<< numBlocks, threadPerBlock >>> (args); // GPU 3

我希望它像这段代码一样工作。

您有任何样品或文件可供参考吗?

标签: cudagpu

解决方案


您可以在每次内核调用之前使用cudaSetDevice(int device) 。

__host__ ​cudaError_t cudaSetDevice ( int device ) 设置用于 GPU 执行的设备。

// Four Kernel Runs Simultaneously
cudaSetDevice(0);
Kernel1 <<< numBlocks, threadPerBlock >>> (args); // GPU 0
cudaSetDevice(1);
Kernel2 <<< numBlocks, threadPerBlock >>> (args); // GPU 1
cudaSetDevice(2);
Kernel3 <<< numBlocks, threadPerBlock >>> (args); // GPU 2
cudaSetDevice(3);
Kernel4 <<< numBlocks, threadPerBlock >>> (args); // GPU 3

推荐阅读