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

Upgrade numpy to 1.21.4 #1934

Merged
merged 8 commits into from Nov 14, 2021
Merged

Upgrade numpy to 1.21.4 #1934

merged 8 commits into from Nov 14, 2021

Conversation

leopsidom
Copy link
Contributor

@leopsidom leopsidom commented Nov 7, 2021

Description

Currently pyodide has numpy @1.17.5 but the newest numpy version is 1.21.4. This PR is to keep the numpy package in pyodide up to date. Some changes made in this PR include:

  1. patches removed: add-emscripten-cpu.patch and rm-duplicate-symbols-link.patch. These patches got removed because the underlying issue has been fixed in the numpy package.
  2. patches added:
    1. fix-invalid-asm-instruction.patch to fix invalid asm instructions
    2. limit-cpu-baseline.patch this is to limit cpu baseline to AVX so it doesn't try to build SIMD feature AVX512 that emscripten doesn't support;
    3. not-build-lapack-lite-as-64-bit.patch this is to prevent building lapack-lite as 64 bit integer mode which emscripten doesn't support;
  3. patches modified (both are needed because the original files got changed and the original patches can no longer apply):
    1. fix-static-init-of-nditer-pywrap.patch
    2. use-local-blas-lapack.patch

Notes: in numpy build file, I'm currently setting:

self.cpu_baseline = "avx"
self.cpu_dispatch = "avx"

I think this means there are still basic SIMD optimization built with this which is supported by emscripten. We might want to check if we want to enable it yet.

Issue: #1827

Checklists

Not all of these steps are necessary for every PR.

  • Add a CHANGELOG entry or explain why an entry is not needed
  • Add / update tests
  • Add new / update outdated documentation

@@ -0,0 +1,13 @@
diff --git a/numpy/distutils/command/build.py b/numpy/distutils/command/build.py
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unintentionally included this file. This patch is not needed.

@ryanking13
Copy link
Member

This must've been a hard job. I appreciate your effort!

A minor comments:

  • patches added:

    1. fix-invalid-asm-instruction.patch to fix invalid asm instructions
    2. limit-cpu-baseline.patch this is to limit cpu baseline to AVX so it doesn't try to build SIMD feature AVX512 that emscripten doesn't support;
    3. not-build-lapack-lite-as-64-bit.patch this is to prevent building lapack-lite as 64 bit integer mode which emscripten doesn't support;

I think adding these descriptions into the patch file would help other people who later see patch files.

  1. It would be great if we add some tests for newly available features of numpy 1.21 (and if possible, 1.18, 1.19, 1.20 also). I'm not sure which are the core new functionalities of these numpy versions, but we could find out from their release notes.

@rth
Copy link
Member

rth commented Nov 7, 2021

Thanks a lot for doing this work @leopsidom !

I think this means there are still basic SIMD optimization built with this which is supported by emscripten. We might want to check if we want to enable it yet.

Right now the CI fails with,

emcc: error: Passing any of -msse, -msse2, -msse3, -mssse3, -msse4.1, -msse4.2, -mavx, -mfpu=neon flags also requires passing -msimd128!

which seems to be expected as discussed in emscripten-core/emscripten#12714. I'm very in favor of investigating what we need to use SIMD a separate issue (and in particular check that it doesn't break Safari), for now maybe the easiest would be,

self.cpu_baseline = "min"
self.cpu_dispatch = "min"

to disable simd ?

Add / update tests

It would be great if we add some tests for newly available features of numpy 1.21 (and if possible, 1.18, 1.19, 1.20 also).

This is another subject we should improve on in Pyodide. Historically we have not run much tests for packages, because while we have the ability to run the package test suites in Pyodide #69 running them would be very slow, and there are also some known failure (cf related open issues about numpy). So we have just written some sanity tests and that's it. However now we have much more CI resources than before and I think we could run them but maybe triggered manually and not for each commit. Improving the package test situation is also somewhat a blocker for #1577

So there is a lot work that can be done there, for this PR for instance running the numpy test suite and report new issues would probably be sufficient. We can also do this after merging of this PR. The only thing maybe we should add a test for, is one of the operations that uses SIMD to make sure that calling it doesn't error after all the workaround that were done here.

@leopsidom
Copy link
Contributor Author

I think adding these descriptions into the patch file would help other people who later see patch files.

Good idea. I have added the description to the corresponding patch files.

It would be great if we add some tests for newly available features of numpy 1.21

I think numpy has it's own test suite. Ideally we might want to see how we can run the tests in pyodide as commented by @rth.

@leopsidom
Copy link
Contributor Author

Right now the CI fails with,
emcc: error: Passing any of -msse, -msse2, -msse3, -mssse3, -msse4.1, -msse4.2, -mavx, -mfpu=neon flags also requires passing -msimd128!

Yeah, that means we have to pass an extra cflag -msimd128 to emscripten when compiling SIMD features. It looks like an explicit restriction that emscripten tries to call out about what it actually supports.

for now maybe the easiest would be
self.cpu_baseline = "min"
self.cpu_dispatch = "min"

Sounds good. I've switched both to min. Though I don't know if this completely disables SIMD. We might have to use self.disable_optimization = True to completely disable it.

@hoodmane
Copy link
Member

Scipy build is failing because it can't link npymath.

@leopsidom
Copy link
Contributor Author

Hmm yeah, will check a little later this week.

@leopsidom
Copy link
Contributor Author

leopsidom commented Nov 13, 2021

The npymath library issue can be fixed by updating NUMPY_LIB here: https://github.com/pyodide/pyodide/blob/main/packages/Makefile#L6. But it seems there are some more compatibility issue between numpy and scipy.

ModuleNotFoundError: No module named 'numpy.testing.decorators'

Looks like numpy.testing.decorators has been removed in the newer version of numpy.

@leopsidom
Copy link
Contributor Author

I think this will depend on success of this upgrade: #1293

@hoodmane
Copy link
Member

Well it's still available as
from numpy.testing._private.decorators import setastest
Maybe we can patch numpy to copy numpy.testing._private.decorators to numpy.testing.decorators.

@leopsidom
Copy link
Contributor Author

Ahh, good point. Let me try that.

@leopsidom leopsidom closed this Nov 13, 2021
@leopsidom leopsidom reopened this Nov 13, 2021
Copy link
Member

@rth rth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @leopsidom, great I see the CI passes!

A few minor comments below otherwise looks good. Could you also please merge upstream/main to sync? I merged #1708 recently which adds a few more patches to numpy, but you should be able to remove the fix-random-double-fill.patch with this update.

@@ -329,6 +329,8 @@ def handle_command(line, args, dryrun=False):
continue
if arg == "-lffi":
continue
if arg == "-mpopcnt":
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe let's add a comment that this is a SSE 4.2 instruction, and we currently build without SIMD.

Just so it's easier to know what to re-enable once we want to build with SIMD.

Copy link
Contributor Author

@leopsidom leopsidom Nov 13, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a comment -

packages/numpy/patches/add-back-decorators-module.patch Outdated Show resolved Hide resolved
@leopsidom
Copy link
Contributor Author

It seems the fix-getters.patch is also not needed: https://github.com/numpy/numpy/blob/main/numpy/core/src/multiarray/getset.c#L29 ?

@rth
Copy link
Member

rth commented Nov 13, 2021

It seems the fix-getters.patch is also not needed

It's possible, I wasn't 100% sure in what release it got included.

@rth
Copy link
Member

rth commented Nov 13, 2021

No actually my initial comment was correct. That patch is not included in 1.21.4, so it's still necessary.

@leopsidom
Copy link
Contributor Author

That patch is not included in 1.21.4, so it's still necessary.

Yeah, I was looking at a newer commit @1.22.0.dev0

@leopsidom
Copy link
Contributor Author

Also I'm seeing two patches not applied in meta.yaml: 0008-fix-dict.patch and make-int-return-values.patch, wonder why we included them in the patches ?

@hoodmane
Copy link
Member

Also I'm seeing two patches not applied in meta.yaml: 0008-fix-dict.patch and make-int-return-values.patch, wonder why we included them in the patches ?

Maybe they aren't needed any more, but we just forgot to delete them?

@leopsidom
Copy link
Contributor Author

Okay, makes sense. Let me just remove them -

@leopsidom
Copy link
Contributor Author

Oh wait I think they are correct. The first one is Cython patch not a numpy patch. The 2nd does get included in meta.yaml.

@rth
Copy link
Member

rth commented Nov 14, 2021

Thanks @leopsidom !

@rth rth merged commit 4662024 into pyodide:main Nov 14, 2021
@hoodmane
Copy link
Member

Thanks @leopsidom! This is very helpful. Though I think we should have a changelog entry for this?

@leopsidom
Copy link
Contributor Author

No problems. Thanks for accepting the PR @rth. @hoodmane sure, I can take a look and add a changelog for it a little later.

@leopsidom
Copy link
Contributor Author

Thanks @leopsidom! This is very helpful. Though I think we should have a changelog entry for this?

Opened a PR to update the change log.

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

Successfully merging this pull request may close these issues.

None yet

4 participants