相关疑难解决方法(0)

设备功能指针

我需要以下主机代码的设备版本:

double (**func)(double x);

double func1(double x)
{
 return x+1.;
}

double func2(double x)
{
 return x+2.;
}

double func3(double x)
{
 return x+3.;
}

void test(void)
{
 double x;

 for(int i=0;i<3;++i){
  x=func[i](2.0);
  printf("%g\n",x);
 }

}

int main(void)
{
 func=(double (**)(double))malloc(10*sizeof(double (*)(double)));

 test();

 return 0;
}
Run Code Online (Sandbox Code Playgroud)

其中func1,func2,func3必须是__device__函数,"test"必须是(适当修改)__global__内核.

我有一台NVIDIA GeForce GTS 450(计算能力2.1),先谢谢Michele

================================================== ======

一个有效的解决方

#define REAL double

typedef REAL (*func)(REAL x);

__host__ __device__ REAL func1(REAL x)
{
    return x+1.0f;
}

__host__ __device__ REAL func2(REAL x)
{
    return x+2.0f;
}

__host__ …
Run Code Online (Sandbox Code Playgroud)

cuda

11
推荐指数
1
解决办法
6939
查看次数

标签 统计

cuda ×1