如何解决在内核代码中调用 Eigen 函数时出现 NVCC 编译错误
我在 Ubuntu 18.04.4 上运行的项目使用 Eigen 3.3.9。在我尝试修改我的项目以获得 CUDA 支持之前,一切都运行良好。我试过 cuda/10.0 和 cuda/10.2。
当我尝试为特征矩阵调用 determinant() 时出现问题。我的编译器产生以下错误。
voxelize.cu(301): error: calling a __host__ function("Eigen::MatrixBase< ::Eigen::Matrix<float,(int)3,(int)0,(int)3> > ::determinant const") from a __global__ function("MeshIterKernel") is not allowed
voxelize.cu(301): error: identifier "Eigen::MatrixBase< ::Eigen::Matrix<float,(int)3> > ::determinant const" is undefined in device code
voxelize.cu(301): error: calling a __host__ function("Eigen::MatrixBase< ::Eigen::Matrix<float,(int)3> > ::determinant const") from a __global__ function("MeshIterKernel") is not allowed
以及同一日志的更多行。
我很确定 Eigen 是受支持的,因为我没有遇到其他 Eigen 函数的任何错误。我看到有关编译时忽略 device 和 host 注释的警告,但没有看到其中之一的决定因素。
./Eigen/src/Core/Block.h(341): warning: __host__ annotation is ignored on a function("BlockImpl_dense") that is explicitly defaulted on its first declaration
./Eigen/src/Core/Block.h(341): warning: __device__ annotation is ignored on a function("BlockImpl_dense") that is explicitly defaulted on its first declaration
./Eigen/src/Core/Transpose.h(66): warning: __host__ annotation is ignored on a function("Transpose") that is explicitly defaulted on its first declaration
./Eigen/src/Core/Transpose.h(66): warning: __device__ annotation is ignored on a function("Transpose") that is explicitly defaulted on its first declaration
__device__
bool Philipp(Vector3f A,Vector3f B,Vector3f C,Vector3f D,Vector3f P)
{
Vector3f a = A - P,b = B - P,c = C - P,d = D - P;
Matrix3f Da,Db,Dc,Dd;
Da << b,c,d;
Db << a,d;
Dc << a,b,d;
Dd << a,c;
if((Da.determinant() * Dc.determinant() >= 0) && (Db.determinant() * Dd.determinant() >= 0) && (Da.determinant() * Db.determinant() <= 0))
return true;
return false;
}
感谢任何帮助。如果这种情况继续发生,我将实现我自己的行列式函数。
编辑: 这是我可以减少以重现问题的最少代码。
#include <Eigen/Dense>
using namespace Eigen;
__device__
bool Foo()
{
Vector3f a,c;
Matrix3f Da;
a << 1,2,3;
b << 2,5,7;
c << 6,1,8;
Da << a,c;
return Da.determinant() >= 0;
}
__global__
void Kernel()
{
Foo();
}
int main(int argc,char** argv)
{
Kernel<<<1,1>>>();
return 0;
}
nvcc add.cu -I .
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。