Skip to content
Draft
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
12 changes: 0 additions & 12 deletions cmake/recipes/spdlog.cmake
Original file line number Diff line number Diff line change
@@ -1,18 +1,6 @@
# spdlog (https://github.com/gabime/spdlog)
# License: MIT
if(TARGET spdlog::spdlog)
# Someone else created the target, so the fmt patch below never runs. That
# is fine without CUDA, but the patch is what makes the bundled fmt
# compile under nvcc at all, so warn rather than fail at the first .cu.
if(IPC_TOOLKIT_WITH_CUDA)
message(WARNING
"spdlog::spdlog was provided by an enclosing project, so IPC "
"Toolkit's cmake/patches/fmt-nvcc-compat.patch was not applied. "
"The bundled fmt does not compile under nvcc unpatched: its "
"literal-encoding probe misfires and a char32_t table uses hex "
"escapes with the high bit set. Apply the same patch to your "
"spdlog, or let IPC Toolkit fetch its own.")
endif()
return()
endif()

Expand Down
5 changes: 5 additions & 0 deletions src/ipc/broad_phase/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,8 @@ set(SOURCES
)

target_sources(ipc_toolkit PRIVATE ${SOURCES})

add_subdirectory(details)
if(IPC_TOOLKIT_WITH_CUDA)
add_subdirectory(cuda)
endif()
44 changes: 10 additions & 34 deletions src/ipc/broad_phase/broad_phase.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "broad_phase.hpp"

#include <ipc/config.hpp>
#include <ipc/broad_phase/details/connectivity_filters.hpp>
#include <ipc/candidates/candidates.hpp>
#include <ipc/utils/profiler.hpp>

Expand Down Expand Up @@ -131,8 +132,7 @@ bool BroadPhase::can_edge_vertex_collide(size_t ei, size_t vi) const
assert(ei < edge_boxes.size());
const auto& [e0i, e1i, _] = edge_boxes[ei].vertex_ids;

return vi != e0i && vi != e1i
&& (can_vertices_collide(vi, e0i) || can_vertices_collide(vi, e1i));
return details::can_edge_vertex_collide(e0i, e1i, vi, can_vertices_collide);
}

bool BroadPhase::can_edges_collide(size_t eai, size_t ebi) const
Expand All @@ -142,23 +142,17 @@ bool BroadPhase::can_edges_collide(size_t eai, size_t ebi) const
assert(ebi < edge_boxes.size());
const auto& [eb0i, eb1i, __] = edge_boxes[ebi].vertex_ids;

const bool share_endpoint =
ea0i == eb0i || ea0i == eb1i || ea1i == eb0i || ea1i == eb1i;

return !share_endpoint
&& (can_vertices_collide(ea0i, eb0i) || can_vertices_collide(ea0i, eb1i)
|| can_vertices_collide(ea1i, eb0i)
|| can_vertices_collide(ea1i, eb1i));
return details::can_edges_collide(
ea0i, ea1i, eb0i, eb1i, can_vertices_collide);
}

bool BroadPhase::can_face_vertex_collide(size_t fi, size_t vi) const
{
assert(fi < face_boxes.size());
const auto& [f0i, f1i, f2i] = face_boxes[fi].vertex_ids;

return vi != f0i && vi != f1i && vi != f2i
&& (can_vertices_collide(vi, f0i) || can_vertices_collide(vi, f1i)
|| can_vertices_collide(vi, f2i));
return details::can_face_vertex_collide(
f0i, f1i, f2i, vi, can_vertices_collide);
}

bool BroadPhase::can_edge_face_collide(size_t ei, size_t fi) const
Expand All @@ -168,14 +162,8 @@ bool BroadPhase::can_edge_face_collide(size_t ei, size_t fi) const
assert(fi < face_boxes.size());
const auto& [f0i, f1i, f2i] = face_boxes[fi].vertex_ids;

const bool share_endpoint = e0i == f0i || e0i == f1i || e0i == f2i
|| e1i == f0i || e1i == f1i || e1i == f2i;

return !share_endpoint
&& (can_vertices_collide(e0i, f0i) || can_vertices_collide(e0i, f1i)
|| can_vertices_collide(e0i, f2i) || can_vertices_collide(e1i, f0i)
|| can_vertices_collide(e1i, f1i)
|| can_vertices_collide(e1i, f2i));
return details::can_edge_face_collide(
e0i, e1i, f0i, f1i, f2i, can_vertices_collide);
}

bool BroadPhase::can_faces_collide(size_t fai, size_t fbi) const
Expand All @@ -185,20 +173,8 @@ bool BroadPhase::can_faces_collide(size_t fai, size_t fbi) const
assert(fbi < face_boxes.size());
const auto& [fb0i, fb1i, fb2i] = face_boxes[fbi].vertex_ids;

const bool share_endpoint = fa0i == fb0i || fa0i == fb1i || fa0i == fb2i
|| fa1i == fb0i || fa1i == fb1i || fa1i == fb2i || fa2i == fb0i
|| fa2i == fb1i || fa2i == fb2i;

return !share_endpoint
&& (can_vertices_collide(fa0i, fb0i) //
|| can_vertices_collide(fa0i, fb1i)
|| can_vertices_collide(fa0i, fb2i)
|| can_vertices_collide(fa1i, fb0i)
|| can_vertices_collide(fa1i, fb1i)
|| can_vertices_collide(fa1i, fb2i)
|| can_vertices_collide(fa2i, fb0i)
|| can_vertices_collide(fa2i, fb1i)
|| can_vertices_collide(fa2i, fb2i));
return details::can_faces_collide(
fa0i, fa1i, fa2i, fb0i, fb1i, fb2i, can_vertices_collide);
}

} // namespace ipc
8 changes: 8 additions & 0 deletions src/ipc/broad_phase/create_broad_phase.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "create_broad_phase.hpp"

#include <ipc/broad_phase/brute_force.hpp>
#include <ipc/broad_phase/cuda/lbvh.hpp>
#include <ipc/broad_phase/hash_grid.hpp>
#include <ipc/broad_phase/lbvh.hpp>
#include <ipc/broad_phase/spatial_hash.hpp>
Expand Down Expand Up @@ -29,6 +30,13 @@ create_broad_phase(const BroadPhaseMethod& broad_phase_method)
#else
log_and_throw_error(
"Sweep and Tiniest Queue broad phase requires CUDA! Enable it through CMake option IPC_TOOLKIT_WITH_CUDA.");
#endif
case BroadPhaseMethod::LBVH_CUDA:
#ifdef IPC_TOOLKIT_WITH_CUDA
return std::make_shared<ipc::cuda::LBVH>();
#else
log_and_throw_error(
"CUDA LBVH broad phase requires CUDA! Enable it through CMake option IPC_TOOLKIT_WITH_CUDA.");
#endif
default:
log_and_throw_error("Unknown broad phase type!");
Expand Down
3 changes: 2 additions & 1 deletion src/ipc/broad_phase/create_broad_phase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ enum class BroadPhaseMethod : uint8_t {
SPATIAL_HASH,
LBVH,
SWEEP_AND_PRUNE,
SWEEP_AND_TINIEST_QUEUE
SWEEP_AND_TINIEST_QUEUE,
LBVH_CUDA
};

std::shared_ptr<BroadPhase>
Expand Down
7 changes: 7 additions & 0 deletions src/ipc/broad_phase/cuda/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
set(SOURCES
lbvh.cu
lbvh.hpp
lbvh_impl.cuh
)

target_sources(ipc_toolkit PRIVATE ${SOURCES})
Loading
Loading