Skip to content

Commit

Permalink
[NFC] math_brute_force: add type argument to getAllowedUlpError
Browse files Browse the repository at this point in the history
Add a type argument so that in the future we can request the ULP
requirement for fp16 and fp64 types through `getAllowedUlpError` too.

Contributes to #867

Signed-off-by: Sven van Haastregt <sven.vanhaastregt@arm.com>
  • Loading branch information
svenvh committed Jul 19, 2024
1 parent 5b5e43e commit a287230
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 30 deletions.
2 changes: 1 addition & 1 deletion test_conformance/math_brute_force/binary_float.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ cl_int Test(cl_uint job_id, cl_uint thread_id, void *data)
fptr func = job->f->func;
int ftz = job->ftz;
bool relaxedMode = job->relaxedMode;
float ulps = getAllowedUlpError(job->f, relaxedMode);
float ulps = getAllowedUlpError(job->f, kfloat, relaxedMode);
MTdata d = tinfo->d;
cl_int error;
std::vector<bool> overflow(buffer_elements, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ cl_int Test(cl_uint job_id, cl_uint thread_id, void *data)
fptr func = job->f->func;
int ftz = job->ftz;
bool relaxedMode = job->relaxedMode;
float ulps = getAllowedUlpError(job->f, relaxedMode);
float ulps = getAllowedUlpError(job->f, kfloat, relaxedMode);
MTdata d = tinfo->d;
cl_int error;
std::vector<bool> overflow(buffer_elements, false);
Expand Down
2 changes: 1 addition & 1 deletion test_conformance/math_brute_force/unary_float.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ cl_int Test(cl_uint job_id, cl_uint thread_id, void *data)
fptr func = job->f->func;
const char *fname = job->f->name;
bool relaxedMode = job->relaxedMode;
float ulps = getAllowedUlpError(job->f, relaxedMode);
float ulps = getAllowedUlpError(job->f, kfloat, relaxedMode);
if (relaxedMode)
{
func = job->f->rfunc;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ int TestFunc_Float2_Float(const Func *f, MTdata d, bool relaxedMode)

logFunctionInfo(f->name, sizeof(cl_float), relaxedMode);

float float_ulps = getAllowedUlpError(f, relaxedMode);
float float_ulps = getAllowedUlpError(f, kfloat, relaxedMode);
// Init the kernels
BuildKernelInfo build_info{ 1, kernels, programs, f->nameInCode,
relaxedMode };
Expand Down
63 changes: 38 additions & 25 deletions test_conformance/math_brute_force/utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
//

#include "utility.h"

#include <cassert>

#include "function_list.h"

#if defined(__PPC__)
Expand Down Expand Up @@ -161,32 +164,42 @@ void logFunctionInfo(const char *fname, unsigned int float_size,
vlog("%15s %4s %4s", fname, fpSizeStr, fpFastRelaxedStr);
}

float getAllowedUlpError(const Func *f, const bool relaxed)
float getAllowedUlpError(const Func *f, Type t, const bool relaxed)
{
float ulp;

if (relaxed)
switch (t)
{
if (gIsEmbedded)
{
ulp = f->relaxed_embedded_error;
}
else
{
ulp = f->relaxed_error;
}
case kfloat:
if (relaxed)
{
if (gIsEmbedded)
{
return f->relaxed_embedded_error;
}
else
{
return f->relaxed_error;
}
}
else
{
if (gIsEmbedded)
{
return f->float_embedded_ulps;
}
else
{
return f->float_ulps;
}
}
case kdouble:
// TODO: distinguish between embedded and full profile.
return f->double_ulps;
case khalf:
// TODO: distinguish between embedded and full profile.
return f->half_ulps;
default:
assert(false && "unsupported type in getAllowedUlpError");
// Return a negative value which will make any test fail.
return -1.f;
}
else
{
if (gIsEmbedded)
{
ulp = f->float_embedded_ulps;
}
else
{
ulp = f->float_ulps;
}
}

return ulp;
}
2 changes: 1 addition & 1 deletion test_conformance/math_brute_force/utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ int compareDoubles(double x, double y);
void logFunctionInfo(const char *fname, unsigned int float_size,
unsigned int isFastRelaxed);

float getAllowedUlpError(const Func *f, const bool relaxed);
float getAllowedUlpError(const Func *f, Type t, const bool relaxed);

inline cl_uint getTestScale(size_t typeSize)
{
Expand Down

0 comments on commit a287230

Please sign in to comment.