Opencl atomic_add()函数返回错误的值 [英] Opencl atomic_add() function returns wrong value

查看:403
本文介绍了Opencl atomic_add()函数返回错误的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

玩得开心



i在OpenCL 1.2中有问题。

看,我在内核中有一个全局数组组大小是1000.

问题是atomic_add()函数无法正常工作。



我的内核代码是:



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 :

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





如果我创建1000个线程,我希望缓冲区[3]的值为1100,我是对的吗?

但是程序的行为是不确定的。

有时会是1100,有时是1064,有时是1093 ......



什么我试过了:



i也启用了如下的opencl扩展名:





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





但问题仍然存在。

in另一个项目我创建了一个简单的opencl项目,atomic_add目前正在工作,我几乎检查了整个项目配置,但我不知道问题在哪里。



你可以帮帮我吗?

谢谢



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

推荐答案

参见 OpenCL 2.0 Atomics Overview [ ^ ]。


```

buffer [3] = 100;

```



是竞争条件。从CPU主机端或其他内核执行。
```
buffer[3] = 100;
```

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


这篇关于Opencl atomic_add()函数返回错误的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆