enqueueWriteImage在GPU上失败 [英] enqueueWriteImage fail on GPU

查看:114
本文介绍了enqueueWriteImage在GPU上失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一些可用于图像缓冲区的内核.问题是,当我通过直接复制图像数据创建Image2D时,一切正常.

I am developing some kernels which works with image buffers. The problem is that when I create my Image2D by directly copying the data of the image, everything works well.

如果我尝试将对写缓冲区的写入队列,则不适用于我的GPU.

If I try to enqueue a write to my image buffer, it won't works for my GPU.

这是一个基本的内核:

__kernel void myKernel(__read_only image2d_t in, __write_only image2d_t out) {
    const int x = get_global_id(0);
    const int y = get_global_id(1);
    const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_CLAMP_TO_EDGE | CLK_FILTER_NEAREST;

    uint4 pixel = read_imageui(in, sampler, (int2)(x, y));
    write_imageui(out, (int2)(x, y), pixel);
}

好吧,那个简单的内核在我的GPU上给我一个黑色的图像,但是在我的CPU上运行良好.

Well, that simple kernel give me a black image on my GPU, but works well on my CPU.

要使其工作,我必须释放缓冲图像并通过直接使用CL_MEM_COPY_HOST_PTR传递数据来创建一个新图像. 我使用了良好的数据格式:CL_RGBA,CL_UNSIGNED_INT8,并且图像的大小也很好.

To make it works, I have to do release the buffer image and creating a new one by directly passing data using CL_MEM_COPY_HOST_PTR. I use the good data format : CL_RGBA, CL_UNSIGNED_INT8 and the size of my image is good.

JOCL和API的C ++绑定遇到问题. (我没有测试C API).

The problem has been encountered with JOCL and the C++ binding of the API. (I didn't test the C API).

最后,它通过重新创建缓冲区来运行,但这是一个好主意吗?这是正常的吗?我可以采取哪些措施来避免这种情况?

Finally, it runs by recreating the buffer, but is it a good idea ? Is it just normal ? Which actions can I perform to avoid it ?

顺便说一下,我正在运行OpenCL的Intel SDK(Intel Core I7)和ATI AMD APP SDK(HD6800).

By the way, I'm running on Intel SDK for OpenCL (Intel Core I7) and ATI AMD APP SDK (HD6800).

这是我用来在缓冲区中编写的代码.

Here is the code I use to write in my buffers.

首先,分配部分:

cl_image_format imageFormat = new cl_image_format();
imageFormat.image_channel_order = CL_RGBA;
imageFormat.image_channel_data_type = CL_UNSIGNED_INT8;

inputImageMem = clCreateImage2D(
    context, CL_MEM_READ_ONLY,
    new cl_image_format[]{imageFormat}, imageSizeX, imageSizeY,
    0, null, null);

运行时,每帧调用一个在GPU上不起作用的部分:

And when running, called for each frame, the part which doesn't work on GPU :

clEnqueueWriteImage(commandQueue, inputImageMem, CL_TRUE, new long[]{0, 0, 0},
        new long[]{imageSizeX, imageSizeY, 1}, 0, 0,
        Pointer.to(data), 0, null, null);

可以在GPU和CPU上运行的部分,但迫使我重新创建缓冲区:

The part which works on both GPU and CPU but force me to recreate the buffer :

clReleaseMemObject(inputImageMem);
cl_image_format imageFormat = new cl_image_format();
imageFormat.image_channel_order = CL_RGBA;
imageFormat.image_channel_data_type = CL_UNSIGNED_INT8;
inputImageMem = clCreateImage2D(context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, new cl_image_format[]{imageFormat}, imageSizeX, imageSizeY, 0, Pointer.to(data), null);

发送的数据是一个大小为imageSizeX*imageSizeY的int数组.我是通过以下代码得到的:

The data sent is an array of int of size imageSizeX*imageSizeY. I get it by this code :

DataBufferInt dataBuffer = (DataBufferInt)image.getRaster().getDataBuffer();
int data[] = dataBuffer.getData();

上面的代码是在Java中使用JOCL的,在使用C ++ OpenCL包装器的另一个C ++程序中也会出现相同的问题.唯一的区别是,在Java中,虚拟机崩溃(在3到4帧后),而在C ++中,结果是黑色图像.

The code above is in java using JOCL, the same problem appear in an another C++ program using the C++ OpenCL Wrapper. The only differences are that in Java the virtual machine crash (after 3~4 frames) and in C++ the result is a black image.

推荐答案

好,我发现了问题.那是我的司机表现得很奇怪.

Well, I found the problem. That was my drivers acting weird.

我使用的是12.4版本(我开始使用OpenCL时安装的版本),而我刚刚安装的是12.6版本,问题就消失了.

I was using the 12.4 version (the version I installed when I began to work with OpenCL) and I just installed the 12.6 version and the problem just disappeared.

因此,请确保您的驱动程序是最新的!

So, keep your drivers up to date !

这篇关于enqueueWriteImage在GPU上失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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