1

我一直在尝试调试我的代码,因为我知道内核中出了问题,并且我一直在试图找出具体是什么。如果我尝试进入内核,它似乎完全越过了内核功能,最终会导致退出时出错:

Single stepping until exit from function dyld_stub_cudaSetupArgument, 
which has no line number information. 
[Launch of CUDA Kernel 0 (incrementArrayOnDevice<<<(3,1,1),(4,1,1)>>>) on 
Device 0] 
[Termination of CUDA Kernel 0 (incrementArrayOnDevice<<<(3,1,1), 
(4,1,1)>>>) on Device 0] 
[Launch of CUDA Kernel 1 (fillinBoth<<<(40,1,1),(1,1,1)>>>) on Device 0] 
[Termination of CUDA Kernel 1 (fillinBoth<<<(40,1,1),(1,1,1)>>>) on Device 0] 
add (below=0x124400, newtip=0x124430, newfork=0x125ac0) at test.cu:1223 

如果我试图闯入内核,我的整个计算机都会崩溃,我必须重新启动它。

我认为我调用内核的方式一定有问题,但我不知道是什么。

代码比较长,我只摘录一段:

__global__ void fillinOne(seqptr qset, long max) {
    int i, j;
    aas aa;
    int idx = blockIdx.x;
    __shared__ long qs[3];
    if(idx < max) 
    {
        memcpy(qs, qset[idx], sizeof(long[3]));
        for (i = 0; i <= 1; i++)
        {
            for (aa = ala; (long)aa <= (long)stop; aa = (aas)((long)aa + 1))
            {
                if (((1L << ((long)aa)) & qs[i]) != 0)
                {
                    for (j = i + 1; j <= 2; j++)
                        qs[j] |= cudaTranslate[(long)aa - (long)ala][j - i];
                }
            }
        }
    }
}

//Kernel for left!= NULL and rt != NULL

void fillin(node *p, node *left, node *rt)
{

    cudaError_t err = cudaGetLastError();
    size_t stepsize = chars * sizeof(long);
    size_t sitesize = chars * sizeof(sitearray);
    //int i, j;
    if (left == NULL)
    {
        //copy rt->numsteps into p->numsteps--doesn't actually require CUDA, because no computation to do
        memcpy(p->numsteps, rt->numsteps, stepsize);
        checkCUDAError("memcpy");

        //allocate siteset (array of sitearrays) on device
        seqptr qsites;    //as in array of qs's
        cudaMalloc((void **) &qsites, sitesize);
        checkCUDAError("malloc");

        //copy rt->siteset into device array (equivalent to memcpy(qs, rs) but for whole array)
        cudaMemcpy(qsites, rt->siteset, sitesize, cudaMemcpyHostToDevice);
        checkCUDAError("memcpy");

        //do loop in device
        int block_size = 1; //each site operated on independently
        int n_blocks = chars;
        fillinOne <<< n_blocks, block_size>>> (qsites, chars);
        cudaThreadSynchronize();

        //put qset in p->siteset--equivalent to memcpy(p->siteset[m], qs)
        cudaMemcpy(p->siteset, qsites, sitesize, cudaMemcpyDeviceToHost);
        checkCUDAError("memcpy");

       //Cleanup
       cudaFree(qsites);
}

如果有人有任何想法,请回复!提前致谢!

4

1 回答 1

1

我想你有一个单卡配置。当您调试 cuda 内核并在其中中断时,您实际上使显示驱动程序处于暂停状态。这会导致您认为是崩溃。如果您只想在一张显卡上使用 cuda-gdb,您必须在命令行模式下使用它(不要启动 X 或从 X 中按 ctrl-alt-fn)。

如果您有两张卡,则必须运行卡中的代码而不运行显示。使用 cudaSelectDevice(n)。

于 2011-11-15T12:26:33.373 回答