Hi,
I’m a CUDA beginner and i have some strange issues with my code…
Kernel:
__global__ void _testkernel( unsigned int* debug){
unsigned int idx = threadIdx.x;
++debug[idx];
}
Host:
{
unsigned int block_size = 512;
unsigned int* d_debug;
CUDA_SAFE_CALL( cudaMalloc((void**)&d_debug, block_size*sizeof( unsigned int)));
CUDA_SAFE_CALL( cudaMemset(d_debug,0,block_size*sizeof(unsigned int)));
dim3 dimBlock; dimBlock.x = block_size;
dim3 dimGrid; dimGrid.x = 512;
_testkernel<<< dimGrid, dimBlock>>>(d_debug);
CUDA_SAFE_THREAD_SYNC();
// check for error
cudaError_t error1 = cudaGetLastError();
if(error1 != cudaSuccess)
{
// print the CUDA error message and exit
printf("CUDA error: %s\n", cudaGetErrorString(error1));
}
unsigned int * h_debug;
CUDA_SAFE_CALL( cudaMallocHost(&h_debug, block_size*sizeof(unsigned int)));
CUDA_SAFE_CALL( cudaMemcpy(h_debug, d_debug, block_size*sizeof(unsigned int), cudaMemcpyDeviceToHost));
for(unsigned int bt=0; bt<block_size;++bt){
std::cerr << h_debug[bt] << ";";
}
}
this is what i expected:
512;512;512;512;512;512;512;512;512;512;512;512;512;512;512;512;512;512;512;512;512;512;512;512;512;512;512;512;512;512;512;512;[...]
512;512;512;512;512;512;512;512;512;512;512;512;512;512;512;512;512;512;512;512;512;512;512;512;512;512;512;512;512;512;512;512;
and this is what i get:
20;20;20;20;20;20;20;20;20;20;20;20;20;20;20;20;20;20;20;20;20;20;20;20;20;20;20;20;20;20;20;20;
21;21;21;21;21;21;21;21;21;21;21;21;21;21;21;21;21;21;21;21;21;21;21;21;21;21;21;21;21;21;21;21;
19;19;19;19;19;19;19;19;19;19;19;19;19;19;19;19;19;19;19;19;19;19;19;19;19;19;19;19;19;19;19;19;
18;18;18;18;18;18;18;18;18;18;18;18;18;18;18;18;18;18;18;18;18;18;18;18;18;18;18;18;18;18;18;18;
17;17;17;17;17;17;17;17;17;17;17;17;17;17;17;17;17;17;17;17;17;17;17;17;17;17;17;17;17;17;17;17;
15;15;15;15;15;15;15;15;15;15;15;15;15;15;15;15;15;15;15;15;15;15;15;15;15;15;15;15;15;15;15;15;
18;18;18;18;18;18;18;18;18;18;18;18;18;18;18;18;18;18;18;18;18;18;18;18;18;18;18;18;18;18;18;18;
16;16;16;16;16;16;16;16;16;16;16;16;16;16;16;16;16;16;16;16;16;16;16;16;16;16;16;16;16;16;16;16;
16;16;16;16;16;16;16;16;16;16;16;16;16;16;16;16;16;16;16;16;16;16;16;16;16;16;16;16;16;16;16;16;
14;14;14;14;14;14;14;14;14;14;14;14;14;14;14;14;14;14;14;14;14;14;14;14;14;14;14;14;14;14;14;14;
16;16;16;16;16;16;16;16;16;16;16;16;16;16;16;16;16;16;16;16;16;16;16;16;16;16;16;16;16;16;16;16;
17;17;17;17;17;17;17;17;17;17;17;17;17;17;17;17;17;17;17;17;17;17;17;17;17;17;17;17;17;17;17;17;
17;17;17;17;17;17;17;17;17;17;17;17;17;17;17;17;17;17;17;17;17;17;17;17;17;17;17;17;17;17;17;17;
19;19;19;19;19;19;19;19;19;19;19;19;19;19;19;19;19;19;19;19;19;19;19;19;19;19;19;19;19;19;19;19;
19;19;19;19;19;19;19;19;19;19;19;19;19;19;19;19;19;19;19;19;19;19;19;19;19;19;19;19;19;19;19;19;
20;20;20;20;20;20;20;20;20;20;20;20;20;20;20;20;20;20;20;20;20;20;20;20;20;20;20;20;20;20;20;20;
I have no Idea what I’m doing wrong. Can someone help me please.
OS: openSUSE Tumbleweed 64bit
GeForce GTX 570
Driver Version: 295.59
CUDA Toolkit 4.2.9