-
Notifications
You must be signed in to change notification settings - Fork 119
Add support for hypot and reciprocal hypot. #1048
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
base: main
Are you sure you want to change the base?
Conversation
fb904f3 to
2d49684
Compare
Removing conditional branches when possible.
|
Ready for review, to avoid underflow/overflow the following algorithms are:
|
nathanielsimard
left a comment
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 think it would be better to have a cubecl function for that instruction instead of re-implementing it for every compilers. Note that I'm not against having specialized implementation for a compiler, but we can use a cubecl function as default. Here's an example:
/// Returns the value at `index` in tensor within bounds.
#[cube]
pub fn read_tensor_checked<C: CubePrimitive>(
tensor: Tensor<C>,
index: u32,
#[comptime] unroll_factor: u32,
) -> C {
let len = tensor.buffer_len() * unroll_factor;
let in_bounds = index < len;
let index = Min::min(index, len);
select(in_bounds, tensor.read_unchecked(index), C::cast_from(0u32))
}Called as follow by compilers:
read_tensor_checked::expand::<Line<NumericExpand<0>>>(
&mut scope,
list.into(),
index.into(),
op.unroll_factor,
)
.expand|
The problem is that for CUDA that has built-in instructions you really want to call hypotf and rhypotf. |
You can use that instruction for cuda and fallback on the default implementation for other compilers. other compiler can expand the cubecl function instead of recreating it with their own IR. |
|
I think it could be reviewed. |
Validate your PR with burn.
It is important that you make sure that you don't introduce any bugs in burn.
Instructions