I'm trying to initialize some structs on the device, but when they come back, theyre all messy. I know that something is wrong with how I'm using my pointers, but I cant seem to figure it out.
heres my memory allocation on the host
body* devBodies;
body** devBodyList;
float* devRandoms;
cudaMalloc((void**)&devBodies, n * sizeof(body));
cudaMalloc((void**)&devBodyList, n * sizeof(body*));
cudaMalloc((void**)&devRandoms, n * 3 * sizeof(float));
heres my function call, where devRandoms is just a list of floats.
CUDAInitBodies<<<n,1>>>(devBodyList, devBodies, devRandoms);
and heres my method:
__global__ void CUDAInitBodies(body** devBodyList, body* devBody, float* rand)
{
int j;
int tid = blockIdx.x;
*(devBodyList[tid]) = devBody[tid];
devBodyList[tid]->id = tid;
devBodyList[tid]->m = 10;
for(j = 0; j < 3; j++)
{
devBodyList[tid]->a[j] = 0;
devBodyList[tid]->v[j] = 0;
devBodyList[tid]->pos[j] = rand[(tid * 3) + j];
}
}
when I then copy the data back to the host:
body* bodies = (body*)malloc(n * sizeof(body));
cudaMemcpy(bodies, devBodies, n * sizeof(body), cudaMemcpyDeviceToHost);
when I print out the variables of my "body", I get this:
====BODY[-581043205]====
M = -42522218781525353518415985938704367616.000000
V = [-311601248975690312470654313562112.000000, 17269896096570671104.000000, 307939529506715418513587721849804947456.000000]
X = -19247336126697914498972549714433540096.000000
Y = 17731266573644159438123340575306416128.000000
Z = -544771403677696.000000
I've trying different ways of doing this for quite a while, but nothing seems to be doing the trick