I’m having trouble trying to debug a simple piece of CUDA C code.
#include <stdio.h>
#include <stdlib.h>
#define N 256
__global__ void bitreverse(unsigned int *data)
{
unsigned int *idata=data;
unsigned int x=idata[threadIdx.x];
x=((0xf0f0f0f0&x) >> 4 | ((0x0f0f0f0f&x) << 4));
x=((0xcccccccc&x) >> 2 | ((0x33333333&x) << 2));
x=((0x55555555&x) >> 1 | ((0x55555555&x) << 1));
idata[threadIdx.x]=x;
}
int main(int argc, char **argv)
{
unsigned int *d=NULL;int i;
unsigned int idata[N],odata[N];
for(i=0;i<N;i++)
idata[i]=(unsigned int)i;
cudaMalloc((void**)&d,sizeof(int)*N);
cudaMemcpy(d,idata,sizeof(int)*N,cudaMemcpyHostToDevice);
bitreverse<<<1,N>>>(d);
cudaMemcpy(odata,d,sizeof(int)*N,cudaMemcpyHostToDevice);
for(i=0;i<N;i++)
printf("%u->%u\n",idata[i],odata[i]);
cudaFree((void*)d);
return 0;
}
I comile the c code :
nvcc -g -G test.cu -o test
I have three breakpoints at main, bitreverse and idata[threadIdx.x]=x.And then I run cuda-gdb test:
(cuda-gdb) run
Starting program: /home/uestc609/gdb/gdbtest1
[Thread debugging using libthread_db enabled]
[New process 5755]
[New Thread -1216379184 (LWP 5755)]
[Switching to Thread -1216379184 (LWP 5755)]
Breakpoint 1, main (argc=1, argv=0xbfcc1584) at gdbtest1.cu:23
23 unsigned int *d=NULL;int i;
(cuda-gdb) continue
Continuing.
fatal: All CUDA devices are used for X11 and cannot be used while debugging. (error code = 24)
I am a novice with CUDA .Can someone tell me what the problem is ?
Thank you for the help!