Skip to content

Commit 34748e0

Browse files
authored
[SYCL] Add tanh in BF16 math (#20883)
We received request for tanh in bfloat16 math functions. This PR adds it for SPIRV targets using fp32 emulation and update extension doc. --------- Signed-off-by: jinge90 <[email protected]>
1 parent 3e1779b commit 34748e0

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

sycl/doc/extensions/experimental/sycl_ext_oneapi_bfloat16_math_functions.asciidoc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,14 @@ specification.
5757

5858
This extension adds `bfloat16` support to the `fma`, `fmin`, `fmax`, `fabs`,
5959
`isnan`, `ceil`, `floor`, `cos`, `sin`, `exp`, `exp2`, `exp10`, `log`, `log2`,
60-
`log10`, `rint`, `sqrt`, `rsqrt` and `trunc` SYCL floating point math functions.
61-
These functions can be used as element wise operations on matrices, supplementing
62-
the `bfloat16` support in the sycl_ext_oneapi_matrix extension.
60+
`log10`, `rint`, `sqrt`, `rsqrt`, `trunc` and `tanh` SYCL floating point math
61+
functions. These functions can be used as element wise operations on matrices,
62+
supplementing the `bfloat16` support in the sycl_ext_oneapi_matrix extension.
6363

6464
The descriptions of the `fma`, `fmin`, `fmax`, `fabs`, `isnan`, `ceil`, `floor`,
6565
`cos`, `sin`, `exp`, `exp2`, `exp10`, `log`, `log2`, `log10`, `rint`, `sqrt`,
66-
`rsqrt` and `trunc` SYCL floating point math functions can be found in the SYCL
67-
specification:
66+
`rsqrt`, `trunc` and `tanh` SYCL floating point math functions can be found in
67+
the SYCL specification:
6868
https://www.khronos.org/registry/SYCL/specs/sycl-2020/html/sycl-2020.html#_math_functions.
6969

7070
[NOTE]

sycl/include/sycl/ext/oneapi/experimental/bfloat16_math.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,10 @@ BFLOAT16_MATH_FP32_WRAPPERS(trunc)
476476
BFLOAT16_MATH_FP32_WRAPPERS_MARRAY(trunc)
477477
BFLOAT16_MATH_FP32_WRAPPERS_VEC(trunc)
478478

479+
BFLOAT16_MATH_FP32_WRAPPERS(tanh)
480+
BFLOAT16_MATH_FP32_WRAPPERS_MARRAY(tanh)
481+
BFLOAT16_MATH_FP32_WRAPPERS_VEC(tanh)
482+
479483
#undef BFLOAT16_MATH_FP32_WRAPPERS
480484
#undef BFLOAT16_MATH_FP32_WRAPPERS_MARRAY
481485
#undef BFLOAT16_MATH_FP32_WRAPPERS_VEC

sycl/test-e2e/BFloat16/bfloat16_builtins.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ void test() {
187187
TEST(exp10, 1);
188188
TEST(exp2, 1);
189189
TEST(rint, 1);
190+
TEST(tanh, 1);
190191

191192
// log, log2, log10, sqrt, rsqrt testing, the input
192193
// must be positive.

0 commit comments

Comments
 (0)