Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
d7b1fc5
build2cmake: merge `write_cmake` functions in `common`
danieldk Feb 2, 2026
26f5da4
build2cmake: merge all `write_torch_ext` implementations in `common`
danieldk Feb 2, 2026
aa8e735
Remove backend from metadata handling
danieldk Feb 2, 2026
a852694
build2cmake: add backend Python dependencies to `pyproject.toml`
danieldk Feb 2, 2026
a40354c
build2cmake: noarch backend-independent dependency generation
danieldk Feb 2, 2026
f00326d
Accommodate build2cmake changes
danieldk Feb 2, 2026
ca767be
build2cmake: add project section to pyproject.toml
danieldk Feb 3, 2026
c5b67ea
Fix XPU build
danieldk Feb 3, 2026
b0ec88d
Merge branch 'fix-xpu' into remove-backend
danieldk Feb 3, 2026
923251f
build2cmake: construct build variant string on all platforms
danieldk Feb 3, 2026
094b622
Try to fix Windows Python build while also keeping XPU fixed
danieldk Feb 3, 2026
c2b1fe8
CI: build XPU cutlass-gemm kernel
danieldk Feb 3, 2026
d3536cf
Merge branch 'fix-xpu' into remove-backend
danieldk Feb 3, 2026
67b2417
Use CMake install-generated build variants in Nix
danieldk Feb 3, 2026
1332548
Use correct directory name when a kernel contains a dash
danieldk Feb 3, 2026
cae7a7f
Correctly install Python files in subdirectories
danieldk Feb 4, 2026
bfc6283
Clear PYTHONPATH in test shells
danieldk Feb 4, 2026
58ac63b
Let CMake write the compat module
danieldk Feb 4, 2026
ed85f10
Merge remote-tracking branch 'origin/main' into remove-backend
danieldk Feb 5, 2026
b03fc22
Clippy fixes
danieldk Feb 5, 2026
13c4af4
Adjust test builder test to use variant directories
danieldk Feb 5, 2026
a99cc41
Support extra data files
danieldk Feb 5, 2026
49ee206
Merge remote-tracking branch 'origin/main' into remove-backend
danieldk Feb 5, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .github/workflows/build_kernel.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,17 @@ jobs:
USER: runner
- name: Nix info
run: nix-shell -p nix-info --run "nix-info -m"

- name: Build relu kernel
run: ( cd builder/examples/relu && nix build .\#redistributable.torch29-cxx11-cu126-x86_64-linux )
- name: Copy relu kernel
run: cp -rL builder/examples/relu/result relu-kernel

- name: Build extra-data kernel
run: ( cd builder/examples/extra-data && nix build .\#redistributable.torch29-cxx11-cu126-x86_64-linux )
- name: Copy extra-data kernel
run: cp -rL builder/examples/extra-data/result extra-data

- name: Build relu kernel (CPU)
run: ( cd builder/examples/relu && nix build .\#redistributable.torch29-cxx11-cpu-x86_64-linux )
- name: Copy relu kernel (CPU)
Expand Down Expand Up @@ -70,6 +76,7 @@ jobs:
path: |
activation-kernel
cutlass-gemm-kernel
extra-data
relu-kernel
relu-kernel-cpu
relu-backprop-compile-kernel
Expand Down
26 changes: 17 additions & 9 deletions build2cmake/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ impl Build {
pub fn is_noarch(&self) -> bool {
self.kernels.is_empty()
}

pub fn supports_backend(&self, backend: &Backend) -> bool {
self.general.backends.contains(backend)
}
}

pub struct General {
Expand Down Expand Up @@ -126,18 +122,18 @@ pub struct Torch {
}

impl Torch {
pub fn data_globs(&self) -> Option<Vec<String>> {
pub fn data_extensions(&self) -> Option<Vec<String>> {
match self.pyext.as_ref() {
Some(exts) => {
let globs = exts
let extensions = exts
.iter()
.filter(|&ext| ext != "py" && ext != "pyi")
.map(|ext| format!("\"**/*.{ext}\""))
.cloned()
.collect_vec();
if globs.is_empty() {
if extensions.is_empty() {
None
} else {
Some(globs)
Some(extensions)
}
}

Expand Down Expand Up @@ -247,6 +243,18 @@ pub enum Backend {
Xpu,
}

impl Backend {
pub const fn all() -> [Backend; 5] {
[
Backend::Cpu,
Backend::Cuda,
Backend::Metal,
Backend::Rocm,
Backend::Xpu,
]
}
}

impl Display for Backend {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Expand Down
58 changes: 10 additions & 48 deletions build2cmake/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ mod torch;
use torch::{write_torch_ext, write_torch_ext_noarch};

mod config;
use config::{v3, Backend, Build, BuildCompat};
use config::{v3, Build, BuildCompat};

mod fileset;
use fileset::FileSet;
Expand Down Expand Up @@ -48,9 +48,6 @@ enum Commands {
/// kernel name to avoid name collisions. (e.g. Git SHA)
#[arg(long)]
ops_id: Option<String>,

#[arg(long)]
backend: Option<Backend>,
},

/// Update a `build.toml` to the current format.
Expand Down Expand Up @@ -93,12 +90,11 @@ fn main() -> Result<()> {
let args = Cli::parse();
match args.command {
Commands::GenerateTorch {
backend,
build_toml,
force,
target_dir,
ops_id,
} => generate_torch(backend, build_toml, target_dir, force, ops_id),
} => generate_torch(build_toml, target_dir, force, ops_id),
Commands::UpdateBuild { build_toml } => update_build(build_toml),
Commands::Validate { build_toml } => {
parse_and_validate(build_toml)?;
Expand All @@ -115,7 +111,6 @@ fn main() -> Result<()> {
}

fn generate_torch(
backend: Option<Backend>,
build_toml: PathBuf,
target_dir: Option<PathBuf>,
force: bool,
Expand All @@ -139,41 +134,10 @@ fn generate_torch(
env.set_trim_blocks(true);
minijinja_embed::load_templates!(&mut env);

let backend = match backend {
Some(backend) => {
if !build.supports_backend(&backend) {
bail!("Kernel does not support backend: {}", backend);
}

backend
}
None => {
let kernel_backends = &build.general.backends;

if kernel_backends.len() > 1 {
let mut kernel_backends = kernel_backends
.iter()
.map(ToString::to_string)
.collect::<Vec<_>>();
kernel_backends.sort();
bail!(
"Multiple supported backends found in build.toml: {}. Please specify one with --backend.",
kernel_backends.join(", ")
);
}

if let Some(backend) = kernel_backends.first() {
*backend
} else {
bail!("No backends are specified in build.toml");
}
}
};

let file_set = if build.is_noarch() {
write_torch_ext_noarch(&env, backend, &build, target_dir.clone(), ops_id)?
write_torch_ext_noarch(&env, &build, target_dir.clone(), ops_id)?
} else {
write_torch_ext(&env, backend, &build, target_dir.clone(), ops_id)?
write_torch_ext(&env, &build, target_dir.clone(), ops_id)?
};
file_set.write(&target_dir, force)?;

Expand Down Expand Up @@ -368,14 +332,12 @@ fn get_generated_files(
) -> Result<Vec<PathBuf>> {
let mut all_set = FileSet::new();

for backend in &build.general.backends {
let set = if build.is_noarch() {
write_torch_ext_noarch(env, *backend, build, target_dir.clone(), ops_id.clone())?
} else {
write_torch_ext(env, *backend, build, target_dir.clone(), ops_id.clone())?
};
all_set.extend(set);
}
let set = if build.is_noarch() {
write_torch_ext_noarch(env, build, target_dir.clone(), ops_id.clone())?
} else {
write_torch_ext(env, build, target_dir.clone(), ops_id.clone())?
};
all_set.extend(set);

Ok(all_set.into_names())
}
Expand Down
Loading
Loading