【发布时间】:2011-07-03 16:20:51
【问题描述】:
使用 CUDA 编程我在尝试将一些数据从主机复制到 gpu 时遇到问题。
我有 3 个这样的嵌套结构:
typedef struct {
char data[128];
short length;
} Cell;
typedef struct {
Cell* elements;
int height;
int width;
} Matrix;
typedef struct {
Matrix* tables;
int count;
} Container;
所以Container“包含”一些Matrix元素,而这些元素又包含一些Cell元素。
假设我以这种方式动态分配主机内存:
Container c;
c.tables = malloc(20 * sizeof(Matrix));
for(int i = 0;i<20;i++){
Matrix m;
m.elements = malloc(100 * sizeof(Cell));
c.tables[i] = m;
}
也就是说,一个包含 20 个矩阵的容器,每个矩阵 100 个单元格。
- 我现在如何使用 cudaMemCpy() 将此数据复制到设备内存中?
- 有没有什么好的方法可以从主机到设备执行“struct of struct”的深层复制?
感谢您的宝贵时间。
安德烈亚
【问题讨论】: