【发布时间】:2015-02-21 10:55:40
【问题描述】:
如果我想做一个 for 循环,其中有一个基于 CUDA 代码的计算,并且有一堆我不想在每次执行代码时在 CPU 和 GPU 之间来回传输的常量,有什么我可以做的吗?
例如:
float* a, *b, *c; // a, b, and c changes each time for loop is executed
int M, N; // M and N get their value prior to the for loop, and
// they do not change during the for loop
for (int n = 0; n < 100; n++)
{
CUDAComputation(a,b,c,M,N);
}
__global__ void CUDAComputation(double *a,
double *b,
double *c,
int M,
int N)
{
// cuda-based code
}
我想我可以在.cu代码中声明全局变量,其中包括我的头文件,但是M和N在全局内存中,谁访问CUDA应该很慢?或者我每次都必须cudamemcpy()M和N到内核?谢谢。
【问题讨论】:
标签: cuda