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

Support switching burn-wgpu between WebGPU implementations (wgpu <-> Dawn) #1583

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "crates/burn-wgpu/dawn"]
path = crates/burn-wgpu/dawn
url = https://dawn.googlesource.com/dawn
123 changes: 123 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions _typos.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ extend-ignore-identifiers-re = ["ratatui", "Ratatui", "NdArray*", "ND"]
extend-exclude = [
"assets/ModuleSerialization.xml",
"examples/image-classification-web/src/model/label.txt",
"crates/burn-wgpu/dawn",
]
2 changes: 1 addition & 1 deletion crates/burn-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ ndarray = ["burn-ndarray"]
tch = ["burn-tch"]
candle = ["burn-candle"]
candle-cuda = ["candle", "burn-candle/cuda"]
wgpu = ["burn-wgpu"]
wgpu = ["burn-wgpu/wgpu"]

# Custom deserializer for Record that is helpful for importing data, such as PyTorch pt files.
record-item-custom-serde = ["thiserror", "regex"]
Expand Down
1 change: 1 addition & 0 deletions crates/burn-jit/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export_tests = [
"burn-ndarray",
"fusion",
]
dawn = []

[dependencies]
burn-common = { path = "../burn-common", version = "0.14.0" }
Expand Down
4 changes: 2 additions & 2 deletions crates/burn-jit/src/kernel/base.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::{compute::WorkGroup, gpu::ComputeShader};

#[cfg(target_family = "wasm")]
#[cfg(any(target_family = "wasm", feature = "dawn"))]
pub(crate) const WORKGROUP_DEFAULT: usize = 16;
#[cfg(not(target_family = "wasm"))]
#[cfg(all(not(target_family = "wasm"), not(feature = "dawn")))]
pub(crate) const WORKGROUP_DEFAULT: usize = 32;

/// Dynamic jit kernel to create a [compute shader](ComputeShader).
Expand Down
9 changes: 8 additions & 1 deletion crates/burn-wgpu/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ repository = "https://github.com/tracel-ai/burn/tree/main/burn-wgpu"
version.workspace = true

[features]
default = ["fusion", "burn-jit/default"]
default = ["fusion", "burn-jit/default", "wgpu"]
fusion = ["burn-fusion", "burn-jit/fusion"]
autotune = ["burn-jit/autotune"]
template = ["burn-jit/template"]
doc = ["burn-jit/doc"]
std = ["burn-jit/std"]
dawn = ["burn-jit/dawn", "dep:bindgen", "dep:cmake", "dep:git2"]
wgpu = []

[dependencies]
burn-jit = { path = "../burn-jit", version = "0.14.0", default-features = false }
Expand All @@ -34,6 +36,11 @@ futures-intrusive = { workspace = true }
derive-new = { workspace = true }
hashbrown = { workspace = true }

[build-dependencies]
bindgen = { version = "0.69.4", optional = true }
cmake = { version = "0.1", optional = true }
git2 = { version = "0.18.2", optional = true }

[dev-dependencies]
burn-jit = { path = "../burn-jit", version = "0.14.0", default-features = false, features = [
"export_tests",
Expand Down
6 changes: 5 additions & 1 deletion crates/burn-wgpu/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
[![license](https://shields.io/badge/license-MIT%2FApache--2.0-blue)](https://github.com/tracel-ai/burn-wgpu/blob/master/README.md)

This crate provides a WGPU backend for [Burn](https://github.com/tracel-ai/burn) using the
[wgpu](https://github.com/gfx-rs/wgpu).
[wgpu](https://github.com/gfx-rs/wgpu) or [Dawn](https://dawn.googlesource.com/dawn/).

The backend supports Vulkan, Metal, DirectX11/12, OpenGL, WebGPU.

Expand Down Expand Up @@ -39,3 +39,7 @@ You can set `BURN_WGPU_MAX_TASKS` to a positive integer that determines how many
| OpenGL | No | Yes | Yes | Yes | Yes | Yes | Yes | No |
| WebGpu | No | Yes | No | No | No | No | No | Yes |
| Dx11/Dx12 | No | Yes | No | No | Yes | No | No | No |

## Building with the `dawn` backend enabled

This crate can be built using Dawn as the backing WebGPU implementation. To do this enable the `dawn` feature. Note that Dawn requires `python3`and `ninja` (https://ninja-build.org/) to build and may take a non-negligible time to compile.