When I want to use atomic_add, what should I do?

Hi guys,

(1) I should declare the array to be volatile, right?
(2) I should put #pragma OPENCL EXTENSION cl_khr_global_int32_base_atomics : enable in the top of the *.cl file, right?

What else should I do?

I use atomic_add(array + index, value), is it OK or should I use atomic_add(&array[index], value); instead?


I think ‘yes’ to all three.

But really - these questions are easily tested by trying it. It wont compile or wont work if you get it wrong.

I was confused because even if I use #pragma OPENCL EXTENSION cl_khr_int32_base_atomics : disable or #pragma OPENCL EXTENSION asdfsadfads : require it still compile… And I seem to receive some confusing result by atomic_add…

IIRC opencl 1.2 includes atomics automatically.

If invalid pragmas still work, well maybe that’s a bug in the compiler (although i don’t know if the spec requires them to fail or not).


Mine is OpenCL 1.1, is it also supposed to include atomics without #pragma?