Skip to content

WebNN/WebGPU device selection for interop #941

Description

@bbernhar

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions