Results 1 to 3 of 3

Thread: OpenCL Image Read/Write problem

  1. #1
    Junior Member
    Join Date
    Mar 2012
    Posts
    2

    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
    Code :
    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:
    Code :
    this.output = CL.clCreateImage2D(
                    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.. 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

    Xor

  2. #2
    Senior Member
    Join Date
    Aug 2011
    Posts
    271

    Re: OpenCL Image Read/Write problem

    I think you're confusing the read_only and write_only qualifiers on the kernel arguments inside the opencl-c code.

    e.g. read/write only is needed here:
    kernel void foo(read_only image2d_t src, write_only image2d_t dst) {
    ...
    }

    But it doesn't matter that much for the image creation: these flags are really only hints to the implementation that might help it make access more efficient (but obviously what you do has to match every possible use of the buffer incase the implementation enforces it).

    Since you want to re-use the memory you probably want to just use read_write for the image/buffer creation; what you're proposing works fine.

  3. #3
    Junior Member
    Join Date
    Mar 2012
    Posts
    2

    Re: OpenCL Image Read/Write problem

    Thank you, fixed it now, it seems I really got it wrong when i read it.
    Anyway, solved!

Similar Threads

  1. Unittesting Image Read an write
    By clint3112 in forum OpenCL
    Replies: 1
    Last Post: 02-09-2013, 08:21 AM
  2. Replies: 1
    Last Post: 09-30-2011, 05:46 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •