Skip to content

Commit cda6680

Browse files
authored
[SYCL][ESIMD] Fix an issue with tanh function implementation (#7265)
1 parent ef792c6 commit cda6680

File tree

1 file changed

+3
-5
lines changed
  • sycl/include/sycl/ext/intel/experimental/esimd

1 file changed

+3
-5
lines changed

sycl/include/sycl/ext/intel/experimental/esimd/math.hpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1574,7 +1574,6 @@ tanh_cody_waite_impl(__ESIMD_NS::simd<float, N> x) {
15741574
constexpr float xsmall = 4.22863966691620432990E-04f;
15751575
constexpr float xmedium = 0.54930614433405484570f;
15761576
constexpr float xlarge = 8.66433975699931636772f;
1577-
constexpr float log2E = 1.442695f; // same as esimd::log(e)
15781577

15791578
using RT = __ESIMD_NS::simd<float, N>;
15801579

@@ -1591,7 +1590,7 @@ tanh_cody_waite_impl(__ESIMD_NS::simd<float, N> x) {
15911590

15921591
RT res;
15931592
res.merge(sign, x, isLarge);
1594-
auto temp = __ESIMD_NS::exp(absX * 2.0f * log2E) + 1.f;
1593+
auto temp = __ESIMD_NS::exp(absX * 2.0f) + 1.f;
15951594
temp = ((temp - 2.f) / temp) * sign;
15961595
res.merge(temp, isGtMed);
15971596
res.merge((absX + absX * g * (g * p1 + p0) / (g + q0)) * sign, isGtSmall);
@@ -1609,8 +1608,7 @@ tanh_impl(__ESIMD_NS::simd<float, N> x) {
16091608
*/
16101609

16111610
constexpr float xsmall = 0.000045f; // same as exp(-10.0f)
1612-
constexpr float xlarge = 88.f;
1613-
constexpr float log2E = 1.442695f; // same as esimd::log(e)
1611+
constexpr float xlarge = 40.f;
16141612

16151613
using RT = __ESIMD_NS::simd<float, N>;
16161614

@@ -1626,7 +1624,7 @@ tanh_impl(__ESIMD_NS::simd<float, N> x) {
16261624
res.merge(sign, x, isLarge);
16271625

16281626
RT exp;
1629-
exp = __ESIMD_NS::exp(absX * 2.f * log2E);
1627+
exp = __ESIMD_NS::exp(absX * 2.f);
16301628

16311629
res.merge(((exp - 1.f) / (exp + 1.f)) * sign, (absX > xsmall) & isLessE);
16321630

0 commit comments

Comments
 (0)