且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

CUDA:如何将多个重复的参数传递给CUDA内核

更新时间:2022-05-14 23:30:38

内核参数通过常量内存(或sm_1x中的共享内存)传递,因此没有您建议的复制。

Kernel arguments are passed in via constant memory (or shared memory in sm_1x), so there is no replication as you suggest.

cf 计划指南


__ global__函数参数传递给设备:

__global__ function parameters are passed to the device:


  • 存储器并且在计算能力1.x,

  • 的设备上通过常数内存限制为256字节,并且在设备上限制为4KB计算能力2的
    .x和更高版本。

当然,如果您随后在代码中修改一个变量,您正在修改本地副本(根据C标准),因此每个线程都将有自己的副本,无论是在寄存器中,或者如果需要,在堆栈上。

Of course, if you subsequently modify one of variable in your code then you're modifying a local copy (as per the C standard) and hence each thread will have its own copy, either in registers or, if needed, on the stack.