From 416d9fbfb6bfd22fe26a3ecffa8b119709d87d13 Mon Sep 17 00:00:00 2001 From: "Yaxun (Sam) Liu" Date: Thu, 22 Apr 2021 14:04:19 -0400 Subject: [PATCH] SWDEV-283048 - Fix hipTestFMA This test is incorrect about _Float16 overloading. Need to keep the test passing for both old and new compiler until the compiler change is in mainline. Change-Id: I2f9be8957282fd0579c74f1e9f23e65c4484f3a2 [ROCm/hip commit: 6eabbc83f7ace17c67855f92ea3e434934c4baff] --- .../hip/tests/src/deviceLib/hipTestFMA.cpp | 49 +++++++++++++++---- 1 file changed, 39 insertions(+), 10 deletions(-) diff --git a/projects/hip/tests/src/deviceLib/hipTestFMA.cpp b/projects/hip/tests/src/deviceLib/hipTestFMA.cpp index e18712d966..74bfd1b2c3 100644 --- a/projects/hip/tests/src/deviceLib/hipTestFMA.cpp +++ b/projects/hip/tests/src/deviceLib/hipTestFMA.cpp @@ -120,16 +120,45 @@ THE SOFTWARE. Check(halfResult != doubleResult); // check promote to half. - Check(fma(h, h, 3) == halfResult); - Check(fma(h, h, (char)3) == halfResult); - Check(fma(h, h, (unsigned char)3) == halfResult); - Check(fma(h, h, (short)3) == halfResult); - Check(fma(h, h, (unsigned short)3) == halfResult); - Check(fma(h, h, (int)3) == halfResult); - Check(fma(h, h, (unsigned int)3) == halfResult); - Check(fma(h, h, (long)3) == halfResult); - Check(fma(h, h, (unsigned long)3) == halfResult); - Check(fma(h, h, true) == fma(h, h, (_Float16)1)); + // fma(_Float16, _Float16, int) should resolve to + // fma(double, double, double). This is similar to + // fma(float, float, int) resolving to fma(double, double, double) + // as required Standard C++ header . + if (sizeof(decltype(fma(h, h, 3))) == 8) { + Check(fma(h, h, 3) == doubleResult); + Check(fma(h, h, (char)3) == doubleResult); + Check(fma(h, h, (unsigned char)3) == doubleResult); + Check(fma(h, h, (short)3) == doubleResult); + Check(fma(h, h, (unsigned short)3) == doubleResult); + Check(fma(h, h, (int)3) == doubleResult); + Check(fma(h, h, (unsigned int)3) == doubleResult); + Check(fma(h, h, (long)3) == doubleResult); + Check(fma(h, h, (unsigned long)3) == doubleResult); + Check(fma(h, h, true) == fma((double)h, (double) h, 1.0)); + } else if (sizeof(decltype(fma(h, h, 3))) == 2) { + // ToDo: Currently there is a bug in clang header + // __clang_hip_cmath.h due to using + // std::numeric_limits::is_specified to define + // overloaded math functions. Since numeric_limits is + // not specicialized for _Float16, overloaded template + // functions with argument promotion are not defined + // for _Float16. As a result, fma(_Float16, _Float16, int) + // is resolved to fma(_Float16, _Float16, _Float16). + // This part should be removed after __clang_hip_cmath.h + // is fixed. + Check(fma(h, h, 3) == halfResult); + Check(fma(h, h, (char)3) == halfResult); + Check(fma(h, h, (unsigned char)3) == halfResult); + Check(fma(h, h, (short)3) == halfResult); + Check(fma(h, h, (unsigned short)3) == halfResult); + Check(fma(h, h, (int)3) == halfResult); + Check(fma(h, h, (unsigned int)3) == halfResult); + Check(fma(h, h, (long)3) == halfResult); + Check(fma(h, h, (unsigned long)3) == halfResult); + Check(fma(h, h, true) == fma(h, h, (_Float16)1)); + } else { + assert(0 && "Invalid fma return type."); + } while (i < LEN) Check(true);