Skip to content

Commit c36dd77

Browse files
authored
Simplify cmake cuda setup (#201)
This PR streamlines the CMake CUDA setup by: * Disabling CUDA builds by default. * Set CUDA architecture to native if not specified. Avoid poking into the internal of the Scalable CCD. * Bump cmake minimum version to 3.24 to support `CMAKE_CUDA_ARCHITECTURES="native"` Since CUDA code is sensitive to environment changes (i.e., IPC fails to build on CUDA 13.0+), enabling it implicitly can create surprises for its consumer. As a library, the CUDA build should be guarded behind a CMake option. Also, ipc-toolkit currently inherits the CUDA architecture from Scalable CCD, which defaults to `"native"` if not defined. Instead, we should handle this explicitly.
1 parent 112712c commit c36dd77

File tree

6 files changed

+23
-26
lines changed

6 files changed

+23
-26
lines changed

.github/workflows/cuda.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ jobs:
7070
cd build
7171
cmake .. \
7272
-DIPC_TOOLKIT_WITH_CUDA=ON \
73+
-DCMAKE_CUDA_ARCHITECTURES=75 \
7374
-DSCALABLE_CCD_CUDA_ARCHITECTURES=75 \
7475
-DIPC_TOOLKIT_BUILD_TESTS=ON \
7576
-DIPC_TOOLKIT_BUILD_PYTHON=ON \

CMakeLists.txt

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ else()
77
endif()
88

99
# Check required CMake version
10-
set(REQUIRED_CMAKE_VERSION "3.18.0")
10+
set(REQUIRED_CMAKE_VERSION "3.24.0")
1111
if(IPC_TOOLKIT_TOPLEVEL_PROJECT)
1212
cmake_minimum_required(VERSION ${REQUIRED_CMAKE_VERSION})
1313
else()
@@ -64,9 +64,6 @@ project(IPCToolkit
6464
LANGUAGES CXX
6565
VERSION "1.5.0")
6666

67-
include(CheckLanguage)
68-
check_language(CUDA)
69-
7067
if(IPC_TOOLKIT_TOPLEVEL_PROJECT)
7168
option(IPC_TOOLKIT_BUILD_TESTS "Build unit-tests" ON)
7269
option(IPC_TOOLKIT_BUILD_PYTHON "Build Python bindings" OFF)
@@ -77,11 +74,7 @@ else()
7774
set(IPC_TOOLKIT_BUILD_PYTHON OFF CACHE BOOL "Build Python bindings" FORCE)
7875
endif()
7976

80-
if(CMAKE_CUDA_COMPILER)
81-
option(IPC_TOOLKIT_WITH_CUDA "Enable CUDA CCD" ON)
82-
else()
83-
option(IPC_TOOLKIT_WITH_CUDA "Enable CUDA CCD" OFF)
84-
endif()
77+
option(IPC_TOOLKIT_WITH_CUDA "Enable CUDA CCD" OFF)
8578
option(IPC_TOOLKIT_WITH_RATIONAL_INTERSECTION "Use rational edge-triangle intersection check" OFF)
8679
option(IPC_TOOLKIT_WITH_ROBIN_MAP "Use Tessil's robin-map rather than std maps" ON)
8780
option(IPC_TOOLKIT_WITH_ABSEIL "Use Abseil's hash functions" ON)
@@ -245,9 +238,14 @@ target_compile_features(ipc_toolkit PUBLIC cxx_std_17)
245238
################################################################################
246239

247240
if(IPC_TOOLKIT_WITH_CUDA)
248-
if(NOT CMAKE_CUDA_COMPILER)
249-
message(FATAL_ERROR "CUDA support requested but no CUDA compiler found!")
241+
# If CMAKE_CUDA_ARCHITECTURES was not specified, set it to native.
242+
if(DEFINED CMAKE_CUDA_ARCHITECTURES)
243+
message(STATUS "CMAKE_CUDA_ARCHITECTURES was specified, skipping auto-detection")
244+
else()
245+
message(STATUS "CMAKE_CUDA_ARCHITECTURES was not specified, set it to native")
246+
set(CMAKE_CUDA_ARCHITECTURES "native")
250247
endif()
248+
message(STATUS "Targeting CUDA_ARCHITECTURES \"${CMAKE_CUDA_ARCHITECTURES}\"")
251249

252250
# Enable CUDA support
253251
enable_language(CUDA)
@@ -256,10 +254,6 @@ if(IPC_TOOLKIT_WITH_CUDA)
256254
# library to be built with -dc as the member functions could be called by
257255
# other libraries and executables.
258256
set_target_properties(ipc_toolkit PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
259-
260-
# Use the same CUDA architectures Scalable CCD
261-
get_target_property(CMAKE_CUDA_ARCHITECTURES scalable_ccd CUDA_ARCHITECTURES)
262-
set_target_properties(ipc_toolkit PROPERTIES CUDA_ARCHITECTURES "${CMAKE_CUDA_ARCHITECTURES}")
263257
endif()
264258

265259
################################################################################
@@ -311,4 +305,4 @@ if (CMAKE_GENERATOR STREQUAL "Xcode")
311305
if(IPC_TOOLKIT_BUILD_PYTHON)
312306
set_target_properties(ipctk PROPERTIES XCODE_GENERATE_SCHEME ON)
313307
endif()
314-
endif()
308+
endif()

CMakePresets.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"version": 3,
33
"cmakeMinimumRequired": {
44
"major": 3,
5-
"minor": 18
5+
"minor": 24
66
},
77
"configurePresets": [{
88
"name": "release",
@@ -166,4 +166,4 @@
166166
}
167167
}
168168
]
169-
}
169+
}

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,19 @@ IPC Toolkit is a set of reusable functions to integrate Incremental Potential Co
1616

1717
### Features
1818

19-
* IPC barrier function and its derivatives and adaptive barrier stiffness algorithm
19+
* IPC barrier function and its derivatives, and adaptive barrier stiffness algorithm
2020
* Broad- and narrow-phase continuous collision detection (CCD) of linear and nonlinear trajectories
2121
* Distance computation and derivatives between edges in 2D and triangles in 3D
2222
* Distance barrier potential and its derivatives
2323
* Smooth and lagged dissipative friction potential and its derivatives
2424

2525
### Limitations
2626

27-
This is not a full simulation library. As such it does not include any physics or solvers. For a full simulation implementation, we recommend [PolyFEM](https://polyfem.github.io/) (a finite element library) or [Rigid IPC](https://github.com/ipc-sim/rigid-ipc) (rigid-body dynamics) both of which utilize the IPC Toolkit.
27+
This is not a full simulation library. As such, it does not include any physics or solvers. For a full simulation implementation, we recommend [PolyFEM](https://polyfem.github.io/) (a finite element library) or [Rigid IPC](https://github.com/ipc-sim/rigid-ipc) (rigid-body dynamics), both of which utilize the IPC Toolkit.
2828

2929
## Build
3030

31-
Instruction for building and including the IPC Toolkit in your CMake project can be found on the website [here](https://ipctk.xyz/build.html).
31+
Instructions for building and including the IPC Toolkit in your CMake project can be found on the website [here](https://ipctk.xyz/build/c++.html).
3232

3333
### Dependencies
3434

@@ -42,7 +42,7 @@ A full list of dependencies can be found on the [dependencies page](https://ipct
4242

4343
We provide Python bindings for functions in the toolkit using [pybind11](https://github.com/pybind/pybind11).
4444

45-
For more information see the [Python documentation](https://ipctk.xyz/python.html).
45+
For more information, see the [Python documentation](https://ipctk.xyz/python.html).
4646

4747
## Usage
4848

@@ -61,7 +61,7 @@ Simply fork this repository and make a Pull Request! We would appreciate:
6161

6262
## Citation
6363

64-
IPC Toolkit is created and maintained by academics: citations let us know our work is having impact! Please cite the IPC Toolkit or otherwise give a shout-out if and when it contributes to published works.
64+
The IPC Toolkit is created and maintained by academics: citations let us know our work is having an impact! Please cite the IPC Toolkit or otherwise give a shout-out if and when it contributes to published works.
6565

6666
```bibtex
6767
@software{ipc_toolkit,
@@ -93,4 +93,4 @@ This project is licensed under the MIT License.
9393

9494
You are free to use, modify, and distribute this code in your projects, even commercial ones, as long as you include the original copyright and license notice. A copy of the full license text can be found in the <a href="https://github.com/ipc-sim/ipc-toolkit/blob/main/LICENSE"><code>LICENSE</code></a> file.
9595

96-
If you use this code in a product you distribute to others, you are required to **include a copy of the original copyright and license notice**. This is typically done in the product's documentation, an "About" or "Third-Party Licenses" section, or in a clear open-source software statement.
96+
If you use this code in a product you distribute to others, you are required to **include a copy of the original copyright and license notice**. This is typically done in the product's documentation, an "About" or "Third-Party Licenses" section, or in a clear open-source software statement.

docs/source/build/c++.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ You can build the IPC Toolkit using CMake as you would any other CMake project.
5353
5454
This will build the IPC Toolkit and all of its dependencies. The ``IPC_TOOLKIT_BUILD_TESTS`` option enables building the unit tests, and the ``IPC_TOOLKIT_BUILD_PYTHON`` option enables building the Python bindings.
5555

56+
CUDA support is disabled by default. Enable it by setting CMake option ``IPC_TOOLKIT_WITH_CUDA`` to ON.
57+
5658
.. warning::
5759
Installing the IPC Toolkit using the ``make install`` has not been tested and is not recommended. The IPC Toolkit is designed to be used as a submodule in your project, and as such does not have a proper install target.
5860

@@ -61,4 +63,4 @@ Dependencies
6163

6264
**All required dependencies are downloaded through CMake** depending on the build options, and are built automatically when you build the IPC Toolkit. You do not need to install them separately.
6365

64-
A full list of dependencies can be found on the `dependencies page <https://ipctk.xyz/dependencies.html>`_.
66+
A full list of dependencies can be found on the `dependencies page <https://ipctk.xyz/dependencies.html>`_.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ requires = [
33
"setuptools>=42",
44
"wheel",
55
"ninja",
6-
# "cmake>=3.14",
6+
# "cmake>=3.24",
77
]
88
build-backend = "setuptools.build_meta"
99

0 commit comments

Comments
 (0)