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

Clapack as so #1236

Merged
merged 14 commits into from Feb 26, 2021
Merged

Clapack as so #1236

merged 14 commits into from Feb 26, 2021

Conversation

joemarshall
Copy link
Contributor

@joemarshall joemarshall commented Feb 11, 2021

And support for shared-library packages in general.

So it doesn't have to be included multiple times in scipy (scipy is now 21mb)

It is mostly a surprisingly minor change, except that I had to change it so that it loads wasm asynchronously in even in firefox. Otherwise scipy couldn't link to clapack in firefox. It also loads shared library packages before anything else when you import, this is important because it means that linked in (as opposed to dlopen) shared library calls work fine. I couldn't work out why they didn't, but they didn't work in firefox.

There's a limitation to this which is that shared libraries that depend on other shared library packages may or may not work, I'm not sure...

Closes #473
Closes #240

@dalcde
Copy link
Contributor

dalcde commented Feb 12, 2021

The next emscripten version allows us to use the built-in preload wasm mechanism instead of writing our own. It will also make it so that we don't have to traverse the entire filesystem every time. #1223

@rth
Copy link
Member

rth commented Feb 12, 2021

The next emscripten version allows us to use the built-in preload wasm mechanism instead of writing our own.

Should we postpone this until the next emscripten release, which I guess will happen soon?
Otherwise this looks very promising indeed thanks @joemarshall !

@joemarshall
Copy link
Contributor Author

joemarshall commented Feb 12, 2021 via email

@joemarshall
Copy link
Contributor Author

Actually, it occurs to me that the thing I just did to make shared libraries in separate packages work - just overriding FS.open for the duration of the package load, could also be pretty trivially altered to remove the need to go through the whole file tree looking for anything added by the new package. Would save having to wait on the changes to emscripten (do they make preloading of wasm work with side modules, or with LZ4 or something?), and for side modules with shared libraries in, they need loadDynamicLibrary as well as instantiating the wasm, so I think the code will need to stay in or be added as a load plugin somehow or else shared lib modules won't work.

@joemarshall
Copy link
Contributor Author

So maybe it is worth putting this in. I'm easy.

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.

It's true that it would be nice to have,

-rw-r--r-- 1 root root   21M Feb 12 16:51 scipy.data
-rw-r--r-- 1 root root  379K Feb 12 16:51 scipy.js

earlier rather than later. I'd also like to look into updating scipy version next, and this would likely be useful there. The changes with patching FS.open look manageable to me.

Could you please resolve merge conflicts?

for lib_name in link_libs:
arg = os.path.join(lapack_dir, f"{lib_name}")
new_args.append(arg)

Copy link
Member

Choose a reason for hiding this comment

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

You can also remove the INLINING_LIMIT=5 and the -Os for CLAPACK below, that was an attempt to reduce its size when statically linking, that's no longer relevant.

packages/CLAPACK/meta.yaml Show resolved Hide resolved
src/pyodide.js Outdated
loadPackageChain = loadPackageChain.then(() => promise.catch(() => {}));
await promise;
Module.FS.open = oldOpen;
console.log("LIBS:", allLibs);
Copy link
Member

Choose a reason for hiding this comment

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

We should probably remove this debugging line, or at least use messageCallback if defined.

@rth
Copy link
Member

rth commented Feb 23, 2021

We now use emscripten 2.0.14. @joemarshall Would you be able to merge master in and address the above comments? I can help if necessary.

@joemarshall
Copy link
Contributor Author

joemarshall commented Feb 24, 2021 via email

@joemarshall
Copy link
Contributor Author

it had an HTTP error on build_packages, I think someone with better circleCI permissions than me needs to force rerun of the testws

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.

Two comments otherwise LGTM.

The next emscripten version allows us to use the built-in preload wasm mechanism instead of writing our own. It will also make it so that we don't have to traverse the entire filesystem every time.

and for side modules with shared libraries in, they need loadDynamicLibrary as well as instantiating the wasm, so I think the code will need to stay in or be added as a load plugin somehow or else shared lib modules won't work.

So if I understand correctly we still need the current code, and only using --use-preload-plugins (or calling emscripten_run_preload_plugins() on each file) by itself won't be enough? cc @dalcde Should we look into that in a separate PR after this one is merged?

src/pyodide.js Outdated
// and means doing a long async operation in firefox,
// which can cause warning messages
await preloadWasm();
self.pyodide._module.reportUndefinedSymbols();
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
self.pyodide._module.reportUndefinedSymbols();
Module.reportUndefinedSymbols();

That was changed earlier in #1195

Copy link
Member

Choose a reason for hiding this comment

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

This still needs reverting..

src/pyodide.js Show resolved Hide resolved
Co-authored-by: Roman Yurchak <rth.yurchak@gmail.com>
@joemarshall
Copy link
Contributor Author

I think preload plugins only compiles and instantiates the wasm, it doesn't do the stuff about bringing symbols from the wasm into the global namespace. It's why even if you use preload plugins you can't call into a module until you dlopen it or otherwise link it in.

(I.e. emscripten-core/emscripten#7220 )

@joemarshall
Copy link
Contributor Author

Incidentally, it is pretty trivial to use the same logic I use here for detecting .so files in shared library modules and apply it to the other module loads, thus removing the need to scan the whole file system. I can put that in as a separate pr once this one is in.

@dalcde
Copy link
Contributor

dalcde commented Feb 24, 2021 via email

@joemarshall
Copy link
Contributor Author

joemarshall commented Feb 25, 2021 via email

@joemarshall
Copy link
Contributor Author

hopefully the latest push works, now using preload_plugins for everything (with an override for the shared lib packages)

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.

Great! This does look much better indeed.

src/pyodide.js Show resolved Hide resolved
src/pyodide.js Outdated
// and means doing a long async operation in firefox,
// which can cause warning messages
await preloadWasm();
self.pyodide._module.reportUndefinedSymbols();
Copy link
Member

Choose a reason for hiding this comment

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

This still needs reverting..

src/pyodide.js Show resolved Hide resolved
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.

One last thing I forgot: could you please add one (or in this case probably even two) changelog entries to docs/project/changelog.md. Thanks!

@joemarshall
Copy link
Contributor Author

Changelog added

@rth rth merged commit 451924b into pyodide:master Feb 26, 2021
@joemarshall joemarshall deleted the clapack_as_so branch February 26, 2021 20:41
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.

Dynamic linking of BLAS / LAPACK
3 participants