Skip to content

Commit

Permalink
[NFC] math_brute_force: move TestInfoBase to common.h (#2059)
Browse files Browse the repository at this point in the history
The various forms of `TestInfoBase` have many members in common, so
avoid duplicating the struct definition and move it to `common.h`.

Provide a description and initializer for every struct member, and drop
initializations done with `memset`.

Signed-off-by: Sven van Haastregt <sven.vanhaastregt@arm.com>
  • Loading branch information
svenvh authored Sep 3, 2024
1 parent eb7a30a commit 9116bb7
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 94 deletions.
23 changes: 1 addition & 22 deletions test_conformance/math_brute_force/binary_half.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,27 +56,8 @@ struct ThreadInfo
tQueue; // per thread command queue to improve performance
};

struct TestInfoBase
{
size_t subBufferSize; // Size of the sub-buffer in elements
const Func *f; // A pointer to the function info

cl_uint threadCount; // Number of worker threads
cl_uint jobCount; // Number of jobs
cl_uint step; // step between each chunk and the next.
cl_uint scale; // stride between individual test values
float ulps; // max_allowed ulps
int ftz; // non-zero if running in flush to zero mode

int isFDim;
int skipNanInf;
int isNextafter;
};

struct TestInfo : public TestInfoBase
{
TestInfo(const TestInfoBase &base): TestInfoBase(base) {}

// Array of thread specific information
std::vector<ThreadInfo> tinfo;

Expand Down Expand Up @@ -646,16 +627,14 @@ cl_int TestHalf(cl_uint job_id, cl_uint thread_id, void *data)
int TestFunc_Half_Half_Half_common(const Func *f, MTdata d, int isNextafter,
bool relaxedMode)
{
TestInfoBase test_info_base;
cl_int error;
float maxError = 0.0f;
double maxErrorVal = 0.0;
double maxErrorVal2 = 0.0;

logFunctionInfo(f->name, sizeof(cl_half), relaxedMode);
// Init test_info
memset(&test_info_base, 0, sizeof(test_info_base));
TestInfo test_info(test_info_base);
TestInfo test_info;

test_info.threadCount = GetThreadCount();
test_info.subBufferSize = BUFFER_SIZE
Expand Down
19 changes: 1 addition & 18 deletions test_conformance/math_brute_force/binary_i_half.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,23 +52,8 @@ typedef struct ThreadInfo
tQueue; // per thread command queue to improve performance
} ThreadInfo;

struct TestInfoBase
{
size_t subBufferSize; // Size of the sub-buffer in elements
const Func *f; // A pointer to the function info

cl_uint threadCount; // Number of worker threads
cl_uint jobCount; // Number of jobs
cl_uint step; // step between each chunk and the next.
cl_uint scale; // stride between individual test values
float ulps; // max_allowed ulps
int ftz; // non-zero if running in flush to zero mode
};

struct TestInfo : public TestInfoBase
{
TestInfo(const TestInfoBase &base): TestInfoBase(base) {}

// Array of thread specific information
std::vector<ThreadInfo> tinfo;

Expand Down Expand Up @@ -415,7 +400,6 @@ cl_int TestHalf(cl_uint job_id, cl_uint thread_id, void *data)

int TestFunc_Half_Half_Int(const Func *f, MTdata d, bool relaxedMode)
{
TestInfoBase test_info_base;
cl_int error;
size_t i, j;
float maxError = 0.0f;
Expand All @@ -425,8 +409,7 @@ int TestFunc_Half_Half_Int(const Func *f, MTdata d, bool relaxedMode)
logFunctionInfo(f->name, sizeof(cl_half), relaxedMode);

// Init test_info
memset(&test_info_base, 0, sizeof(test_info_base));
TestInfo test_info(test_info_base);
TestInfo test_info;

test_info.threadCount = GetThreadCount();
test_info.subBufferSize = BUFFER_SIZE
Expand Down
47 changes: 47 additions & 0 deletions test_conformance/math_brute_force/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,53 @@ struct BuildKernelInfo
bool relaxedMode;
};

// Data common to all math tests.
struct TestInfoBase
{
TestInfoBase() = default;
~TestInfoBase() = default;

// Prevent accidental copy/move.
TestInfoBase(const TestInfoBase &) = delete;
TestInfoBase &operator=(const TestInfoBase &) = delete;
TestInfoBase(TestInfoBase &&h) = delete;
TestInfoBase &operator=(TestInfoBase &&h) = delete;

// Size of the sub-buffer in elements.
size_t subBufferSize = 0;
// Function info.
const Func *f = nullptr;

// Number of worker threads.
cl_uint threadCount = 0;
// Number of jobs.
cl_uint jobCount = 0;
// step between each chunk and the next.
cl_uint step = 0;
// stride between individual test values.
cl_uint scale = 0;
// max_allowed ulps.
float ulps = -1.f;
// non-zero if running in flush to zero mode.
int ftz = 0;

// 1 if running the fdim test.
int isFDim = 0;
// 1 if input/output NaNs and INFs are skipped.
int skipNanInf = 0;
// 1 if running the nextafter test.
int isNextafter = 0;

// 1 if the function is only to be evaluated over a range.
int isRangeLimited = 0;

// Result limit for half_sin/half_cos/half_tan.
float half_sin_cos_tan_limit = -1.f;

// Whether the test is being run in relaxed mode.
bool relaxedMode = false;
};

using SourceGenerator = std::string (*)(const std::string &kernel_name,
const char *builtin,
cl_uint vector_size_index);
Expand Down
18 changes: 1 addition & 17 deletions test_conformance/math_brute_force/macro_binary_half.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,22 +45,8 @@ struct ThreadInfo
tQueue; // per thread command queue to improve performance
};

struct TestInfoBase
{
size_t subBufferSize; // Size of the sub-buffer in elements
const Func *f; // A pointer to the function info

cl_uint threadCount; // Number of worker threads
cl_uint jobCount; // Number of jobs
cl_uint step; // step between each chunk and the next.
cl_uint scale; // stride between individual test values
int ftz; // non-zero if running in flush to zero mode
};

struct TestInfo : public TestInfoBase
{
TestInfo(const TestInfoBase &base): TestInfoBase(base) {}

// Array of thread specific information
std::vector<ThreadInfo> tinfo;

Expand Down Expand Up @@ -430,15 +416,13 @@ cl_int TestHalf(cl_uint job_id, cl_uint thread_id, void *data)

int TestMacro_Int_Half_Half(const Func *f, MTdata d, bool relaxedMode)
{
TestInfoBase test_info_base;
cl_int error;
size_t i, j;

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

// Init test_info
memset(&test_info_base, 0, sizeof(test_info_base));
TestInfo test_info(test_info_base);
TestInfo test_info;

test_info.threadCount = GetThreadCount();
test_info.subBufferSize = BUFFER_SIZE
Expand Down
17 changes: 1 addition & 16 deletions test_conformance/math_brute_force/macro_unary_half.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,8 @@ struct ThreadInfo
tQueue; // per thread command queue to improve performance
};

struct TestInfoBase
{
size_t subBufferSize; // Size of the sub-buffer in elements
const Func *f; // A pointer to the function info
cl_uint threadCount; // Number of worker threads
cl_uint jobCount; // Number of jobs
cl_uint step; // step between each chunk and the next.
cl_uint scale; // stride between individual test values
int ftz; // non-zero if running in flush to zero mode
};

struct TestInfo : public TestInfoBase
{
TestInfo(const TestInfoBase &base): TestInfoBase(base) {}

// Array of thread specific information
std::vector<ThreadInfo> tinfo;

Expand Down Expand Up @@ -328,14 +315,12 @@ cl_int TestHalf(cl_uint job_id, cl_uint thread_id, void *data)

int TestMacro_Int_Half(const Func *f, MTdata d, bool relaxedMode)
{
TestInfoBase test_info_base;
cl_int error;
size_t i, j;

logFunctionInfo(f->name, sizeof(cl_half), relaxedMode);
// Init test_info
memset(&test_info_base, 0, sizeof(test_info_base));
TestInfo test_info(test_info_base);
TestInfo test_info;

test_info.threadCount = GetThreadCount();
test_info.subBufferSize = BUFFER_SIZE
Expand Down
22 changes: 1 addition & 21 deletions test_conformance/math_brute_force/unary_half.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,26 +45,8 @@ typedef struct ThreadInfo
tQueue; // per thread command queue to improve performance
} ThreadInfo;

struct TestInfoBase
{
size_t subBufferSize; // Size of the sub-buffer in elements
const Func *f; // A pointer to the function info
cl_uint threadCount; // Number of worker threads
cl_uint jobCount; // Number of jobs
cl_uint step; // step between each chunk and the next.
cl_uint scale; // stride between individual test values
float ulps; // max_allowed ulps
int ftz; // non-zero if running in flush to zero mode

int isRangeLimited; // 1 if the function is only to be evaluated over a
// range
float half_sin_cos_tan_limit;
};

struct TestInfo : public TestInfoBase
{
TestInfo(const TestInfoBase &base): TestInfoBase(base) {}

// Array of thread specific information
std::vector<ThreadInfo> tinfo;

Expand Down Expand Up @@ -351,7 +333,6 @@ cl_int TestHalf(cl_uint job_id, cl_uint thread_id, void *data)

int TestFunc_Half_Half(const Func *f, MTdata d, bool relaxedMode)
{
TestInfoBase test_info_base;
cl_int error;
size_t i, j;
float maxError = 0.0f;
Expand All @@ -360,8 +341,7 @@ int TestFunc_Half_Half(const Func *f, MTdata d, bool relaxedMode)
logFunctionInfo(f->name, sizeof(cl_half), relaxedMode);

// Init test_info
memset(&test_info_base, 0, sizeof(test_info_base));
TestInfo test_info(test_info_base);
TestInfo test_info;

test_info.threadCount = GetThreadCount();

Expand Down

0 comments on commit 9116bb7

Please sign in to comment.