#![cfg_attr(docsrs, feature(doc_cfg))]
extern crate alloc;
#[cfg(feature = "template")]
pub use burn_cubecl::{
kernel::{KernelMetadata, into_contiguous},
kernel_source,
template::{KernelSource, SourceKernel, SourceTemplate, build_info},
};
pub use burn_cubecl::{BoolElement, FloatElement, IntElement};
pub use burn_cubecl::{CubeBackend, tensor::CubeTensor};
pub use cubecl::CubeDim;
pub use cubecl::flex32;
use cubecl::throughput::{ThroughputKey, ThroughputValue};
#[cfg(feature = "metal")]
use cubecl::wgpu::MslCompiler;
#[cfg(feature = "vulkan")]
use cubecl::wgpu::SpirvCompiler;
#[cfg(feature = "webgpu")]
use cubecl::wgpu::WgslCompiler;
pub use cubecl::wgpu::{
AutoCompiler, MemoryConfiguration, RuntimeOptions, WgpuDevice, WgpuResource, WgpuRuntime,
WgpuSetup, WgpuStorage, init_device, init_setup, init_setup_async,
};
pub mod graphics {
pub use cubecl::wgpu::{AutoGraphicsApi, Dx12, GraphicsApi, Metal, OpenGl, Vulkan, WebGpu};
}
#[cfg(feature = "fusion")]
type WgpuInner<C> = burn_fusion::Fusion<CubeBackend<cubecl::wgpu::WgpuRuntime<C>>>;
#[cfg(not(feature = "fusion"))]
type WgpuInner<C> = CubeBackend<cubecl::wgpu::WgpuRuntime<C>>;
pub type Wgpu = WgpuInner<AutoCompiler>;
pub fn device_throughput(
device: &WgpuDevice,
keys: &[ThroughputKey],
) -> alloc::vec::Vec<ThroughputValue> {
cubecl::std::throughput::device_throughput::<cubecl::wgpu::WgpuRuntime<AutoCompiler>>(
device, keys,
)
}
#[cfg(feature = "vulkan")]
pub type Vulkan = WgpuInner<SpirvCompiler>;
#[cfg(feature = "webgpu")]
pub type WebGpu = WgpuInner<WgslCompiler>;
#[cfg(feature = "metal")]
pub type Metal = WgpuInner<MslCompiler>;
#[cfg(test)]
mod tests {
use super::*;
use burn_backend::{Backend, BoolStore, DType, DeviceOps};
#[test]
fn should_support_dtypes() {
type B = Wgpu;
let device = WgpuDevice::default();
let scheme = device.defaults().quantization.scheme;
assert!(B::supports_dtype(&device, DType::F32));
assert!(B::supports_dtype(&device, DType::I64));
assert!(B::supports_dtype(&device, DType::I32));
assert!(B::supports_dtype(&device, DType::U64));
assert!(B::supports_dtype(&device, DType::U32));
assert!(B::supports_dtype(&device, DType::QFloat(scheme)));
assert!(!B::supports_dtype(&device, DType::Bool(BoolStore::Native)));
#[cfg(feature = "vulkan")]
{
assert!(B::supports_dtype(&device, DType::F16));
assert!(B::supports_dtype(&device, DType::I16));
assert!(B::supports_dtype(&device, DType::I8));
assert!(B::supports_dtype(&device, DType::U16));
assert!(B::supports_dtype(&device, DType::U8));
assert!(B::supports_dtype(&device, DType::F64));
assert!(!B::supports_dtype(&device, DType::Flex32));
assert!(!B::supports_dtype(&device, DType::BF16));
}
#[cfg(feature = "metal")]
{
assert!(B::supports_dtype(&device, DType::F16));
assert!(B::supports_dtype(&device, DType::I16));
assert!(B::supports_dtype(&device, DType::I8));
assert!(B::supports_dtype(&device, DType::U16));
assert!(B::supports_dtype(&device, DType::U8));
assert!(!B::supports_dtype(&device, DType::F64));
assert!(!B::supports_dtype(&device, DType::BF16));
assert!(!B::supports_dtype(&device, DType::Flex32));
}
#[cfg(all(not(any(feature = "vulkan", feature = "metal")), target_os = "macos"))]
{
assert!(B::supports_dtype(&device, DType::Flex32));
assert!(B::supports_dtype(&device, DType::F16));
assert!(!B::supports_dtype(&device, DType::F64));
assert!(!B::supports_dtype(&device, DType::BF16));
assert!(!B::supports_dtype(&device, DType::I16));
assert!(!B::supports_dtype(&device, DType::I8));
assert!(!B::supports_dtype(&device, DType::U16));
assert!(!B::supports_dtype(&device, DType::U8));
}
#[cfg(not(any(feature = "vulkan", feature = "metal", target_os = "macos")))]
{
assert!(B::supports_dtype(&device, DType::F64));
assert!(B::supports_dtype(&device, DType::Flex32));
assert!(B::supports_dtype(&device, DType::F16));
assert!(!B::supports_dtype(&device, DType::BF16));
assert!(!B::supports_dtype(&device, DType::I16));
assert!(!B::supports_dtype(&device, DType::I8));
assert!(!B::supports_dtype(&device, DType::U16));
assert!(!B::supports_dtype(&device, DType::U8));
}
}
}