我需要以下主机代码的设备版本:
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 ×1