Skip to content

Commit

Permalink
conversions: fix ZeroNanToIntCases from #1975 (#2030)
Browse files Browse the repository at this point in the history
The handling of NaN values in the templated function was incorrect due
to improper initialization of the input data source. Specifically, the
function ZeroNanToIntCases used a global pointer gIn, which was not
correctly set or did not point to the same data as the local input
pointer s used in the non-templated implementation.

to solve the issue I updated the templated function ZeroNanToIntCases to
take an additional parameter for the input data source.
and then passed the correct input data (s) to the templated function
during its invocation.

Co-authored-by: Banan Ashkar <banan.ashkar@mobileye.com>
  • Loading branch information
banan328 and bananAshkar committed Aug 6, 2024
1 parent 89a720d commit 8974d74
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions test_conformance/conversions/basic_test_conversions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1064,9 +1064,9 @@ template <typename T> static bool isnan_fp(const T &v)
}

template <typename InType>
void ZeroNanToIntCases(cl_uint count, void *mapped, Type outType)
void ZeroNanToIntCases(cl_uint count, void *mapped, Type outType, void *input)
{
InType *inp = (InType *)gIn;
InType *inp = (InType *)input;
for (auto j = 0; j < count; j++)
{
if (isnan_fp<InType>(inp[j]))
Expand All @@ -1091,16 +1091,17 @@ void FixNanToFltConversions(InType *inp, OutType *outp, cl_uint count)
}
}

void FixNanConversions(Type outType, Type inType, void *d, cl_uint count)
void FixNanConversions(Type outType, Type inType, void *d, cl_uint count,
void *inp)
{
if (outType != kfloat && outType != kdouble && outType != khalf)
{
if (inType == kfloat)
ZeroNanToIntCases<float>(count, d, outType);
ZeroNanToIntCases<float>(count, d, outType, inp);
else if (inType == kdouble)
ZeroNanToIntCases<double>(count, d, outType);
ZeroNanToIntCases<double>(count, d, outType, inp);
else if (inType == khalf)
ZeroNanToIntCases<cl_half>(count, d, outType);
ZeroNanToIntCases<cl_half>(count, d, outType, inp);
}
else if (inType == kfloat || inType == kdouble || inType == khalf)
{
Expand Down Expand Up @@ -1184,7 +1185,7 @@ void CL_CALLBACK CalcReferenceValuesComplete(cl_event e, cl_int status,

// Patch up NaNs conversions to integer to zero -- these can be converted to
// any integer
FixNanConversions(outType, inType, mapped, count);
FixNanConversions(outType, inType, mapped, count, gIn);

if (memcmp(mapped, gRef, count * gTypeSizes[outType]))
info->result =
Expand Down Expand Up @@ -1346,7 +1347,7 @@ cl_int PrepareReference(cl_uint job_id, cl_uint thread_id, void *p)

// Patch up NaNs conversions to integer to zero -- these can be converted to
// any integer
FixNanConversions(outType, inType, d, count);
FixNanConversions(outType, inType, d, count, s);

return CL_SUCCESS;
}
Expand Down

0 comments on commit 8974d74

Please sign in to comment.