-
Notifications
You must be signed in to change notification settings - Fork 46
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
[MLBuffer] Support interop with WebGPU #688
Comments
"Neutering" is an existing concept that's part of the Transferrable Object section of the HTML 5 spec. In that spec, once you neuter an object, you can't bring it back like you described above. We need to come up with a different term to describe what we're doing. The term "renting" comes to mind but hopefully we can come up with a better one.
I presume you by "dropped", you mean garbage collected?
WebGPU today has one queue but in the future, it might have more than one. Since we haven't (yet) speced the concept of a "queue" in WebNN, your description is confusing because the reader doesn't know which queue you're referring to. Should reword this to say that, upon import, WebNN operations on MLBuffers in flight on the WebNN device timeline will complete before work queued on WebGPU queue commences. Similarly, on GPUBuffer destruction, work on WebGPU queues will complete before the WebNN device timeline reads the results of the operation. In other words, upon import WebGPU reads will see previous WebNN writes. Upon GPUBuffer destruction, WebNN reads will see previous WebGPU writes. |
Thanks @RafaelCintron Makes sense.
OK. Perhaps expire and un-expire?
Yes, thanks for pointing this out.
WebNN does not define what a device timeline is nor does it distinguish what operations can be enqueued on it. If you can comment on #529 then the actual interop spec will follow that. |
Closing as this proposal has been superseded by #754 |
Purpose/Motivation
WebNN lacks an API to import video frames or run custom ML ops. ML use-cases like semantic segmentation or real-time video could benefit by avoiding JS copies. WebGPU also lacks NPU support which means use-cases like Super Resolution cannot be further accelerated by WebNN ML ops. This is a sub-issue of #482.
Proposed Solution: direct buffer sharing
Export WebNN's
MLBuffer
datatype, import it into WebGPU as as standardGPUBuffer
, which can be directly bound in a WGSL compute shader. Any needed conversions and synchronization for the shared buffer is performed by the WebNN runtime.MLBuffer
is imported, it is considered "neutered". A validation error is generated if used by the WebNN context.GPUBuffer
, created upon import, could be a copy of aMLBuffer
contents.MLBuffer
is no longer "neutered" and will un-expire to be re-used again.JS example
FAQ
What happens if the web developer never calls GPUBuffer.Destroy()?
If an imported
MLBuffer
is dropped, without being destroyed, the importedGPUBuffer
object will stay alive until it is also dropped.Why is there explicit handoff between WebGPU and WebNN?
Ensures
MLBuffer
cannot be modified by WebNN once imported (https://www.w3.org/TR/webgpu/#programming-model-resource-usages) and performs any necessary copies of its contents.What are the synchronization guarantees between WebGPU's command queue and MLGraph?
WebNN ensures API access of
MLBuffer
will be mutually exclusive (no simultaneous access).MLGraph
operations usingMLBuffer
are submitted for execution before WebNN waits for completion of work by WebGPU's queues. Similarly, WebGPU queues cannot execute or must wait until WebNN operations are completed.Why not import
MLBuffer
asGPUExternalTexture
?Unlike textures,
MLBuffer
cannot be GPU sampled which restricts WebGPU shaders from performing color-space mapping and may require tensor-to-video format conversion. Since an importedMLBuffer
layout will matchGPUBuffer
, a linear layout, the web developer could use it as aGPUBuffer
.Can you interop with mixed WebNN and WebGPU devices?
Currently, it is out of scope of v1. Only the same
GPUDevice
used to createMLContext
can be used. In the future, explicit importExternalBuffer() could be added toMLContext
or if zero-copy is disallowed.The text was updated successfully, but these errors were encountered: