cubecl_core/codegen/
compiler.rs

1use cubecl_common::ExecutionMode;
2
3use crate::{compute::KernelDefinition, ir::Elem};
4
5/// Compiles the representation into its own representation that can be formatted into tokens.
6pub trait Compiler: Sync + Send + 'static + Clone + core::fmt::Debug {
7    /// The representation for the compiled code.
8    type Representation: core::fmt::Display;
9    type CompilationOptions: Send + Default + core::fmt::Debug;
10
11    /// Compiles the [kernel definition](KernelDefinition) into the compiler's representation.
12    fn compile(
13        &mut self,
14        kernel: KernelDefinition,
15        compilation_options: &Self::CompilationOptions,
16        mode: ExecutionMode,
17    ) -> Self::Representation;
18    /// The size of the given element in bytes.
19    fn elem_size(&self, elem: Elem) -> usize;
20
21    /// The default extension for the runtime's kernel/shader code.
22    /// Might change based on which compiler is used.
23    fn extension(&self) -> &'static str;
24}
25
26// We cannot put this struct in cubecl-wgpu crate due to circular dependencies.
27#[derive(Clone, Debug, Default)]
28pub struct WgpuCompilationOptions {
29    pub supports_fp_fast_math: bool,
30    pub supports_u64: bool,
31}