Skip to main content

cubecl_core/codegen/
integrator.rs

1use cubecl_ir::{ElemType, Scope, metadata::Info, settings::KernelSettings};
2use cubecl_runtime::kernel::KernelDefinition;
3
4/// The kernel integrator allows you to create a [kernel definition](KernelDefinition) based on
5/// [kernel expansion](KernelExpansion) and [kernel settings](KernelSettings).
6#[derive(Debug)]
7pub struct KernelIntegrator {
8    expansion: KernelExpansion,
9}
10
11/// The information necessary to compile a [kernel definition](KernelDefinition).
12#[derive(Debug)]
13pub struct KernelExpansion {
14    pub scope: Scope,
15    pub info: Info,
16}
17
18/// Information related to a scalar input.
19#[derive(Clone, Debug)]
20pub struct ScalarInfo {
21    pub ty: ElemType,
22    pub count: usize,
23}
24
25impl KernelIntegrator {
26    /// Starts a new compilation.
27    pub fn new(info: KernelExpansion) -> Self {
28        Self { expansion: info }
29    }
30
31    /// Performs the compilation with the provided [settings](KernelSettings).
32    #[cfg_attr(feature = "tracing", tracing::instrument(level = "trace", skip(self)))]
33    pub fn integrate(self, settings: KernelSettings) -> KernelDefinition {
34        KernelDefinition {
35            body: self.expansion.scope,
36            info: self.expansion.info,
37            settings,
38        }
39    }
40}