use alloc::{string::ToString, sync::Arc};
use cubecl_ir::{
DeviceIdentity, DeviceProperties, HardwareProperties, MemoryDeviceProperties, VectorSize,
features::Features, settings::DebugInfo,
};
use cubecl_runtime::kernel::CubeKernel;
use crate as cubecl;
use crate::prelude::*;
use crate::profile::TimingMethod;
#[must_use]
pub fn offline_device_properties(plane_dim: u32) -> DeviceProperties {
let hardware = HardwareProperties {
load_width: 128,
vector_register_count: None,
plane_size_min: plane_dim,
plane_size_max: plane_dim,
max_bindings: 32,
max_shared_memory_size: 65536,
max_cube_count: (u32::MAX, u32::from(u16::MAX), u32::from(u16::MAX)),
max_units_per_cube: 1024,
max_cube_dim: (1024, 1024, 1024),
num_streaming_multiprocessors: None,
num_tensor_cores: None,
min_tensor_cores_dim: None,
num_cpu_cores: None,
last_level_cache_size: None,
max_vector_size: VectorSize::MAX,
cube_mma_reserved_shared_memory: 0,
};
DeviceProperties::new(
Features::default(),
MemoryDeviceProperties::new(u64::MAX, 256),
hardware,
TimingMethod::Device,
DeviceIdentity {
name: "offline".to_string(),
fingerprint: "offline".to_string(),
physical: None,
},
)
}
#[cube]
#[must_use]
pub fn square_third(x: f32) -> f32 {
let y = x * x;
y / 3.0
}
#[cube]
#[must_use]
pub fn doubled(x: f32) -> f32 {
let third = square_third(x);
third * 2.0
}
#[cube(launch)]
pub fn nested_calls(input: &[f32], output: &mut [f32]) {
if ABSOLUTE_POS < input.len() {
output[ABSOLUTE_POS] = doubled(input[ABSOLUTE_POS]);
}
}
#[cube(launch, debug_symbols)]
pub fn nested_calls_with_source(input: &[f32], output: &mut [f32]) {
if ABSOLUTE_POS < input.len() {
output[ABSOLUTE_POS] = doubled(input[ABSOLUTE_POS]) + 1.0;
}
}
pub const SOURCE: &str = include_str!("offline.rs");
pub const SOURCE_PATH: &str = "crates/cubecl-core/src/runtime_tests/offline.rs";
#[must_use]
pub fn source_line(text: &str) -> u32 {
let mut lines = SOURCE
.lines()
.zip(1..)
.filter(|(line, _)| line.contains(text));
let (_, number) = lines
.next()
.unwrap_or_else(|| panic!("no line has `{text}`"));
assert!(lines.next().is_none(), "more than one line has `{text}`");
number
}
fn settings(level: DebugInfo) -> KernelSettings {
KernelSettings::new(
*CubeDim::new_1d(64),
ExecutionMode::Checked,
AddressType::U32,
)
.debug_info(level)
}
#[must_use]
pub fn nested_calls_kernel(properties: Arc<DeviceProperties>, level: DebugInfo) -> impl CubeKernel {
nested_calls::NestedCalls::new(
settings(level),
properties,
Arc::new(TargetProperties::default()),
BufferCompilationArg { inplace: None },
BufferCompilationArg { inplace: None },
)
}
#[must_use]
pub fn nested_calls_with_source_kernel(properties: Arc<DeviceProperties>) -> impl CubeKernel {
nested_calls_with_source::NestedCallsWithSource::new(
settings(DebugInfo::Full),
properties,
Arc::new(TargetProperties::default()),
BufferCompilationArg { inplace: None },
BufferCompilationArg { inplace: None },
)
}