Skip to content

Commit

Permalink
Merge pull request easybuilders#19419 from Flamefire/20231214094225_n…
Browse files Browse the repository at this point in the history
…ew_pr_SciPy-bundle202307

Fix numpy build on Sapphire Rapids CPUs in SciPy-bundle-2023.07-gfbf-2023a
  • Loading branch information
branfosj authored Dec 15, 2023
2 parents fc21a5e + 6ed4cf4 commit eb83477
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,24 @@ use_pip = True
# order is important!
exts_list = [
('numpy', '1.25.1', {
'patches': ['numpy-1.22.3_disable-broken-override-test.patch'],
'patches': [
'numpy-1.22.3_disable-broken-override-test.patch',
('numpy-1.25.1_fix-duplicate-avx512-symbols.patch', 'numpy/core/src/npysort/x86-simd-sort'),
'numpy-1.25.1_fix-undefined-avx512-reference.patch',
'numpy-1.25.1_fix-test_features.patch',
'numpy-1.25.1_fix-test_half.patch',
],
'checksums': [
{'numpy-1.25.1.tar.gz': '9a3a9f3a61480cc086117b426a8bd86869c213fc4072e606f01c4e4b66eb92bf'},
{'numpy-1.22.3_disable-broken-override-test.patch':
'9c589bb073b28b25ff45eb3c63c57966aa508dd8b318d0b885b6295271e4983c'},
{'numpy-1.25.1_fix-duplicate-avx512-symbols.patch':
'8e32087c279b7193ae3507953480601200c9eff021819f3001d78c232c5852e6'},
{'numpy-1.25.1_fix-undefined-avx512-reference.patch':
'c4b66da93bf36071663f122de1ae668386cc6ab0154d21fa3e14ed7ddfe2a72c'},
{'numpy-1.25.1_fix-test_features.patch':
'1c05ee5d105fe2f824416dd6dd5c64ed0c1cd710a002b4e6dbfafff19203adc5'},
{'numpy-1.25.1_fix-test_half.patch': '341b99ae1801feebf382c92591794eeefdf451bc34b98f20aa985ea897488951'},
],
}),
('ply', '3.11', {
Expand All @@ -52,6 +65,8 @@ exts_list = [
'checksums': ['5ab283b9857211d61b53318b7c792cf68e798e765ee17c27ade9f6c924235731'],
}),
('scipy', '1.11.1', {
'enable_slow_tests': True,
'ignore_test_result': False,
'patches': [
'scipy-1.11.1_disable-tests.patch',
'scipy-1.11.1_xfail-aarch64_test_maxiter_worsening.patch',
Expand All @@ -62,8 +77,6 @@ exts_list = [
{'scipy-1.11.1_xfail-aarch64_test_maxiter_worsening.patch':
'918c8e6fa8215d459126f267764c961bde729ea4a116c7f6287cddfdc58ffcea'},
],
'enable_slow_tests': True,
'ignore_test_result': False,
}),
('numexpr', '2.8.4', {
'checksums': ['d5432537418d18691b9115d615d6daa17ee8275baef3edf1afbbf8bc69806147'],
Expand All @@ -82,8 +95,8 @@ exts_list = [
'checksums': ['7a28eb2a9774d00c7bc92411c19a89209d5da7c4c9a9e227be8330a23a25b91f'],
}),
('deap', '1.4.0', {
'checksums': ['ffef2921932a0edbe634fcb6d156189e7a364bf638a2af4ae5d59931a9a4c8cc'],
'modulename': 'deap.base',
'checksums': ['ffef2921932a0edbe634fcb6d156189e7a364bf638a2af4ae5d59931a9a4c8cc'],
}),
]

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
test_half_conversions fails when there is hardware support for Float16 (e.g. AVX512) as NaNs are not kept the same.
Error looks like:
# Convert from float64 back to float16
b = np.array(self.all_f64, dtype=float16)
bv = b.view(dtype=uint16)
fv = self.all_f16.view(dtype=uint16)
> assert_equal(self.all_f16.view(dtype=uint16),
b.view(dtype=uint16))
...
E AssertionError:
E Arrays are not equal
E
E Mismatched elements: 1022 / 65536 (1.56%)
E Max absolute difference: 512
E Max relative difference: 0.01587252
E x: array([ 0, 1, 2, ..., 65533, 65534, 65535], dtype=uint16)
E y: array([ 0, 1, 2, ..., 65533, 65534, 65535], dtype=uint16)

Deeper investigation shows a difference of exactly 512 in indices 31745-32255 & 64513-65023

Fix using https://github.com/numpy/numpy/commit/7a84442b1caa4904a9b8e58bd6b93045b4ad350f
from Sayed Adel <[email protected]>

Author: Alexander Grund (TU Dresden)

diff --git a/numpy/core/tests/test_half.py b/numpy/core/tests/test_half.py
index ca849ad52..3e72eba89 100644
--- a/numpy/core/tests/test_half.py
+++ b/numpy/core/tests/test_half.py
@@ -21,8 +21,11 @@ def setup_method(self):
# An array of all possible float16 values
self.all_f16 = np.arange(0x10000, dtype=uint16)
self.all_f16.dtype = float16
- self.all_f32 = np.array(self.all_f16, dtype=float32)
- self.all_f64 = np.array(self.all_f16, dtype=float64)
+
+ # NaN value can cause an invalid FP exception if HW is been used
+ with np.errstate(invalid='ignore'):
+ self.all_f32 = np.array(self.all_f16, dtype=float32)
+ self.all_f64 = np.array(self.all_f16, dtype=float64)

# An array of all non-NaN float16 values, in sorted order
self.nonan_f16 = np.concatenate(
@@ -44,14 +47,19 @@ def test_half_conversions(self):
# value is preserved when converting to/from other floats.

# Convert from float32 back to float16
- b = np.array(self.all_f32, dtype=float16)
- assert_equal(self.all_f16.view(dtype=uint16),
- b.view(dtype=uint16))
+ with np.errstate(invalid='ignore'):
+ b = np.array(self.all_f32, dtype=float16)
+ # avoid testing NaNs due to differ bits wither Q/SNaNs
+ b_nn = b == b
+ assert_equal(self.all_f16[b_nn].view(dtype=uint16),
+ b[b_nn].view(dtype=uint16))

# Convert from float64 back to float16
- b = np.array(self.all_f64, dtype=float16)
- assert_equal(self.all_f16.view(dtype=uint16),
- b.view(dtype=uint16))
+ with np.errstate(invalid='ignore'):
+ b = np.array(self.all_f64, dtype=float16)
+ b_nn = b == b
+ assert_equal(self.all_f16[b_nn].view(dtype=uint16),
+ b[b_nn].view(dtype=uint16))

# Convert float16 to longdouble and back
# This doesn't necessarily preserve the extra NaN bits,

0 comments on commit eb83477

Please sign in to comment.