# generic inline function

**URL:** <https://forums.developer.nvidia.com/t/generic-inline-function/15990>\
**Category:** CUDA Programming and Performance\
**Created:** [April 8, 2010, 10:17am UTC](https://forums.developer.nvidia.com/t/generic-inline-function/15990 "2010-04-08T10:17:36Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![shravan](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@shravan](https://forums.developer.nvidia.com/u/shravan)\
**Post date:** [April 8, 2010, 10:17am UTC](https://forums.developer.nvidia.com/t/generic-inline-function/15990/1 "2010-04-08T10:17:36Z")

</div>

I have a query in the below given code, i want to make  
it generic,inline function (poly(d\_x[i],d\_func,N)) which is kernel.  
Can i call any other inline function having same argument  
without changing the function name in kernel.

**global** void Matrix\_generation(float \*d\_x,float \*d\_y,float \*d\_b,float \*d\_svU,float \*d\_sig,float \*d\_func,int M,int N)  
{  
float tmp=0.0;

```
     int i=blockIdx.x*blockDim.x+threadIdx.x;
     if(i<M)
    {
    poly(d_x[i],d_func,N);
    if(d_sig[i]==0.0)
    tmp=1.0;
    else
    tmp=1.0/d_sig[i];
    for(int j=0;j<N;j++){
    d_svU[i*N+j]=d_func[j]*tmp;}
    d_b[i]=d_y[i]*tmp;
    }__syncthreads();

```

}

**device** void poly(float d\_x,float \*d\_func,int N)  
{  
int j;  
d\_func[0]=1.0;  
for(j=1;j\<N;j++)  
{  
d\_func[j]=d\_func[j-1]\*d\_x;  
}  
}

---

<div class="post-metadata">

**Author:** ![avidday](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/avidday/32/59219_2.png) [@avidday](https://forums.developer.nvidia.com/u/avidday)\
**Post date:** [April 8, 2010, 10:26am UTC](https://forums.developer.nvidia.com/t/generic-inline-function/15990/2 "2010-04-08T10:26:56Z")

</div>

There aren’t any function pointers in CUDA and all **device** functions are inlined at compile time, so short of compiling multiple versions of the kernel, I think the answer is no.

---

<div class="post-metadata">

**Author:** ![StickGuy](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@StickGuy](https://forums.developer.nvidia.com/u/StickGuy)\
**Post date:** [April 8, 2010, 11:20am UTC](https://forums.developer.nvidia.com/t/generic-inline-function/15990/3 "2010-04-08T11:20:54Z")

</div>

> [@](#):
>
> There aren’t any function pointers in CUDA and all **device** functions are inlined at compile time, so short of compiling multiple versions of the kernel, I think the answer is no.

I think you can work around this by using functor objects though. I believe this is the way thrust works. Take a look at the saxpy\_functor here:

http://code.google.com/p/thrust/wiki/QuickStartGuide
