Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xt::cos funtion ruturn totally wrong number in release build #2811

Open
XinyuKhan opened this issue Oct 19, 2024 · 1 comment
Open

xt::cos funtion ruturn totally wrong number in release build #2811

XinyuKhan opened this issue Oct 19, 2024 · 1 comment

Comments

@XinyuKhan
Copy link

XinyuKhan commented Oct 19, 2024

Version:
xtensor version: 0.25.0
xsimd version: 13.0.0
xtl version: 0.7.7
Here is the gcc info

gcc -v                                                                                                                                         ─╯
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-linux-gnu/13/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none:amdgcn-amdhsa
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 13.1.0-8ubuntu1~22.04' --with-bugurl=file:///usr/share/doc/gcc-13/README.Bugs --enable-languages=c,ada,c++,go,d,fortran,objc,obj-c++,m2,rust --prefix=/usr --with-gcc-major-version-only --program-suffix=-13 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/libexec --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-bootstrap --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib --enable-libphobos-checking=release --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-werror --enable-cet --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none=/build/gcc-13-IvzKaI/gcc-13-13.1.0/debian/tmp-nvptx/usr,amdgcn-amdhsa=/build/gcc-13-IvzKaI/gcc-13-13.1.0/debian/tmp-gcn/usr --enable-offload-defaulted --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu --with-build-config=bootstrap-lto-lean --enable-link-serialization=2
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 13.1.0 (Ubuntu 13.1.0-8ubuntu1~22.04) 

Here is the complile flag
-fPIC -Wno-array-bounds -std=gnu++20 -mno-avx512f -msse4.2 -mavx2 -mfma

Here is the test code:
TEST(cos, test) {
  xt::xtensor<float, 2> test_data = xt::zeros<float>({180, 4});
  for (int i = 0; i < 180; i++) {
    test_data(i, 0) = i * M_PI / 180;
    test_data(i, 1) = i * M_PI / 180;
    test_data(i, 2) = i * M_PI / 180 + M_PI;
    test_data(i, 3) = i * M_PI / 180 + M_PI;
  }

  xt::xtensor<float, 2> cos_data = xt::cos(test_data);
  for (int i = 0; i < 180; i++) {
    std::cout << cos_data(i, 0) << " " << cos_data(i, 1) << " " << cos_data(i, 2) << " " << cos_data(i, 3) << std::endl;
    EXPECT_NEAR(cos_data(i, 0), std::cos(i * M_PI / 180), 1e-6);
    // EXPECT_NEAR(cos_data(i, 1), std::cos(i * M_PI / 180), 1e-6);
    // EXPECT_NEAR(cos_data(i, 2), std::cos(i * M_PI / 180 + M_PI), 1e-6);
    // EXPECT_NEAR(cos_data(i, 3), std::cos(i * M_PI / 180 + M_PI), 1e-6);
  }

}
@XinyuKhan XinyuKhan changed the title xt::cos funtion ruture totally wrong number in release build xt::cos funtion ruturn totally wrong number in release build Oct 19, 2024
@XinyuKhan
Copy link
Author

More Information: There is no problem when I use gcc 11 with -ffast-math flag and gcc13 without -ffast-math. But problem is exist when I use gcc13 with -ffast-math

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant