Skip to content

Commit ba24d37

Browse files
authored
Compile CUDA in Continuous Integration (#125)
1 parent 7b70ae3 commit ba24d37

File tree

10 files changed

+105
-32
lines changed

10 files changed

+105
-32
lines changed

.github/workflows/cuda.yml

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
name: CUDA
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
paths:
8+
- '.github/workflows/cuda.yml'
9+
- 'cmake/**'
10+
- 'src/**'
11+
- 'tests/**'
12+
- 'python/**'
13+
- 'CMakeLists.txt'
14+
15+
env:
16+
CTEST_OUTPUT_ON_FAILURE: ON
17+
CTEST_PARALLEL_LEVEL: 2
18+
19+
jobs:
20+
Build:
21+
name: CUDA (${{ matrix.config }})
22+
runs-on: ubuntu-latest
23+
strategy:
24+
fail-fast: false
25+
matrix:
26+
config:
27+
- Debug
28+
- Release
29+
steps:
30+
- name: Checkout repository
31+
uses: actions/[email protected]
32+
with:
33+
fetch-depth: 10
34+
35+
- name: Dependencies
36+
run: |
37+
sudo apt-get install ccache
38+
echo 'CACHE_PATH=~/.cache/ccache' >> "$GITHUB_ENV"
39+
40+
- uses: Jimver/[email protected]
41+
id: cuda-toolkit
42+
with:
43+
cuda: '12.4.0'
44+
sub-packages: '["nvcc"]'
45+
method: 'network'
46+
47+
- name: Get number of CPU cores
48+
uses: SimenB/[email protected]
49+
id: cpu-cores
50+
51+
- name: Cache Build
52+
id: cache-build
53+
uses: actions/[email protected]
54+
with:
55+
path: ${{ env.CACHE_PATH }}
56+
key: ${{ runner.os }}-${{ matrix.config }}-cache
57+
58+
- name: Prepare ccache
59+
run: |
60+
ccache --max-size=1.0G
61+
ccache -V && ccache --show-config
62+
ccache --show-stats && ccache --zero-stats
63+
64+
- name: Configure
65+
run: |
66+
mkdir -p build
67+
cd build
68+
cmake .. \
69+
-DIPC_TOOLKIT_WITH_CUDA=ON \
70+
-DSCALABLE_CCD_CUDA_ARCHITECTURES=75 \
71+
-DIPC_TOOLKIT_BUILD_TESTS=ON \
72+
-DIPC_TOOLKIT_BUILD_PYTHON=ON \
73+
-DCMAKE_BUILD_TYPE=${{ matrix.config }}
74+
75+
- name: Build
76+
run: |
77+
cmake --build build -j ${{ steps.cpu-cores.outputs.count }}
78+
ccache --show-stats

.github/workflows/python.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
fail-fast: false
2424
matrix:
2525
os: [ubuntu-latest, macos-latest, windows-latest]
26-
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
26+
python-version: ["3.9", "3.10", "3.11", "3.12"]
2727
include:
2828
- os: ubuntu-latest
2929
name: Linux

CMakeLists.txt

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ target_compile_features(ipc_toolkit PUBLIC cxx_std_17)
218218
if(IPC_TOOLKIT_WITH_CUDA)
219219
include(CheckLanguage)
220220
check_language(CUDA)
221+
221222
if(CMAKE_CUDA_COMPILER)
222223
enable_language(CUDA)
223224
else()
@@ -229,17 +230,9 @@ if(IPC_TOOLKIT_WITH_CUDA)
229230
# other libraries and executables.
230231
set_target_properties(ipc_toolkit PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
231232

232-
if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.24.0")
233-
set(CMAKE_CUDA_ARCHITECTURES "native")
234-
else()
235-
include(FindCUDA/select_compute_arch)
236-
CUDA_DETECT_INSTALLED_GPUS(CUDA_ARCH_LIST)
237-
string(STRIP "${CUDA_ARCH_LIST}" CUDA_ARCH_LIST)
238-
string(REPLACE " " ";" CUDA_ARCH_LIST "${CUDA_ARCH_LIST}")
239-
string(REPLACE "." "" CUDA_ARCH_LIST "${CUDA_ARCH_LIST}")
240-
set(CMAKE_CUDA_ARCHITECTURES ${CUDA_ARCH_LIST})
241-
endif()
242-
set_target_properties(scalable_ccd PROPERTIES CUDA_ARCHITECTURES "${CMAKE_CUDA_ARCHITECTURES}")
233+
# Use the same CUDA architectures Scalable CCD
234+
get_target_property(CMAKE_CUDA_ARCHITECTURES scalable_ccd CUDA_ARCHITECTURES)
235+
set_target_properties(ipc_toolkit PROPERTIES CUDA_ARCHITECTURES "${CMAKE_CUDA_ARCHITECTURES}")
243236
endif()
244237

245238
################################################################################

cmake/recipes/scalable_ccd.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ message(STATUS "Third-party: creating target 'scalable_ccd::scalable_ccd'")
99
set(SCALABLE_CCD_WITH_CUDA ${IPC_TOOLKIT_WITH_CUDA} CACHE BOOL "Enable CUDA CCD" FORCE)
1010

1111
include(CPM)
12-
CPMAddPackage("gh:continuous-collision-detection/scalable-ccd#318352e6aa3c1008a67c80547c6fa21bf18fb1a5")
12+
CPMAddPackage("gh:continuous-collision-detection/scalable-ccd#95a078bbaf9659f2e1b4285d51475deff163bfa0")

src/ipc/ccd/additive_ccd.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ namespace {
6060
}
6161
} // namespace
6262

63-
AdditiveCCD::AdditiveCCD(const double conservative_rescaling)
64-
: conservative_rescaling(conservative_rescaling)
63+
AdditiveCCD::AdditiveCCD(const double _conservative_rescaling)
64+
: conservative_rescaling(_conservative_rescaling)
6565
{
6666
}
6767

src/ipc/ccd/tight_inclusion_ccd.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ static constexpr double INITIAL_DISTANCE_TOLERANCE_SCALE = 0.5;
2121
static constexpr long TIGHT_INCLUSION_UNLIMITED_ITERATIONS = -1;
2222

2323
TightInclusionCCD::TightInclusionCCD(
24-
const double tolerance,
25-
const long max_iterations,
26-
const double conservative_rescaling)
27-
: tolerance(tolerance)
28-
, max_iterations(max_iterations)
29-
, conservative_rescaling(conservative_rescaling)
24+
const double _tolerance,
25+
const long _max_iterations,
26+
const double _conservative_rescaling)
27+
: tolerance(_tolerance)
28+
, max_iterations(_max_iterations)
29+
, conservative_rescaling(_conservative_rescaling)
3030
{
3131
}
3232

src/ipc/implicits/plane.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ double compute_point_plane_collision_free_stepsize(
100100
const double earliest_toi = tbb::parallel_reduce(
101101
tbb::blocked_range<size_t>(0, points_t0.rows()),
102102
/*inital_step_size=*/1.0,
103-
[&](tbb::blocked_range<size_t> r, double earliest_toi) {
103+
[&](tbb::blocked_range<size_t> r, double current_toi) {
104104
for (size_t vi = r.begin(); vi < r.end(); vi++) {
105105
for (size_t pi = 0; pi < n_planes; pi++) {
106106
if (!can_collide(vi, pi)) {
@@ -116,13 +116,13 @@ double compute_point_plane_collision_free_stepsize(
116116
plane_normal, toi);
117117

118118
if (are_colliding) {
119-
if (toi < earliest_toi) {
120-
earliest_toi = toi;
119+
if (toi < current_toi) {
120+
current_toi = toi;
121121
}
122122
}
123123
}
124124
}
125-
return earliest_toi;
125+
return current_toi;
126126
},
127127
[&](double a, double b) { return std::min(a, b); });
128128

src/ipc/ipc.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,10 @@ double compute_collision_free_stepsize(
5656
"Sweep and Tiniest Queue is only supported in 3D!");
5757
}
5858
// TODO: Use correct min_distance
59-
const double tolerance = TightInclusionCCD::DEFAULT_TOLERANCE;
60-
const long max_iterations = TightInclusionCCD::DEFAULT_MAX_ITERATIONS;
59+
// TODO: Expose tolerance and max_iterations
60+
constexpr double tolerance = TightInclusionCCD::DEFAULT_TOLERANCE;
61+
constexpr long max_iterations =
62+
TightInclusionCCD::DEFAULT_MAX_ITERATIONS;
6163
const double step_size = scalable_ccd::cuda::ipc_ccd_strategy(
6264
vertices_t0, vertices_t1, mesh.edges(), mesh.faces(),
6365
/*min_distance=*/0.0, max_iterations, tolerance);

tests/src/tests/barrier/test_barrier.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class NormalizedClampedLogBarrier : public ipc::Barrier {
5959
/// @warning This implementation will not work with dmin > 0
6060
class PhysicalBarrier : public ipc::NormalizedClampedLogBarrier {
6161
public:
62-
PhysicalBarrier(const bool use_dist_sqr) : use_dist_sqr(use_dist_sqr) { }
62+
PhysicalBarrier(const bool _use_dist_sqr) : use_dist_sqr(_use_dist_sqr) { }
6363

6464
double operator()(const double d, const double dhat) const override
6565
{

tests/src/tests/ccd/test_gpu_ccd.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,15 @@ TEST_CASE("GPU CCD", "[ccd][gpu]")
4343
const double min_distance = 0;
4444

4545
const double toi_cpu = compute_collision_free_stepsize(
46-
mesh, V0, V1, BroadPhaseMethod::SWEEP_AND_PRUNE, min_distance,
47-
tolerance, max_iterations);
46+
mesh, V0, V1, min_distance, BroadPhaseMethod::SWEEP_AND_PRUNE,
47+
TightInclusionCCD(tolerance, max_iterations));
4848

4949
// Got this value from running the code
5050
CHECK(toi_cpu == Catch::Approx(4.76837158203125000e-06));
5151

5252
const double toi_gpu = compute_collision_free_stepsize(
53-
mesh, V0, V1, BroadPhaseMethod::SWEEP_AND_TINIEST_QUEUE, min_distance,
54-
tolerance, max_iterations);
53+
mesh, V0, V1, min_distance, BroadPhaseMethod::SWEEP_AND_TINIEST_QUEUE,
54+
TightInclusionCCD(tolerance, max_iterations));
5555

5656
// Got this value from running the code
5757
CHECK(toi_gpu == Catch::Approx(3.05175781250000017e-6));

0 commit comments

Comments
 (0)