Results 1 to 6 of 6

Thread: Passing 2 times the same buffer as input ?

  1. #1

    Passing 2 times the same buffer as input ?


    I'm reading an already existing OpenCL code and it's the first time I see the following.
    The code as different layers of complexity so it's difficult for me to really understand what's going on.
    But basically, I have the feeling that the author is passing a buffer as argument to a kernel 2 times : one time as read only and the other time as write only...
    It C++, the code would be something like that:

    Code :
    // Function
    void f(cont int * input, int * output){
    // Calling the function
    int * buffer;
    f(buffer, buffer);

    I thought that the compiler would complain and generate an error.
    But my concern is more about the performance...
    Have you already seen something like that? What do you think?



  2. #2
    Senior Member
    Join Date
    Oct 2012
    If the Buffer really is a Read Only Buffer, this should not work. If it is only defined as const in that function this may work. Is it a local funktion in the kernel or the kernelfunction itself?

  3. #3
    The kernel does something like that:

    Code :
    __kernel void myKernel(
    __global const float * input,
    __global float * output,
    int size) {
    output[i] = something * input[i];

  4. #4
    Senior Member
    Join Date
    Oct 2012
    hmm, this shouldn't work i think. but the compiler will not complain because he can't know that you are passing invalid arguments. The buffer definition mustn't be Read_Only

  5. #5
    Join Date
    Aug 2013
    In the code there should be a place using clCreateBuffer(), with CL_MEM_READ_ONLY / CL_MEM_WRITE_ONLY / CL_MEM_READ_WRITE. May be you could use CL_MEM_READ_WRITE and send only one arguement to let it read/write data. I would simply make 2 buffers to set one as an input, and the other one as an output.

  6. #6
    I get that My question is different. The code has been written by somebody else and there are like 10 layers of code above OpenCL.
    The way I see it is that the initial coder called a function where the input and the output buffers are the same OpenCL memory address.
    That's why I got confused. Why would anybody do this?
    Maybe, in the different layers under this function, one check if the memory addresses are the same and if yes use a different temporary buffer and then copy value back in the initial buffer.
    To be continued...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Proudly hosted by Digital Ocean