-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tuple expression in cube derive macro (#49)
- Loading branch information
1 parent
32feabc
commit cbbf866
Showing
6 changed files
with
110 additions
and
5 deletions.
There are no files selected for viewing
This file contains 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 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 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 |
---|---|---|
|
@@ -20,4 +20,6 @@ mod r#struct; | |
mod tensor; | ||
mod topology; | ||
mod r#trait; | ||
|
||
mod tuple; | ||
mod vectorization; |
This file contains 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,43 @@ | ||
use cubecl_core as cubecl; | ||
use cubecl_core::prelude::*; | ||
|
||
#[cube] | ||
pub fn tuple_const() -> (UInt, UInt) { | ||
let x = UInt::new(0); | ||
let y = UInt::new(1); | ||
(x, y) | ||
} | ||
|
||
mod tests { | ||
use super::*; | ||
use cubecl_core::{ | ||
cpa, | ||
ir::{Elem, Item, Operation, Variable}, | ||
}; | ||
|
||
#[test] | ||
fn cube_tuple_const_test() { | ||
let mut context = CubeContext::root(); | ||
|
||
tuple_const::__expand(&mut context); | ||
let scope = context.into_scope(); | ||
|
||
assert_eq!(scope.operations, inline_macro_ref_tuple_const()); | ||
} | ||
|
||
fn inline_macro_ref_tuple_const() -> Vec<Operation> { | ||
let context = CubeContext::root(); | ||
|
||
let mut scope = context.into_scope(); | ||
let x = scope.create_local(Item::new(Elem::UInt)); | ||
let y = scope.create_local(Item::new(Elem::UInt)); | ||
|
||
let zero: Variable = 0u32.into(); | ||
let one: Variable = 1u32.into(); | ||
|
||
cpa!(scope, x = zero); | ||
cpa!(scope, y = one); | ||
|
||
scope.operations | ||
} | ||
} |
This file contains 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 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 |
---|---|---|
|
@@ -199,7 +199,6 @@ fn codegen_cube( | |
#signature { | ||
#body | ||
} | ||
|
||
} | ||
}) | ||
} |