I have a hard time getting my struct malloc to work for cuda.
my struct looks like this:
typedef struct Map{
int length;
double *A;
int *x;
int *dx;
int *y;
int *dy;
int *delta;
int *phi;
}Map;
The malloc function I try to call is as follows:
void cudaMallocMap(Map **m, int p){
cudaMalloc((void**)m, sizeof(Map));
cudaMemset(&((**m).length), p, 1);
if(p>0){
cudaMalloc((void**)&((**m).A), p*sizeof(double));
cudaMalloc((void**)&((**m).x), p*sizeof(int));
cudaMalloc((void**)&((**m).dx), p*sizeof(int));
cudaMalloc((void**)&((**m).y), p*sizeof(int));
cudaMalloc((void**)&((**m).dy), p*sizeof(int));
cudaMalloc((void**)&((**m).delta), p*sizeof(int));
cudaMalloc((void**)&((**m).phi), p*sizeof(int));
}
}
It is called in the following way:
Map *dev_x;
int xSize = 31;
...
cudaMallocMap(&dev_x, xSize);
It gives an "Access violation writing location 0x________" at or after the first cudaMalloc in the if-statement.
What is wrong with this code and how can I fix it?