mirror of
https://github.com/KhronosGroup/OpenCL-CTS.git
synced 2026-03-19 06:09:01 +00:00
Fix 'fpclassify: ambiguous call' compile fail in MSVC 2022 (#2426)
Similar to #2219, we see "'fpclassify': ambiguous call" error in test_conformance\basic\test_fpmath.cpp due to missing constexpr at https://github.com/KhronosGroup/OpenCL-CTS/blob/9265cbb2c274/test_conformance/basic/test_fpmath.cpp#L104 This PR fixes the issue by moving utility function isnan_fp in testHarness.h and use it. Note this PR doesn't modify use of isnan in many tests where only float/double values are checked.
This commit is contained in:
@@ -14,7 +14,6 @@
|
||||
// limitations under the License.
|
||||
//
|
||||
#include <cmath>
|
||||
using std::isnan;
|
||||
#include "harness/compat.h"
|
||||
|
||||
#include <stdio.h>
|
||||
@@ -26,6 +25,7 @@ using std::isnan;
|
||||
|
||||
#include <CL/cl_half.h>
|
||||
#include "harness/conversions.h"
|
||||
#include "harness/mathHelpers.h"
|
||||
#include "harness/typeWrappers.h"
|
||||
|
||||
extern cl_half_rounding_mode halfRoundingMode;
|
||||
@@ -102,16 +102,6 @@ const char * kernel_explicit_s2v_set[NUM_VEC_TYPES][NUM_VEC_TYPES][5] = {
|
||||
|
||||
// clang-format on
|
||||
|
||||
bool IsHalfNaN(cl_half v)
|
||||
{
|
||||
// Extract FP16 exponent and mantissa
|
||||
uint16_t h_exp = (((cl_half)v) >> (CL_HALF_MANT_DIG - 1)) & 0x1F;
|
||||
uint16_t h_mant = ((cl_half)v) & 0x3FF;
|
||||
|
||||
// NaN test
|
||||
return (h_exp == 0x1F && h_mant != 0);
|
||||
}
|
||||
|
||||
static int test_explicit_s2v_function(cl_context context,
|
||||
cl_command_queue queue, cl_kernel kernel,
|
||||
ExplicitType srcType, unsigned int count,
|
||||
@@ -183,20 +173,21 @@ static int test_explicit_s2v_function(cl_context context,
|
||||
{
|
||||
bool isSrcNaN =
|
||||
(((srcType == kHalf)
|
||||
&& IsHalfNaN(*reinterpret_cast<cl_half *>(inPtr)))
|
||||
&& isnan_fp(*reinterpret_cast<cl_half *>(inPtr)))
|
||||
|| ((srcType == kFloat)
|
||||
&& isnan(*reinterpret_cast<cl_float *>(inPtr)))
|
||||
&& isnan_fp(*reinterpret_cast<cl_float *>(inPtr)))
|
||||
|| ((srcType == kDouble)
|
||||
&& isnan(*reinterpret_cast<cl_double *>(inPtr))));
|
||||
bool isDestNaN = (((destType == kHalf)
|
||||
&& IsHalfNaN(*reinterpret_cast<cl_half *>(
|
||||
outPtr + destTypeSize * s)))
|
||||
|| ((destType == kFloat)
|
||||
&& isnan(*reinterpret_cast<cl_float *>(
|
||||
outPtr + destTypeSize * s)))
|
||||
|| ((destType == kDouble)
|
||||
&& isnan(*reinterpret_cast<cl_double *>(
|
||||
outPtr + destTypeSize * s))));
|
||||
&& isnan_fp(*reinterpret_cast<cl_double *>(inPtr))));
|
||||
bool isDestNaN =
|
||||
(((destType == kHalf)
|
||||
&& isnan_fp(*reinterpret_cast<cl_half *>(
|
||||
outPtr + destTypeSize * s)))
|
||||
|| ((destType == kFloat)
|
||||
&& isnan_fp(*reinterpret_cast<cl_float *>(
|
||||
outPtr + destTypeSize * s)))
|
||||
|| ((destType == kDouble)
|
||||
&& isnan_fp(*reinterpret_cast<cl_double *>(
|
||||
outPtr + destTypeSize * s))));
|
||||
|
||||
if (isSrcNaN && isDestNaN)
|
||||
{
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
// limitations under the License.
|
||||
//
|
||||
#include "harness/compat.h"
|
||||
#include "harness/mathHelpers.h"
|
||||
#include "harness/rounding_mode.h"
|
||||
#include "harness/stringHelpers.h"
|
||||
|
||||
@@ -57,16 +58,6 @@ template <typename T> double toDouble(T val)
|
||||
return val;
|
||||
}
|
||||
|
||||
bool isHalfNan(cl_half v)
|
||||
{
|
||||
// Extract FP16 exponent and mantissa
|
||||
uint16_t h_exp = (v >> (CL_HALF_MANT_DIG - 1)) & 0x1F;
|
||||
uint16_t h_mant = v & 0x3FF;
|
||||
|
||||
// NaN test
|
||||
return (h_exp == 0x1F && h_mant != 0);
|
||||
}
|
||||
|
||||
cl_half half_plus(cl_half a, cl_half b)
|
||||
{
|
||||
return HFF(std::plus<float>()(HTF(a), HTF(b)));
|
||||
@@ -101,14 +92,7 @@ int verify_fp(std::vector<T> (&input)[2], std::vector<T> &output,
|
||||
T r = test.ref(inA[i], inB[i]);
|
||||
bool both_nan = false;
|
||||
|
||||
if (std::is_same<T, cl_half>::value)
|
||||
{
|
||||
both_nan = isHalfNan(r) && isHalfNan(output[i]);
|
||||
}
|
||||
else if (std::is_floating_point<T>::value)
|
||||
{
|
||||
both_nan = std::isnan(r) && std::isnan(output[i]);
|
||||
}
|
||||
both_nan = isnan_fp(r) && isnan_fp(output[i]);
|
||||
|
||||
// If not both nan, check if the result is the same
|
||||
if (!both_nan && (r != output[i]))
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
#include "harness/mathHelpers.h"
|
||||
#include "harness/testHarness.h"
|
||||
#include "harness/compat.h"
|
||||
#include "harness/ThreadPool.h"
|
||||
@@ -955,24 +956,6 @@ void MapResultValuesComplete(const std::unique_ptr<CalcRefValsBase> &info)
|
||||
// destroyed automatically soon after we exit.
|
||||
}
|
||||
|
||||
template <typename T> static bool isnan_fp(const T &v)
|
||||
{
|
||||
if (std::is_same<T, cl_half>::value)
|
||||
{
|
||||
uint16_t h_exp = (((cl_half)v) >> (CL_HALF_MANT_DIG - 1)) & 0x1F;
|
||||
uint16_t h_mant = ((cl_half)v) & 0x3FF;
|
||||
return (h_exp == 0x1F && h_mant != 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
#if !defined(_WIN32)
|
||||
return std::isnan(v);
|
||||
#else
|
||||
return _isnan(v);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
template <typename InType>
|
||||
void ZeroNanToIntCases(cl_uint count, void *mapped, Type outType, void *input)
|
||||
{
|
||||
|
||||
@@ -260,7 +260,7 @@ int TestFunc_HalfI_Half_Half(const Func *f, MTdata d, bool relaxedMode)
|
||||
if (t[j] == q[j] && t2[j] == q2[j]) continue;
|
||||
|
||||
// Check for paired NaNs
|
||||
if (IsHalfNaN(t[j]) && IsHalfNaN(q[j]) && t2[j] == q2[j])
|
||||
if (isnan_fp(t[j]) && isnan_fp(q[j]) && t2[j] == q2[j])
|
||||
continue;
|
||||
|
||||
cl_half test = ((cl_half *)q)[j];
|
||||
@@ -282,7 +282,7 @@ int TestFunc_HalfI_Half_Half(const Func *f, MTdata d, bool relaxedMode)
|
||||
// then the standard either neglects to say what is returned
|
||||
// in iptr or leaves it undefined or implementation defined.
|
||||
int iptrUndefined = IsHalfInfinity(p[j]) || (HTF(p2[j]) == 0.0f)
|
||||
|| IsHalfNaN(p2[j]) || IsHalfNaN(p[j]);
|
||||
|| isnan_fp(p2[j]) || isnan_fp(p[j]);
|
||||
if (iptrUndefined) iErr = 0;
|
||||
|
||||
int fail = !(fabsf(err) <= half_ulps && iErr == 0);
|
||||
|
||||
@@ -274,10 +274,10 @@ int TestFunc_Half_Half_Half_Half(const Func *f, MTdata d, bool relaxedMode)
|
||||
if (skipNanInf)
|
||||
{
|
||||
if (overflow[j] || IsHalfInfinity(correct)
|
||||
|| IsHalfNaN(correct) || IsHalfInfinity(hp0[j])
|
||||
|| IsHalfNaN(hp0[j]) || IsHalfInfinity(hp1[j])
|
||||
|| IsHalfNaN(hp1[j]) || IsHalfInfinity(hp2[j])
|
||||
|| IsHalfNaN(hp2[j]))
|
||||
|| isnan_fp(correct) || IsHalfInfinity(hp0[j])
|
||||
|| isnan_fp(hp0[j]) || IsHalfInfinity(hp1[j])
|
||||
|| isnan_fp(hp1[j]) || IsHalfInfinity(hp2[j])
|
||||
|| isnan_fp(hp2[j]))
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -318,9 +318,9 @@ int TestFunc_Half_Half_Half_Half(const Func *f, MTdata d, bool relaxedMode)
|
||||
// Note: no double rounding here. Reference
|
||||
// functions calculate in single precision.
|
||||
if (IsHalfInfinity(correct2)
|
||||
|| IsHalfNaN(correct2)
|
||||
|| isnan_fp(correct2)
|
||||
|| IsHalfInfinity(correct3)
|
||||
|| IsHalfNaN(correct3))
|
||||
|| isnan_fp(correct3))
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -381,13 +381,13 @@ int TestFunc_Half_Half_Half_Half(const Func *f, MTdata d, bool relaxedMode)
|
||||
// Note: no double rounding here. Reference
|
||||
// functions calculate in single precision.
|
||||
if (IsHalfInfinity(correct2)
|
||||
|| IsHalfNaN(correct2)
|
||||
|| isnan_fp(correct2)
|
||||
|| IsHalfInfinity(correct3)
|
||||
|| IsHalfNaN(correct3)
|
||||
|| isnan_fp(correct3)
|
||||
|| IsHalfInfinity(correct4)
|
||||
|| IsHalfNaN(correct4)
|
||||
|| isnan_fp(correct4)
|
||||
|| IsHalfInfinity(correct5)
|
||||
|| IsHalfNaN(correct5))
|
||||
|| isnan_fp(correct5))
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -474,13 +474,13 @@ int TestFunc_Half_Half_Half_Half(const Func *f, MTdata d, bool relaxedMode)
|
||||
// Note: no double rounding here. Reference
|
||||
// functions calculate in single precision.
|
||||
if (IsHalfInfinity(correct2)
|
||||
|| IsHalfNaN(correct2)
|
||||
|| isnan_fp(correct2)
|
||||
|| IsHalfInfinity(correct3)
|
||||
|| IsHalfNaN(correct3)
|
||||
|| isnan_fp(correct3)
|
||||
|| IsHalfInfinity(correct4)
|
||||
|| IsHalfNaN(correct4)
|
||||
|| isnan_fp(correct4)
|
||||
|| IsHalfInfinity(correct5)
|
||||
|| IsHalfNaN(correct5))
|
||||
|| isnan_fp(correct5))
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -551,9 +551,9 @@ int TestFunc_Half_Half_Half_Half(const Func *f, MTdata d, bool relaxedMode)
|
||||
// Note: no double rounding here. Reference
|
||||
// functions calculate in single precision.
|
||||
if (IsHalfInfinity(correct2)
|
||||
|| IsHalfNaN(correct2)
|
||||
|| isnan_fp(correct2)
|
||||
|| IsHalfInfinity(correct3)
|
||||
|| IsHalfNaN(correct3))
|
||||
|| isnan_fp(correct3))
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -613,13 +613,13 @@ int TestFunc_Half_Half_Half_Half(const Func *f, MTdata d, bool relaxedMode)
|
||||
// Note: no double rounding here. Reference
|
||||
// functions calculate in single precision.
|
||||
if (IsHalfInfinity(correct2)
|
||||
|| IsHalfNaN(correct2)
|
||||
|| isnan_fp(correct2)
|
||||
|| IsHalfInfinity(correct3)
|
||||
|| IsHalfNaN(correct3)
|
||||
|| isnan_fp(correct3)
|
||||
|| IsHalfInfinity(correct4)
|
||||
|| IsHalfNaN(correct4)
|
||||
|| isnan_fp(correct4)
|
||||
|| IsHalfInfinity(correct5)
|
||||
|| IsHalfNaN(correct5))
|
||||
|| isnan_fp(correct5))
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -689,9 +689,9 @@ int TestFunc_Half_Half_Half_Half(const Func *f, MTdata d, bool relaxedMode)
|
||||
// Note: no double rounding here. Reference
|
||||
// functions calculate in single precision.
|
||||
if (IsHalfInfinity(correct2)
|
||||
|| IsHalfNaN(correct2)
|
||||
|| isnan_fp(correct2)
|
||||
|| IsHalfInfinity(correct3)
|
||||
|| IsHalfNaN(correct3))
|
||||
|| isnan_fp(correct3))
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
@@ -249,9 +249,9 @@ int TestFunc_Half2_Half(const Func *f, MTdata d, bool relaxedMode)
|
||||
if (skipNanInf && overflow[j]) continue;
|
||||
// Note: no double rounding here. Reference functions
|
||||
// calculate in single precision.
|
||||
if (IsHalfInfinity(correct1) || IsHalfNaN(correct1)
|
||||
|| IsHalfInfinity(correct2) || IsHalfNaN(correct2)
|
||||
|| IsHalfInfinity(pIn[j]) || IsHalfNaN(pIn[j]))
|
||||
if (IsHalfInfinity(correct1) || isnan_fp(correct1)
|
||||
|| IsHalfInfinity(correct2) || isnan_fp(correct2)
|
||||
|| IsHalfInfinity(pIn[j]) || isnan_fp(pIn[j]))
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -320,13 +320,13 @@ int TestFunc_Half2_Half(const Func *f, MTdata d, bool relaxedMode)
|
||||
// Note: no double rounding here. Reference
|
||||
// functions calculate in single precision.
|
||||
if (IsHalfInfinity(correctp)
|
||||
|| IsHalfNaN(correctp)
|
||||
|| isnan_fp(correctp)
|
||||
|| IsHalfInfinity(correctn)
|
||||
|| IsHalfNaN(correctn)
|
||||
|| isnan_fp(correctn)
|
||||
|| IsHalfInfinity(correct2p)
|
||||
|| IsHalfNaN(correct2p)
|
||||
|| isnan_fp(correct2p)
|
||||
|| IsHalfInfinity(correct2n)
|
||||
|| IsHalfNaN(correct2n))
|
||||
|| isnan_fp(correct2n))
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#include "harness/compat.h"
|
||||
#include "harness/rounding_mode.h"
|
||||
#include "harness/fpcontrol.h"
|
||||
#include "harness/mathHelpers.h"
|
||||
#include "harness/testHarness.h"
|
||||
#include "harness/ThreadPool.h"
|
||||
#include "harness/conversions.h"
|
||||
@@ -172,16 +173,6 @@ inline int IsFloatNaN(double x)
|
||||
return ((u.u & 0x7fffffffU) > 0x7F800000U);
|
||||
}
|
||||
|
||||
inline bool IsHalfNaN(const cl_half v)
|
||||
{
|
||||
// Extract FP16 exponent and mantissa
|
||||
uint16_t h_exp = (((cl_half)v) >> (CL_HALF_MANT_DIG - 1)) & 0x1F;
|
||||
uint16_t h_mant = ((cl_half)v) & 0x3FF;
|
||||
|
||||
// NaN test
|
||||
return (h_exp == 0x1F && h_mant != 0);
|
||||
}
|
||||
|
||||
inline bool IsHalfInfinity(const cl_half v)
|
||||
{
|
||||
// Extract FP16 exponent and mantissa
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include <stdexcept>
|
||||
#include <vector>
|
||||
|
||||
#include "harness/mathHelpers.h"
|
||||
#include "harness/stringHelpers.h"
|
||||
|
||||
#include <CL/cl_half.h>
|
||||
@@ -368,9 +369,8 @@ int RelationalsFPTest::test_equiv_kernel(unsigned int vecSize,
|
||||
{
|
||||
if (gInfNanSupport == 0)
|
||||
{
|
||||
float a = inDataA[i * vecSize + j];
|
||||
float b = inDataB[i * vecSize + j];
|
||||
if (isnan(a) || isnan(b))
|
||||
if (isnan_fp(inDataA[i * vecSize + j])
|
||||
|| isnan_fp(inDataB[i * vecSize + j]))
|
||||
fail = 0;
|
||||
else
|
||||
fail = 1;
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
// limitations under the License.
|
||||
//
|
||||
#include "harness/errorHelpers.h"
|
||||
#include "harness/mathHelpers.h"
|
||||
#include "harness/testHarness.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <cinttypes>
|
||||
@@ -834,9 +836,9 @@ size_t check_half(const void *const test, const void *const correct,
|
||||
// Allow nans to be binary different
|
||||
for (i = 0; i < count; i++)
|
||||
{
|
||||
float fcorrect = cl_half_to_float(c[i]);
|
||||
float ftest = cl_half_to_float(t[i]);
|
||||
if ((t[i] != c[i]) && !(isnan(fcorrect) && isnan(ftest)))
|
||||
if ((t[i] != c[i])
|
||||
&& !(isnan_fp(cl_half_to_float(c[i]))
|
||||
&& isnan_fp(cl_half_to_float(t[i]))))
|
||||
{
|
||||
log_error("\n(check_half) Error for vector size %zu found at "
|
||||
"0x%8.8zx (of 0x%8.8zx): "
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#define _testBase_h
|
||||
|
||||
#include "harness/compat.h"
|
||||
#include "harness/mathHelpers.h"
|
||||
#include "harness/rounding_mode.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
@@ -231,7 +231,7 @@ static inline
|
||||
f = cl_half_to_float(cl_half_from_float(f, half_rounding));
|
||||
|
||||
To val = static_cast<To>(std::min<float>(std::max<float>(f, loVal), hiVal));
|
||||
if (isnan(cl_half_to_float(rhs)))
|
||||
if (isnan_fp(rhs))
|
||||
{
|
||||
val = 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user