Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subclass MLGraph based on the context that creates it #344

Closed
huningxin opened this issue Feb 15, 2023 · 6 comments
Closed

Subclass MLGraph based on the context that creates it #344

huningxin opened this issue Feb 15, 2023 · 6 comments
Labels

Comments

@huningxin
Copy link
Contributor

Split from #341 (comment), where @wacky6 mentioned

Maybe we should subclass MLGraph based on the context that creates it. For example, CPU context returns a MLCpuGraph with compute(). GPU context returns a MLGpuGraph with compute() and GPU interop methods (commandBuffer, dispatch, etc).

If we fold the command recording methods into MLGpuGraph, it may not support recording multiple MLGraphs into one command buffer that MLCommandEncoder supports. Pipelining models execution may reduce the GPU queue submission overhead and improve the throughput.

/cc @wchao1115

@anssiko
Copy link
Member

anssiko commented May 19, 2023

I'm hearing this redesign would impact the current MLCommandEncoder design. I'm proposing to revisit this issue when we have received further implementation experience and user feedback for the current MLCommandEncoder interface.

Perhaps we are able to address this issue with better example code on how to use the GPU command encoder.

@zolkis
Copy link
Collaborator

zolkis commented May 19, 2023

What about including the graph as internal slot to context as barinstormed in #303.
(Note that whether builder is also part of context, is a different issue, it may not necessarily need to be).

As for command encoder, there opportunities to simplify that, too, for instance some brainstorming in #333.
Also related to #322.

I agree we should address these points together when more impl experience/clarity is available.

@a-sully
Copy link
Contributor

a-sully commented Jan 25, 2024

Does subclassing MLGraph still provide value if MLCommandEncoder does not exist?

My reading of this issue is that it has so far provided the following reasons for subclassing MLGraph:

  1. Creating an MLCommandEncoder from an MLGraph only makes sense if the MLGraph will execute on GPU (and the GPU)
  2. You may call compute() if the MLGraph will execute on CPU, or dispatch() if the MLGraph will execute on GPU

With regards to (1), the MLCommandEncoder proposal is no longer being pursued (#528). This is no longer relevant

With regards to (2), I see a few problems to this. Would we have to add another subclass to support an NPU backend? This does not seem sustainable. IMHO it would be nice to have one method to perform "execute the graph", regardless of the backend, and MLBuffer might provide a path forward for this. But for the sake of keeping this issue on track I think the details are best left for another issue :)


Are there other reasons to want this subclassing? If not, I would like to advocate for closing this issue

@inexorabletash
Copy link
Member

+1 to closing

@zolkis
Copy link
Collaborator

zolkis commented Feb 16, 2024

IMHO it would be nice to have one method to perform "execute the graph", regardless of the backend

+1 for that.

@huningxin
Copy link
Contributor Author

+1 to closing this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants