enqueueWriteImage在GPU上失败

时间:2012-08-08 14:39:04

标签: opencl gpgpu

我正在开发一些与图像缓冲区配合使用的内核。问题是当我通过直接复制图像数据来创建我的Image2D时,一切都运行良好。

如果我尝试将写入队列写入我的图像缓冲区,它将无法用于我的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上工作得很好。

为了使其正常工作,我必须通过使用CL_MEM_COPY_HOST_PTR直接传递数据来释放缓冲区图像并创建一个新图像。 我使用了良好的数据格式:CL_RGBA,CL_UNSIGNED_INT8,我的图像尺寸很好。

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

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

顺便说一下,我正在使用英特尔SDK for OpenCL(英特尔酷睿i7)和ATI AMD APP SDK(HD6800)。

[编辑]

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

首先,分配部分:

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上不起作用的部分:

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上运行但强制我重新创建缓冲区的部分:

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数组。我通过这段代码得到它:

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

上面的代码是在使用JOCL的java中,同样的问题出现在使用C ++ OpenCL Wrapper的另一个C ++程序中。唯一的区别是在Java中虚拟机崩溃(3~4帧后)和C ++中的结果是黑色图像。

1 个答案:

答案 0 :(得分:2)

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

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

所以,让你的司机保持最新!