0
我想从主机到CUDA中的设备复制结构数组。例如:CUDA中从主机到设备的结构数组复制
#define N 1000;
#define M 100000;
typedef struct {
int i;
float L[N];
}t ;
__global__ void kernel() {
//do something
}
main() {
t *B, *B_d; // Pointer to host & device arrays of structure
int size = M * sizeof(t);
B=(t*)calloc(M,sizeof(t));
cudaMalloc((void **) &B_d, size); // Allocate array of structure on device
// readind B from file ...
cudaMemcpy(B_d, B, size, cudaMemcpyHostToDevice);
kernel<<<1, 1 >>>();
}
这是正确与否?我怎样才能使用内核功能?
1 - 我可以将B_d传递给类型(t *)的内核而不是B吗? 2 - 我怎样才能使联合阅读? – user1285050
您应该将指针传递给GPU内存(即B-d)。要执行合并内存访问以获得最佳GPU内存性能,您应该从结构阵列切换到由数组组成的结构(例如,其字段为原始阵列)。请注意,此类结构构件应该正确对齐。 – Eugene