Skip to main content

cubecl_runtime/
runtime.rs

1use alloc::boxed::Box;
2use cubecl_common::device::Device;
3use cubecl_ir::TargetProperties;
4
5use crate::{
6    client::ComputeClient,
7    compiler::{Compiler, CubeTask},
8    server::ComputeServer,
9};
10
11/// Runtime for the `CubeCL`.
12pub trait Runtime: Sized + Send + Sync + 'static + core::fmt::Debug {
13    /// The compiler used to compile the inner representation into tokens.
14    type Compiler: Compiler;
15    /// The compute server used to run kernels and perform autotuning.
16    type Server: ComputeServer<Kernel = Box<dyn CubeTask<Self::Compiler>>>;
17    /// The device used to retrieve the compute client.
18    type Device: Device;
19
20    /// Retrieve the compute client from the runtime device.
21    fn client(device: &Self::Device) -> ComputeClient<Self>;
22
23    /// The runtime name on the given device.
24    fn name(client: &ComputeClient<Self>) -> &'static str;
25
26    /// Return true if global input array lengths should be added to kernel info.
27    fn require_array_lengths() -> bool {
28        false
29    }
30
31    /// Returns the maximum cube count on each dimension that can be launched.
32    fn max_cube_count() -> (u32, u32, u32);
33
34    /// Whether a tensor with `shape` and `strides` can be read as is. If the result is false, the
35    /// tensor should be made contiguous before reading.
36    fn can_read_tensor(shape: &[usize], strides: &[usize]) -> bool;
37
38    /// Returns the properties of the target hardware architecture.
39    fn target_properties() -> TargetProperties;
40}