PDA

View Full Version : When I want to use atomic_add, what should I do?



linyufly
11-05-2012, 04:04 PM
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?

Thanks!

notzed
11-05-2012, 06:24 PM
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.

linyufly
11-05-2012, 07:00 PM
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...


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.

notzed
11-05-2012, 07:15 PM
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).


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...


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.

linyufly
11-05-2012, 07:19 PM
Mine is OpenCL 1.1, is it also supposed to include atomics without #pragma?

Thanks!


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).


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...


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.