我有一个结构
struct packet
{
int src_ip;
int dest_ip;
int src_port;
int dest_port;
int protocol;
};
一个cuda内核如下:
__global__
void GPU(struct packet * packets,int * gpu_action)
{
int i;
i = (int) packets[6]->src_ip;
}
主要功能如下:
int main ()
{
int * gpu_action;
struct packet * gpu_packets;
struct packet * cpu_gpu_packets;
int * action;
action = (int *)malloc(TOTAL_PACKETS*sizeof(int));
cpu_gpu_packets = (struct packet *)malloc(TOTAL_PACKETS*sizeof(struct packet));
cudaMalloc((void**)&gpu_action,TOTAL_PACKETS*sizeof(int));
cudaMalloc((void**)&gpu_packets,TOTAL_PACKETS*sizeof(struct packet));
cudaMemcpy(gpu_packets,cpu_gpu_packets,TOTAL_PACKETS*sizeof(struct packet),cudaMemcpyHostToDevice);
GPU<<<1,1>>>(gpu_packets,gpu_action);
}
当我使用 nvcc 编译它时,我收到错误和警告。它在以下点给了我一个错误“表达式必须是指向完整对象类型的指针”
i = packets[6]->src_ip;
语法有什么问题吗??上面的代码适用于主机函数,但不适用于 cuda __global__ 函数。