Passing GPU pointer to an element of a struct within host code

Hi all,

Suppose I have a struct Structure allocated and copied onto GPU memory, with its address stored on the host from memcpy.

Structure* Structure_dev;

Structure Structure_host;

cudaMemcpy(Structure_dev, &Structure_host, sizeof(Structure), cudaMemcpyHostToDevice);

This structure has an array of structs MiniStructure. Suppose I want to update the value of an element ((int) time) of a MiniStructure from host code. Right now my guess as to how to do this is

cudaMemcpy(Structure_dev->MiniStructure.time, &(Structure_host.MiniStructure.time), sizeof(int), cudaMemcpyHostToDevice);

But I worry that ‘Structure_dev->MiniStructure.time’ is either a pointer to host memory or not a pointer at all (indeed, it sure looks like an int, but I can’t just add & because that would yield a host memory address) so I was wondering what the general technique for this sort of nested structure problem is. I’d prefer to edit the memory from the host but since this isn’t a very frequent operation I could call a <<<1,1>>> kernel with ‘time’ passed as an argument to have free reign over device memory but this seems inelegant.

Thanks!

S

Is MiniStructure allocated statically or dynamically?
If your structure is not large I’d copy the whole thing since the cost for small transfers is pretty much constant.