cubecl_spirv/
lib.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
use std::fmt::{Debug, Display};

use cubecl_core::CompilerRepresentation;
use cubecl_opt::Optimizer;
use rspirv::{
    binary::{Assemble, Disassemble},
    dr::Module,
};

mod branch;
mod cmma;
mod compiler;
mod extensions;
mod instruction;
mod item;
mod lookups;
mod metadata;
mod subgroup;
mod sync;
mod target;
mod variable;

pub use compiler::*;
pub use target::*;

#[derive(Debug, Clone)]
pub struct SpirvKernel {
    pub module: Module,
    pub optimizer: Optimizer,
    pub num_bindings: usize,
}

impl CompilerRepresentation for SpirvKernel {
    fn shared_memory_size(&self) -> usize {
        // not used in wgsl compiler
        0
    }
}

impl Display for SpirvKernel {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "{}", self.module.disassemble())
    }
}

impl SpirvKernel {
    pub fn assemble(&self) -> Vec<u32> {
        self.module.assemble()
    }
}