webmachinelearning / webnn

🧠 Web Neural Network API
https://www.w3.org/TR/webnn/
Other
369 stars 46 forks source link

Clarify/simplify graph execution on GPU / MLCommandEncoder #333

Closed zolkis closed 8 months ago

zolkis commented 1 year ago

A few purely API design related comments on MLCommandEncoder. (Context: I am trying to update some of the algorithms, and specify missing ones, and I stumbled upon these questions).

Graph initialization

Proposal (question): collate the command encoder factory with graph initialization, to bind the MLCommandEncoder to that graph (and context). That might even be an async method.

partial interface MLContext {
    Promise<MLCommandEncoder> createCommandEncoder(MLGraph graph);
};

Command encoder steps

Assuming the change above, the interface becomes:

[SecureContext, Exposed=(Window, DedicatedWorker)]
interface MLCommandEncoder { 
    undefined dispatch(MLGraph graph, MLNamedGPUResources inputs, MLNamedGPUResources outputs);
    GPUCommandBuffer finish(optional GPUCommandBufferDescriptor descriptor = {});
};

In summary, I would appreciate more explanation/examples/script use cases for this (graph init and graph execution on GPU).

I am aware of this relevant comment and the (still open) discussion in #264 as well - somewhat related to this.

anssiko commented 1 year ago

@zolkis we should focus this issue to updates to the algorithms outside the MLCommandEncoder interface when possible. That is, prepare the core API to allow for MLCommandEncoder to be plugged in.

We have identified the WebGPU interoperability as a feature at risk for CR initial publication in https://github.com/webmachinelearning/webnn/issues/240. We agreed this feature needs more implementation experience and the MLCommandEncoder interface spec (and possibly also its normative WebGPU interface dependencies) need to undergo a round of updates based on that implementation experience. I recommend not to invest too much time in redesigning the MLCommandEncoder before we have adequate implementation experience.

a-sully commented 8 months ago

Same question as https://github.com/webmachinelearning/webnn/issues/264#issuecomment-1910593270

It's my understanding that the MLCommandEncoder proposal has been superseded by MLBuffer (https://github.com/webmachinelearning/webnn/issues/482) and we should consider removing it (https://github.com/webmachinelearning/webnn/issues/528).

Can we close this issue?

anssiko commented 8 months ago

Per our discussion https://www.w3.org/2024/01/25-webmachinelearning-minutes.html#t09 the group wants to clarify interaction between WebNN and WebGPU timelines as a priority, using MLBuffer as a prototype. That has a separate issue, closing this.

@zolkis, feel free to salvage any bits from this issue as needed.