cubecl_runtime/
compiler.rs1use crate::kernel::{CompiledKernel, KernelDefinition, KernelMetadata};
2use alloc::{string::String, vec::Vec};
3use cubecl_common::ExecutionMode;
4use cubecl_ir::ElemType;
5
6pub trait CubeTask<C: Compiler>: KernelMetadata + Send + Sync {
9 fn compile(
11 &self,
12 compiler: &mut C,
13 compilation_options: &C::CompilationOptions,
14 mode: ExecutionMode,
15 ) -> Result<CompiledKernel<C>, CompilationError>;
16}
17
18#[derive(Debug, PartialEq, Eq, Clone, Hash)]
20#[cfg_attr(std_io, derive(serde::Serialize, serde::Deserialize))]
21pub enum CompilationError {
22 UnsupportedInstruction {
24 context: String,
26 },
27
28 Multiple {
30 context: String,
32 errors: Vec<Self>,
34 },
35
36 Generic {
38 context: String,
40 },
41}
42
43impl core::fmt::Display for CompilationError {
44 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
45 f.write_fmt(format_args!("{:?}", self))
47 }
48}
49
50pub trait Compiler: Sync + Send + 'static + Clone + core::fmt::Debug {
52 type Representation: core::fmt::Display;
54 type CompilationOptions: Send + Default + core::fmt::Debug;
56
57 fn compile(
59 &mut self,
60 kernel: KernelDefinition,
61 compilation_options: &Self::CompilationOptions,
62 mode: ExecutionMode,
63 ) -> Result<Self::Representation, CompilationError>;
64
65 fn elem_size(&self, elem: ElemType) -> usize;
67
68 fn extension(&self) -> &'static str;
71}