Skip to content

Commit

Permalink
Fix TriangleMesh::SelectByIndex on CUDA (#6556)
Browse files Browse the repository at this point in the history
* Use correct devices for attr tensors in SelectByIndex.
* Dependencies for lxml python package (documentation)
  • Loading branch information
ssheorey authored Dec 30, 2023
1 parent c948c45 commit f3960d9
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
6 changes: 5 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ option(BUILD_BENCHMARKS "Build the micro benchmarks" OFF
option(BUILD_PYTHON_MODULE "Build the python module" ON )
option(BUILD_CUDA_MODULE "Build the CUDA module" OFF)
option(BUILD_COMMON_CUDA_ARCHS "Build for common CUDA GPUs (for release)" OFF)
option(ENABLE_CACHED_CUDA_MANAGER "Enable cached CUDA memory manager" ON )
if (WIN32) # Causes CUDA runtime error on Windows (See issue #6555)
option(ENABLE_CACHED_CUDA_MANAGER "Enable cached CUDA memory manager" OFF)
else()
option(ENABLE_CACHED_CUDA_MANAGER "Enable cached CUDA memory manager" ON )
endif()
if(NOT LINUX_AARCH64 AND NOT APPLE_AARCH64)
option(BUILD_ISPC_MODULE "Build the ISPC module" ON )
else()
Expand Down
24 changes: 14 additions & 10 deletions cpp/open3d/t/geometry/TriangleMesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1029,8 +1029,8 @@ int TriangleMesh::PCAPartition(int max_faces) {
}

/// A helper to compute new vertex indices out of vertex mask.
/// \param tris_cpu tensor with triangle indices to update.
/// \param vertex_mask tensor with the mask for vertices.
/// \param tris_cpu CPU tensor with triangle indices to update.
/// \param vertex_mask CPU tensor with the mask for vertices.
template <typename T>
static void UpdateTriangleIndicesByVertexMask(core::Tensor &tris_cpu,
const core::Tensor &vertex_mask) {
Expand Down Expand Up @@ -1148,11 +1148,13 @@ static bool IsNegative(T val) {
}

TriangleMesh TriangleMesh::SelectByIndex(const core::Tensor &indices) const {
TriangleMesh result;
core::AssertTensorShape(indices, {indices.GetLength()});
if (indices.NumElements() == 0) {
return {};
}
if (!HasVertexPositions()) {
utility::LogWarning("[SelectByIndex] TriangleMesh has no vertices.");
return result;
return {};
}
GetVertexAttr().AssertSizeSynchronized();

Expand Down Expand Up @@ -1194,7 +1196,7 @@ TriangleMesh TriangleMesh::SelectByIndex(const core::Tensor &indices) const {
scalar_tris_t *vertex_mask_ptr =
vertex_mask.GetDataPtr<scalar_tris_t>();
const scalar_indices_t *indices_ptr =
indices.GetDataPtr<scalar_indices_t>();
indices_cpu.GetDataPtr<scalar_indices_t>();
for (int64_t i = 0; i < indices.GetLength(); ++i) {
if (IsNegative(indices_ptr[i]) ||
indices_ptr[i] >=
Expand Down Expand Up @@ -1233,16 +1235,18 @@ TriangleMesh TriangleMesh::SelectByIndex(const core::Tensor &indices) const {
});
});

// send the vertex mask to original device and apply to vertices
// send the vertex mask and triangle mask to original device and apply to
// vertices
vertex_mask = vertex_mask.To(GetDevice(), core::Bool);
if (tri_mask.NumElements() > 0) { // To() needs non-empty tensor
tri_mask = tri_mask.To(GetDevice());
}
core::Tensor new_vertices = GetVertexPositions().IndexGet({vertex_mask});
TriangleMesh result(GetDevice());
result.SetVertexPositions(new_vertices);

if (HasTriangleIndices()) {
// select triangles and send the selected ones to the original device
if (tris_cpu.NumElements() > 0) { // To() needs non-empty tensor
result.SetTriangleIndices(tris_cpu.To(GetDevice()));
}

CopyAttributesByMasks(result, *this, vertex_mask, tri_mask);

return result;
Expand Down
1 change: 1 addition & 0 deletions util/ci_utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@ install_docs_dependencies() {
sudo apt-add-repository --yes 'deb https://apt.kitware.com/ubuntu/ bionic main'
./util/install_deps_ubuntu.sh assume-yes
sudo apt-get install --yes cmake
sudo apt-get install --yes libxml2-dev libxslt-dev python3-dev
sudo apt-get install --yes doxygen
sudo apt-get install --yes texlive
sudo apt-get install --yes texlive-latex-extra
Expand Down

0 comments on commit f3960d9

Please sign in to comment.