pub type Wgpu = Fusion<CubeBackend>;Expand description
Tensor backend that uses the wgpu crate for executing GPU compute shaders.
This backend can target multiple graphics APIs, including:
- Vulkan on Linux, Windows, and Android.
- OpenGL on Linux, Windows, and Android.
- DirectX 12 on Windows.
- Metal on Apple hardware.
- WebGPU on supported browsers and
wasmruntimes.
Automatic devices use AutoCompiler to select WGSL, SPIR-V or MSL, with WGSL fallback
when a native compiler is unavailable. Enabling metal makes MSL available without changing
the compiler used by unrelated devices.
With metal enabled, an explicitly selected Metal device, created with Burn’s
burn::tensor::Device::metal or cubecl::Device::metal_msl, requires native MSL and panics
during initialization if it is unavailable. The same applies to init_setup or
init_setup_async with graphics::Metal, and to init_device_with_api with
graphics::Metal. Importing through init_device retains automatic compiler selection
and fallback. The corresponding try_* functions return initialization errors instead
of panicking.
Multiple backend features can be enabled together. The deprecated Vulkan, WebGpu and
Metal aliases name the same backend; use Wgpu with an explicit device constructor to
select the graphics API. Compiler selection follows the device and enabled features.
Application code configures and initializes the runtime with Device::wgpu_options:
use burn::tensor::{Device, wgpu::WgpuBackend};
let device = Device::wgpu_options()
.graphics_api(WgpuBackend::Vulkan)
.tasks_max(32)
.init()?;Use init_async().await for native async applications and browsers, or
.setup(existing_setup).init() to share an application’s existing device and queue.
Initialize once, then clone the Burn device to share its runtime. The low-level
try_init_setup_async and try_init_device APIs remain available for backend authors.
§Notes
When the fusion feature flag is enabled (the default), this backend uses burn_fusion to
compile and optimize streams of tensor operations for improved performance. You can disable
the fusion feature flag to remove that functionality, which might be necessary on wasm
for now.
Aliased Type§
pub struct Wgpu { /* private fields */ }