-
Notifications
You must be signed in to change notification settings - Fork 59
Closed
Labels
Description
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
- 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
- Must an MLBuffer only be used with an MLContext it was created from? @a-sully
- Can an MLBuffer's size always be known at the time of buffer allocation? @a-sully
- When will MLBuffer be deallocated if destroy() is not called? @a-sully
- Does MLBuffer require explicit buffer usages (ex. input, output, or both)? @bbernhar
- Does MLBuffer need to support being a staging buffer? @bbernhar
- Is a zero sized MLBuffer allowed? @bbernhar
Reactions are currently unavailable