Question

Hello Everybody, as an example consider two openCL kernel one kernel let us say add and other is sub.

the add kernel is

__kernel void add(global int *output1,global int *input1,global int *input2
    /* Put other parameters here */
    ) 
       {
    int i = get_global_id(0);
    output1[i] = input1[i] + input2[i];
       }

the sub kernel is

__kernel void add(global int *output2,global int *input1,global int *input2
    /* Put other parameters here */
    ) 
        {
    int i = get_global_id(0);
    output2[i] = input1[i] - input2[i];
       }

for these two kernels whose 2 inputs are same i need to copy same inputs(input1 & input2) twice to the device from host memory and that may add some cost in terms of performance.
Is there any way so that i can copy the data once and re-utilize it in any function till i am not releasing the memory?

Was it helpful?

Solution

Making this an answer since it seems to fully answer the question.

You normally create the buffer in device memory, and you can reuse these buffers by redefining the kernel arguments via clSetKernelArg() (unless, of course, you want to use them at the same time which is trickier, and I'm not sure it's even allowed by the OpenCL standard in fact).

OTHER TIPS

You should use GL_interopeting ability. You use this for communication between opencl and opengl. Your openCL wouldnt delete an openGL vertex buffer object (VBO) after termination, would it? But this kind of kernel is harder to write and could need jogl files too!

cl_mem clCreateFromGLBuffer(cl_context context, cl_mem_flags flags, 
                        GLuint vbo_desc, cl_int *err)

Creates the object for gl-cl sharing.

glFinish();
clEnqueueAcquireGLObjects(queue, 1, &buff, 0, NULL, NULL);

clEnqueueNDRangeKernel(queue, proc, 1, NULL, global_size, local_size, 0, NULL, NULL);

clEnqueueReleaseGLObjects(queue, 1, &buff, 0, NULL, NULL);
clFinish();

is an example for this execution. Taken from: http://www.dyn-lab.com/articles/cl-gl.html

So you dont have to copy buffers to host every time.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top