0

I happen to come across __threadfence() in CUDA manual! What is __threadfence() and how is it useful? also can we use __threadfence() to simulate a block level syncronization?

0

1 Answer 1

1

Modern architectures have a relaxed memory model, this means that the memory accesses are not necessarily executed in the order they appear in the program.

The Threadfence instruction is actually a memory fence - it assures that memory accesses appearing before the fence are actually executed before the fence. As you probably saw in the manual there are 3 variations of the fence dealing with shared (block) memory, global memory and host memory.

__syncthreads by the other hand offer block level syncronization ie threads in the block will wait. Note that __syncthreads also acts as a memory fence for the threads in the same block.

The example from the manual is a good illustration.

Check out the responses from the nv forum too https://devtalk.nvidia.com/default/topic/412600/trying-to-understand-memory-fence-function-example/

Not the answer you're looking for? Browse other questions tagged or ask your own question.