Click here to Skip to main content
15,881,559 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Have a good time

i have a problem in OpenCL 1.2.
Look, i have an array as global in the kernel and the group size is 1000.
The problem is that the atomic_add() function doesn't work correctly.

My kernel code is :

C++
buffer[3] = 100;
atomic_add(&buffer[3], 1);


if i create 1000 threads, i expect the value of buffer[3] will be 1100, am i right?
but the behavior of the program is undefined.
sometime it will be 1100, sometimes 1064, sometimes 1093 and ...

What I have tried:

i also enable the opencl extension like below :

#pragma OPENCL EXTENSION cl_khr_global_int32_base_atomics : enable


but the problem is still exists.
in the another project i'de create a simple opencl project and the atomic_add works currectly, and i've checked almost the entire of project configuraton but i don't know the problem where is.

can you help me?
thanks
Posted
Updated 14-May-17 21:18pm
v2

 
Share this answer
 
v2
Comments
Mahdi Nejadsahebi 26-Mar-17 8:04am    
Excuse me my friend
i can't findout my problem when i read the link that you've sent.
can you explain for me?
although i'm working with opencl 1.2.
thanks
Richard MacCutchan 26-Mar-17 12:45pm    
Sorry, I have never worked with OpenCL, but the chances are quite high that there is something in your code that is not correct.
Richard MacCutchan 26-Mar-17 12:47pm    
Where is buffer defined, and what type is it? Has it been initialised correctly as described in the documentation?
[no name] 26-Mar-17 14:12pm    
No vote from my side. But this is not an answer! Googled, choosed one of the first best hits, copied as answer, nothing more!
Richard MacCutchan 27-Mar-17 3:46am    
Please go away, you are being a child.
```
buffer[3] = 100;
```

is a race condition. Do it from CPU host side or another kernel.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900