I'm trying to display kernel progress by incrementing a value in int pointer. My kernel is very simple:
Code :
__kernel void raycastHeightmap(__read_only  image2d_t srcImg,
                       __global int* totalProgress)

I execute the kernel n number of times to prevent Windows watchdog kicking my kernel out:
Code :
int[] mapBakeProgress = new int[1];
Cl.Mem progressBuffer = Cl.CreateBuffer(_context, Cl.MemFlags.CopyHostPtr | Cl.MemFlags.WriteOnly, (IntPtr)(sizeof(int)), mapBakeProgress, out error);
CheckErr(error, "Cl.CreateBuffer");
error = Cl.SetKernelArg(kernel, 0, (IntPtr)intPtrSize, progressBuffer);
CheckErr(error, "Cl.SetKernelArg");
IntPtr[] workGroupSizePtr = new IntPtr[] { (IntPtr)128, (IntPtr)128, (IntPtr)64};
for (int i = 0; i < 64; i++) {
	error = Cl.EnqueueNDRangeKernel(cmdQueue, kernel, 3, null, workGroupSizePtr, null, 0, null, out clevent);
	CheckErr(error, "Cl.EnqueueNDRangeKernel");
	error = Cl.Finish(cmdQueue);
	CheckErr(error, "Cl.Finish");
	//Update progress
	error = Cl.EnqueueReadBuffer(
		cmdQueue, progressBuffer, Cl.Bool.False, IntPtr.Zero,
		new IntPtr(sizeof(int)),
		mapBakeProgress, 0, null, out clevent);
	CheckErr(error, "Cl.EnqueueReadBuffer");
	Console.Writeline("Progress: " + mapBakeProgress[0]);

As far as I understand my progress should get increased by 128*128*64 = 1048576 (total work group size) with every iteration in my host application. However I'm getting totally random numbers like:
Code :
Progress: 588
Progress: 1173
Progress: 1758
Progress: 2352

And what's even more strange, those numbers change every time I relaunch my application.

What's wrong with my code and how can I make it properly update the progress value with every kernel execution?