如何将四面体树结构复制到 CUDA 设备内存?

2022-01-05 00:00:00 c memory-management cuda tree c++

如果我想将下面的结构 TetrahedronStruct 移动到 CUDA 设备内存,我应该如何进行?

If I want to move the below structure TetrahedronStruct to CUDA device memory, how should I proceed?

struct TetrahedronStruct {
  int index;
  int region;
  TriangleFaces Faces[4];
  Vertex Vertices[4];
  struct TetrahedronStruct *adjTetrahedrons[4];
};

typedef struct {
  long double Nx, Ny, Nz;
  long double d;
  Vertex V[3];
} TriangleFaces;

typedef struct {
  long double x, y, z;
} Vertex;

详情:

提供了网格细节(节点数、四面体、坐标和区域).树的创建是在 for 循环中完成的.基本上,每个人脸都根据其坐标和相邻关系在树中定位和排列.

The mesh details (number of nodes, tetrahedrons, coordinates, and regions) are provided. The creation of the tree is done in a for-loop. Basically, each face is being located and arranged in the tree accordingly with its coordinates and adjacency.

在 CUDA 设备中,我需要使用此结构叠加在媒体上以模拟粒子将如何穿过该媒体.百万粒子中的每一个都在从四面体移动到四面体(每个四面体都具有其所在介质的属性).

In the CUDA device, I need to use this structure to overlay on a media to simulate how particles will travel across that media. Each of the million particles are moving from tetrahedron to tetrahedron (each tetrahedron has the properties of the media where it resides).

推荐答案

将结构线性化,然后将它们复制到设备会更容易.

It will be easier to linearize the structures and then copy them to device.

在新的 CUDA 6 深拷贝中,只要您的计算能力是 3.x 或更高,并且使用 统一内存.

In the new CUDA 6 deep copies will be much easier as long as your compute capability is 3.x or higher with the Unified Memory.

相关文章