Remove gTestFastRelaxed Dependencies in Brute Force (#807)

* The global variable `gTestFastRelaxed` has state which is used to
control the behaviour of the compiler flag `-cl-fast-relaxed-math` and
the precision testing of relaxed, fp32 and fp64 types. This is confusing
since the global variable is being set and read in different translation
units, making it very difficult to reason about the logic of the brute
force framework. It is particular difficult to follow since the global
variables is cached and then turned off in the case of fp32 and f64 in
order to use the same code path as relaxed testing, after it is then
turned back on.

* Remove uses of the global variable outside of `main.cpp` (the global
variable remains in use within `main.cpp` since it is a command line
option and used to turn of relaxed testing completely). Replace all uses
of the global variable with boolean `relaxedMode` which is passed as a
function paramter but replaces `gTestFastRelaxed` semantically.
This commit is contained in:
Jack Frankland
2020-06-04 10:44:39 +01:00
committed by GitHub
parent 519f658b51
commit ecee2c18d2
16 changed files with 480 additions and 288 deletions

View File

@@ -18,17 +18,20 @@
#include <string.h>
#include "FunctionList.h"
int TestFunc_Float_UInt(const Func *f, MTdata);
int TestFunc_Double_ULong(const Func *f, MTdata);
int TestFunc_Float_UInt(const Func *f, MTdata, bool relaxedMode);
int TestFunc_Double_ULong(const Func *f, MTdata, bool relaxedMode);
extern const vtbl _unary_u = { "unary_u", TestFunc_Float_UInt,
TestFunc_Double_ULong };
static int BuildKernel( const char *name, int vectorSize, cl_kernel *k, cl_program *p );
static int BuildKernelDouble( const char *name, int vectorSize, cl_kernel *k, cl_program *p );
static int BuildKernel(const char *name, int vectorSize, cl_kernel *k,
cl_program *p, bool relaxedMode);
static int BuildKernelDouble(const char *name, int vectorSize, cl_kernel *k,
cl_program *p, bool relaxedMode);
static int BuildKernel( const char *name, int vectorSize, cl_kernel *k, cl_program *p )
static int BuildKernel(const char *name, int vectorSize, cl_kernel *k,
cl_program *p, bool relaxedMode)
{
const char *c[] = {
"__kernel void math_kernel", sizeNames[vectorSize], "( __global float", sizeNames[vectorSize], "* out, __global uint", sizeNames[vectorSize], "* in)\n"
@@ -86,10 +89,11 @@ static int BuildKernel( const char *name, int vectorSize, cl_kernel *k, cl_progr
char testName[32];
snprintf( testName, sizeof( testName ) -1, "math_kernel%s", sizeNames[vectorSize] );
return MakeKernel(kern, (cl_uint) kernSize, testName, k, p);
return MakeKernel(kern, (cl_uint)kernSize, testName, k, p, relaxedMode);
}
static int BuildKernelDouble( const char *name, int vectorSize, cl_kernel *k, cl_program *p )
static int BuildKernelDouble(const char *name, int vectorSize, cl_kernel *k,
cl_program *p, bool relaxedMode)
{
const char *c[] = {
"#pragma OPENCL EXTENSION cl_khr_fp64 : enable\n",
@@ -150,7 +154,7 @@ static int BuildKernelDouble( const char *name, int vectorSize, cl_kernel *k, cl
char testName[32];
snprintf( testName, sizeof( testName ) -1, "math_kernel%s", sizeNames[vectorSize] );
return MakeKernel(kern, (cl_uint) kernSize, testName, k, p);
return MakeKernel(kern, (cl_uint)kernSize, testName, k, p, relaxedMode);
}
typedef struct BuildKernelInfo
@@ -159,6 +163,7 @@ typedef struct BuildKernelInfo
cl_kernel *kernels;
cl_program *programs;
const char *nameInCode;
bool relaxedMode; // Whether to build with -cl-fast-relaxed-math.
}BuildKernelInfo;
static cl_int BuildKernel_FloatFn( cl_uint job_id, cl_uint thread_id UNUSED, void *p );
@@ -166,7 +171,8 @@ static cl_int BuildKernel_FloatFn( cl_uint job_id, cl_uint thread_id UNUSED, voi
{
BuildKernelInfo *info = (BuildKernelInfo*) p;
cl_uint i = info->offset + job_id;
return BuildKernel( info->nameInCode, i, info->kernels + i, info->programs + i );
return BuildKernel(info->nameInCode, i, info->kernels + i,
info->programs + i, info->relaxedMode);
}
static cl_int BuildKernel_DoubleFn( cl_uint job_id, cl_uint thread_id UNUSED, void *p );
@@ -174,10 +180,11 @@ static cl_int BuildKernel_DoubleFn( cl_uint job_id, cl_uint thread_id UNUSED, vo
{
BuildKernelInfo *info = (BuildKernelInfo*) p;
cl_uint i = info->offset + job_id;
return BuildKernelDouble( info->nameInCode, i, info->kernels + i, info->programs + i );
return BuildKernelDouble(info->nameInCode, i, info->kernels + i,
info->programs + i, info->relaxedMode);
}
int TestFunc_Float_UInt(const Func *f, MTdata d)
int TestFunc_Float_UInt(const Func *f, MTdata d, bool relaxedMode)
{
uint64_t i;
uint32_t j, k;
@@ -195,7 +202,7 @@ int TestFunc_Float_UInt(const Func *f, MTdata d)
float float_ulps;
float half_sin_cos_tan_limit = 0;
logFunctionInfo(f->name,sizeof(cl_float),gTestFastRelaxed);
logFunctionInfo(f->name, sizeof(cl_float), relaxedMode);
if( gWimpyMode )
{
step = (1ULL<<32) * gWimpyReductionFactor / (512);
@@ -206,7 +213,8 @@ int TestFunc_Float_UInt(const Func *f, MTdata d)
float_ulps = f->float_ulps;
// Init the kernels
BuildKernelInfo build_info = { gMinVectorSizeIndex, kernels, programs, f->nameInCode };
BuildKernelInfo build_info = { gMinVectorSizeIndex, kernels, programs,
f->nameInCode, relaxedMode };
if( (error = ThreadPool_Do( BuildKernel_FloatFn, gMaxVectorSizeIndex - gMinVectorSizeIndex, &build_info ) ))
return error;
/*
@@ -454,7 +462,7 @@ static cl_ulong random64( MTdata d )
return (cl_ulong) genrand_int32(d) | ((cl_ulong) genrand_int32(d) << 32);
}
int TestFunc_Double_ULong(const Func *f, MTdata d)
int TestFunc_Double_ULong(const Func *f, MTdata d, bool relaxedMode)
{
uint64_t i;
uint32_t j, k;
@@ -467,7 +475,7 @@ int TestFunc_Double_ULong(const Func *f, MTdata d)
size_t bufferSize = (gWimpyMode)? gWimpyBufferSize: BUFFER_SIZE;
uint64_t step = bufferSize / sizeof( cl_double );
logFunctionInfo(f->name,sizeof(cl_double),gTestFastRelaxed);
logFunctionInfo(f->name, sizeof(cl_double), relaxedMode);
if( gWimpyMode )
{
step = (1ULL<<32) * gWimpyReductionFactor / (512);
@@ -475,7 +483,8 @@ int TestFunc_Double_ULong(const Func *f, MTdata d)
Force64BitFPUPrecision();
// Init the kernels
BuildKernelInfo build_info = { gMinVectorSizeIndex, kernels, programs, f->nameInCode };
BuildKernelInfo build_info = { gMinVectorSizeIndex, kernels, programs,
f->nameInCode, relaxedMode };
if( (error = ThreadPool_Do( BuildKernel_DoubleFn,
gMaxVectorSizeIndex - gMinVectorSizeIndex,
&build_info ) ))
@@ -689,4 +698,3 @@ exit:
return error;
}