Skip to content

Commit fe724d3

Browse files
authored
GPU bug fix (#7)
* [bug] fix typos * [bug] fix compile error when using single-precision floating-point arithmetic
1 parent b42005a commit fe724d3

File tree

4 files changed

+20
-8
lines changed

4 files changed

+20
-8
lines changed

src/scalable_ccd/cuda/ccd.cu

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ namespace {
7777
}
7878
} // namespace
7979

80-
double
80+
Scalar
8181
ccd(const Eigen::MatrixXd& vertices_t0,
8282
const Eigen::MatrixXd& vertices_t1,
8383
const Eigen::MatrixXi& edges,

src/scalable_ccd/cuda/ipc_ccd_strategy.hpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#pragma once
22

33
#include <Eigen/Core>
4+
#include <scalable_ccd/scalar.hpp>
45

56
namespace scalable_ccd::cuda {
67

@@ -13,13 +14,13 @@ namespace scalable_ccd::cuda {
1314
/// @param max_iter Maximum number of iterations
1415
/// @param tolerance Tolerance for the CCD algorithm
1516
/// @return Time of impact
16-
double ipc_ccd_strategy(
17+
Scalar ipc_ccd_strategy(
1718
const Eigen::MatrixXd& V0,
1819
const Eigen::MatrixXd& V1,
1920
const Eigen::MatrixXi& E,
2021
const Eigen::MatrixXi& F,
21-
const double min_distance,
22+
const Scalar min_distance,
2223
const int max_iter,
23-
const double tolerance);
24+
const Scalar tolerance);
2425

2526
} // namespace scalable_ccd::cuda

src/scalable_ccd/cuda/scalar.cuh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ make_Scalar3(const Scalar& a, const Scalar& b, const Scalar& c)
2828

2929
#else
3030

31+
__device__ constexpr float SCALAR_MAX = scalable_ccd::SCALAR_MAX;
32+
3133
using Scalar2 = float2;
3234
using Scalar3 = float3;
3335

src/scalable_ccd/cuda/utils/device_matrix.cuh

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,23 @@ public:
3434
thrust::copy(mat.data(), mat.data() + mat.size(), m_data.begin());
3535
}
3636

37-
#ifndef SCALABLE_CCD_USE_DOUBLE
38-
DeviceMatrix(const Eigen::MatrixXd& mat) : DeviceMatrix(mat.cast<T>()) { }
37+
template <typename U = T, typename std::enable_if<!std::is_same<U, double>::value>::type* = nullptr>
38+
DeviceMatrix(const Eigen::MatrixXd& mat)
39+
: m_rows(mat.rows())
40+
, m_cols(mat.cols())
41+
, m_data(mat.size())
42+
{
43+
thrust::copy(mat.data(), mat.data() + mat.size(), m_data.begin());
44+
}
3945

46+
template <typename U = T, typename std::enable_if<!std::is_same<U, double>::value>::type* = nullptr>
4047
void operator=(const Eigen::MatrixXd& mat)
4148
{
42-
return operator=(mat.cast<T>());
49+
m_rows = mat.rows();
50+
m_cols = mat.cols();
51+
m_data.resize(mat.size());
52+
thrust::copy(mat.data(), mat.data() + mat.size(), m_data.begin());
4353
}
44-
#endif
4554

4655
// TODO: Add function to retrieve the matrix from the device.
4756

0 commit comments

Comments
 (0)