Results 1 to 5 of 5

Thread: Calling another (non kernel) function in kernel function

  1. #1
    Junior Member
    Join Date
    Apr 2014
    Posts
    17

    Calling another (non kernel) function in kernel function

    Hello everyone !
    Can I call a (non kernel)function in the kernel function? Its giving so many errors. Also can we call non kernel function recursively in a kernel function or in .cl file?? If yes then how?? Plz Reply ASAP.

  2. #2
    Senior Member
    Join Date
    Dec 2011
    Posts
    153
    You can't make recursive calls in OpenCL C.

  3. #3
    Junior Member
    Join Date
    Apr 2014
    Posts
    17
    Thanks Dithermaster! But I call a (non kernel)function in the kernel function? ie can we write non kernel function in .cl file ??

  4. #4
    Junior Member
    Join Date
    Oct 2011
    Posts
    25
    You can call non-kernel functions in a kernel function.

    For example
    Code :
    double doStuff(double a, double b, int n)
    {
        double ret = 1.0;
     
        for(int i = 0; i < n; i++)
            ret =  ret + (x*x - 2*x*y + y*y)/(ret + x*x + y*y)
     
        return ret;
    }
     
    __kernel void doLotsOfStuff(__global const int *N, __global const double *A, __global const double *B, __global double *C)
    {
        const ulong i0 = get_global_id(0);
        const ulong i1 = get_global_id(1);
     
        if(i0 < N[0] && i1 < N[1])
           C[i0 + i1*N[0]] = doStuff(A[i0],B[i1],10);
    }

    I havent tested the above code for bugs but in principle it should be valid.

  5. #5
    Junior Member
    Join Date
    Apr 2014
    Posts
    17
    Thank you very much Peccable !

Tags for this Thread

Posting Permissions

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