Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Support multi-threading in the RayCastingScene function to commit scene #6051

Merged
merged 4 commits into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* Fix raycasting scene: Allow setting of number of threads that are used for building a raycasting scene
* Fix Python bindings for CUDA device synchronization, voxel grid saving (PR #5425)
* Support msgpack versions without cmake
* Support multi-threading in the RayCastingScene function to commit scene (PR #6051).
* Fix some bad triangle generation in TriangleMesh::SimplifyQuadricDecimation

## 0.13
Expand Down
36 changes: 20 additions & 16 deletions cpp/open3d/t/geometry/RaycastingScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,19 @@ struct RaycastingScene::Impl {
geometry_ptrs_;
core::Device tensor_device_; // cpu

bool devprop_join_commit;

void CommitScene() {
if (!scene_committed_) {
if (devprop_join_commit) {
rtcJoinCommitScene(scene_);
} else {
rtcCommitScene(scene_);
}
scene_committed_ = true;
}
}

template <bool LINE_INTERSECTION>
void CastRays(const float* const rays,
const size_t num_rays,
Expand All @@ -276,10 +289,7 @@ struct RaycastingScene::Impl {
float* primitive_uvs,
float* primitive_normals,
const int nthreads) {
if (!scene_committed_) {
rtcCommitScene(scene_);
scene_committed_ = true;
}
CommitScene();

struct RTCIntersectContext context;
rtcInitIntersectContext(&context);
Expand Down Expand Up @@ -365,10 +375,7 @@ struct RaycastingScene::Impl {
const float tfar,
int8_t* occluded,
const int nthreads) {
if (!scene_committed_) {
rtcCommitScene(scene_);
scene_committed_ = true;
}
CommitScene();

struct RTCIntersectContext context;
rtcInitIntersectContext(&context);
Expand Down Expand Up @@ -420,10 +427,7 @@ struct RaycastingScene::Impl {
const size_t num_rays,
int* intersections,
const int nthreads) {
if (!scene_committed_) {
rtcCommitScene(scene_);
scene_committed_ = true;
}
CommitScene();

memset(intersections, 0, sizeof(int) * num_rays);

Expand Down Expand Up @@ -486,10 +490,7 @@ struct RaycastingScene::Impl {
float* primitive_uvs,
float* primitive_normals,
const int nthreads) {
if (!scene_committed_) {
rtcCommitScene(scene_);
scene_committed_ = true;
}
CommitScene();

auto LoopFn = [&](const tbb::blocked_range<size_t>& range) {
for (size_t i = range.begin(); i < range.end(); ++i) {
Expand Down Expand Up @@ -552,6 +553,9 @@ RaycastingScene::RaycastingScene(int64_t nthreads)
impl_->scene_,
RTC_SCENE_FLAG_ROBUST | RTC_SCENE_FLAG_CONTEXT_FILTER_FUNCTION);

impl_->devprop_join_commit = rtcGetDeviceProperty(
impl_->device_, RTC_DEVICE_PROPERTY_JOIN_COMMIT_SUPPORTED);

impl_->scene_committed_ = false;
}

Expand Down
Loading