cuda - 在 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
我希望它像这段代码一样工作。
您有任何样品或文件可供参考吗?
解决方案
您可以在每次内核调用之前使用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
推荐阅读
- windows - windows visual studio git configuration can not change remote to use https
- php - 上传文件时如何获取id
- python - Python Prime Number for-else 范围
- kotlin - Is there posibility to disable "string templates"?
- pointers - invalid memory address in Golang
- c# - C# Multithreading conflicts on shared variables
- c - 循环遍历 C 中的索引
- windows - How to resolve IP Addresses into Hostnames in Windows Kernel Driver
- php - PHP 将主页徽标链接到主页(来自 wordpress.org 的预制主题)
- java - 我在修复继承中的“getter”和“setter”时遇到问题