-
Notifications
You must be signed in to change notification settings - Fork 481
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
CubeCL first iteration #1756
CubeCL first iteration #1756
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1756 +/- ##
==========================================
- Coverage 86.61% 86.41% -0.21%
==========================================
Files 700 734 +34
Lines 83423 85575 +2152
==========================================
+ Hits 72258 73947 +1689
- Misses 11165 11628 +463 ☔ View full report in Codecov by Sentry. |
/// Derive macro for the module. | ||
#[proc_macro_attribute] | ||
pub fn cube(attr: TokenStream, tokens: TokenStream) -> TokenStream { | ||
let args = parse_macro_input!(attr with Punctuated::<Meta, syn::Token![,]>::parse_terminated); |
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.
What is that 😮
|
||
pub struct CubeContext { | ||
pub root: Rc<RefCell<Scope>>, | ||
pub scope: Rc<RefCell<Scope>>, |
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.
Do we need to put the scope in a cell (Rc) if yes where do we clone it?
#[derive(new, Clone, Debug)] | ||
/// Reference to a JIT variable | ||
/// It's the expand element that is actually kept in the variable pool | ||
pub struct ExpandElement { |
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.
I don't like the name, maybe CubeVariable would be better?
crates/burn-cube/src/element/int.rs
Outdated
+ std::cmp::PartialOrd | ||
+ std::ops::Add<Output = Self> | ||
+ std::ops::Sub<Output = Self> | ||
+ std::ops::Mul<Output = Self> | ||
+ std::ops::Div<Output = Self> | ||
+ std::ops::AddAssign | ||
+ std::ops::Rem<Output = Self> |
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.
Could all of those be moved to the Numeric
trait ?
pub trait RuntimeType: CubeType<ExpandType = ExpandElement> { | ||
type Primitive; | ||
fn val(&self) -> Self::Primitive; | ||
fn into_elem() -> Elem; | ||
fn from_expand(context: &mut CubeContext, val: ExpandElement) -> ExpandElement { | ||
let new_var = context.create_local(Item::Scalar(<Self as RuntimeType>::into_elem())); | ||
assign::expand(context, val, new_var.clone()); | ||
new_var | ||
} | ||
} |
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.
We should add documentation on that trait, since it's so central.
Part of #1665
Since the goal of CubeCL is to rewrite all our JIT kernels with a readable rusty syntax, I started by supporting all the basic syntax to parse it into to the JIT intermediate representation, and figured out an enjoyable type system for element types, with support for easy casting. To look at examples, navigate to
crates/burn-cube/tests
where kernels marked with#[cube]
are tested against theirgpu!
macro counterparts.Next steps: