-
Notifications
You must be signed in to change notification settings - Fork 25
feat: enable compilation without requiring a GPU #30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
572147b
feat: enable compilation without requiring a GPU
drbh 3a339bf
fix: adjust names
drbh ad6d185
feat: add shared interface crate
drbh ff3687e
fix: improve examples deps
drbh 9e98070
fix: update var name entry_functions to kernel_launchers
drbh c614a91
feat: update flake to run compile only example on osx
drbh 5c71edd
Merge branch 'main' into support-gpuless-compilation
elibol d039c6d
Merge branch 'main' into support-gpuless-compilation
elibol 5b9b030
fix: move validators into core and feature flag bindings
drbh 7046c41
feat: avoid compile only and prefer feature flag driver
drbh df78f6f
fix: move candle dependency into examples crate
drbh 5e21365
fix: bump version
drbh cb0a47a
Merge branch 'main' into support-gpuless-compilation
drbh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,7 @@ | |
| target | ||
|
|
||
| **/*.bc | ||
| **/*.mlir | ||
| **/*.cubin | ||
| **/core | ||
| scratch | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| /* | ||
| * SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| //! Shared kernel interface metadata used at the compiler/runtime boundary. | ||
|
|
||
| #[derive(Debug, Clone)] | ||
| pub enum ValidParamType { | ||
| Scalar(ScalarParamType), | ||
| Pointer(PointerParamType), | ||
| Tensor(TensorParamType), | ||
| } | ||
|
|
||
| #[derive(Debug, Clone)] | ||
| pub struct ScalarParamType { | ||
| pub element_type: String, | ||
| } | ||
|
|
||
| #[derive(Debug, Clone)] | ||
| pub struct PointerParamType { | ||
| pub mutable: bool, | ||
| pub element_type: String, | ||
| } | ||
|
|
||
| #[derive(Debug, Clone)] | ||
| pub struct TensorParamType { | ||
| pub element_type: String, | ||
| pub shape: Vec<i32>, | ||
| } | ||
|
|
||
| #[derive(Debug, Clone)] | ||
| pub struct Validator { | ||
| pub params: Vec<ValidParamType>, | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| /* | ||
| * SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * | ||
| * Example: Compile to without requiring a GPU to run on | ||
|
elibol marked this conversation as resolved.
|
||
| * | ||
| * Run with: cargo run -p cutile-examples --example compile_only --no-default-features | ||
| */ | ||
|
|
||
| use cutile::cutile_compiler::compiler::{CUDATileFunctionCompiler, CUDATileModules}; | ||
| use cutile::cutile_compiler::cuda_tile_write_bytecode_to_buffer; | ||
| use std::env; | ||
| use std::slice; | ||
|
|
||
| // Build with --no-default-features to compile kernels without a GPU. | ||
| #[cutile::module] | ||
| mod my_kernels { | ||
| use cutile::core::*; | ||
|
|
||
| /// Simple kernel that does tile math without dynamic tensor inputs | ||
| #[cutile::entry()] | ||
|
elibol marked this conversation as resolved.
|
||
| fn tile_math<const S: [i32; 1]>(output: &mut Tensor<f32, S>, scalar: f32) { | ||
| // Get block ID and create tiles | ||
| let _pid = get_tile_block_id().0; | ||
| let scalar_tile: Tile<f32, S> = broadcast_scalar(scalar, output.shape()); | ||
| let ones: Tile<f32, S> = broadcast_scalar(1.0f32, output.shape()); | ||
|
|
||
| // Simple computation | ||
| let result = scalar_tile + ones; | ||
| output.store(result); | ||
| } | ||
| } | ||
|
|
||
| fn main() { | ||
| // Default to sm_90 (Hopper) if not specified | ||
| let gpu_name = env::args().nth(1).unwrap_or_else(|| "sm_90".to_string()); | ||
| println!("Target GPU: {}", gpu_name); | ||
|
|
||
| // Get the module ASTs from the generated code | ||
| let module_asts = my_kernels::_module_asts(); | ||
|
|
||
| // Create the modules container | ||
| let modules = match CUDATileModules::new(module_asts) { | ||
| Ok(m) => m, | ||
| Err(e) => { | ||
| eprintln!("Failed to create modules: {:?}", e); | ||
| return; | ||
| } | ||
| }; | ||
|
|
||
| // Compile with specific generic args (tile size = 32) | ||
| let module_name = "my_kernels"; | ||
| let function_name = "tile_math"; | ||
| let function_generics = vec!["32".to_string()]; | ||
| // Stride args for the output tensor (1D tensor with stride 1) | ||
| let output_strides: [i32; 1] = [1]; | ||
| let stride_args: Vec<(&str, &[i32])> = vec![("output", &output_strides)]; | ||
| let const_grid: Option<(u32, u32, u32)> = None; | ||
|
|
||
| println!("Compiling {module_name}::{function_name}"); | ||
|
|
||
| let compiler = match CUDATileFunctionCompiler::new( | ||
| &modules, | ||
| module_name, | ||
| function_name, | ||
| &function_generics, | ||
| &stride_args, | ||
| const_grid, | ||
| gpu_name.clone(), | ||
| ) { | ||
| Ok(c) => c, | ||
| Err(e) => { | ||
| eprintln!("Failed to create compiler: {:?}", e); | ||
| return; | ||
| } | ||
| }; | ||
|
|
||
| let module_op = match compiler.compile() { | ||
| Ok(m) => m, | ||
| Err(e) => { | ||
| eprintln!("Compilation failed: {:?}", e); | ||
| return; | ||
| } | ||
| }; | ||
|
|
||
| // Print human readable MLIR IR | ||
| let mlir_string = module_op.as_operation().to_string(); | ||
| println!("Generated MLIR IR:\n"); | ||
| println!("{}", mlir_string); | ||
|
|
||
| // Get compiled bytecode | ||
| let bytecode = cuda_tile_write_bytecode_to_buffer(&module_op); | ||
| let raw = bytecode.to_raw(); | ||
| let bytes: &[u8] = unsafe { slice::from_raw_parts(raw.data as *const u8, raw.length) }; | ||
|
|
||
| println!("\nCompiled bytecode: {} bytes", bytes.len()); | ||
| println!( | ||
| "First 32 bytes (hex): {:02x?}", | ||
| &bytes[..bytes.len().min(32)] | ||
| ); | ||
|
|
||
| // Write MLIR and bytecode to files | ||
| std::fs::write("output.mlir", mlir_string).unwrap(); | ||
| std::fs::write("output.bc", bytes).unwrap(); | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The main thing we need here is to preserve the generality of
cuda-async.cutile-compileris tile-specific, whereascuda-asyncshould be usable by both tile and custom CUDA kernels written outside of tile. At least that is the intent :)Perhaps the intent behind your changes here are that the validator bit is closer from a concerns point-of-view to the compiler? I am okay with moving the validator stuff to the compiler, but we ought to avoid having
cuda-asyncdepend oncutile-compiler.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
very good points, I'm going to rework the changes to remove this dependency.
yea the original intent was to avoid depending on
cuda-asyncinside ofcutile-compilersince thecutile-compileronly seemed to need the validator structs fromcuda-asyncwill push updates shortly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One option is to move the validator code to
cuda-core. I haven't thought through the gpu-dependence implications of this (there are a lot of moving parts right now), but I think it should work as a solution which provides visibility of the validator code to bothcuda-asyncandcutile-compiler.The dependence graph should look something like this (I'll add it to the README):
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
okay i've opt'd to move the type validation structs into their own crate and now the deps are
and when
--no-default-featuresis added(namely the examples do not depend on either core or async in this case)
ps the helper used to dump the dep tree is