构建使用 Eigen(C++)的项目时出现编译器错误线性代数模板库

发布于 2024-09-10 17:41:54 字数 5355 浏览 7 评论 0原文

在我的项目中,我使用 Eigen C++ 库进行线性代数,当我打开 ARM NEON 的矢量化标志 (mfpu=neon -mfloat-abi=softfp) 时,出现编译器错误。我无法理解出了什么问题。我是否需要在 Eigen 库中为 ARM NEON 启用任何预处理器指令?


main.c

#include<iostream>
#include <Eigen/Core>

// import most common Eigen types
using namespace Eigen;

int main(int, char *[])
{
    Matrix4f m3;
    m3 << 1, 2, 3, 0, 4, 5, 6, 0, 7, 8, 9, 0, 0, 0, 0, 0;
    Matrix4f m4;

    asm("#begins here");
    m4 = m3*m3;
    asm("#ends here");

    std::cout << "m3\n" << m3 << "\nm4:\n"
        << m4 << std::endl;

    std::cout << "DONE!!";
}

makefile

main: main.cpp
    g++ -mfpu=neon -mfloat-abi=softfp -I /home/ubuntu/Documents/eigen/ main.cpp -o main

错误

 ubuntu@ubuntu-desktop:~/Documents/mat_mul$ make
g++ -mfpu=neon -mfloat-abi=softfp -I /home/ubuntu/Documents/eigen/ main.cpp -o main
In file included from /home/ubuntu/Documents/eigen/Eigen/Core:227,
                 from main.cpp:2:
/home/ubuntu/Documents/eigen/Eigen/src/Core/arch/NEON/PacketMath.h: In function ‘typename Eigen::ei_packet_traits<T>::type Eigen::ei_pload(const Scalar*) [with Scalar = float]’:
/home/ubuntu/Documents/eigen/Eigen/src/Core/arch/NEON/PacketMath.h:163: error: cannot convert ‘const float*’ to ‘const float32_t*’ for argument ‘1’ to ‘__builtin_neon_sf __vector__ vld1q_f32(const float32_t*)’
/home/ubuntu/Documents/eigen/Eigen/src/Core/arch/NEON/PacketMath.h: In function ‘typename Eigen::ei_packet_traits<T>::type Eigen::ei_ploadu(const Scalar*) [with Scalar = float]’:
/home/ubuntu/Documents/eigen/Eigen/src/Core/arch/NEON/PacketMath.h:166: error: cannot convert ‘const float*’ to ‘const float32_t*’ for argument ‘1’ to ‘__builtin_neon_sf __vector__ vld1q_f32(const float32_t*)’
/home/ubuntu/Documents/eigen/Eigen/src/Core/arch/NEON/PacketMath.h: In function ‘void Eigen::ei_pstore(Scalar*, const Packet&) [with Scalar = float, Packet = __builtin_neon_sf __vector__]’:
/home/ubuntu/Documents/eigen/Eigen/src/Core/arch/NEON/PacketMath.h:169: error: cannot convert ‘float*’ to ‘float32_t*’ for argument ‘1’ to ‘void vst1q_f32(float32_t*, __builtin_neon_sf __vector__)’
/home/ubuntu/Documents/eigen/Eigen/src/Core/arch/NEON/PacketMath.h: In function ‘void Eigen::ei_pstoreu(Scalar*, const Packet&) [with Scalar = float, Packet = __builtin_neon_sf __vector__]’:
/home/ubuntu/Documents/eigen/Eigen/src/Core/arch/NEON/PacketMath.h:172: error: cannot convert ‘float*’ to ‘float32_t*’ for argument ‘1’ to ‘void vst1q_f32(float32_t*, __builtin_neon_sf __vector__)’
/home/ubuntu/Documents/eigen/Eigen/src/Core/arch/NEON/PacketMath.h: In function ‘typename Eigen::ei_unpacket_traits<T>::type Eigen::ei_pfirst(const Packet&) [with Packet = __builtin_neon_sf __vector__]’:
/home/ubuntu/Documents/eigen/Eigen/src/Core/arch/NEON/PacketMath.h:179: error: cannot convert ‘float*’ to ‘float32_t*’ for argument ‘1’ to ‘void vst1q_f32(float32_t*, __builtin_neon_sf __vector__)’
/home/ubuntu/Documents/eigen/Eigen/src/Core/arch/NEON/PacketMath.h: In function ‘typename Eigen::ei_unpacket_traits<T>::type Eigen::ei_predux(const Packet&) [with Packet = __builtin_neon_sf __vector__]’:
/home/ubuntu/Documents/eigen/Eigen/src/Core/arch/NEON/PacketMath.h:216: error: cannot convert ‘float*’ to ‘float32_t*’ for argument ‘1’ to ‘void vst1_f32(float32_t*, __builtin_neon_sf __vector__)’
/home/ubuntu/Documents/eigen/Eigen/src/Core/arch/NEON/PacketMath.h: In function ‘typename Eigen::ei_unpacket_traits<T>::type Eigen::ei_predux_mul(const Packet&) [with Packet = __builtin_neon_sf __vector__]’:
/home/ubuntu/Documents/eigen/Eigen/src/Core/arch/NEON/PacketMath.h:289: error: cannot convert ‘float*’ to ‘float32_t*’ for argument ‘1’ to ‘void vst1_f32(float32_t*, __builtin_neon_sf __vector__)’
/home/ubuntu/Documents/eigen/Eigen/src/Core/arch/NEON/PacketMath.h: In function ‘typename Eigen::ei_unpacket_traits<T>::type Eigen::ei_predux_min(const Packet&) [with Packet = __builtin_neon_sf __vector__]’:
/home/ubuntu/Documents/eigen/Eigen/src/Core/arch/NEON/PacketMath.h:320: error: cannot convert ‘float*’ to ‘float32_t*’ for argument ‘1’ to ‘void vst1_f32(float32_t*, __builtin_neon_sf __vector__)’
/home/ubuntu/Documents/eigen/Eigen/src/Core/arch/NEON/PacketMath.h: In function ‘typename Eigen::ei_unpacket_traits<T>::type Eigen::ei_predux_max(const Packet&) [with Packet = __builtin_neon_sf __vector__]’:
/home/ubuntu/Documents/eigen/Eigen/src/Core/arch/NEON/PacketMath.h:348: error: cannot convert ‘float*’ to ‘float32_t*’ for argument ‘1’ to ‘void vst1_f32(float32_t*, __builtin_neon_sf __vector__)’
make: *** [main] Error 1
ubuntu@ubuntu-desktop:~/Documents/mat_mul$ 

我使用 Code Sourcery 工具链时遇到的错误

ubuntu@ubuntu-desktop:~/Documents/CodeSourcery_WS/Test_Eigen$ make
/home/ubuntu/CodeSourcery/Sourcery_G++/bin/arm-none-linux-gnueabi-c++ -mfpu=neon -mfloat-abi=softfp -I /home/ubuntu/Documents/eigen/ main.cpp -o main
In file included from main.cpp:1:
/home/ubuntu/CodeSourcery/Sourcery_G++/bin/../lib/gcc/arm-none-linux-gnueabi/4.4.1/../../../../arm-none-linux-gnueabi/include/c++/4.4.1/iostream:39: fatal error: bits/c++config.h: No such file or directory
compilation terminated.
make: *** [main] Error 1

in my project I'm making use of Eigen C++ library for linear algebra and ONLY when I turn on the vectorization flags (mfpu=neon -mfloat-abi=softfp) for ARM NEON, I get compiler errors. I'm not able to understand whats going wrong. Do I need to enable any preprocessor directives for ARM NEON in the Eigen Library?


main.c

#include<iostream>
#include <Eigen/Core>

// import most common Eigen types
using namespace Eigen;

int main(int, char *[])
{
    Matrix4f m3;
    m3 << 1, 2, 3, 0, 4, 5, 6, 0, 7, 8, 9, 0, 0, 0, 0, 0;
    Matrix4f m4;

    asm("#begins here");
    m4 = m3*m3;
    asm("#ends here");

    std::cout << "m3\n" << m3 << "\nm4:\n"
        << m4 << std::endl;

    std::cout << "DONE!!";
}

makefile

main: main.cpp
    g++ -mfpu=neon -mfloat-abi=softfp -I /home/ubuntu/Documents/eigen/ main.cpp -o main

errors

 ubuntu@ubuntu-desktop:~/Documents/mat_mul$ make
g++ -mfpu=neon -mfloat-abi=softfp -I /home/ubuntu/Documents/eigen/ main.cpp -o main
In file included from /home/ubuntu/Documents/eigen/Eigen/Core:227,
                 from main.cpp:2:
/home/ubuntu/Documents/eigen/Eigen/src/Core/arch/NEON/PacketMath.h: In function ‘typename Eigen::ei_packet_traits<T>::type Eigen::ei_pload(const Scalar*) [with Scalar = float]’:
/home/ubuntu/Documents/eigen/Eigen/src/Core/arch/NEON/PacketMath.h:163: error: cannot convert ‘const float*’ to ‘const float32_t*’ for argument ‘1’ to ‘__builtin_neon_sf __vector__ vld1q_f32(const float32_t*)’
/home/ubuntu/Documents/eigen/Eigen/src/Core/arch/NEON/PacketMath.h: In function ‘typename Eigen::ei_packet_traits<T>::type Eigen::ei_ploadu(const Scalar*) [with Scalar = float]’:
/home/ubuntu/Documents/eigen/Eigen/src/Core/arch/NEON/PacketMath.h:166: error: cannot convert ‘const float*’ to ‘const float32_t*’ for argument ‘1’ to ‘__builtin_neon_sf __vector__ vld1q_f32(const float32_t*)’
/home/ubuntu/Documents/eigen/Eigen/src/Core/arch/NEON/PacketMath.h: In function ‘void Eigen::ei_pstore(Scalar*, const Packet&) [with Scalar = float, Packet = __builtin_neon_sf __vector__]’:
/home/ubuntu/Documents/eigen/Eigen/src/Core/arch/NEON/PacketMath.h:169: error: cannot convert ‘float*’ to ‘float32_t*’ for argument ‘1’ to ‘void vst1q_f32(float32_t*, __builtin_neon_sf __vector__)’
/home/ubuntu/Documents/eigen/Eigen/src/Core/arch/NEON/PacketMath.h: In function ‘void Eigen::ei_pstoreu(Scalar*, const Packet&) [with Scalar = float, Packet = __builtin_neon_sf __vector__]’:
/home/ubuntu/Documents/eigen/Eigen/src/Core/arch/NEON/PacketMath.h:172: error: cannot convert ‘float*’ to ‘float32_t*’ for argument ‘1’ to ‘void vst1q_f32(float32_t*, __builtin_neon_sf __vector__)’
/home/ubuntu/Documents/eigen/Eigen/src/Core/arch/NEON/PacketMath.h: In function ‘typename Eigen::ei_unpacket_traits<T>::type Eigen::ei_pfirst(const Packet&) [with Packet = __builtin_neon_sf __vector__]’:
/home/ubuntu/Documents/eigen/Eigen/src/Core/arch/NEON/PacketMath.h:179: error: cannot convert ‘float*’ to ‘float32_t*’ for argument ‘1’ to ‘void vst1q_f32(float32_t*, __builtin_neon_sf __vector__)’
/home/ubuntu/Documents/eigen/Eigen/src/Core/arch/NEON/PacketMath.h: In function ‘typename Eigen::ei_unpacket_traits<T>::type Eigen::ei_predux(const Packet&) [with Packet = __builtin_neon_sf __vector__]’:
/home/ubuntu/Documents/eigen/Eigen/src/Core/arch/NEON/PacketMath.h:216: error: cannot convert ‘float*’ to ‘float32_t*’ for argument ‘1’ to ‘void vst1_f32(float32_t*, __builtin_neon_sf __vector__)’
/home/ubuntu/Documents/eigen/Eigen/src/Core/arch/NEON/PacketMath.h: In function ‘typename Eigen::ei_unpacket_traits<T>::type Eigen::ei_predux_mul(const Packet&) [with Packet = __builtin_neon_sf __vector__]’:
/home/ubuntu/Documents/eigen/Eigen/src/Core/arch/NEON/PacketMath.h:289: error: cannot convert ‘float*’ to ‘float32_t*’ for argument ‘1’ to ‘void vst1_f32(float32_t*, __builtin_neon_sf __vector__)’
/home/ubuntu/Documents/eigen/Eigen/src/Core/arch/NEON/PacketMath.h: In function ‘typename Eigen::ei_unpacket_traits<T>::type Eigen::ei_predux_min(const Packet&) [with Packet = __builtin_neon_sf __vector__]’:
/home/ubuntu/Documents/eigen/Eigen/src/Core/arch/NEON/PacketMath.h:320: error: cannot convert ‘float*’ to ‘float32_t*’ for argument ‘1’ to ‘void vst1_f32(float32_t*, __builtin_neon_sf __vector__)’
/home/ubuntu/Documents/eigen/Eigen/src/Core/arch/NEON/PacketMath.h: In function ‘typename Eigen::ei_unpacket_traits<T>::type Eigen::ei_predux_max(const Packet&) [with Packet = __builtin_neon_sf __vector__]’:
/home/ubuntu/Documents/eigen/Eigen/src/Core/arch/NEON/PacketMath.h:348: error: cannot convert ‘float*’ to ‘float32_t*’ for argument ‘1’ to ‘void vst1_f32(float32_t*, __builtin_neon_sf __vector__)’
make: *** [main] Error 1
ubuntu@ubuntu-desktop:~/Documents/mat_mul$ 

Errors I got when I used Code Sourcery toolchain

ubuntu@ubuntu-desktop:~/Documents/CodeSourcery_WS/Test_Eigen$ make
/home/ubuntu/CodeSourcery/Sourcery_G++/bin/arm-none-linux-gnueabi-c++ -mfpu=neon -mfloat-abi=softfp -I /home/ubuntu/Documents/eigen/ main.cpp -o main
In file included from main.cpp:1:
/home/ubuntu/CodeSourcery/Sourcery_G++/bin/../lib/gcc/arm-none-linux-gnueabi/4.4.1/../../../../arm-none-linux-gnueabi/include/c++/4.4.1/iostream:39: fatal error: bits/c++config.h: No such file or directory
compilation terminated.
make: *** [main] Error 1

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

柳絮泡泡 2024-09-17 17:41:54

看起来像 gcc bug,它确实应该混合 float 和 float32_t 而不会出现错误。检查这个

编辑:这已在 CodeSourcery 工具链中修复。这是来自发行说明:

float32_t 的编译器错误。修复了导致
使用时编译器错误
来自arm_neon.h的float32_t类型。

Looks like gcc bug, it really should mix float and float32_t without errors. Check this out.

Edit: This has been fixed in CodeSourcery toolchain. This is from release notes:

Compiler errors with float32_t. A bug has been fixed that caused
compiler errors when using the
float32_t type from arm_neon.h.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文