-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
workaround eigen bug with matrix inversion
- Loading branch information
Showing
2 changed files
with
47 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#pragma once | ||
|
||
#include <cuda.h> | ||
#include "rxmesh/types.h" | ||
|
||
#include <Eigen/Dense> | ||
|
||
namespace rxmesh { | ||
/** | ||
* @brief since 3x3 matrix inverse in eigen is buggy on device (it results into | ||
* "unspecified launch failure"), we convert eigen matrix into glm, inverse it, | ||
* then convert it back to eigen matrix | ||
* @tparam T the floating point type of the matrix | ||
* @tparam n the size of the matrix, expected/tested sizes are 2,3, and 4. | ||
*/ | ||
|
||
template <typename T, int n> | ||
__device__ __host__ __inline__ Eigen::Matrix<T, n, n> inverse( | ||
const Eigen::Matrix<T, n, n>& in) | ||
{ | ||
glm::mat<n, n, T, glm::defaultp> glm_mat; | ||
|
||
for (int i = 0; i < n; ++i) { | ||
for (int j = 0; j < n; ++j) { | ||
glm_mat[i][j] = in(i, j); | ||
} | ||
} | ||
|
||
auto glm_inv = glm::inverse(glm_mat); | ||
|
||
Eigen::Matrix<T, n, n> eig_inv; | ||
|
||
for (int i = 0; i < n; ++i) { | ||
for (int j = 0; j < n; ++j) { | ||
eig_inv(i, j) = glm_inv[i][j]; | ||
} | ||
} | ||
return eig_inv; | ||
} | ||
|
||
|
||
} // namespace rxmesh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters