-
Notifications
You must be signed in to change notification settings - Fork 37
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
Simplify allocator #388
base: main
Are you sure you want to change the base?
Simplify allocator #388
Conversation
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'm not sure if the frontend tests are necessary anymore. They are impacted by the new allocator and I don't think it's worth updating them.
@@ -206,7 +206,7 @@ pub mod plane_any { | |||
elem: ExpandElementTyped<bool>, | |||
) -> ExpandElementTyped<bool> { | |||
let elem: ExpandElement = elem.into(); | |||
let output = context.create_local_binding(elem.item); | |||
let output = context.create_local_mut(elem.item); |
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.
Is it only for cuda? Does mutability work differently in wgsl?
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.
In fact, it is an issue with the planeAny implementation of cuda. I will fix it.
let array_len = scope.create_local_mut(Item::new(Elem::UInt(UIntKind::U32))); | ||
let inside_bound = scope.create_local_mut(Item::new(Elem::Bool)); | ||
let item = scope.create_local_mut(out.item); |
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.
Is mut necessary?
let array_len = scope.create_local_mut(Item::new(Elem::UInt(UIntKind::U32))); | ||
let inside_bound = scope.create_local_mut(Item::new(Elem::Bool)); |
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.
Is mut necessary?
@@ -67,7 +67,7 @@ impl Scope { | |||
|
|||
/// Create a variable initialized at zero. | |||
pub fn zero<I: Into<Item>>(&mut self, item: I) -> Variable { | |||
let local = self.create_local(item); | |||
let local = self.create_local_mut(item); |
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.
Is mut necessary?
@@ -88,7 +88,7 @@ impl Scope { | |||
Elem::AtomicUInt(kind) => ConstantScalarValue::UInt(value.to_u64().unwrap(), kind), | |||
Elem::Bool => ConstantScalarValue::Bool(value.to_u32().unwrap() == 1), | |||
}; | |||
let local = self.create_local(item); | |||
let local = self.create_local_mut(item); |
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.
Is mut necessary?
@@ -208,7 +208,7 @@ macro_rules! impl_line_comparison { | |||
let lhs = self.expand.into(); | |||
let rhs = rhs.expand.into(); | |||
|
|||
let output = context.create_local_binding(Item::vectorized(bool::as_elem(), size)); | |||
let output = context.create_local_mut(Item::vectorized(bool::as_elem(), size)); |
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 think this needs to be mut?
@@ -79,7 +79,7 @@ mod fill { | |||
value: ExpandElementTyped<P>, | |||
) -> Self { | |||
let length = self.expand.item.vectorization; | |||
let output = context.create_local_binding(Item::vectorized(P::as_elem(), length)); | |||
let output = context.create_local(Item::vectorized(P::as_elem(), length)); |
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.
Is mut required?
@@ -170,7 +170,7 @@ where | |||
F: Fn(UnaryOperator) -> Operator, | |||
{ | |||
let input = input.consume(); | |||
let output = context.create_local_binding(out_item); | |||
let output = context.create_local_mut(out_item); |
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.
Is mut required?
@@ -694,11 +694,12 @@ impl<D: Dialect> Remainder<D> { | |||
|
|||
write_op(&lhs, &rhs, &out_tmp, item_out_optimized)?; | |||
|
|||
let maybe_const = if out.is_const() { " cosnt" } else { "" }; |
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.
typo: cosnt
|
||
fn cast<D: Dialect>(input: &Variable<D>, target: Item<D>) -> String { | ||
if target != input.item() { | ||
let maybe_const = if input.is_const() { " const" } else { "" }; |
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 could have a method for that, it's repeated at multiple places.
// let mut file = std::fs::File::create("tests/plane_elect.wgsl").unwrap(); | ||
// write!(file, "{compiled}").unwrap(); |
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.
deadcode
// let mut file = std::fs::File::create("tests/sequence_for_loop.wgsl").unwrap(); | ||
// write!(file, "{compiled}").unwrap(); |
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.
deadcode
// let mut file = std::fs::File::create("tests/unary_bench.wgsl").unwrap(); | ||
// write!(file, "{compiled}").unwrap(); |
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.
deadcode
// let mut file = std::fs::File::create("tests/constant_array.wgsl").unwrap(); | ||
// write!(file, "{compiled}").unwrap(); |
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.
deadcode
// let mut file = std::fs::File::create("tests/naming.wgsl").unwrap(); | ||
// write!(file, "{compiled}").unwrap(); |
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.
deadcode
Highlights
Allocator refactor
VariableKind
to match the changes.Changing the backends
Variable
enum to matchcubecl-core
.depth
field toLocalVariable
.l_{depth}_{id}
.l_mut_{depth}_{id}
.Allocation strategy
Discovered bugs
With all the above changes, I discovered a few bugs in cubecl that I fixed.
fmt_left
in the cpp backend.Benchmarks
There are no statistically meaningful changes.
bench_cuda_main.txt
bench_cuda_new_alloc.txt
bench_wgpu_main.txt
bench_wgpu_new_alloc.txt