逐一拷贝结构体元素
code:
struct cudaWeakr
{
int* loc;
float* detaSb;
};
int main()
{
float arrayA[2][3] = { {1, 2 ,3},{11,22,33}};
int arrayB[3]={1, 2 ,3};
const int K=3;
cudaWeakr*cuda_weaks;
cudaWeakr tempweaks[3];
float*sb;
int*loc;
size_t size;
for(int i=0;i<3;i++)
{
size=sizeof(float)*6;
sb=(float*)malloc(size);
memcpy(sb,arrayA,size);
loc=(int*)malloc(sizeof(int)*3);
memcpy(loc,arrayB,sizeof(int)*3);
tempweaks[i].loc=loc;
tempweaks[i].detaSb=sb;
}
size=K*(sizeof(int)*6+sizeof(float)*3);
cudaMalloc((void**)&cuda_weaks,size);
for (int i=0; i<K; i++)
{
cudaMemcpy(&(cuda_weaks[i]),&tempweaks[i],size,cudaMemcpyHostToDevice);
}
cudaWeakr testweak[K];
for (int i=0; i<K; i++)
{
cudaMemcpy(testweak,cuda_weaks,(sizeof(int)*6&#