WebNN and WebGPU select devices independently, so zero-copy interop is not guaranteed. Web developers need a reliable way to determine whether a WebNN context and GPUDevice are compatible for zero-copy.
The WebNN spec does not define how createContext() and exportToGPU() interact with device selection when both a GPUDevice and MLContextOptions (such as powerPreference) are provided.
For example, if an app passes a WebGPU GPUDevice to createContext(), zero-copy is only possible if WebNN selects that same device or a compatible one (for example, an NPU or integrated GPU sharing the same memory). Otherwise, exportToGPU() may require a copy or fail because the selected devices are incompatible.
One possible solution would be to add an { interopDevice: gpuDevice } option to createContext() as a hint for interop compatibility. If provided, WebNN would preferentially select a compatible device, allowing exportToGPU() to remain zero-copy when possible.
@reillyeon @RafaelCintron @huningxin @anssiko
WebNN and WebGPU select devices independently, so zero-copy interop is not guaranteed. Web developers need a reliable way to determine whether a WebNN context and
GPUDeviceare compatible for zero-copy.The WebNN spec does not define how
createContext()andexportToGPU()interact with device selection when both aGPUDeviceandMLContextOptions(such aspowerPreference) are provided.For example, if an app passes a WebGPU
GPUDevicetocreateContext(), zero-copy is only possible if WebNN selects that same device or a compatible one (for example, an NPU or integrated GPU sharing the same memory). Otherwise,exportToGPU()may require a copy or fail because the selected devices are incompatible.One possible solution would be to add an
{ interopDevice: gpuDevice }option tocreateContext()as a hint for interop compatibility. If provided, WebNN would preferentially select a compatible device, allowingexportToGPU()to remain zero-copy when possible.@reillyeon @RafaelCintron @huningxin @anssiko