Wednesday, September 10, 2014

be careful not to mix (early) return and barriers

A common practice (and who here has always a perfect [integer] global/local size ratio) is to create a padded global size and then within an opencl thread check for if the global_id() < some limit and return otherwise. What happens if there is a barrier later on in the code as shown below:

if global_id < some limit
    return
end

... do something ...

barrier(CLK_LOCAL_MEM_FENCE);


In this case the kernel may run or not. Specs say "All work-items in a work-group executing the kernel on a processor must execute this function before any are allowed to continue execution beyond the barrier. This function must be encountered by all work-items in a work-group executing the kernel."

http://www.khronos.org/registry/cl/sdk/1.0/docs/man/xhtml/barrier.html

Either pad the arrays being acted on or do a conditional if global_id < some limit (run code) end everywhere