Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Web assembly? #2779

Quafadas started this conversation in General
Aug 11, 2024 · 2 comments · 10 replies
Discussion options

Are any parts of the library compiled to web assembly? I was thinking in particular of the blas module...

I could find no reference in the docs, so I’m just checking I’m not missing a trick here...

You must be logged in to vote

Replies: 2 comments 10 replies

Comment options

@Quafadas We do support compiling to WebAssembly, but we are not currently shipping WebAssembly binaries. What is your use case and what BLAS functionality do you need?

You must be logged in to vote
0 replies
Comment options

It’s a curiosity now that anything else . I have an application which does some basic linear algebra (arrays only) and I was thinking about converting to wasm to see if there was a runtime benefit.

As things stand I think I have only level 1 functions in use. I wouldn’t want to absorb a lot of time.

Is that enough of a picture or should I provide more detail?

You must be logged in to vote
10 replies
Comment options

Gosh! That’s a cool picture. If that picture generalises, then I’m wasting my time!

My arrays are more or less Float64Array of size 10,000. I guess I’m wondering about the extent that sum could be aggressively optimised as it’s a common operation. Only way would be to measure my workflow I guess.

Could things like simd potential inn wasm make a difference? Although presumably, that’s more custom work?

To me, this seems to would imply that only parrallism , perhaps webworkers could help. And that is not to do with wasm or stdlib. Hmmmm.

Comment options

@Quafadas Quick follow-up. Here is a benchmark with the BLAS level 1 routine daxpy. For the Wasm benchmark, computation is repeated on the same vectors allocated on the WebAssembly module heap. For the Wasm (copy) benchmark, data is copied into and out of the WebAssembly module heap (e.g., as might be the case when scripting or working with data coming from dynamic sources).

As can be seen from the chart, unless the FLOPS of the routine warrants the cost of marshalling data to and from Wasm memory, one can achieve equivalent, if not better, performance in just JavaScript.

...and this doesn't even address the increased complexity associated with memory fragmentation and unbounded growth which may occur when using Wasm modules.

Depends on your use case, but getting optimal Wasm performance can be a bit tricky to realize. I ran similar benchmarks on dgemm and there it was worth the perf penalty of marshalling data to and from the heap, as matmul is O(N^3) and copying data is O(N^2), where N corresponds to the number of elements along each dimension of a square matrix.

daxpy_wasm_comparison_benchmarks

Comment options

@Quafadas Quick update. We've started work on adding WebAssembly implementations of BLAS Level 1 routines. E.g., @stdlib/blas/base/daxpy-wasm.

Comment options

Another update: we've continued working on WebAssembly APIs for various BLAS packages, which can be found in the BLAS namespace: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/blas/base. WebAssembly-specific package names end with -wasm.

Comment options

@kgryte I did go away and do some homework. I watched the video, read your benchmark, did some experiments, read other peoples experiments etc.

At the moment, the extra complexity of trying to get webassembly working, doesn't seem to be worth the uncertainty / perceived gain. I'm probably going to drop this for the time being. My plan will probably be to revisit it every now and again as webassembly evolves particulaly / when it becomes easier to get modules to interop? Currently, it seems a bit lower level than I want to be... I'll keep an eye out here though...

And thank you so much, for the time and being willing to write and think about this 🙏 I do believe it could be beneficial in future!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants

AltStyle によって変換されたページ (->オリジナル) /