cancel
Showing results for 
Search instead for 
Did you mean: 

Archives Discussions

boxerab
Challenger

Is global barrier necessary for memory region that only one work item uses ?

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?

0 Likes
1 Solution
realhet
Miniboss

No, it's not needed.

You can even store the data interleaved, it doesn't needed to separate those memory regions either.

View solution in original post

4 Replies
realhet
Miniboss

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 ?

0 Likes

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.

0 Likes

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 ?

0 Likes