Skip to content

[MLBuffer] Creation and representing MLBuffer on a XPU devices #542

Description

@bbernhar

Purpose/Motivation

Defines a device-based storage object that may be used by WebNN operations. This is a sub-issue of #482.

Proposed API

typedef unsigned long MLFlagsConstant;

[Exposed=(Window, DedicatedWorker)]
interface MLBuffer {
  readonly attribute MLFlagsConstant usage;
  readonly attribute MLOperandDescriptor descriptor;
  [CallWith=Isolate] void destroy();
}
[Exposed=(Window, DedicatedWorker), SecureContext]
namespace MLBufferUsage {
    // TBD
};

[Exposed=(Window, DedicatedWorker), SecureContext]
partial interface MLContext {
    Promise<MLBuffer> createBuffer(MLOperandDescriptor descriptor, MLBufferUsage usages);
};

Example JS

const ml_buffer = await mlContext.createBuffer(descriptor, usages);
ml_buffer.Destroy(); // invalid
  • The buffer's allocation will be zeroed (as it is for WebGPU's createBuffer() method)
  • Layout of MLBuffer is always known (and linear access is assumed).
  • Destroy() gets called on the context timeline but doesn't actually release until the device signals completion.

Edits

  • 5/14/24 - Removed "size" in favor or using MLOperandDescriptor
  • 6/03/24 - Added usage flags and descriptor attributes
  • 7/09/24 - createBuffer() now returns promise.

Alternative API proposals

N/A

Opens

  1. Where will an MLBuffer's memory be allocated on systems where an MLContext may not be as closely tied to a given physical device as an IDMLDevice? See Need to understand how WebNN supports implementation that involves multiple devices and timelines #350 @a-sully
  2. Must an MLBuffer only be used with an MLContext it was created from? @a-sully
  3. Can an MLBuffer's size always be known at the time of buffer allocation? @a-sully
  4. When will MLBuffer be deallocated if destroy() is not called? @a-sully
  5. Does MLBuffer require explicit buffer usages (ex. input, output, or both)? @bbernhar
  6. Does MLBuffer need to support being a staging buffer? @bbernhar
  7. Is a zero sized MLBuffer allowed? @bbernhar

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions