Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
e678cbd
WIP
wingertge Jun 12, 2026
d2bbe7a
tmp
wingertge Jun 15, 2026
19ac431
Const eval
wingertge Jun 16, 2026
ad10259
CUDA first test pass
wingertge Jun 18, 2026
1a5513b
More const propagate
wingertge Jun 23, 2026
86d6052
Unroll C++
wingertge Jun 25, 2026
ccce459
WIP
wingertge Jun 27, 2026
7fd2577
WIP
wingertge Jul 9, 2026
21f9762
Split ops by semantics
wingertge Jul 10, 2026
f6cb292
Remove incorrect negate impl for unsigned
wingertge Jul 10, 2026
1670cba
First test pass SPIR-V
wingertge Jul 11, 2026
c7c3a85
Convert break/return, fix mem2reg
wingertge Jul 12, 2026
19aa601
Separate plane ops by type
wingertge Jul 15, 2026
5448d89
feat: make cubecl-cpu compile by commenting the compiler
marcantoinem Jul 2, 2026
29e9e5a
feat: start porting mlir to pliron
marcantoinem Jul 7, 2026
315b460
feat: put old compiler in another folder for comparaison
marcantoinem Jul 7, 2026
6eb134b
feat: add printing of cubecl ir
marcantoinem Jul 9, 2026
f7a7738
feat: add pass
marcantoinem Jul 10, 2026
3593017
feat: add entrypoint
marcantoinem Jul 10, 2026
1d70142
feat: temporary move
marcantoinem Jul 10, 2026
ca408d0
feat: add IR printing
marcantoinem Jul 13, 2026
60564a1
feat: derive pass name
marcantoinem Jul 14, 2026
58ae05c
feat: modify entrypoint logic
marcantoinem Jul 14, 2026
5024ea2
feat: add entrypoint
marcantoinem Jul 15, 2026
4d6b4fe
More Vulkan implementations
wingertge Jul 17, 2026
2a7398c
Merge pull request #2 from marcantoinem/feature/pliron-cpu
wingertge Jul 17, 2026
1712bbe
SPIR-V tests passing
wingertge Jul 18, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
9 changes: 7 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ invalid_html_tags = "warn"
bitflags = { version = "2.9.1", features = ["serde"] }
derive-new = { version = "0.7.0", default-features = false }
derive_more = { version = "2", default-features = false }
num = "0.4"
oneshot = { version = "0.2.1", default-features = false }
tynm = { version = "0.2" }

Expand Down Expand Up @@ -69,7 +70,7 @@ smallvec = { version = "1", features = [
"const_generics",
"const_new",
] }
spin = { version = "0.10.0", features = ["mutex", "spin_mutex"] }
spin = { version = "0.11.0", features = ["mutex", "spin_mutex", "lazylock"] }
xxhash-rust = { version = "0.8", default-features = false }

rand = { version = "0.10.0", default-features = false, features = [
Expand Down Expand Up @@ -141,6 +142,9 @@ tracel-llvm-bundler = { git = "https://github.com/tracel-ai/tracel-llvm", rev =
libc = "^0.2.186"
winapi = { version = "^0.3.9", features = ["processthreadsapi", "winbase"] }

inflections = "1"
pliron = { path = "../pliron", default-features = false }
# pliron = { git = "https://github.com/pliron-org/pliron.git", rev = "3190215a8f0fb8d9b7ace9e700b512709a078cac", default-features = false }

cudarc = { version = "0.19.6", features = [
"std",
Expand All @@ -153,7 +157,8 @@ cudarc = { version = "0.19.6", features = [
], default-features = false } # CubeCL-CUDA

# CubeCL-SPIR-V
rspirv = { package = "tracel-rspirv", version = "0.13.0" }
pliron-spirv = { package = "pliron-spirv", path = "../tracel-rspirv/pliron-spirv" }
rspirv = { package = "tracel-rspirv", path = "../tracel-rspirv/rspirv" }

# CubeCL-WGPU
ash = "0.38"
Expand Down
6 changes: 6 additions & 0 deletions crates/cubecl-common/src/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@ pub fn type_name_short_sanitized<T>() -> String {
name.replace(|c: char| !c.is_alphanumeric() && c != '_', "_")
}

/// Provide a long, sanitized type name for use in context identifiers
pub fn type_name_sanitized<T>() -> String {
let name = core::any::type_name::<T>();
name.replace(|c: char| !c.is_alphanumeric() && c != '_', "_")
}

#[cfg(test)]
#[cfg(feature = "std")]
mod tests {
Expand Down
4 changes: 2 additions & 2 deletions crates/cubecl-common/src/stub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ use std::sync::{
};

#[cfg(not(feature = "std"))]
pub use spin::{Lazy, RwLockReadGuard, RwLockWriteGuard};
pub use spin::{LazyLock, RwLockReadGuard, RwLockWriteGuard};
#[cfg(feature = "std")]
pub use std::sync::{LazyLock as Lazy, RwLockReadGuard, RwLockWriteGuard};
pub use std::sync::{LazyLock, RwLockReadGuard, RwLockWriteGuard};

#[cfg(target_has_atomic = "ptr")]
pub use alloc::sync::Arc;
Expand Down
4 changes: 3 additions & 1 deletion crates/cubecl-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ workspace = true
[features]
default = ["cubecl-runtime/default", "cubecl-ir/default"]
export_tests = ["tempfile", "test-log/trace", "test-log/log", "std"]
std = ["cubecl-runtime/std", "cubecl-ir/std"]
std = ["cubecl-runtime/std", "pliron/std"]
template = []

tracing = ["dep:tracing", "cubecl-runtime/tracing", "cubecl-ir/tracing"]
Expand Down Expand Up @@ -65,6 +65,8 @@ serde_json = { workspace = true }
tempfile = { version = "3.20", optional = true }
variadics_please = { workspace = true }

pliron = { workspace = true }

[dev-dependencies]
pretty_assertions = { workspace = true }
test-log = { workspace = true, features = ["trace"] }
Expand Down
74 changes: 4 additions & 70 deletions crates/cubecl-core/src/codegen/info.rs
Original file line number Diff line number Diff line change
@@ -1,75 +1,9 @@
use alloc::{vec, vec::Vec};
use alloc::vec;

use cubecl_ir::{AddressType, StorageType};
use cubecl_runtime::{kernel::ScalarKernelArg, server::MetadataBindingInfo};
use cubecl_ir::{AddressType, metadata::INFO_ALIGN};
use cubecl_runtime::server::MetadataBindingInfo;

use crate::{Metadata, MetadataBuilder, ScalarBuilder};

pub(crate) const INFO_ALIGN: usize = size_of::<u64>();

/// Helper to calculate info struct fields
#[derive(Clone, Debug, Default)]
pub struct Info {
pub scalars: Vec<SizedInfoField>,
pub sized_meta: Option<SizedInfoField>,
pub has_dynamic_meta: bool,
pub dynamic_meta_offset: usize,
pub metadata: Metadata,
}

#[derive(Clone, Copy, Debug)]
pub struct SizedInfoField {
pub ty: StorageType,
pub size: usize,
pub offset: usize,
}

impl SizedInfoField {
pub fn padded_size(&self) -> usize {
let padding_factor = INFO_ALIGN / self.ty.size();
self.size.next_multiple_of(padding_factor)
}
}

impl Info {
pub fn new(scalars: &[ScalarKernelArg], metadata: Metadata, address_type: StorageType) -> Self {
let mut scalar_fields = Vec::with_capacity(scalars.len());
let mut sized_meta = None;

let mut offset = 0;

for scalar in scalars {
scalar_fields.push(SizedInfoField {
ty: scalar.ty,
size: scalar.count,
offset,
});
offset += (scalar.ty.size() * scalar.count).next_multiple_of(INFO_ALIGN);
}

if metadata.static_len() > 0 {
let size = metadata.static_len() as usize;
sized_meta = Some(SizedInfoField {
ty: address_type,
size,
offset,
});
offset += (address_type.size() * size).next_multiple_of(INFO_ALIGN);
}

Info {
scalars: scalar_fields,
sized_meta,
has_dynamic_meta: metadata.num_extended_meta() > 0,
dynamic_meta_offset: offset,
metadata,
}
}

pub fn has_info(&self) -> bool {
!self.scalars.is_empty() || self.sized_meta.is_some()
}
}
use crate::{MetadataBuilder, ScalarBuilder};

#[derive(Default)]
pub struct InfoBuilder {
Expand Down
132 changes: 10 additions & 122 deletions crates/cubecl-core/src/codegen/integrator.rs
Original file line number Diff line number Diff line change
@@ -1,152 +1,40 @@
use alloc::{string::ToString, vec::Vec};
use cubecl_ir::{Id, Scope, StorageType, Value};
use cubecl_runtime::{
kernel::{KernelArg, KernelDefinition, KernelOptions, ScalarKernelArg},
server::CubeDim,
};

use crate::prelude::AddressType;
use cubecl_ir::{ElemType, Scope, metadata::Info, settings::KernelSettings};
use cubecl_runtime::kernel::KernelDefinition;

/// The kernel integrator allows you to create a [kernel definition](KernelDefinition) based on
/// [kernel expansion](KernelExpansion) and [kernel settings](KernelSettings).
#[derive(Clone, Debug)]
#[derive(Debug)]
pub struct KernelIntegrator {
expansion: KernelExpansion,
buffer_bindings: Vec<KernelArg>,
scalar_bindings: Vec<ScalarKernelArg>,
tensor_maps: Vec<KernelArg>,
}

/// The information necessary to compile a [kernel definition](KernelDefinition).
#[derive(Clone, Debug)]
#[derive(Debug)]
pub struct KernelExpansion {
pub buffers: Vec<BufferInfo>,
pub scalars: Vec<ScalarInfo>,
pub tensor_maps: Vec<BufferInfo>,
pub scope: Scope,
}

#[derive(Clone, Debug, PartialEq, Eq)]
pub struct KernelSettings {
pub cube_dim: CubeDim,
pub address_type: AddressType,
pub options: KernelOptions,
}

impl Default for KernelSettings {
fn default() -> Self {
Self {
cube_dim: CubeDim::new_1d(1),
address_type: AddressType::U32,
options: Default::default(),
}
}
}

impl KernelSettings {
/// Set cube dimension.
pub fn cube_dim(mut self, cube_dim: CubeDim) -> Self {
self.cube_dim = cube_dim;
self
}

/// Set address type.
pub fn address_type(mut self, ty: AddressType) -> Self {
self.address_type = ty;
self
}

/// Set kernel name.
pub fn kernel_name<S: AsRef<str>>(mut self, name: S) -> Self {
self.options.kernel_name = name.as_ref().to_string();
self
}

/// Activate debug symbols
pub fn debug_symbols(mut self) -> Self {
self.options.debug_symbols = true;
self
}

/// Set cluster dim
pub fn cluster_dim(mut self, cluster_dim: CubeDim) -> Self {
self.options.cluster_dim = Some(cluster_dim);
self
}
}

/// Information related to a buffer binding.
#[derive(Clone, Debug)]
pub struct BufferInfo {
pub id: Id,
pub value: Value,
/// Whether this input has extended metadata (rank, shape, strides)
pub has_extended_meta: bool,
pub info: Info,
}

/// Information related to a scalar input.
#[derive(Clone, Debug)]
pub struct ScalarInfo {
pub ty: StorageType,
pub ty: ElemType,
pub count: usize,
}

impl KernelIntegrator {
/// Starts a new compilation.
pub fn new(info: KernelExpansion) -> Self {
Self {
expansion: info,
buffer_bindings: Default::default(),
scalar_bindings: Default::default(),
tensor_maps: Default::default(),
}
Self { expansion: info }
}

/// Performs the compilation with the provided [settings](KernelSettings).
#[cfg_attr(feature = "tracing", tracing::instrument(level = "trace", skip(self)))]
pub fn integrate(mut self, settings: KernelSettings) -> KernelDefinition {
self.register_buffers();
self.register_scalars();
self.register_tensor_maps();

self.scalar_bindings.sort_by_key(|binding| binding.ty);

pub fn integrate(self, settings: KernelSettings) -> KernelDefinition {
KernelDefinition {
buffers: self.buffer_bindings,
tensor_maps: self.tensor_maps,
scalars: self.scalar_bindings,
cube_dim: settings.cube_dim,
body: self.expansion.scope,
options: settings.options,
}
}

fn register_buffers(&mut self) {
for buffer in self.expansion.buffers.drain(..) {
self.buffer_bindings.push(KernelArg {
id: buffer.id,
value: buffer.value,
has_extended_meta: buffer.has_extended_meta,
});
}
}

fn register_scalars(&mut self) {
for scalar in self.expansion.scalars.drain(..) {
self.scalar_bindings.push(ScalarKernelArg {
ty: scalar.ty,
count: scalar.count,
});
}
}

fn register_tensor_maps(&mut self) {
for buffer in self.expansion.tensor_maps.drain(..) {
self.tensor_maps.push(KernelArg {
id: buffer.id,
value: buffer.value,
has_extended_meta: buffer.has_extended_meta,
});
info: self.expansion.info,
settings,
}
}
}
Loading