I have a struct with multiple members and I want to do some operations on parts of the member by GPUs. To make the size of communication as small as possible, I hope to copy back only those members which have been modified. Can cuda do that?
struct nodeInfo;
typedef struct nodeInfo
{
int x;
int y;
}nodeProp;
int main(int argc, char* argv[]){
int ngpus;
CHECK(cudaGetDeviceCount(&ngpus));
cudaStream_t stream[ngpus];
nodeProp *Nodes;
nodeProp *gpuNodes[ngpus];
int rankSize = 10;
int deviceSize = rankSize/ngpus;
CHECK(cudaMallocHost((void**)&Nodes,rankSize*sizeof(nodeProp)));
for(int i = 0; i < ngpus; i++)
{
cudaSetDevice(i);
cudaStreamCreate(&stream[i]);
CHECK(cudaMalloc((void**)&gpuNodes[i],deviceSize*sizeof(nodeProp)));
CHECK(cudaMemcpyAsync(gpuNodes[i],Nodes+i*deviceSize,deviceSize*sizeof(nodeProp),cudaMemcpyHostToDevice,stream[i]));
}
for(int i = 0; i < ngpus; i++)
{
cudaSetDevice(i);
kernel_x_Operation<<<grid_size,block_size,0,stream[i]>>>(gpuNodes[i]);//Some operation on gpuNodes.x
//How to write the memcpy function? Can I just copy one member of the struct back?
CHECK((void*)cudaMemcpyAsync((Nodes+i*deviceSize)->x, gpuNodes[i]->x), sizeof(int)*deviceSize,cudaMemcpyDeviceToHost,stream[i]));
cudaDeviceSynchronize();
}
}