Skip to main content

cubecl_cpp/hip/
unary.rs

1use cubecl_core::{
2    self as cubecl,
3    ir::{dialect::math::TanhOp, prelude::*},
4    prelude::*,
5};
6
7use crate::{shared::ty::TypedExtCPP, shared::unary::lower_target_unop, target::Hip};
8
9// HIP's fp16 headers don't provide `htanh`/`h2tanh` like CUDA does, so half precision `tanh` has
10// to be computed in f32.
11lower_target_unop!(TanhOp, tanh_via_f32, Hip, |op, ctx| op
12    .get_result(ctx)
13    .is_half(ctx));
14
15#[cube]
16fn tanh_via_f32<T: Float, N: Size>(input: Vector<T, N>) -> Vector<T, N> {
17    Vector::cast_from(Vector::<f32, N>::cast_from(input).tanh())
18}