首页 > 解决方案 > 使用 PGI 编译器编译 Eigen 时出错

问题描述

我正在尝试使用 PGI 的 C++ 编译器编译包含 Eigen 标头的代码,但出现以下错误:

"/opt/local/include/eigen3/Eigen/src/Core/arch/SSE/PacketMath.h", line 413:
          error: more than one instance of overloaded function "_mm_prefetch"
          matches the argument list:
            function "_mm_prefetch(const char *, int)"
            function "_mm_prefetch(const void *, _mm_hint)"
            argument types are: (const char *, _mm_hint)
  template<> EIGEN_STRONG_INLINE void prefetch<float>(const float*   addr) { _mm_prefetch((const char*)(addr), _MM_HINT_T0); }
                                                                             ^

"/opt/local/include/eigen3/Eigen/src/Core/arch/SSE/PacketMath.h", line 414:
          error: more than one instance of overloaded function "_mm_prefetch"
          matches the argument list:
            function "_mm_prefetch(const char *, int)"
            function "_mm_prefetch(const void *, _mm_hint)"
            argument types are: (const char *, _mm_hint)
  template<> EIGEN_STRONG_INLINE void prefetch<double>(const double* addr) { _mm_prefetch((const char*)(addr), _MM_HINT_T0); }
                                                                             ^

"/opt/local/include/eigen3/Eigen/src/Core/arch/SSE/PacketMath.h", line 415:
          error: more than one instance of overloaded function "_mm_prefetch"
          matches the argument list:
            function "_mm_prefetch(const char *, int)"
            function "_mm_prefetch(const void *, _mm_hint)"
            argument types are: (const char *, _mm_hint)
  template<> EIGEN_STRONG_INLINE void prefetch<int>(const int*       addr) { _mm_prefetch((const char*)(addr), _MM_HINT_T0); }
                                                                             ^

"/opt/local/include/eigen3/Eigen/src/Core/arch/SSE/Complex.h", line 131: error:
          more than one instance of overloaded function "_mm_prefetch" matches
          the argument list:
            function "_mm_prefetch(const char *, int)"
            function "_mm_prefetch(const void *, _mm_hint)"
            argument types are: (const char *, _mm_hint)
  template<> EIGEN_STRONG_INLINE void prefetch<std::complex<float> >(const std::complex<float> *   addr) { _mm_prefetch((const char*)(addr), _MM_HINT_T0); }
                                                                                                           ^

"/opt/local/include/eigen3/Eigen/src/Core/arch/SSE/Complex.h", line 343: error:
          more than one instance of overloaded function "_mm_prefetch" matches
          the argument list:
            function "_mm_prefetch(const char *, int)"
            function "_mm_prefetch(const void *, _mm_hint)"
            argument types are: (const char *, _mm_hint)
  template<> EIGEN_STRONG_INLINE void prefetch<std::complex<double> >(const std::complex<double> *   addr) { _mm_prefetch((const char*)(addr), _MM_HINT_T0); }
                                                                                                             ^

5 errors detected in the compilation of "/Users/wooden/CLionProjects/EigenTest/main.cpp".
make[2]: *** [CMakeFiles/EigenTest.dir/main.cpp.o] Error 2
make[1]: *** [CMakeFiles/EigenTest.dir/all] Error 2
make: *** [all] Error 2

只要包含 Eigen 标头,无论正在编译的代码如何,我都会得到相同的错误。更具体地说,我包括以下内容:

#include <Eigen/Eigen>

并尝试编译一个简单的“Hello World”程序。除了 Eigen 的指令之外,CMakeLists.txt 也是准系统。

cmake_minimum_required(VERSION 3.10)
project(EigenTest)

set(CMAKE_CXX_STANDARD 11)

add_executable(EigenTest main.cpp)

find_package (Eigen3 3.3 REQUIRED NO_MODULE)
target_link_libraries (EigenTest Eigen3::Eigen)

我应该注意,我使用的是 macOS Sierra (10.12.6),并且我已经尝试了 PGI 的 v17.10 和 v18.4。没有特殊标志用于编译。安装的 Eigen 包是 MacPorts (eigen3 3.3.4) 上最新的一个。

我之前已经对 Eigen 进行了非平凡的使用,并且在 GCC 上一切正常。我之前也毫无问题地使用过 PGI 的编译器。我试图同时使用两者的原因是我需要在使用 Eigen 的代码的某些部分中使用 OpenACC 编译指示。

任何引导我走向正确方向的帮助将不胜感激。

更新 1

在Eigen的源文件中转换addr到错误的上述行(或评论所述行),const void*而不是const char*在 Eigen 的源文件中,我不再收到编译错误。我可以从 Eigen 获得基本功能,但更复杂的代码无法成功链接。产生以下错误:

Undefined symbols for architecture x86_64:


"__ZN98_INTERNAL_76__Users_wooden_CLionProjects_MLProject_src_Classification_LogisticRegression_cpp_c51a32f316_mm_castpd_si128E7__m128d", referenced from:
      __ZN5Eigen8internal29general_matrix_vector_productIldNS0_22const_blas_data_mapperIdlLi1EEELi1ELb0EdNS2_IdlLi0EEELb0ELi0EE3runEllRKS3_RKS4_Pdld in LogisticRegression.cpp.o
      __ZN5Eigen8internal11palign_implILi1E7__m128dE3runERS2_RKS2_ in LogisticRegression.cpp.o
      __ZN5Eigen8internal6palignILi1E7__m128dEEvRT0_RKS3_ in LogisticRegression.cpp.o
  "__ZN98_INTERNAL_76__Users_wooden_CLionProjects_MLProject_src_Classification_LogisticRegression_cpp_c51a32f316_mm_castsi128_pdE7__m128i", referenced from:
      __ZN5Eigen8internal29general_matrix_vector_productIldNS0_22const_blas_data_mapperIdlLi1EEELi1ELb0EdNS2_IdlLi0EEELb0ELi0EE3runEllRKS3_RKS4_Pdld in LogisticRegression.cpp.o
      __ZN5Eigen8internal11palign_implILi1E7__m128dE3runERS2_RKS2_ in LogisticRegression.cpp.o
      __ZN5Eigen8internal4pexpI7__m128dEET_RKS3_ in LogisticRegression.cpp.o
      __ZN5Eigen8internal6palignILi1E7__m128dEEvRT0_RKS3_ in LogisticRegression.cpp.o
ld: symbol(s) not found for architecture x86_64
make[2]: *** [MLProject] Error 2
make[1]: *** [CMakeFiles/MLProject.dir/all] Error 2
make: *** [all] Error 2

更新 2

按照@chtz 对评论的建议使用-DEIGEN_DONT_VECTORIZE,这会禁用 Eigen 的内置矢量化,项目代码编译、链接并成功执行。然而,这产生了一个主要问题,因为 Eigen 最初被用于其矢量化线性代数实现。

_mm_castpd_si128至于编译错误,根据@ggael ,可能与PGI对类型的支持有关。

总而言之,似乎 Eigen 与 PGI 的 C++ 编译器的兼容性充其量只是部分的。

标签: c++eigenpgi

解决方案


推荐阅读