Skip to content

Commit

Permalink
Update Scalable CCD (#92)
Browse files Browse the repository at this point in the history
* Add scalable CCD library and remove GPU CCD and Sweep and Tiniest Queue libraries

* Add CUDA_ARCHITECTURES in CMakeLists.txt

* Update SweepAndTiniestQueue to new API

* Add all candidate types to SweepAndTiniestQueue

* Rename STQ to SAP

* Update Aabb name

* Refactor Python module structure
  • Loading branch information
zfergus committed Feb 20, 2024
1 parent 913409a commit 7474c7c
Show file tree
Hide file tree
Showing 51 changed files with 856 additions and 619 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -265,5 +265,5 @@ tests/src/tests/config.hpp
docs/_doxygen

notebooks/*.[ch]pp
tests/data/cloth_ball_bf_ccd_candidated.json
tests/data/cloth_ball_bf_ccd_candidates.json
python/update_bindings.py
29 changes: 5 additions & 24 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@ target_link_libraries(ipc_toolkit PUBLIC TBB::tbb)
include(tight_inclusion)
target_link_libraries(ipc_toolkit PUBLIC tight_inclusion::tight_inclusion)

# Scalable CCD (STQ broad phase and GPU Tight Inclusion)
include(scalable_ccd)
target_link_libraries(ipc_toolkit PUBLIC scalable_ccd::scalable_ccd)

# CCD
if(IPC_TOOLKIT_WITH_INEXACT_CCD)
# Etienne Vouga's CTCD Library for the floating point root finding algorithm
Expand All @@ -167,17 +171,6 @@ if(IPC_TOOLKIT_WITH_RATIONAL_INTERSECTION)
target_link_libraries(ipc_toolkit PUBLIC rational::rational)
endif()

# Sweep and Tiniest Queue and CCD
if(IPC_TOOLKIT_WITH_CUDA)
include(gpu_ccd)
target_link_libraries(ipc_toolkit PUBLIC gpu_ccd::gpu_ccd)
target_link_libraries(ipc_toolkit PUBLIC STQ::CPU)
else()
set(STQ_WITH_CUDA OFF CACHE BOOL "Enable CUDA Implementation" FORCE)
include(sweep_and_tiniest_queue)
target_link_libraries(ipc_toolkit PUBLIC STQ::CPU)
endif()

# Faster unordered map
if(IPC_TOOLKIT_WITH_ROBIN_MAP)
include(robin_map)
Expand Down Expand Up @@ -239,27 +232,15 @@ if(IPC_TOOLKIT_WITH_CUDA)

if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.24.0")
set(CMAKE_CUDA_ARCHITECTURES "native")
set_target_properties(ipc_toolkit PROPERTIES CUDA_ARCHITECTURES "native")
else()
include(FindCUDA/select_compute_arch)
CUDA_DETECT_INSTALLED_GPUS(CUDA_ARCH_LIST)
string(STRIP "${CUDA_ARCH_LIST}" CUDA_ARCH_LIST)
string(REPLACE " " ";" CUDA_ARCH_LIST "${CUDA_ARCH_LIST}")
string(REPLACE "." "" CUDA_ARCH_LIST "${CUDA_ARCH_LIST}")
set(CMAKE_CUDA_ARCHITECTURES ${CUDA_ARCH_LIST})
set_target_properties(ipc_toolkit PROPERTIES CUDA_ARCHITECTURES "${CUDA_ARCH_LIST}")
endif()

if(APPLE)
# We need to add the path to the driver (libcuda.dylib) as an rpath,
# so that the static cuda runtime can find it at runtime.
set_property(TARGET ipc_toolkit
PROPERTY
BUILD_RPATH ${CMAKE_CUDA_IMPLICIT_LINK_DIRECTORIES})
endif()

find_package(CUDAToolkit)
target_link_libraries(ipc_toolkit PRIVATE CUDA::cudart)
set_target_properties(scalable_ccd PROPERTIES CUDA_ARCHITECTURES "${CMAKE_CUDA_ARCHITECTURES}")
endif()

################################################################################
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ The following libraries are used in this project:
* [oneTBB](https://github.com/oneapi-src/oneTBB): parallelism
* [Tight-Inclusion](https://github.com/Continuous-Collision-Detection/Tight-Inclusion): provably conservative CCD of [Wang and Ferguson et al. 2021]
* [SimpleBVH](https://github.com/ipc-sim/SimpleBVH): a simple bounding volume hierarchy data structure
* [Scalable-CCD](https://github.com/Continuous-Collision-Detection/Scalable-CCD): scalable (GPU) CCD of [Belgrod et al. 2023]
* [spdlog](https://github.com/gabime/spdlog): logging information

#### Optional
Expand Down
20 changes: 0 additions & 20 deletions cmake/recipes/gpu_ccd.cmake

This file was deleted.

2 changes: 1 addition & 1 deletion cmake/recipes/json.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ add_library(nlohmann_json INTERFACE)
add_library(nlohmann_json::nlohmann_json ALIAS nlohmann_json)

include(GNUInstallDirs)
target_include_directories(nlohmann_json INTERFACE
target_include_directories(nlohmann_json SYSTEM INTERFACE
"$<BUILD_INTERFACE:${nlohmann_json_SOURCE_DIR}>/include"
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>"
)
Expand Down
12 changes: 12 additions & 0 deletions cmake/recipes/scalable_ccd.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Abseil (https://github.com/continuous-collision-detection/scalable-ccd)
# License: Apache 2.0
if(TARGET scalable_ccd::scalable_ccd)
return()
endif()

message(STATUS "Third-party: creating target 'scalable_ccd::scalable_ccd'")

set(SCALABLE_CCD_WITH_CUDA ${IPC_TOOLKIT_WITH_CUDA} CACHE BOOL "Enable CUDA CCD" FORCE)

include(CPM)
CPMAddPackage("gh:continuous-collision-detection/scalable-ccd#c03efa095173b44c13d8440bbc859eeaa0ec550b")
13 changes: 0 additions & 13 deletions cmake/recipes/sweep_and_tiniest_queue.cmake

This file was deleted.

7 changes: 5 additions & 2 deletions docs/source/cpp-api/broad_phase.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,13 @@ BVH

.. doxygenclass:: ipc::BVH

Sweep and Tiniest Queue
Sweep and Prune
-----------------------

.. doxygenclass:: ipc::SweepAndTiniestQueue
.. doxygenclass:: ipc::SweepAndPrune

Sweep and Tiniest Queue
-----------------------

.. .. doxygenclass:: ipc::SweepAndTiniestQueueGPU
Expand Down
9 changes: 6 additions & 3 deletions docs/source/python-api/broad_phase.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,16 @@ BVH

.. autoclasstoc::

Sweep and Tiniest Queue
-----------------------
Sweep and Prune
---------------

.. autoclass:: ipctk.SweepAndTiniestQueue
.. autoclass:: ipctk.SweepAndPrune

.. autoclasstoc::

Sweep and Tiniest Queue
-----------------------

.. .. autoclass:: ipctk.SweepAndTiniestQueueGPU
.. :members:
Expand Down
2 changes: 1 addition & 1 deletion docs/source/tutorial/getting_started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ The ``Candidates`` class represents the culled set of candidate pairs and is bui
broad_phase_method=ipctk.BroadPhaseMethod.HASH_GRID)
Possible values for ``broad_phase_method`` are: ``BRUTE_FORCE`` (parallel brute force culling), ``HASH_GRID`` (default), ``SPATIAL_HASH`` (implementation from the original IPC codebase),
``BVH`` (`SimpleBVH <https://github.com/geometryprocessing/SimpleBVH>`_), ``SWEEP_AND_TINIEST_QUEUE`` (method of :cite:t:`Belgrod2023Time`), or ``SWEEP_AND_TINIEST_QUEUE_GPU`` (requires CUDA).
``BVH`` (`SimpleBVH <https://github.com/geometryprocessing/SimpleBVH>`_), ``SWEEP_AND_PRUNE`` (method of :cite:t:`Belgrod2023Time`), or ``SWEEP_AND_TINIEST_QUEUE`` (requires CUDA).

Narrow-Phase
^^^^^^^^^^^^
Expand Down
87 changes: 4 additions & 83 deletions python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,91 +2,12 @@
# Create Python module for IPC Toolkit
include(pybind11)

pybind11_add_module(ipctk
src/bindings.cpp
pybind11_add_module(ipctk)

src/barrier/adaptive_stiffness.cpp
src/barrier/barrier.cpp

src/broad_phase/aabb.cpp
src/broad_phase/broad_phase.cpp
src/broad_phase/brute_force.cpp
src/broad_phase/bvh.cpp
src/broad_phase/hash_grid.cpp
src/broad_phase/spatial_hash.cpp
src/broad_phase/sweep_and_tiniest_queue.cpp
src/broad_phase/voxel_size_heuristic.cpp

src/candidates/candidates.cpp
src/candidates/collision_stencil.cpp
src/candidates/continuous_collision_candidate.cpp
src/candidates/edge_edge.cpp
src/candidates/edge_face.cpp
src/candidates/edge_vertex.cpp
src/candidates/face_vertex.cpp
src/candidates/vertex_vertex.cpp

src/ccd/aabb.cpp
src/ccd/ccd.cpp
src/ccd/additive_ccd.cpp
src/ccd/inexact_point_edge.cpp
src/ccd/nonlinear_ccd.cpp
src/ccd/point_static_plane.cpp

src/collisions/collision.cpp
src/collisions/collisions.cpp
src/collisions/edge_edge.cpp
src/collisions/edge_vertex.cpp
src/collisions/face_vertex.cpp
src/collisions/plane_vertex.cpp
src/collisions/vertex_vertex.cpp

src/distance/distance_type.cpp
src/distance/edge_edge.cpp
src/distance/edge_edge_mollifier.cpp
src/distance/line_line.cpp
src/distance/point_edge.cpp
src/distance/point_line.cpp
src/distance/point_plane.cpp
src/distance/point_point.cpp
src/distance/point_triangle.cpp

src/friction/closest_point.cpp
src/friction/friction_collisions.cpp
src/friction/normal_force_magnitude.cpp
src/friction/relative_velocity.cpp
src/friction/smooth_friction_mollifier.cpp
src/friction/tangent_basis.cpp

src/friction/collisions/edge_edge.cpp
src/friction/collisions/edge_vertex.cpp
src/friction/collisions/face_vertex.cpp
src/friction/collisions/friction_collision.cpp
src/friction/collisions/vertex_vertex.cpp

src/implicits/plane.cpp

src/potentials/barrier_potential.cpp
src/potentials/friction_potential.cpp

src/utils/area_gradient.cpp
src/utils/eigen_ext.cpp
src/utils/interval.cpp
src/utils/intersection.cpp
src/utils/logger.cpp
src/utils/thread_limiter.cpp
src/utils/vertex_to_min_edge.cpp
src/utils/world_bbox_diagonal_length.cpp

src/collision_mesh.cpp
src/ipc.cpp
)
add_subdirectory(src) # Add sources to ipctk
target_include_directories(ipctk PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/src")

target_link_libraries(ipctk PRIVATE ipc::toolkit)
target_include_directories(ipctk PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/src")

# Extra warnings
# target_link_libraries(ipctk PRIVATE IPCToolkit::warnings)

# Move Python library to build root
set_target_properties(ipctk PROPERTIES LIBRARY_OUTPUT_PATH "${CMAKE_BINARY_DIR}")
# target_link_libraries(ipctk PRIVATE IPCToolkit::warnings)
23 changes: 23 additions & 0 deletions python/src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
set(SOURCES
bindings.cpp
collision_mesh.cpp
ipc.cpp
)

source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}" PREFIX "Source Files" FILES ${SOURCES})
target_sources(ipctk PRIVATE ${SOURCES})

################################################################################
# Subfolders
################################################################################

add_subdirectory(barrier)
add_subdirectory(broad_phase)
add_subdirectory(candidates)
add_subdirectory(ccd)
add_subdirectory(collisions)
add_subdirectory(distance)
add_subdirectory(friction)
add_subdirectory(implicits)
add_subdirectory(potentials)
add_subdirectory(utils)
7 changes: 7 additions & 0 deletions python/src/barrier/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
set(SOURCES
barrier.cpp
adaptive_stiffness.cpp
)

source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}" PREFIX "Source Files" FILES ${SOURCES})
target_sources(ipctk PRIVATE ${SOURCES})
1 change: 1 addition & 0 deletions python/src/bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ PYBIND11_MODULE(ipctk, m)
define_bvh(m);
define_hash_grid(m);
define_spatial_hash(m);
define_sweep_and_prune(m);
define_sweep_and_tiniest_queue(m);
define_voxel_size_heuristic(m);

Expand Down
14 changes: 14 additions & 0 deletions python/src/broad_phase/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
set(SOURCES
aabb.cpp
broad_phase.cpp
brute_force.cpp
bvh.cpp
hash_grid.cpp
spatial_hash.cpp
sweep_and_prune.cpp
sweep_and_tiniest_queue.cpp
voxel_size_heuristic.cpp
)

source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}" PREFIX "Source Files" FILES ${SOURCES})
target_sources(ipctk PRIVATE ${SOURCES})
1 change: 1 addition & 0 deletions python/src/broad_phase/bindings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ void define_brute_force(py::module_& m);
void define_bvh(py::module_& m);
void define_hash_grid(py::module_& m);
void define_spatial_hash(py::module_& m);
void define_sweep_and_prune(py::module_& m);
void define_sweep_and_tiniest_queue(py::module_& m);
void define_voxel_size_heuristic(py::module_& m);
17 changes: 8 additions & 9 deletions python/src/broad_phase/broad_phase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,19 @@ void define_broad_phase(py::module_& m)
py::enum_<BroadPhaseMethod>(
m, "BroadPhaseMethod",
"Enumeration of implemented broad phase methods.")
.value("BRUTE_FORCE", BroadPhaseMethod::BRUTE_FORCE, "Brute force.")
.value("HASH_GRID", BroadPhaseMethod::HASH_GRID, "Hash grid.")
.value("SPATIAL_HASH", BroadPhaseMethod::SPATIAL_HASH, "Spatial hash.")
.value("BRUTE_FORCE", BroadPhaseMethod::BRUTE_FORCE, "Brute force")
.value("HASH_GRID", BroadPhaseMethod::HASH_GRID, "Hash grid")
.value("SPATIAL_HASH", BroadPhaseMethod::SPATIAL_HASH, "Spatial hash")
.value(
"BOUNDING_VOLUME_HIERARCHY", BroadPhaseMethod::BVH,
"Bounding volume hierarchy.")
"Bounding volume hierarchy")
.value(
"SWEEP_AND_PRUNE", BroadPhaseMethod::SWEEP_AND_PRUNE,
"Sweep and prune")
.value(
"SWEEP_AND_TINIEST_QUEUE",
BroadPhaseMethod::SWEEP_AND_TINIEST_QUEUE,
"Sweep and tiniest queue.")
.value(
"SWEEP_AND_TINIEST_QUEUE_GPU",
BroadPhaseMethod::SWEEP_AND_TINIEST_QUEUE_GPU,
"Sweep and tiniest queue (GPU).")
"Sweep and tiniest queue (GPU)")
.export_values();

py::class_<BroadPhase>(m, "BroadPhase")
Expand Down
11 changes: 11 additions & 0 deletions python/src/broad_phase/sweep_and_prune.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include <common.hpp>

#include <ipc/broad_phase/sweep_and_prune.hpp>

namespace py = pybind11;
using namespace ipc;

void define_sweep_and_prune(py::module_& m)
{
py::class_<SweepAndPrune, BroadPhase>(m, "SweepAndPrune");
}
Loading

0 comments on commit 7474c7c

Please sign in to comment.