Search code examples
openclgpupyopencl

Where should I define a C function that will be called in C kernel code when using PYOPENCL


Since Kernel Code in PyOpenCl needs to be written only in C, I have written few functions that need to be called inside the Kernel code in PyOpenCL.Where should I store these functions? how to pass a global variable to that function. In PyOpenCl my kernel code looks like this:

program = cl.Program(context, """
        __kernel void Kernel_OVERLAP_BETWEEN_N_IP_GPU(__constant int *FBNs_array,__local int *Binary_IP, __local int *cc,__global const int *olp)
{
  function1(int *x, int *y,__global const int *olp);
}
    """).build()

Where should I write and store the function1 function. should I define it in kernel itself, or in some other file and provide a path. If i need to define it at some other place and provide a path, please provide me some details , I am completely new to C. Thanks


Solution

  • program = cl.Program(context, """
            void function1(int x, int *y,__global const int *cc)
            {
                x=10;
            }
    
            __kernel void kernel_name(__global const int *cc)
            {
                int x=1;
                int y[1]={10};
                function1(x,y,cc); //now x=10
            }""").build()