Using Pinned Memory with Global Device Memory


I had a question regarding the use of Pinned Memory with Global Device Memory.

I have a C “struct” which goes as follows,

typedef struct data_s {
unsigned int id;
int* array;
} Data

Further, I need to allocate an array of above structure on the Pinned Memory for using the “Zero Copy” feature i.e. doing something like,
Data* h_data = NULL;
Data* d_data = NULL;
cudaHostAlloc((void**)&h_data, sizeof(Data)TOTAL_INSTANCES, cudaHostAllocMapped);
*)&d_data, (void*)h_data, 0);

Going ahead, I want to dynamically allocate a huge chunk of memory in the Device Global array, and then distribute the chunk across the “array” member of various “struct data_s” i.e.

int chunk_array;
*)&chunk_array, TOTAL_ARRAY_SIZE*sizeof(int));

Further, In the Device kernel that would be launched, I would do something as follows and pass the pointers to the global and pinned memories to the kernel. i.e.

global void kernel_initialize(Data* d_data, int* chunk_array) {
int threadID = threadIdx.x + blockIdx.x * blockDim.x;

if(threadID == 0) {
for(int i=0; i<TOTAL_INSTANCES; i++) {
unsigned int offset = 5 * i;
d_data[i].array = &chunk_array[offset];

So, What I am trying to do is to assign a pointer in the Device global memory to an element of a structure that sits in the pinned memory.
Is this type of coding valid in CUDA? Can we do such an interaction between Pinned memory and the global memory? Is there a better way to do this?

Thanks a lot for the help!!