Results 1 to 5 of 5

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

  1. #1
    Junior Member
    Join Date
    May 2012
    Posts
    25

    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?

    Thanks!

  2. #2
    Senior Member
    Join Date
    Aug 2011
    Posts
    271

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

    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.

  3. #3
    Junior Member
    Join Date
    May 2012
    Posts
    25

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

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

    Quote Originally Posted by notzed
    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.

  4. #4
    Senior Member
    Join Date
    Aug 2011
    Posts
    271

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

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

    Quote Originally Posted by linyufly
    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...

    Quote Originally Posted by notzed
    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.

  5. #5
    Junior Member
    Join Date
    May 2012
    Posts
    25

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

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

    Thanks!

    Quote Originally Posted by notzed
    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).

    Quote Originally Posted by linyufly
    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...

    Quote Originally Posted by notzed
    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.

Similar Threads

  1. Do I need atomic_add in that case?
    By linyufly in forum OpenCL
    Replies: 6
    Last Post: 09-10-2012, 02:12 PM
  2. atomic_add for local variable
    By perlish in forum OpenCL
    Replies: 0
    Last Post: 09-02-2012, 10:52 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •