pub use burn::backend::wgpu;
pub mod quant;
use burn::backend::wgpu::{RuntimeOptions, WgpuDevice, WgpuSetup, graphics::AutoGraphicsApi};
#[cfg(not(feature = "f16"))]
pub type CombsBackend = burn::backend::Wgpu<f32, i32, u32>;
pub type CombsBackendF32 = burn::backend::Wgpu<f32, i32, u32>;
#[cfg(feature = "f16")]
pub type CombsBackend = burn::backend::wgpu::CubeBackend<
burn::backend::wgpu::WgpuRuntime,
burn::tensor::f16,
i32,
u32,
>;
pub type CombsDevice = WgpuDevice;
pub fn init_device() -> CombsDevice {
WgpuDevice::default()
}
pub fn gpu_available() -> bool {
static AVAILABLE: std::sync::OnceLock<bool> = std::sync::OnceLock::new();
*AVAILABLE.get_or_init(|| {
let instance = ::wgpu::Instance::default();
let adapters =
cubecl::future::block_on(instance.enumerate_adapters(::wgpu::Backends::all()));
!adapters.is_empty()
})
}
#[derive(Debug, Clone)]
pub struct DeviceInfo {
pub name: String,
pub backend: String,
pub device_type: String,
pub driver: String,
}
#[derive(Debug, Clone, serde::Serialize)]
pub struct DeviceCaps {
pub name: String,
pub backend: String,
pub device_type: String,
pub max_storage_buffer_binding_size: u64,
pub max_buffer_size: u64,
pub max_compute_workgroup_size_x: u32,
pub max_compute_invocations_per_workgroup: u32,
pub features: String,
}
pub fn device_caps(device: &CombsDevice) -> DeviceCaps {
let setup: WgpuSetup =
burn::backend::wgpu::init_setup::<AutoGraphicsApi>(device, RuntimeOptions::default());
let info = setup.adapter.get_info();
let limits = setup.adapter.limits();
let features = setup.adapter.features();
DeviceCaps {
name: info.name,
backend: format!("{:?}", info.backend),
device_type: format!("{:?}", info.device_type),
max_storage_buffer_binding_size: limits.max_storage_buffer_binding_size as u64,
max_buffer_size: limits.max_buffer_size,
max_compute_workgroup_size_x: limits.max_compute_workgroup_size_x,
max_compute_invocations_per_workgroup: limits.max_compute_invocations_per_workgroup,
features: format!("{:?}", features),
}
}
#[derive(Debug, Clone, Copy, Default, serde::Serialize)]
pub struct GpuMemory {
pub bytes_in_use: u64,
pub bytes_reserved: u64,
pub bytes_padding: u64,
pub number_allocs: u64,
}
pub fn gpu_memory(device: &CombsDevice) -> Option<GpuMemory> {
let client =
<burn::backend::wgpu::WgpuRuntime as cubecl::prelude::Runtime>::client(device);
client.memory_usage().ok().map(|m| GpuMemory {
bytes_in_use: m.bytes_in_use,
bytes_reserved: m.bytes_reserved,
bytes_padding: m.bytes_padding,
number_allocs: m.number_allocs,
})
}
pub fn device_info(device: &CombsDevice) -> DeviceInfo {
let setup: WgpuSetup =
burn::backend::wgpu::init_setup::<AutoGraphicsApi>(device, RuntimeOptions::default());
let info = setup.adapter.get_info();
DeviceInfo {
name: info.name,
backend: format!("{:?}", info.backend),
device_type: format!("{:?}", info.device_type),
driver: format!("{} ({})", info.driver, info.driver_info),
}
}
#[derive(Debug, Default, Clone, Copy)]
pub struct BufferPool;
impl BufferPool {
pub fn new() -> Self {
BufferPool
}
pub fn pin_persistent(&self) {
}
pub fn cleanup(&self) {
}
}