OpenCL Image Read/Write problem

Hello

I’m trying to build a program that applies a certain amount of operations on an image, one after another.
To boost performance i would like to reuse the memory output from the first operation as input for the second operation without reading the memory from the gpu memory.

For example operation1 has IMG1 as input and stores IMG1OUT as output, still in gpu memory.
Now i want to use that part of the memory as input for operation2, and so on until i did all my operations.

The problem i stumbled upon was an INVALID_KERNEL_ARG, i figured it out but do not know how to solve it:

To make the first input memory i use the following memObject = clCreateImage2D(platform.getContext(), CL_MEM_READ_ONLY | CL_MEM_USE_HOST_PTR, new cl_image_format[]{imgformat}, width, height, width * Sizeof.cl_uint, Pointer.to(dataSrc), null);

As you can see the type of memory is set as READ_ONLY, while the output argument i give is WRITE_ONLY:

                platform.getContext(), CL_MEM_WRITE_ONLY,
                new cl_image_format[]{imageFormat}, imgWidth[0], imgHeight[0],
                0, null, null);```

The difference has to be made because of openCL specific stuff.. :P I read it somewhere ;)

Anyway, how can I use the output immediately again as input for the next operatiion? It would be stupid to read the image back into a bufferedImage into my workmemory and the reallocate again on my gpu memory.
That's just more datatransfer then needed i think.

There has to be a way to change the read/write flags or something like that.
I hope you can help me :)

kindly

Stef Janssens

Hello

I just had a quick look at this. Without checking the spec, I assume that the INVALID_KERNEL_ARG may be thrown when a READ_ONLY image is passed into a kernel for writing. Couldn’t this be solved by creating the image with CL_MEM_READ_WRITE instead of CL_MEM_READ_ONLY ?

Note that you may not pass the same image for reading AND writing to a kernel, i.e. in the kernel you have to specify arguments
read_only image2d_t inputImage
and
write_only image2d_t outputImage
and these have to point to different images. But I think that in both cases, the image can be one created with CL_MEM_READ_WRITE, so that the images may “swap their roles” between the kernel launches (without having to copy memory explicitly).

If it does not work, I’ll try to investigate this further, and create an example if possible.

bye
Marco

I always thought that the memory object can either be read or write. :o

Nevertheless, this most certainly helped me out, it did the trick. :wink:

Thank you!

Stef