OpenCL-两次传递image2d_t以从内核进行读取和写入? [英] OpenCL - Pass image2d_t twice to get both read and write from kernel?

查看:570
本文介绍了OpenCL-两次传递image2d_t以从内核进行读取和写入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的OpenCL内核中,我想读写image2d_t对象.根据OpenCL标准,我只能指定__read_only或__write_only. 但是,我想出如果我将相同的cl_mem发送给两个单独的内核参数(一个带有__read_only,另一个带有__write_only),则我可以两者都做.

In my OpenCL kernel I would like to both read and write to an image2d_t object. According to OpenCL standard I can only specify either __read_only or __write_only. However, I figured if I send the same cl_mem as two separate kernel arguments (one with __read_only and one with __write_only) I can do both.

可能是我先写又读,但可能会得到旧值(?),但就我而言,我希望先获取旧值,然后将其更新并写回到映像中.一个简单的示例是每个像素增加1".看起来它的使用率达到99.9%,但有时会给我带来伪影.

Probably when I do a write followed by a read, I might get the old value(?) but in my case I would like the old value first, update it and write it back to the image. A simple example would be "increment each pixel by 1". It looks like it works in 99.9% but gives me artifacts sometimes.

有人知道这是否完全可能,或者我是否必须期待不确定的行为?

Does anybody know if this is possible at all or if I have to expect undefined behaviour?

推荐答案

根据OpenCL标准,可以在一个内核中使用一个Image进行读取或写入.因此,如果需要读写相同的内存对象,则必须使用2个图像,或切换到常规Buffer.无法保证您的内核可以正常工作.

According to OpenCL standard, one Image can be used either for reading, or for writing within one kernel. So, if you need to read-write into same memory object, you have to use 2 Images, or switch to regular Buffer. No guarantee can be made that your kernel will work fine.

这篇关于OpenCL-两次传递image2d_t以从内核进行读取和写入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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