Bug: atomicInc() always inc's by one

I have been pulling my hair out trying to figure out why I couldn’t get the right output from a program. After tons of tracing in the debugger, I finally decided to verify the output of the cuda API function I was using, atomicInc(). This function takes two args, an address to increment and a value to increment by. It returns the old value.

I was incrementing by fives.

I was getting values back each time incremented by one.

Go figure…

Suggestions?

Can you post a concise, compilable, runnable repro-case demonstrating this behaviour?

How is the behavior you are reporting different from the documented behavior?

atomicInc(), as the name suggests, always increments by one. If you want to add anything else than a one, atomicAdd() is what you are looking for.

Ah, jeez… looks like I read the docs wrong:

unsigned int atomicInc(unsigned int* address, unsigned int val);

reads the 32-bit word old located at the address address in global or shared

memory, computes ((old >= val) ? 0 : (old+1)), and stores the result

back to memory at the same address. These three operations are performed in one

atomic transaction. The function returns old.

Edit: Incidentally, this explains why I keep seeing my counter get reset :) :)