In my kernel, each work item has a reserved memory region in a buffer that only it writes to and reads from. |
Is it necessary to use memory barriers in this case?
Solved! Go to Solution.
No, it's not needed.
You can even store the data interleaved, it doesn't needed to separate those memory regions either.
No, it's not needed.
You can even store the data interleaved, it doesn't needed to separate those memory regions either.
THanks! So, I don't even need a memory fence ?
You only need it to synchronize 'communication' across multiple threads:
For example:
if(globalId=123) write x;
if(globalId=254) read x;
It is not guaranteed that thread thread123's write will be executed before thread254's read, so there is a chance that thread254 will not able to read the value that thread123 will write in the future. So you can put a barrier between them and the barrier will pause thread254 until thread 123 finished writing x.
Thanks again. My concern is about a single work item that is writing to global memory, then reading it back in:
kernel void foo(global uchar* buffer) {
uchar temp = 12345;
buffer[0] = temp;
.
.
mem_fence(CLK_GLOBAL_MEM_FENCE); // ?????
uchar temp2 = buffer[0];
}
Do I need a mem_fence() after the store, so that the read is coherent ?