I am trying to copy a data structure from host to device that has pointers to objects that themselves have pointers to other objects. (At the end of the chain of pointers is an array that the kernel on the device would operate on.) However, I am not sure whether this is possible as I encounter segmentation fault when performing the second cudaMalloc (3rd statement below).
// Allocate and copy top object
Param_t dparam;
CUDA_SAFE_CALL(cudaMalloc((void*)&dparam, sizeof(Param_t)));
CUDA_SAFE_CALL(cudaMemcpy(dparam, param, sizeof(Param_t), cudaMemcpyHostToDevice));
// Now allocate and copy member object
CUDA_SAFE_CALL(cudaMalloc((void**)&dparam->Field1, sizeof(Field_t)));
CUDA_SAFE_CALL(cudaMemcpy(dparam->Field, param->Field1, sizeof(Field_t), cudaMemcpyHostToDevice));
It seg faults at the second cudaMalloc. Is it possible to dereference dparam->Field1 on the host when dparam is allocated for the device with cudaMalloc?
If it cannot be done, then pointer manipulation on the host side like below would not be possible, right?
dparam->Field3 = dparam->Field1 + offset;
Thanks.