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 supported line sizes for the current runtime's compiler.
32    fn supported_line_sizes() -> &'static [u8];
33
34    /// The maximum line size that can be used for global buffer bindings.
35    fn max_global_line_size() -> u8 {
36        u8::MAX
37    }
38
39    /// Returns the maximum cube count on each dimension that can be launched.
40    fn max_cube_count() -> (u32, u32, u32);
41
42    /// Whether a tensor with `shape` and `strides` can be read as is. If the result is false, the
43    /// tensor should be made contiguous before reading.
44    fn can_read_tensor(shape: &[usize], strides: &[usize]) -> bool;
45
46    /// Returns the properties of the target hardware architecture.
47    fn target_properties() -> TargetProperties;
48}