global memory writing question


I’m wondering, is it possible to write to the same location in global memory more than once within the same kernel function?



Sure it is.

but what value would appear there could actualy be in-determinate… With so many threads executing the kernel without any synchronization, any value could appear there at the end depending on who wrote last.

Not necessarily. If the same thread is writing the same location twice (sequentially), then it’s determinate. Also, if you use synchronization in your kernel, then you can code it so the value is determinate.

But since you are writing twice to the same location within your kernel, there is probably a better way to do it. The only value you care about at the end of the kernel is the last one written to that location, so maybe it’d be better to keep the intermediate value in shared memory (or somewhere else) and only write to global memory once? Of course, I don’t know the exact aim of your application, so I can’t comment on exactly how this would be accomplished, but just some food for thought.