-
Notifications
You must be signed in to change notification settings - Fork 221
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
feat: provide a f32x16 abstraction to make unrolling 256-bit code easier #1495
Conversation
Also update
|
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 cool
@@ -249,4 +498,23 @@ mod tests { | |||
format!("{:?}", simd_power) | |||
); | |||
} | |||
|
|||
#[test] | |||
fn test_basic_f32x16_ops() { |
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.
It's probably tedious but given how technical these methods are, it might be a good idea to add tests for all the methods (e.g. add, add assign, sub, etc.)
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.
sure i can add some
let dim = self.len(); | ||
if dim % 16 == 0 { | ||
let mut sum = f32x16::zeros(); | ||
for i in (0..dim).step_by(16) { | ||
let x = unsafe { f32x16::load_unaligned(self.as_ptr().add(i)) }; | ||
sum += x * x; | ||
} | ||
sum.reduce_sum().sqrt() | ||
} else if dim % 8 == 0 { | ||
let mut sum = f32x8::zeros(); | ||
for i in (0..dim).step_by(8) { | ||
let x = unsafe { f32x8::load_unaligned(self.as_ptr().add(i)) }; | ||
sum += x * x; | ||
} | ||
sum.reduce_sum().sqrt() | ||
} else { | ||
// Fallback to scalar | ||
return self.iter().map(|v| v * v).sum::<f32>().sqrt(); |
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 like how readable this is (well, readable for SIMD :)
x2 -= y2; | ||
sum1.multiply_add(x1, x1); | ||
sum2.multiply_add(x2, x2); | ||
let mut x = f32x16::load_unaligned(self.as_ptr().add(i)); |
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 want to unroll more than twice?
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.
Yea we can add it later? did not see improvement last time on my CPU tho.
No description provided.