【发布时间】:2012-10-16 10:16:43
【问题描述】:
当我使用 cuda-gdb 为特定输入运行它时,我编写了一个由于设备非法地址而面临内核启动失败的代码。我使用 cuda-memcheck 运行它并得到 Invalid write of size 4 错误。代码太大,所以我将在这里解释场景。
我有一个主内核,我将一个用作堆栈的数组指针传递给它。 我有一个从主内核调用并使用堆栈的设备函数。
__device__ void find(int v , int* p, int* pv,int n, int* d_stackContents)
{
int d_stackTop;
d_stackTop = -1;
*pv = p[v];
if(*pv == -1){
*pv = v;
}
else{
cuPrintf("Stack top is %d\n",d_stackTop);
d_stackTop = d_stackTop + 1;
d_stackContents[d_stackTop] = v;
cuPrintf("Stack top is %d\n",d_stackTop);
while(*pv != -1){
d_stackTop = d_stackTop + 1;
d_stackContents[d_stackTop] = *pv;
cuPrintf("Stack top is %d\n",d_stackTop);
*pv = p[*pv];
}
}
错误发生在 d_stackContents[d_stackTop] = *pv;
我在主内核中调用设备函数如下:
find(v[idx], p,&pv,n, d_stackContents);
其中 idx = threadIdx.x + blockDim.x * blockIdx.x 并且我已将 pv 声明为 int pv;
此外,d_stackContents 数组使用 cudaMalloc 在 main 中分配,并作为参数传递给主内核
【问题讨论】:
标签: cuda