GeezerVison is showing github.com — BUG,TST: Test again failing on spurious invalid values on M1 for sin, cos with clang < 16. · Issue #27313 · numpy/numpy
BUG,TST: Test again failing on spurious invalid values on M1 for sin, cos with clang < 16. #27313DescriptionDescribe the issue:
Building and testing the 2.1.0 release as well as main produces tests failures on a M1 mac if clang < 16 is used.
❯ clang --version
clang version 15.0.7
Target: arm64-apple-darwin23.6.0
Thread model: posix
InstalledDir: /Users/jhelmus/mc/envs/dev/bin
FAILED ../_core/tests/test_umath.py::TestSpecialFloats::test_unary_spurious_fpexception[data10-escape10-f-cos] - AssertionError: Got warnings: [<warnings.WarningMessage object at 0x30ae098b0>]
FAILED ../_core/tests/test_umath.py::TestSpecialFloats::test_unary_spurious_fpexception[data10-escape10-f-sin] - AssertionError: Got warnings: [<warnings.WarningMessage object at 0x30ae0bb60>]
FAILED ../_core/tests/test_umath.py::TestSpecialFloats::test_unary_spurious_fpexception[data11-escape11-f-cos] - AssertionError: Got warnings: [<warnings.WarningMessage object at 0x30adc87d0>]
FAILED ../_core/tests/test_umath.py::TestSpecialFloats::test_unary_spurious_fpexception[data11-escape11-f-sin] - AssertionError: Got warnings: [<warnings.WarningMessage object at 0x30932bf80>]
FAILED ../_core/tests/test_umath.py::TestSpecialFloats::test_unary_spurious_fpexception[data12-escape12-f-cos] - AssertionError: Got warnings: [<warnings.WarningMessage object at 0x30188dd00>]
FAILED ../_core/tests/test_umath.py::TestSpecialFloats::test_unary_spurious_fpexception[data12-escape12-f-sin] - AssertionError: Got warnings: [<warnings.WarningMessage object at 0x30193c7d0>]
FAILED ../_core/tests/test_umath.py::TestSpecialFloats::test_unary_spurious_fpexception[data13-escape13-f-cos] - AssertionError: Got warnings: [<warnings.WarningMessage object at 0x3018f4860>]
FAILED ../_core/tests/test_umath.py::TestSpecialFloats::test_unary_spurious_fpexception[data13-escape13-f-sin] - AssertionError: Got warnings: [<warnings.WarningMessage object at 0x3018f5460>]
FAILED ../_core/tests/test_umath.py::TestSpecialFloats::test_unary_spurious_fpexception[data14-escape14-f-cos] - AssertionError: Got warnings: [<warnings.WarningMessage object at 0x3010fd940>]
FAILED ../_core/tests/test_umath.py::TestSpecialFloats::test_unary_spurious_fpexception[data14-escape14-f-sin] - AssertionError: Got warnings: [<warnings.WarningMessage object at 0x301d6e9f0>]
FAILED ../_core/tests/test_umath.py::TestSpecialFloats::test_unary_spurious_fpexception[data15-escape15-f-cos] - AssertionError: Got warnings: [<warnings.WarningMessage object at 0x30adca660>]
FAILED ../_core/tests/test_umath.py::TestSpecialFloats::test_unary_spurious_fpexception[data15-escape15-f-sin] - AssertionError: Got warnings: [<warnings.WarningMessage object at 0x30af2cf80>]
Note that these tests pass with clang 16 or above (at least for all the version I've tested) as well as clang 15.0.0 provided by Apple via XCode.
An environment can be created with a toolchain which shows this behavior using:
conda create -n dev -c conda-forge python=3.12 pip clang_osx-arm64=15 clangxx_osx-arm64=15
These are the same tests failures from #22933 which were addressed in #22954.
Bisection found that #25781 reintroduced these tests failures, likely because the mitigation in #22954 are not present in highway.
Reproduce the code example:
import numpy as np
np.test(verbose=True)
Error message:
NumPy version 2.2.0.dev0+git20240829.6fbd06b
NumPy CPU features: NEON NEON_FP16 NEON_VFPV4 ASIMD ASIMDHP* ASIMDFHM?
...<clip>...
========================================================================================================= short test summary info ==========================================================================================================
FAILED ../_core/tests/test_umath.py::TestSpecialFloats::test_unary_spurious_fpexception[data10-escape10-f-cos] - AssertionError: Got warnings: [<warnings.WarningMessage object at 0x17f3e9e20>]
FAILED ../_core/tests/test_umath.py::TestSpecialFloats::test_unary_spurious_fpexception[data10-escape10-f-sin] - AssertionError: Got warnings: [<warnings.WarningMessage object at 0x17ebd8cb0>]
FAILED ../_core/tests/test_umath.py::TestSpecialFloats::test_unary_spurious_fpexception[data11-escape11-f-cos] - AssertionError: Got warnings: [<warnings.WarningMessage object at 0x17ec14f20>]
FAILED ../_core/tests/test_umath.py::TestSpecialFloats::test_unary_spurious_fpexception[data11-escape11-f-sin] - AssertionError: Got warnings: [<warnings.WarningMessage object at 0x17d3e40e0>]
FAILED ../_core/tests/test_umath.py::TestSpecialFloats::test_unary_spurious_fpexception[data12-escape12-f-cos] - AssertionError: Got warnings: [<warnings.WarningMessage object at 0x175af9b50>]
FAILED ../_core/tests/test_umath.py::TestSpecialFloats::test_unary_spurious_fpexception[data12-escape12-f-sin] - AssertionError: Got warnings: [<warnings.WarningMessage object at 0x175b36810>]
FAILED ../_core/tests/test_umath.py::TestSpecialFloats::test_unary_spurious_fpexception[data13-escape13-f-cos] - AssertionError: Got warnings: [<warnings.WarningMessage object at 0x175a7a3c0>]
FAILED ../_core/tests/test_umath.py::TestSpecialFloats::test_unary_spurious_fpexception[data13-escape13-f-sin] - AssertionError: Got warnings: [<warnings.WarningMessage object at 0x175a09940>]
FAILED ../_core/tests/test_umath.py::TestSpecialFloats::test_unary_spurious_fpexception[data14-escape14-f-cos] - AssertionError: Got warnings: [<warnings.WarningMessage object at 0x1764b2870>]
FAILED ../_core/tests/test_umath.py::TestSpecialFloats::test_unary_spurious_fpexception[data14-escape14-f-sin] - AssertionError: Got warnings: [<warnings.WarningMessage object at 0x1763a6cf0>]
FAILED ../_core/tests/test_umath.py::TestSpecialFloats::test_unary_spurious_fpexception[data15-escape15-f-cos] - AssertionError: Got warnings: [<warnings.WarningMessage object at 0x17ec15b20>]
FAILED ../_core/tests/test_umath.py::TestSpecialFloats::test_unary_spurious_fpexception[data15-escape15-f-sin] - AssertionError: Got warnings: [<warnings.WarningMessage object at 0x17f6ad5b0>]
12 failed, 43662 passed, 872 skipped, 2798 deselected, 44 xfailed, 6 xpassed in 82.06s (0:01:22)
Python and NumPy Versions:
2.2.0.dev0+git20240829.6fbd06b
3.12.5 | packaged by conda-forge | (main, Aug 8 2024, 18:32:50) [Clang 16.0.6 ]
Runtime Environment:
[{'numpy_version': '2.2.0.dev0+git20240829.6fbd06b',
'python': '3.12.5 | packaged by conda-forge | (main, Aug 8 2024, 18:32:50) '
'[Clang 16.0.6 ]',
'uname': uname_result(system='Darwin', node='Jonathans-MacBook-Pro.local', release='23.6.0', version='Darwin Kernel Version 23.6.0: Mon Jul 29 21:14:30 PDT 2024; root:xnu-10063.141.2~1/RELEASE_ARM64_T6000', machine='arm64')},
{'simd_extensions': {'baseline': ['NEON', 'NEON_FP16', 'NEON_VFPV4', 'ASIMD'],
'found': ['ASIMDHP'],
'not_found': ['ASIMDFHM']}}]
Context for the issue:
I noticed this when trying to build NumPy 2.1.0 using the clang 14 compilers available from Anaconda in the defaults channel.
I'm fine is the tagged as won't fix or low priority. Updating to a new compiler is a reasonable fix for this issue. Activityandyfaff commented on Aug 29, 2024 We have a CI entry where we use conda-forge compilers to test on macos 13.6.9, but only x86_64. All other mac tests use system compilers, M1 and x86_64.
EDIT: and all these entries are currently green. mattip commented on Aug 30, 2024 jan-wassenberg commented on Aug 30, 2024 Thanks for the heads-up, seems we'll be able to work around this. I am currently sick but intend to get to this next week. jan-wassenberg commented on Sep 3, 2024 This should fix the issue for arm64. jan-wassenberg commented on Sep 10, 2024 We're seeing strange and likely erroneous compiler codegen after this patch, which is why it hasn't gone in yet. I have not yet found a working approach. For reference, our current code is:
template <typename T, size_t N, HWY_IF_F32(T), HWY_IF_V_SIZE(T, N, 16)>
HWY_API Mask128<T, N> IsNaN(const Vec128<T, N> v) {
typename Mask128<T, N>::Raw ret;
__asm__ volatile("fcmeq %0.4s, %1.4s, %1.4s" : "=w"(ret) : "w"(v.raw));
return Mask128<T, N>(ret);
}
I'll ask our compiler folks for some guidance. seiko2plus commented on Sep 14, 2024
For reference, our current code is:
template <typename T, size_t N, HWY_IF_F32(T), HWY_IF_V_SIZE(T, N, 16)>
HWY_API Mask128<T, N> IsNaN(const Vec128<T, N> v) {
typename Mask128<T, N>::Raw ret;
asm volatile("fcmeq %0.4s, %1.4s, %1.4s" : "=w"(ret) : "w"(v.raw));
return Mask128<T, N>(ret);
}
The code you just provide is testing "NotNaN", what you need is to invert the mask to test "IsNaN":
template <typename T, size_t N, HWY_IF_F32(T), HWY_IF_V_SIZE(T, N, 16)>
HWY_API Mask128<T, N> IsNaN(const Vec128<T, N> v) {
typename Mask128<T, N>::Raw ret;
__asm__ volatile("fcmeq %0.4s, %1.4s, %1.4s" : "=w"(ret) : "w"(v.raw));
ret = vmvnq_u32(ret); // the fix
return Mask128<T, N>(ret);
}r-devulap commented on Oct 4, 2024 jan-wassenberg commented on Oct 7, 2024 Thanks for pinging, and thanks @seiko2plus for noticing the bug :( After fixing that, local tests+CI succeed. Apparently, the prior unrelated test failures were due to UB because of the negated IsNaN, even though they seem completely unrelated.
Will be merged soon. r-devulap commented on Oct 16, 2024 jan-wassenberg commented on Oct 17, 2024 r-devulap commented on Oct 17, 2024 @jjhelmus #27586 should hopefully fix the errors. Is it possible to verify? jjhelmus commented on Oct 22, 2024 ContributorAuthor More actions I was able to confirm this was fixed. I rebuilt numpy from a fresh git check out using clang 15 and all test pass. Thanks for the fix! Reacted by Jan Wassenberg and Raghuveer Devulapalli
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|