-
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.
- Loading branch information
1 parent
16a79fc
commit 447968e
Showing
21 changed files
with
505 additions
and
258 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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
mod sequence; | ||
|
||
pub use sequence::*; |
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
107 changes: 107 additions & 0 deletions
107
crates/cubecl-core/src/frontend/container/sequence/launch.rs
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,107 @@ | ||
use std::{cell::RefCell, rc::Rc}; | ||
|
||
use crate::{ | ||
compute::KernelBuilder, | ||
prelude::{ArgSettings, LaunchArg, LaunchArgExpand}, | ||
Runtime, | ||
}; | ||
|
||
use super::{Sequence, SequenceExpand}; | ||
|
||
pub struct SequenceArg<'a, R: Runtime, T: LaunchArg> { | ||
values: Vec<T::RuntimeArg<'a, R>>, | ||
} | ||
|
||
impl<'a, R: Runtime, T: LaunchArg> Default for SequenceArg<'a, R, T> { | ||
fn default() -> Self { | ||
Self::new() | ||
} | ||
} | ||
|
||
impl<'a, R: Runtime, T: LaunchArg> SequenceArg<'a, R, T> { | ||
pub fn new() -> Self { | ||
Self { values: Vec::new() } | ||
} | ||
pub fn push(&mut self, arg: T::RuntimeArg<'a, R>) { | ||
self.values.push(arg); | ||
} | ||
} | ||
|
||
pub struct SequenceCompilationArg<C: LaunchArg> { | ||
values: Vec<C::CompilationArg>, | ||
} | ||
|
||
impl<C: LaunchArg> Clone for SequenceCompilationArg<C> { | ||
fn clone(&self) -> Self { | ||
Self { | ||
values: self.values.clone(), | ||
} | ||
} | ||
} | ||
|
||
impl<C: LaunchArg> core::hash::Hash for SequenceCompilationArg<C> { | ||
fn hash<H: std::hash::Hasher>(&self, state: &mut H) { | ||
self.values.hash(state) | ||
} | ||
} | ||
|
||
impl<C: LaunchArg> core::cmp::PartialEq for SequenceCompilationArg<C> { | ||
fn eq(&self, other: &Self) -> bool { | ||
self.values.eq(&other.values) | ||
} | ||
} | ||
|
||
impl<C: LaunchArg> core::fmt::Debug for SequenceCompilationArg<C> { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
f.write_fmt(format_args!("SequenceCompilationArg {:?}", self.values)) | ||
} | ||
} | ||
impl<C: LaunchArg> core::cmp::Eq for SequenceCompilationArg<C> {} | ||
|
||
impl<C: LaunchArg> LaunchArg for Sequence<C> { | ||
type RuntimeArg<'a, R: Runtime> = SequenceArg<'a, R, C>; | ||
|
||
fn compilation_arg<R: Runtime>(runtime_arg: &Self::RuntimeArg<'_, R>) -> Self::CompilationArg { | ||
SequenceCompilationArg { | ||
values: runtime_arg | ||
.values | ||
.iter() | ||
.map(|value| C::compilation_arg(value)) | ||
.collect(), | ||
} | ||
} | ||
} | ||
|
||
impl<'a, R: Runtime, T: LaunchArg> ArgSettings<R> for SequenceArg<'a, R, T> { | ||
fn register(&self, launcher: &mut crate::prelude::KernelLauncher<R>) { | ||
self.values.iter().for_each(|arg| arg.register(launcher)); | ||
} | ||
} | ||
|
||
impl<C: LaunchArg> LaunchArgExpand for Sequence<C> { | ||
type CompilationArg = SequenceCompilationArg<C>; | ||
|
||
fn expand(arg: &Self::CompilationArg, builder: &mut KernelBuilder) -> SequenceExpand<C> { | ||
let values = arg | ||
.values | ||
.iter() | ||
.map(|value| C::expand(value, builder)) | ||
.collect::<Vec<_>>(); | ||
|
||
SequenceExpand { | ||
values: Rc::new(RefCell::new(values)), | ||
} | ||
} | ||
|
||
fn expand_output(arg: &Self::CompilationArg, builder: &mut KernelBuilder) -> SequenceExpand<C> { | ||
let values = arg | ||
.values | ||
.iter() | ||
.map(|value| C::expand_output(value, builder)) | ||
.collect::<Vec<_>>(); | ||
|
||
SequenceExpand { | ||
values: Rc::new(RefCell::new(values)), | ||
} | ||
} | ||
} |
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,5 @@ | ||
mod base; | ||
mod launch; | ||
|
||
pub use base::*; | ||
pub use launch::*; |
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
Oops, something went wrong.