15 releases (9 breaking)

Uses new Rust 2024

0.17.0 Apr 23, 2025
0.16.0 Jan 14, 2025
0.15.0 Oct 28, 2024
0.13.2 May 3, 2024
0.8.0 Jul 25, 2023

#1220 in Machine learning

Download history 3085/week @ 2025-01-15 3155/week @ 2025-01-22 3027/week @ 2025-01-29 2997/week @ 2025-02-05 2533/week @ 2025-02-12 4906/week @ 2025-02-19 4038/week @ 2025-02-26 3934/week @ 2025-03-05 3595/week @ 2025-03-12 3252/week @ 2025-03-19 3118/week @ 2025-03-26 2217/week @ 2025-04-02 2437/week @ 2025-04-09 3939/week @ 2025-04-16 7042/week @ 2025-04-23 3655/week @ 2025-04-30

17,312 downloads per month
Used in 41 crates (6 directly)

MIT/Apache

2MB
41K SLoC

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

Dependencies

~30–63MB
~1M SLoC