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

Idea: auto-generated bindings for webgpu-native #487

Open
Korijn opened this issue Mar 29, 2024 · 3 comments
Open

Idea: auto-generated bindings for webgpu-native #487

Korijn opened this issue Mar 29, 2024 · 3 comments

Comments

@Korijn
Copy link
Collaborator

Korijn commented Mar 29, 2024

We could consider "splitting" the webgpu-native backend in 2 parts, one being autogenerated direct python bindings, and one being the translation layer to the IDL-standardized webgpu API, I documented this idea here. Idea originates from #480

We can combine the following tools to automatically generate bindings for webgpu-native:

  • pyo3 and maturin to build python bindings
  • a python script generate pyo3 bindings, using cffi to parse wgpu.h

These bindings will be more performant since they don't rely on cffi at runtime.

This would need to be done in a separate lib, that we can then depend on in wgpu-py to layer the IDL based API on top of the bindings.

We would not be able to use the binary releases of webgpu-native though; we'd have to build the bindings ourselves directly from rust source. So that's a bit of a bummer but not impossible. Because of that, we have a few choices:

  • fork the webgpu-native repo
  • depend on webgpu-native with cargo (not sure if this is realistic)

There is one other project we can look at for inspiration that already autogenerates bindings for C++ here: https://github.com/eliemichel/WebGPU-Cpp/

@almarklein
Copy link
Member

What if we go for C-API bindings instead? Then we can use the binary wgpu-native releases, and use simpler tooling (e.g. cython).

@Korijn
Copy link
Collaborator Author

Korijn commented Apr 2, 2024

What if we go for C-API bindings instead? Then we can use the binary wgpu-native releases, and use simpler tooling (e.g. cython).

So we take the binary, the header file, and then wrap with cython? I'm not sure I know how to compile something like that. Would we dynamically link to the binary then?

It would indeed be a lot simpler to set up, that's for sure. I strongly prefer going this route if we can.

@almarklein
Copy link
Member

The answer to all questions is "I think so". I'm pretty sure ppl use Cython for this sort of thing. But perhaps there are other tools too.

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

No branches or pull requests

2 participants