【发布时间】:2015-02-14 22:43:20
【问题描述】:
我在 dPointsWS 的设备内存中有一个点云,其内存布局首先存储所有 x 坐标,然后存储所有 y 坐标,最后存储所有 z 坐标。我使用推力来计算这个点云的紧轴对齐边界框 (AABB)。这是我的代码:
// use CUDA thrust library for AABB computation
thrust::pair<thrust::device_ptr<Real>, thrust::device_ptr<Real>> thrustAABB[3];
// do parrallel min_max reduction on GPU for each coordinate axis
thrust::device_ptr<Real> dPointsWS(mDPointsWS);
for (uint32 i = 0, offset = 0; i < 3; ++i, offset += mPointCount)
thrustAABB[i] = thrust::minmax_element(dPointsWS + offset,
dPointsWS + offset + mPointCount);
cudaDeviceSynchronize();
// get results from the GPU
for (uint32 i = 0; i < 3; ++i)
{
mAABBWS[2 * i + 0] = *thrustAABB[i].first;
mAABBWS[2 * i + 1] = *thrustAABB[i].second;
}
我想知道thrust::minmax_element 的结果存储在最后一个代码块之前的位置。我已经清楚地将结果下载到最后的主机内存,但我想避免这种情况。
我找到了以下文章:
thrust reduction result on device memory。
但是,我的情况不同,因为我使用了返回类型thrust::pair<thrust::device_ptr<Real>, thrust::device_ptr<Real>>。
由于归约函数返回一对device_ptrobjects,最小和最大结果应该存储在GPU上还是我误解了这一点?但如果结果存储在 GPU 上,我如何控制它们的生命周期。例如,我想直接使用OpenGL绘制AABB的结果,而不需要将它们下载到主机内存中。
【问题讨论】:
标签: memory-management cuda thrust reduction