# Missing Kernel executions

**URL:** <https://forums.developer.nvidia.com/t/missing-kernel-executions/27035>\
**Category:** CUDA Programming and Performance\
**Created:** [June 27, 2012, 9:27am UTC](https://forums.developer.nvidia.com/t/missing-kernel-executions/27035 "2012-06-27T09:27:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![OnkelDagobert](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@OnkelDagobert](https://forums.developer.nvidia.com/u/OnkelDagobert)\
**Post date:** [June 27, 2012, 9:27am UTC](https://forums.developer.nvidia.com/t/missing-kernel-executions/27035/1 "2012-06-27T09:27:30Z")

</div>

Hi,

I’m a CUDA beginner and i have some strange issues with my code…

Kernel:

```auto
__global__ void _testkernel( unsigned int* debug){

	unsigned int idx = threadIdx.x;

	++debug[idx];	

}

```

Host:

```auto
{

	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:

```auto
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:

```auto
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

---

<div class="post-metadata">

**Author:** ![tera](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@tera](https://forums.developer.nvidia.com/u/tera)\
**Post date:** [June 27, 2012, 9:53am UTC](https://forums.developer.nvidia.com/t/missing-kernel-executions/27035/2 "2012-06-27T09:53:38Z")

</div>

You need to use atomic operations for the increment, because multiple blocks will execute in parallel.

---

<div class="post-metadata">

**Author:** ![OnkelDagobert](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@OnkelDagobert](https://forums.developer.nvidia.com/u/OnkelDagobert)\
**Post date:** [June 27, 2012, 10:13am UTC](https://forums.developer.nvidia.com/t/missing-kernel-executions/27035/3 "2012-06-27T10:13:24Z")

</div>

thx it worked
