Skip to main content

ArtifactCompiler

Trait ArtifactCompiler 

Source
pub trait ArtifactCompiler: Sync {
    type Variant: Clone + Eq + Hash + Debug + Send + Sync;
    type Lowered: Send;
    type Artifact: Send;

    // Required methods
    fn lower(
        &self,
        kernel: &dyn CubeKernel,
        id: &ArtifactId<Self::Variant>,
        recording: &mut CompilationRecording,
        logger: &ServerLogger,
    ) -> Result<Self::Lowered, LaunchError>;
    fn finalize(
        &self,
        id: &ArtifactId<Self::Variant>,
        lowered: Self::Lowered,
    ) -> Result<Self::Artifact, LaunchError>;

    // Provided method
    fn source(lowered: &Self::Lowered) -> Option<&str> { ... }
}
Expand description

The half of a backend’s compilation that may run on any thread: from a kernel to the artifact the device loads, in two steps — a lowering pass through cubecl’s compiler, then whatever finishes the artifact — with one chance between them to reuse an artifact already finalized. A backend whose device lets several threads create objects at once may use it here.

Sync because it is shared by every thread compiling at once.

Required Associated Types§

Source

type Variant: Clone + Eq + Hash + Debug + Send + Sync

Source

type Lowered: Send

A kernel lowered by cubecl’s compiler for this backend, not yet finalized into what the device loads.

Source

type Artifact: Send

What the device loads. The compilation store keeps it, or the part of it that outlives the process: a pipeline the driver built is rebuilt from the kept source.

Required Methods§

Source

fn lower( &self, kernel: &dyn CubeKernel, id: &ArtifactId<Self::Variant>, recording: &mut CompilationRecording, logger: &ServerLogger, ) -> Result<Self::Lowered, LaunchError>

Validates kernel against the device, expands it to IR and lowers it with cubecl’s compiler for this backend, telling recording its IR and source and logger the compilation.

Source

fn finalize( &self, id: &ArtifactId<Self::Variant>, lowered: Self::Lowered, ) -> Result<Self::Artifact, LaunchError>

Turns lowered, lowered for id, into what the device loads: compiles its source with the platform’s compiler, or takes out the artifact lowering produced.

A backend whose driver compiles again once handed the artifact, and lets several threads do so, does that here too and carries the result in the artifact, so the driver’s compilations run alongside each other rather than one by one in CompilationTarget::load.

Provided Methods§

Source

fn source(lowered: &Self::Lowered) -> Option<&str>

The text an artifact finalized from lowered can be reused by: the source finalizing compiles, when that is slow enough that an artifact another kernel id already finalized from the same text is worth reusing — a C++ source two kernel ids expand to, or one expanded again by a rebuild that changed the build id.

None, the default, finalizes every time. It says nothing about whether lowered has text: a backend whose lowering already produced the artifact, LLVM’s, has text and nothing to save by reusing it.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§