I have some tables on the CPU that I would like to move over to the GPU for future calculations. The tables are setup ahead of time and don’t change after they are intialized. Therefore, I wanted to move them over as soon as they’re set and come back to them later. I think this is possible, but my device pointer becomes invalid as soon as I return from the function that sets it up.
Example:
struct type_a{
int id;
type_b *b;
}
struct type_b{
int id;
}
...
type_a *helper = malloc (sizeof(type_a)*10);
//store ids in helper's id field from a master table on CPU
...
type_a *main;
allocateArrays(main,helper);
doSomething(main,helper);
extern "C"
allocateArrays(type_a* main, type_a* helper){
for (0 to 9)
cudaMalloc(helper[index],sizeof(type_b)*5);
cudaMalloc(main,sizeof(type_a)*10);
cudaMemcpy(main,helper,sizeof(type_a)*10,HostToDevice)
}
After that code runs, I can still use helper, but main gives me invalid device pointer. I’ve tried cudaMemcpy on helper, which will work, but as soon as I try that on main, it throws the invalid error. Do I have to allocate some dummy CPU memory for main for this to work? Am I just doing something stupid? Is there any way to retain this pointer? Sorry for the long post, but I couldn’t make it much shorter without leaving out stuff.
-skiz