OpenCL synchronization between work-groups

。_饼干妹妹 提交于 2019-12-23 07:38:29

问题


Is it possible to synchronize OpenCL work-groups?

For example, I have 100 work-groups every work-groups have only one item (don't ask me why, this is an example), and I need to put barrier to every work-item which ensure that all work-groups will be continue after every work-item in this 100 work-groups reaches this barrier point.


回答1:


No, you can't. You can synchronize threads inside a group, and you can synchronize kernel executions inside a command queue.

You may be able to synchronize a small number of groups as long as they are all executed simutaneously, using atomic accesses. But it will freeze if some groups are scheduled later, and you have no control on this.




回答2:


In a word, no you can't. The OpenCL paradigm is a data parallel one where workgroups are intended to be independent. The only workgroup scope synchronization mechanism is at the command queue level, ie. separate kernel launches. If you algorithm can't accommodate that, you either need a new algorithm, or use a different programming model.

You need to keep in mind that there are often far more workgroups than hardware to execute them simultaneously. Synchronization in such cases is impossible. There are ways to implement a spinlock or critical section across a hardware dependent number of work groups using atomic memory access primitives, however they are really an abuse of the programming model and tend to only be useful where there is relatively little interaction between workgroups.



来源:https://stackoverflow.com/questions/5895001/opencl-synchronization-between-work-groups

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!