@@ -19,6 +19,25 @@ namespace gtsam_points {
1919
2020namespace {
2121
22+ void make_sure_loaded_on_gpu (const GaussianVoxelMapGPU::ConstPtr& target_gpu, CUstream_st* stream) {
23+ if (!target_gpu->loaded_on_gpu ()) {
24+ // A bit hacky, but we need to ensure that the target voxelmap is loaded on GPU
25+ const_cast <GaussianVoxelMapGPU*>(target_gpu.get ())->touch (stream);
26+ }
27+ }
28+
29+ void make_sure_loaded_on_gpu (const PointCloud::ConstPtr& source, CUstream_st* stream) {
30+ auto source_gpu = std::dynamic_pointer_cast<const PointCloudGPU>(source);
31+ if (!source_gpu) {
32+ std::cerr << " error: Source point cloud is not a PointCloudGPU!!" << std::endl;
33+ abort ();
34+ }
35+
36+ if (!source_gpu->has_points_gpu ()) {
37+ const_cast <PointCloudGPU*>(source_gpu.get ())->touch (stream);
38+ }
39+ }
40+
2241struct transform_means_kernel {
2342 transform_means_kernel (const thrust::device_ptr<const Eigen::Isometry3f>& transform_ptr) : transform_ptr(transform_ptr) {}
2443
@@ -167,6 +186,9 @@ overlap_gpu(const GaussianVoxelMap::ConstPtr& target_, const PointCloud::ConstPt
167186 abort ();
168187 }
169188
189+ make_sure_loaded_on_gpu (target, stream);
190+ make_sure_loaded_on_gpu (source, stream);
191+
170192 bool * overlap;
171193 check_error << cudaMallocAsync (&overlap, sizeof (bool ) * source->size (), stream);
172194 thrust::device_ptr<bool > overlap_ptr (overlap);
@@ -210,6 +232,9 @@ overlap_gpu(const GaussianVoxelMap::ConstPtr& target_, const PointCloud::ConstPt
210232 abort ();
211233 }
212234
235+ make_sure_loaded_on_gpu (target, stream);
236+ make_sure_loaded_on_gpu (source, stream);
237+
213238 Eigen::Isometry3f h_delta = delta.cast <float >();
214239 Eigen::Isometry3f* d_delta;
215240 check_error << cudaMallocAsync (&d_delta, sizeof (Eigen::Isometry3f), stream);
@@ -237,7 +262,10 @@ double overlap_gpu(
237262 if (!targets[i]) {
238263 std::cerr << " error: Failed to cast target voxelmap to GaussianVoxelMapGPU!!" << std::endl;
239264 }
265+
266+ make_sure_loaded_on_gpu (targets[i], stream);
240267 }
268+ make_sure_loaded_on_gpu (source, stream);
241269
242270 std::vector<Eigen::Isometry3f> h_deltas (deltas_.size ());
243271 std::transform (deltas_.begin (), deltas_.end (), h_deltas.begin (), [](const Eigen::Isometry3d& delta) { return delta.cast <float >(); });
@@ -304,9 +332,8 @@ std::vector<double> overlap_gpu(
304332 std::cerr << " error: Failed to cast target voxelmap to GaussianVoxelMapGPU!!" << std::endl;
305333 }
306334
307- if (!sources[i]->has_points_gpu ()) {
308- std::cerr << " error: GPU source points have not been allocated!!" << std::endl;
309- }
335+ make_sure_loaded_on_gpu (targets[i], stream);
336+ make_sure_loaded_on_gpu (sources[i], stream);
310337
311338 max_num_points = std::max (max_num_points, sources[i]->size ());
312339 }
0 commit comments