Sunday, 8 September 2013

Using structures with CUDA

Using structures with CUDA

I have a structure
struct packet
{
int src_ip;
int dest_ip;
int src_port;
int dest_port;
int protocol;
};
A cuda kernel is as follows:
__global__ void GPU(struct packet * packets,int * gpu_action)
{
int i;
i = (int) packets[6]->src_ip;
}
main function is as follows:
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);
}
When I am compiling it using nvcc, I get errors and warnings. It gives me
a error "expression must be a pointer to a complete object type" at the
following point i = packets[6]->src_ip; Is any thing wrong in the syntax
?? The above code works fine with host functions but not with cuda global
functions.
Please Help???

No comments:

Post a Comment