webmachinelearning / webnn

🧠 Web Neural Network API
https://www.w3.org/TR/webnn/
Other
397 stars 48 forks source link

`MLGraphBuilder.constant()` should take an `AllowSharedBufferSource` #788

Closed a-sully closed 1 day ago

a-sully commented 1 week ago

Currently, constant() takes an ArrayBufferView (https://www.w3.org/TR/webnn/#ref-for-dom-mlgraphbuilder-constant)

AllowSharedBufferSource is specified here as the following:

typedef (ArrayBuffer or SharedArrayBuffer or [AllowShared] ArrayBufferView) AllowSharedBufferSource;

Since this buffer data is always immediately copied (https://www.w3.org/TR/webnn/#dom-mlgraphbuilder-constant) I see no reason why we shouldn't allow passing an ArrayBuffer, SharedArrayBuffer or shared ArrayBufferView to this method, as well.

huningxin commented 1 week ago

Yes, it should support SharedArrayBuffer.

The current restriction prevents a multi-threaded build of Wasm framework, e.g. ONNXRuntime Web, from passing memory views (emscripten::typed_memory_view) to MLGraphBuilder.constant(), that is unfortunate.