首页 > 解决方案 > 有没有办法以编程方式知道我们的 CUDA 代码在哪个 GPU 上运行?

问题描述

我想知道我的 CUDA 内核将在哪个 GPU 上运行,以便我可以以编程方式决定要使用的最佳块大小,以最大限度地提高任何算法的 GPU 实现的性能。

标签: cudagpu

解决方案


Yes, the deviceQuery sample code demonstrates how to query the device for information such as the number of SMs which could be used to optimize kernel launch configuration.

In addition, CUDA provides an occupancy API which demonstrates how to construct thread block sizes that can yield highest occupancy. There is a sample code also.

If you have 3 GPU devices, and you don't make use of the cudaSetDevice() API in your code to select a particular GPU, then CUDA will run your code on the first GPU enumerated by CUDA, which is the same as the first GPU displayed by the deviceQuery sample code.


推荐阅读