I need a device version of the following host code:
double (**func)(double x);
double func1(double x)
{
return x+1.;
}
double func2(double x)
{
return x+
function pointers are allowed on Fermi. This is how you could do it:
typedef double (*func)(double x);
__device__ double func1(double x)
{
return x+1.0f;
}
__device__ double func2(double x)
{
return x+2.0f;
}
__device__ double func3(double x)
{
return x+3.0f;
}
__device__ func pfunc1 = func1;
__device__ func pfunc2 = func2;
__device__ func pfunc3 = func3;
__global__ void test_kernel(func* f, int n)
{
double x;
for(int i=0;i>>(d_f,N);
cudaFree(d_f);
free(h_f);
return 0;
}