1#![cfg_attr(docsrs, feature(doc_cfg))]
2
3extern crate alloc;
4
5#[cfg(feature = "template")]
6pub use burn_cubecl::{
7 kernel::{KernelMetadata, into_contiguous},
8 kernel_source,
9 template::{KernelSource, SourceKernel, SourceTemplate, build_info},
10};
11
12pub use burn_cubecl::{BoolElement, FloatElement, IntElement};
13pub use burn_cubecl::{CubeBackend, tensor::CubeTensor};
14pub use cubecl::CubeDim;
15pub use cubecl::flex32;
16use cubecl::throughput::{ThroughputKey, ThroughputValue};
17
18#[cfg(feature = "metal")]
19use cubecl::wgpu::MslCompiler;
20#[cfg(feature = "vulkan")]
21use cubecl::wgpu::SpirvCompiler;
22#[cfg(feature = "webgpu")]
23use cubecl::wgpu::WgslCompiler;
24
25pub use cubecl::wgpu::{
26 AutoCompiler, MemoryConfiguration, RuntimeOptions, WgpuDevice, WgpuResource, WgpuRuntime,
27 WgpuSetup, WgpuStorage, init_device, init_setup, init_setup_async,
28};
29pub mod graphics {
31 pub use cubecl::wgpu::{AutoGraphicsApi, Dx12, GraphicsApi, Metal, OpenGl, Vulkan, WebGpu};
32}
33
34#[cfg(feature = "fusion")]
35type WgpuInner<C> = burn_fusion::Fusion<CubeBackend<cubecl::wgpu::WgpuRuntime<C>>>;
36
37#[cfg(not(feature = "fusion"))]
38type WgpuInner<C> = CubeBackend<cubecl::wgpu::WgpuRuntime<C>>;
39
40pub type Wgpu = WgpuInner<AutoCompiler>;
77
78pub fn device_throughput(
82 device: &WgpuDevice,
83 keys: &[ThroughputKey],
84) -> alloc::vec::Vec<ThroughputValue> {
85 cubecl::std::throughput::device_throughput::<cubecl::wgpu::WgpuRuntime<AutoCompiler>>(
86 device, keys,
87 )
88}
89
90#[cfg(feature = "vulkan")]
97pub type Vulkan = WgpuInner<SpirvCompiler>;
98
99#[cfg(feature = "webgpu")]
104pub type WebGpu = WgpuInner<WgslCompiler>;
105
106#[cfg(feature = "metal")]
111pub type Metal = WgpuInner<MslCompiler>;
112
113#[cfg(test)]
114mod tests {
115 use super::*;
116 use burn_backend::{Backend, BoolStore, DType, DeviceOps};
117
118 #[test]
119 fn should_support_dtypes() {
120 type B = Wgpu;
121 let device = WgpuDevice::default();
122 let scheme = device.defaults().quantization.scheme;
123
124 assert!(B::supports_dtype(&device, DType::F32));
125 assert!(B::supports_dtype(&device, DType::I64));
126 assert!(B::supports_dtype(&device, DType::I32));
127 assert!(B::supports_dtype(&device, DType::U64));
128 assert!(B::supports_dtype(&device, DType::U32));
129 assert!(B::supports_dtype(&device, DType::QFloat(scheme)));
130 assert!(!B::supports_dtype(&device, DType::Bool(BoolStore::Native)));
131
132 #[cfg(feature = "vulkan")]
133 {
134 assert!(B::supports_dtype(&device, DType::F16));
135 assert!(B::supports_dtype(&device, DType::I16));
136 assert!(B::supports_dtype(&device, DType::I8));
137 assert!(B::supports_dtype(&device, DType::U16));
138 assert!(B::supports_dtype(&device, DType::U8));
139
140 assert!(B::supports_dtype(&device, DType::F64));
142 assert!(!B::supports_dtype(&device, DType::Flex32));
143 assert!(!B::supports_dtype(&device, DType::BF16));
145 }
146
147 #[cfg(feature = "metal")]
148 {
149 assert!(B::supports_dtype(&device, DType::F16));
150 assert!(B::supports_dtype(&device, DType::I16));
151 assert!(B::supports_dtype(&device, DType::I8));
152 assert!(B::supports_dtype(&device, DType::U16));
153 assert!(B::supports_dtype(&device, DType::U8));
154
155 assert!(!B::supports_dtype(&device, DType::F64));
156 assert!(!B::supports_dtype(&device, DType::BF16));
157 assert!(!B::supports_dtype(&device, DType::Flex32));
158 }
159
160 #[cfg(all(not(any(feature = "vulkan", feature = "metal")), target_os = "macos"))]
163 {
164 assert!(B::supports_dtype(&device, DType::Flex32));
165 assert!(B::supports_dtype(&device, DType::F16));
166
167 assert!(!B::supports_dtype(&device, DType::F64));
168 assert!(!B::supports_dtype(&device, DType::BF16));
169 assert!(!B::supports_dtype(&device, DType::I16));
170 assert!(!B::supports_dtype(&device, DType::I8));
171 assert!(!B::supports_dtype(&device, DType::U16));
172 assert!(!B::supports_dtype(&device, DType::U8));
173 }
174
175 #[cfg(not(any(feature = "vulkan", feature = "metal", target_os = "macos")))]
176 {
177 assert!(B::supports_dtype(&device, DType::F64));
178 assert!(B::supports_dtype(&device, DType::Flex32));
179 assert!(B::supports_dtype(&device, DType::F16));
180
181 assert!(!B::supports_dtype(&device, DType::BF16));
182 assert!(!B::supports_dtype(&device, DType::I16));
183 assert!(!B::supports_dtype(&device, DType::I8));
184 assert!(!B::supports_dtype(&device, DType::U16));
185 assert!(!B::supports_dtype(&device, DType::U8));
186 }
187 }
188}