-
-
Notifications
You must be signed in to change notification settings - Fork 887
-
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...
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 2 comments 10 replies
-
@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?
Beta Was this translation helpful? Give feedback.
All reactions
-
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?
Beta Was this translation helpful? Give feedback.
All reactions
-
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.
Beta Was this translation helpful? Give feedback.
All reactions
-
@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.
Beta Was this translation helpful? Give feedback.
All reactions
-
@Quafadas Quick update. We've started work on adding WebAssembly implementations of BLAS Level 1 routines. E.g., @stdlib/blas/base/daxpy-wasm
.
Beta Was this translation helpful? Give feedback.
All reactions
-
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
.
Beta Was this translation helpful? Give feedback.
All reactions
-
@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!
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 1