In CUDA PTX, what does %warpid mean, really?

时间:2016-07-11 22:11:35

标签: cuda ptx

IN CUDA PTX, there's a special register which holds a thread's warp's index: %warpid. Now, the spec says:

Note that %warpid is volatile and returns the location of a thread at the moment when read, but its value may change during execution, e.g., due to rescheduling of threads following preemption.

Umm, what location is that? Shouldn't it be the location within the block, e.g. for a 1-dimensional grid %tid.x / warpSize? Is it some slot-for-a-warp within the SM (e.g. warp scheduler or some internal queue)? I'm confused.

Motivation: I wanted to spare myself the trouble of calculating %tid.x / warpSize as well as free up a register, by using this special register.

1 个答案:

答案 0 :(得分:4)

您需要阅读在您在问题中发布的报价后直接跟随的文档的下25个字:

  

出于这个原因,应该使用%ctaid和%tid来计算虚拟   warp索引,如果内核代码中需要这样的值;

然后

  

%warpid主要用于启用性能分析和诊断代码   样本和日志信息,例如工作场所映射和负载   分布。

所以不,你不能用它来做你想要的。 %warpid实际上是一个调度程序插槽ID ,而不是一个块中的常量,唯一的warp索引。