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.

You can’t make recursive calls in OpenCL C.

Thanks Dithermaster! But I call a (non kernel)function in the kernel function? ie can we write non kernel function in .cl file ??

You can call non-kernel functions in a kernel function.

For example


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.

Thank you very much Peccable !