randy randy - 1 month ago 7
C Question

Block Level Atomic Write

is it possible to do an atomic write on the block level?

as an example consider the following:

__global__ kernel (int atomic)
{
atomic+=blockid.x; //should be atomic for each block
}

Answer

While unclear what you mean with block/block level, it sounds like you just need an atomic add. Those are found in the kernel in #include <asm/atomic.h> your code would be

__global__ kernel (int atomic)
{
    atomic_add(blockid.x,&atomic);
}

atomic would have to be of type atomic_t and blockid.x an int.