我有这个(工作)CPU代码:
#define NF 3
int ND;
typedef double (*POT)(double x, double y);
typedef struct {
POT pot[NF];
} DATAMPOT;
DATAMPOT *datampot;
double func0(double x, double y);
double func1(double x, double y);
double func2(double x, double y);
int main(void)
{
int i;
ND=5;
datampot=(DATAMPOT *)malloc(ND*sizeof(DATAMPOT));
for(i=0;i<ND;i++){
datampot[i].pot[0]=func0;
datampot[i].pot[1]=func1;
datampot[i].pot[2]=func2;
}
return 0;
}
现在我尝试这样的 GPU 版本
#define NF 3
int ND;
typedef double (*POT)(double x, double y);
typedef struct {
POT pot[NF];
} DATAMPOT;
DATAMPOT *dev_datampot;
__device__ double z_func0(double x, double y);
__device__ double z_func1(double x, double y);
__device__ double z_func2(double x, double y);
__global__ void assign(DATAMPOT *dmp, int n)
{
int i;
for(i=0;i<n;i++){
(dmp+i)->pot[0]=z_func0;
(dmp+i)->pot[1]=z_func1;
(dmp+i)->pot[2]=z_func2;
}
}
int main(void)
{
int i;
ND=5;
cudaMalloc((void**)&dev_datampot,ND*sizeof(DATAMPOT));
assign<<<1,1>>>(dev_datampot,ND);
return 0;
}
但是设备函数指针的分配不起作用。错误在哪里?以及如何纠正?非常感谢你提前。米歇尔