https://github.com/wpmed92/pydawn
A Python interface for the Dawn WebGPU engine
https://github.com/wpmed92/pydawn
ctypes dawn python webgpu
Last synced: 3 months ago
JSON representation
A Python interface for the Dawn WebGPU engine
- Host: GitHub
- URL: https://github.com/wpmed92/pydawn
- Owner: wpmed92
- License: bsd-3-clause
- Created: 2024-12-17T22:30:18.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-01-16T13:16:50.000Z (12 months ago)
- Last Synced: 2025-02-14T20:36:18.545Z (11 months ago)
- Topics: ctypes, dawn, python, webgpu
- Language: Python
- Homepage:
- Size: 8.56 MB
- Stars: 7
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# dawn-python
[](https://badge.fury.io/py/dawn-python)
[ctypeslib](https://github.com/trolldbois/ctypeslib) based python bindings to the [Dawn](https://dawn.googlesource.com/dawn) WebGPU engine with a focus on the compute pipeline. Besides the autogenerated bindings, a small `utils` interface (similar to [wgpu-py](https://github.com/pygfx/wgpu-py)) is provided to make it easier to run compute.
Chromium version used in pydawn: [133.0.6940.0](https://dawn.googlesource.com/dawn/+/refs/heads/chromium/6940)
## How to use
1. Install from PyPI
`pip install dawn-python`
2. Import utils, and webgpu
```python
from pydawn import utils, webgpu
if __name__ == "__main__":
# Creating an adapter
adapter = utils.request_adapter_sync(power_preference=webgpu.WGPUPowerPreference_HighPerformance)
# Creating a device with a list of required features
dev = utils.request_device_sync(adapter, [webgpu.WGPUFeatureName_ShaderF16, webgpu.WGPUFeatureName_TimestampQuery])
```
For more details see `examples/query_set.py`
## Generating bindings
1. [Build dawn](https://dawn.googlesource.com/dawn/+/HEAD/docs/quickstart-cmake.md) or use the pre-built lib in the repo
2. `pip install ctypeslib2`
3. `clang2py -l libwebgpu_dawn.dylib webgpu.h --nm nm_patch.py -o webgpu.py`
## Examples
`python3 examples/simple_compute.py`
## Projects using pydawn
* [tinygrad](https://github.com/tinygrad/tinygrad) - tinygrad is a deep learning framework, and in its WebGPU backend it uses the Dawn binaries from pydawn. It uses the same autogened python around the binaries as pydawn.
## Supported platforms
| Platform | Architectures | Backend |
|----------|-------------------|-----------------|
| macOS | `x86_64`, `arm64` | Metal |
| Ubuntu | `x86_64`, `arm64` | Vulkan |
| Windows | `x86_64` | DirectX |
## License
BSD 3-Clause, please see [LICENSE](https://dawn.googlesource.com/dawn/+/HEAD/LICENSE)