Skip to content

Commit

Permalink
Added multiple corrections related to code review
Browse files Browse the repository at this point in the history
  • Loading branch information
shajder committed Jun 15, 2023
1 parent 122a08b commit 616ef76
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 49 deletions.
24 changes: 8 additions & 16 deletions test_conformance/conversions/basic_test_conversions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,10 +283,9 @@ static inline void Force64BitFPUPrecision(void)
}


template <typename InType, typename OutType, bool InFP, bool OutFP>
int CalcRefValsPat<InType, OutType, InFP, OutFP>::check_result(void *test,
uint32_t count,
int vectorSize)
template <typename InType, typename OutType>
int CalcRefValsPat<InType, OutType>::check_result(void *test, uint32_t count,
int vectorSize)
{
const cl_uchar *a = (const cl_uchar *)gAllowZ;

Expand Down Expand Up @@ -449,7 +448,7 @@ cl_int ConversionsTest::SetUp(int elements)
}


template <typename InType, typename OutType, bool InFP, bool OutFP>
template <typename InType, typename OutType>
void ConversionsTest::TestTypesConversion(const Type &inType,
const Type &outType, int &testNumber)
{
Expand Down Expand Up @@ -517,8 +516,7 @@ void ConversionsTest::TestTypesConversion(const Type &inType,
gMinVectorSize = 0;
}

if ((error = DoTest<InType, OutType, InFP, OutFP>(outType, inType,
sat, round)))
if ((error = DoTest<InType, OutType>(outType, inType, sat, round)))
{
vlog_error("\t *** %d) convert_%sn%s%s( %sn ) "
"FAILED ** \n",
Expand All @@ -531,23 +529,19 @@ void ConversionsTest::TestTypesConversion(const Type &inType,
}


template <typename InType, typename OutType, bool InFP, bool OutFP>
template <typename InType, typename OutType>
int ConversionsTest::DoTest(Type outType, Type inType, SaturationMode sat,
RoundingMode round)
{
#ifdef __APPLE__
cl_ulong wall_start = mach_absolute_time();
#endif

#if 0
uint64_t lastCase = 1ULL << (8 * gTypeSizes[inType]);
#else
cl_uint threads = GetThreadCount();
uint64_t lastCase = 1000000ULL;
#endif

DataInitInfo info = { 0, 0, outType, inType, sat, round, threads };
DataInfoSpec<InType, OutType, InFP, OutFP> init_info(info);
DataInfoSpec<InType, OutType> init_info(info);
WriteInputBufferInfo writeInputBufferInfo;
int vectorSize;
int error = 0;
Expand All @@ -570,7 +564,7 @@ int ConversionsTest::DoTest(Type outType, Type inType, SaturationMode sat,
for (vectorSize = gMinVectorSize; vectorSize < gMaxVectorSize; vectorSize++)
{
writeInputBufferInfo.calcInfo[vectorSize].reset(
new CalcRefValsPat<InType, OutType, InFP, OutFP>());
new CalcRefValsPat<InType, OutType>());
writeInputBufferInfo.calcInfo[vectorSize]->program =
conv_test::MakeProgram(
outType, inType, sat, round, vectorSize,
Expand Down Expand Up @@ -604,11 +598,9 @@ int ConversionsTest::DoTest(Type outType, Type inType, SaturationMode sat,
init_info.round = round = kRoundTowardZero;
}

#if 0
// Figure out how many elements are in a work block
// we handle 64-bit types a bit differently.
if (8 * gTypeSizes[inType] > 32) lastCase = 0x100000000ULL;
#endif

if (!gWimpyMode && gIsEmbedded)
step = blockCount * EMBEDDED_REDUCTION_FACTOR;
Expand Down
20 changes: 9 additions & 11 deletions test_conformance/conversions/basic_test_conversions.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ struct CalcRefValsBase
cl_int result;
};

template <typename InType, typename OutType, bool InFP, bool OutFP>
template <typename InType, typename OutType>
struct CalcRefValsPat : CalcRefValsBase
{
int check_result(void *, uint32_t, int) override;
Expand Down Expand Up @@ -165,12 +165,12 @@ struct WriteInputBufferInfo
using TypeIter = std::tuple<cl_uchar, cl_char, cl_ushort, cl_short, cl_uint,
cl_int, cl_float, cl_double, cl_ulong, cl_long>;

constexpr bool isTypeFp[] = { 0, 0, 0, 0, 0, 0, 1, 1, 0, 0 };

// Helper test fixture for constructing OpenCL objects used in testing
// a variety of simple command-buffer enqueue scenarios.
struct ConversionsTest
{
virtual ~ConversionsTest() = default;

ConversionsTest(cl_device_id device, cl_context context,
cl_command_queue queue);

Expand All @@ -179,11 +179,11 @@ struct ConversionsTest
// Test body returning an OpenCL error code
cl_int Run();

template <typename InType, typename OutType, bool InFP, bool OutFP>
template <typename InType, typename OutType>
int DoTest(Type outType, Type inType, SaturationMode sat,
RoundingMode round);

template <typename InType, typename OutType, bool InFP, bool OutFP>
template <typename InType, typename OutType>
void TestTypesConversion(const Type &inType, const Type &outType, int &tn);

protected:
Expand All @@ -210,7 +210,7 @@ template <class T>
int MakeAndRunTest(cl_device_id device, cl_context context,
cl_command_queue queue, int num_elements)
{
auto test_fixture = T(device, context, queue);
T test_fixture(device, context, queue);

cl_int error = test_fixture.SetUp(num_elements);
test_error_ret(error, "Error in test initialization", TEST_FAIL);
Expand Down Expand Up @@ -267,8 +267,7 @@ struct IterOverTypes : public TestType
if (!testType<OutType>(outType)) vlog_error("Unexpected data type!\n");

// run the conversions
test.TestTypesConversion<InType, OutType, isTypeFp[In], isTypeFp[Out]>(
inType, outType, testNumber);
test.TestTypesConversion<InType, OutType>(inType, outType, testNumber);
inType = (Type)(inType + 1);
}

Expand Down Expand Up @@ -336,9 +335,8 @@ struct IterOverSelectedTypes : public TestType
if (testType<InType>(inType) && testType<OutType>(outType))
{
// run the conversions
test.TestTypesConversion<InType, OutType, isTypeFp[In],
isTypeFp[Out]>(inType, outType,
testNumber);
test.TestTypesConversion<InType, OutType>(inType, outType,
testNumber);
}
}

Expand Down
42 changes: 20 additions & 22 deletions test_conformance/conversions/conversions_data_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,21 +60,22 @@ struct DataInitInfo
RoundingMode round;
cl_uint threads;


static std::vector<uint32_t> specialValuesUInt;
static std::vector<float> specialValuesFloat;
static std::vector<double> specialValuesDouble;
};

struct DataInitBase : public DataInitInfo
{
virtual ~DataInitBase() = default;

explicit DataInitBase(const DataInitInfo &agg): DataInitInfo(agg) {}
virtual void conv_array(void *out, void *in, size_t n) {}
virtual void conv_array_sat(void *out, void *in, size_t n) {}
virtual void init(const cl_uint &, const cl_uint &) {}
};

template <typename InType, typename OutType, bool InFP, bool OutFP>
template <typename InType, typename OutType>
struct DataInfoSpec : public DataInitBase
{
explicit DataInfoSpec(const DataInitInfo &agg);
Expand Down Expand Up @@ -124,9 +125,8 @@ struct DataInfoSpec : public DataInitBase
}
};

template <typename InType, typename OutType, bool InFP, bool OutFP>
DataInfoSpec<InType, OutType, InFP, OutFP>::DataInfoSpec(
const DataInitInfo &agg)
template <typename InType, typename OutType>
DataInfoSpec<InType, OutType>::DataInfoSpec(const DataInitInfo &agg)
: DataInitBase(agg), mdv(0)
{
if (std::is_same<cl_float, OutType>::value)
Expand Down Expand Up @@ -252,8 +252,8 @@ DataInfoSpec<InType, OutType, InFP, OutFP>::DataInfoSpec(
// clang-format on
}

template <typename InType, typename OutType, bool InFP, bool OutFP>
float DataInfoSpec<InType, OutType, InFP, OutFP>::round_to_int(float f)
template <typename InType, typename OutType>
float DataInfoSpec<InType, OutType>::round_to_int(float f)
{
static const float magic[2] = { MAKE_HEX_FLOAT(0x1.0p23f, 0x1, 23),
-MAKE_HEX_FLOAT(0x1.0p23f, 0x1, 23) };
Expand Down Expand Up @@ -281,9 +281,8 @@ float DataInfoSpec<InType, OutType, InFP, OutFP>::round_to_int(float f)
return f;
}

template <typename InType, typename OutType, bool InFP, bool OutFP>
long long
DataInfoSpec<InType, OutType, InFP, OutFP>::round_to_int_and_clamp(double f)
template <typename InType, typename OutType>
long long DataInfoSpec<InType, OutType>::round_to_int_and_clamp(double f)
{
static const double magic[2] = { MAKE_HEX_DOUBLE(0x1.0p52, 0x1LL, 52),
MAKE_HEX_DOUBLE(-0x1.0p52, -0x1LL, 52) };
Expand Down Expand Up @@ -314,8 +313,8 @@ DataInfoSpec<InType, OutType, InFP, OutFP>::round_to_int_and_clamp(double f)
return (long long)f;
}

template <typename InType, typename OutType, bool InFP, bool OutFP>
OutType DataInfoSpec<InType, OutType, InFP, OutFP>::absolute(const OutType &x)
template <typename InType, typename OutType>
OutType DataInfoSpec<InType, OutType>::absolute(const OutType &x)
{
union {
cl_uint u;
Expand All @@ -332,8 +331,8 @@ OutType DataInfoSpec<InType, OutType, InFP, OutFP>::absolute(const OutType &x)
return u.f;
}

template <typename InType, typename OutType, bool InFP, bool OutFP>
void DataInfoSpec<InType, OutType, InFP, OutFP>::conv(OutType *out, InType *in)
template <typename InType, typename OutType>
void DataInfoSpec<InType, OutType>::conv(OutType *out, InType *in)
{
if (std::is_same<cl_float, InType>::value)
{
Expand Down Expand Up @@ -480,9 +479,8 @@ void DataInfoSpec<InType, OutType, InFP, OutFP>::conv(OutType *out, InType *in)
#define CLAMP(_lo, _x, _hi) \
((_x) < (_lo) ? (_lo) : ((_x) > (_hi) ? (_hi) : (_x)))

template <typename InType, typename OutType, bool InFP, bool OutFP>
void DataInfoSpec<InType, OutType, InFP, OutFP>::conv_sat(OutType *out,
InType *in)
template <typename InType, typename OutType>
void DataInfoSpec<InType, OutType>::conv_sat(OutType *out, InType *in)
{
if (std::is_floating_point<InType>::value)
{
Expand Down Expand Up @@ -599,9 +597,9 @@ void DataInfoSpec<InType, OutType, InFP, OutFP>::conv_sat(OutType *out,
}
}

template <typename InType, typename OutType, bool InFP, bool OutFP>
void DataInfoSpec<InType, OutType, InFP, OutFP>::init(const cl_uint &job_id,
const cl_uint &thread_id)
template <typename InType, typename OutType>
void DataInfoSpec<InType, OutType>::init(const cl_uint &job_id,
const cl_uint &thread_id)
{
uint64_t ulStart = start;
void *pIn = (char *)gIn + job_id * size * gTypeSizes[inType];
Expand Down Expand Up @@ -761,8 +759,8 @@ void DataInfoSpec<InType, OutType, InFP, OutFP>::init(const cl_uint &job_id,
}
}

template <typename InType, typename OutType, bool InFP, bool OutFP>
InType DataInfoSpec<InType, OutType, InFP, OutFP>::clamp(const InType &in)
template <typename InType, typename OutType>
InType DataInfoSpec<InType, OutType>::clamp(const InType &in)
{
if (std::is_integral<OutType>::value)
{
Expand Down

0 comments on commit 616ef76

Please sign in to comment.