Skip to content

[MLBuffer] Support for MLBuffer in graph execution #544

@bbernhar

Description

@bbernhar

Purpose/Motivation

Provides a means to execute a MLGraph using MLBuffer. This is a sub-issue of #482.

Proposed API

dictionary MLBufferView {
  required MLBuffer buffer;
  MLSize64 offset = 0;
  MLSize64 size;
};

typedef record<DOMString, MLBufferView> MLNamedMLBufferViews;

[Exposed=(Window, DedicatedWorker), SecureContext]
partial interface MLContext {
  undefined dispatch(
        MLGraph graph, MLNamedMLBufferViews inputs, MLNamedMLBufferViews outputs);
}

Example JS

const bufferA = new MLBuffer({size:4});
const bufferB = new MLBuffer({size:4});
const inputs = {'A': {bufferA, 0, bufferA.size()};
const outputs = {'B': {bufferB, 0, bufferB.size()};
context.dispatch(graph, inputs, outputs);
  • Enqueues a request to compute the graph onto some WebNN timeline
  • Execution cannot start until all input and output MLBuffers are available
  • All input and output MLBuffers are unavailable while execution is in progress
  • All work submitted after this dispatch() call which relies on an input or output MLBuffer will be queued behind this execution

Alternative API proposals

N/A

Opens

  1. Should this method be on the MLGraph (related to API simplification: context owns builder, graph becomes internal slot #303)? @a-sully
  2. Is it valid to pass the same MLBuffer as both an input and output of the same dispatch() call? @a-sully
  3. If the approach is flexible enough to allow for graph execution on all backends. Do we need a separate compute() method? @a-sully
  4. Can dispatch be exclusive to MLBuffer bindings? @bbernhar

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