burn/crates/burn-wgpu
Arthur Brussee c51045c608
Update CubeCL for client based profiling (#3222)
2025-05-23 11:21:28 -04:00
..
src Update CubeCL for client based profiling (#3222) 2025-05-23 11:21:28 -04:00
Cargo.toml Chain lint inheritance [was: Disable new default clippy tests] (#3200) 2025-05-20 08:23:11 -04:00
LICENSE-APACHE Update licenses symlinks (#1613) 2024-04-12 14:43:58 -04:00
LICENSE-MIT Update licenses symlinks (#1613) 2024-04-12 14:43:58 -04:00
README.md Fix/docs (#3071) 2025-04-23 15:00:42 -04:00

README.md

Burn WGPU Backend

Burn WGPU backend

Current Crates.io Version license

This crate provides a WGPU backend for Burn using the wgpu.

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

Usage Example

#[cfg(feature = "wgpu")]
mod wgpu {
    use burn_autodiff::Autodiff;
    use burn_wgpu::{Wgpu, WgpuDevice};
    use mnist::training;

    pub fn run() {
        let device = WgpuDevice::default();
        training::run::<Autodiff<Wgpu<f32, i32>>>(device);
    }
}

⚠️ Warning
When using one of the wgpu backends, you may encounter compilation errors related to recursive type evaluation. This is due to complex type nesting within the wgpu dependency chain.
To resolve this issue, add the following line at the top of your main.rs or lib.rs file:

#![recursion_limit = "256"]

The default recursion limit (128) is often just below the required depth (typically 130-150) due to deeply nested associated types and trait bounds.

Configuration

You can set BURN_WGPU_MAX_TASKS to a positive integer that determines how many computing tasks are submitted in batches to the graphics API.

Alternative SPIR-V backend

When targeting Vulkan, the spirv feature flag can be enabled to enable the SPIR-V compiler backend, which performs significantly better than WGSL. This is especially true for matrix multiplication, where SPIR-V can make use of TensorCores and run at f16 precision. This isn't currently supported by WGSL. The compiler can also be selected at runtime by setting the corresponding generic parameter to either SpirV or Wgsl.

Platform Support

Option CPU GPU Linux MacOS Windows Android iOS WASM
Metal No Yes No Yes No No Yes No
Vulkan Yes Yes Yes Yes Yes Yes Yes No
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