0

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?

EDIT:

I call mem_fence(CLK_GLOBAL_MEM_FENCE) before each write and before each read. Is this enough to guarantee load/store consistency?

Also, is this even necessary if only one work item is loading storing to this memory region ?

See this other stack overflow question:

In OpenCL, what does mem_fence() do, as opposed to barrier()?

Community
  • 1
  • 1
Jacko
  • 12,665
  • 18
  • 75
  • 126
  • Your question is too broad. Please describe what you are trying to achieve. From what you say the global barriers might not be necessary, but local (per group) ones might be needed. – Sergei Kulik Dec 29 '15 at 01:55

1 Answers1

0

The memory barriers work at a workgroup level, this is, stopping the threads belonging to the same block of threads until all of them reach the barrier. If there is not intersection between the memory spaces of different work items, there is not needed any extra synchronization point.

Also, is this even necessary if only one work item is loading storing to this memory region ?

Theoretically, mem_fence only guarantees the commit of the previous memory accesses before the later ones. In my case, I never saw differences in the results of applications using or not this mem_fence call.

Best regards

Moises Viñas
  • 1,073
  • 2
  • 7
  • 9