use cubecl_core::ir::ElemType;
use cubecl_runtime::{client::Client, server::CubeDim};
const CPU_CHAIN_DEPTH: usize = 64;
const PROBE_UNITS_PER_CUBE: u32 = 256;
#[derive(Clone, Copy)]
pub struct LaunchConfig {
pub cube_dim: CubeDim,
pub cube_count: usize,
pub vector_size: usize,
pub plane_size: usize,
}
impl LaunchConfig {
pub(super) fn for_device(client: &Client, dtype: ElemType) -> Self {
let hardware = &client.properties().hardware;
let plane_size = hardware.plane_size_max.max(1);
let vector_size = client
.io_optimized_vector_sizes(dtype.size())
.next()
.unwrap_or(1);
let (units, cube_count) = match hardware.num_cpu_cores {
Some(cores) => (cores, CPU_CHAIN_DEPTH as u32),
None => {
let sms = hardware.num_streaming_multiprocessors.unwrap_or(64);
(
PROBE_UNITS_PER_CUBE,
(sms * 32).min(hardware.max_cube_count.0),
)
}
};
Self {
cube_dim: CubeDim::new(client, units as usize),
cube_count: cube_count as usize,
vector_size,
plane_size: plane_size as usize,
}
}
pub(super) fn with_units(self, client: &Client, units: u32) -> Self {
Self {
cube_dim: CubeDim::new(client, units as usize),
..self
}
}
}