cubecl_core/codegen/
compiler.rs

1use crate::ir::{Elem, KernelDefinition};
2use cubecl_runtime::ExecutionMode;
3use std::fmt::Display;
4
5/// Trait for compiled code representation
6pub trait CompilerRepresentation: Display {
7    /// Computes and returns the shared memory size
8    fn shared_memory_size(&self) -> usize;
9}
10
11/// Compiles the representation into its own representation that can be formatted into tokens.
12pub trait Compiler: Sync + Send + 'static + Clone + Default + core::fmt::Debug {
13    /// The representation for the compiled code.
14    type Representation: CompilerRepresentation;
15    type CompilationOptions: Send + Default + core::fmt::Debug;
16
17    /// Compiles the [kernel definition](KernelDefinition) into the compiler's representation.
18    fn compile(
19        kernel: KernelDefinition,
20        compilation_options: &Self::CompilationOptions,
21        mode: ExecutionMode,
22    ) -> Self::Representation;
23    /// The size of the given element in bytes.
24    fn elem_size(elem: Elem) -> usize;
25    /// The maximal size of a shared memory, in bytes
26    fn max_shared_memory_size() -> usize;
27}