GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

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. #27313

New issue
Copy link
New issue
Copy link
Closed
#27586
Closed
BUG,TST: Test again failing on spurious invalid values on M1 for sin, cos with clang < 16.#27313
#27586
Copy link
Labels
00 - BugHWYfeatures related to google Highwaycomponent: SIMDIssues in SIMD (fast instruction sets) code or machinery

Description

@jjhelmus
jjhelmus
opened on Aug 29, 2024
Issue body actions

Describe 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.

Activity

  1. jjhelmus
    added
    00 - Bug
    on Aug 29, 2024
  2. andyfaff commented on Aug 29, 2024

    @andyfaff
    andyfaff
    on Aug 29, 2024
    Member
    More actions

    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.

  3. mattip
    added
    component: SIMDIssues in SIMD (fast instruction sets) code or machinery
    on Aug 30, 2024
  4. mattip commented on Aug 30, 2024

    @mattip
    mattip
    on Aug 30, 2024
    Member
    More actions

    cc @jan-wassenberg.

  5. jan-wassenberg commented on Aug 30, 2024

    @jan-wassenberg
    jan-wassenberg
    on Aug 30, 2024
    Contributor
    More actions

    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.

  6. copybara-service
    added 2 commits that reference this issue on Sep 3, 2024

    fix IsNaN codegen for clang < 18.1. Refs numpy/numpy/issues/27313

    710bcb2

    fix IsNaN codegen for clang < 18.1. Refs numpy/numpy/issues/27313

    6142e78
  7. jan-wassenberg commented on Sep 3, 2024

    @jan-wassenberg
    jan-wassenberg
    on Sep 3, 2024
    Contributor
    More actions

    This should fix the issue for arm64.

  8. jan-wassenberg commented on Sep 10, 2024

    @jan-wassenberg
    jan-wassenberg
    on Sep 10, 2024
    Contributor
    More actions

    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.

  9. copybara-service
    added a commit that references this issue on Sep 10, 2024

    fix IsNaN codegen for clang < 18.1. Refs numpy/numpy/issues/27313

    ddbc0b9
  10. seiko2plus commented on Sep 14, 2024

    @seiko2plus
    seiko2plus
    on Sep 14, 2024
    Member
    More actions

    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);
    }
  11. seberg
    modified the milestone: 2.2.0 release on Oct 1, 2024
  12. r-devulap commented on Oct 4, 2024

    @r-devulap
    r-devulap
    on Oct 4, 2024
    Member
    More actions

    @jan-wassenberg is the fixed merged into highway?

  13. copybara-service
    added a commit that references this issue on Oct 7, 2024

    fix IsNaN codegen for clang < 18.1. Refs numpy/numpy/issues/27313

    b1bb12b
  14. r-devulap
    added
    HWYfeatures related to google Highway
    on Oct 7, 2024
  15. copybara-service
    added a commit that references this issue on Oct 7, 2024

    fix IsNaN codegen for clang < 18.1. Refs numpy/numpy/issues/27313

    33b07ad
  16. jan-wassenberg commented on Oct 7, 2024

    @jan-wassenberg
    jan-wassenberg
    on Oct 7, 2024
    Contributor
    More actions

    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.

  17. copybara-service
    added 2 commits that reference this issue on Oct 7, 2024

    fix IsNaN codegen for clang < 18.1. Refs numpy/numpy/issues/27313

    a6d17c4

    fix IsNaN codegen for clang < 18.1. Refs numpy/numpy/issues/27313

    523aff7
  18. aarongable
    added a commit that references this issue on Oct 16, 2024

    Roll src/third_party/highway/src/ 8295336dd..a97b5d371 (117 commits)

    88d1f0d
  19. r-devulap commented on Oct 16, 2024

    @r-devulap
    r-devulap
    on Oct 16, 2024
    Member
    More actions

    @jan-wassenberg assuming this is merged into Highway?

  20. jan-wassenberg commented on Oct 17, 2024

    @jan-wassenberg
    jan-wassenberg
    on Oct 17, 2024
    Contributor
    More actions

    Yes indeed :)

  21. r-devulap commented on Oct 17, 2024

    @r-devulap
    r-devulap
    on Oct 17, 2024
    Member
    More actions

    @jjhelmus #27586 should hopefully fix the errors. Is it possible to verify?

  22. charris
    closed this as completedin #27586on Oct 18, 2024
  23. jjhelmus commented on Oct 22, 2024

    @jjhelmus
    jjhelmus
    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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    00 - BugHWYfeatures related to google Highwaycomponent: SIMDIssues in SIMD (fast instruction sets) code or machinery

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.