Skip to content

Commit

Permalink
Make Version function to_uint() for consistency
Browse files Browse the repository at this point in the history
Includes fix for MacOS build error

Contributes #787

Signed-off-by: Ellen Norris-Thompson <ellen.norris-thompson@arm.com>
  • Loading branch information
ellnor01 committed Feb 10, 2021
1 parent a0e012e commit f46c622
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 15 deletions.
2 changes: 1 addition & 1 deletion test_common/harness/kernelHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1745,7 +1745,7 @@ Version get_device_cl_c_version(cl_device_id device)
auto major = opencl_c_version[opencl_c_version.find('.') - 1];
auto minor = opencl_c_version[opencl_c_version.find('.') + 1];

return Version{ (uint)(major - '0'), (uint)(minor - '0') };
return Version{ (cl_uint)(major - '0'), (cl_uint)(minor - '0') };
}

Version get_device_latest_cl_c_version(cl_device_id device)
Expand Down
4 changes: 2 additions & 2 deletions test_common/harness/rounding_mode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ void *FlushToZero(void)
#if defined(__APPLE__) || defined(__linux__) || defined(_WIN32)
#if defined(__i386__) || defined(__x86_64__) || defined(_MSC_VER)
union {
uint i;
unsigned int i;
void *p;
} u = { _mm_getcsr() };
_mm_setcsr(u.i | 0x8040);
Expand Down Expand Up @@ -235,7 +235,7 @@ void UnFlushToZero(void *p)
#if defined(__i386__) || defined(__x86_64__) || defined(_MSC_VER)
union {
void *p;
uint i;
unsigned int i;
} u = { p };
_mm_setcsr(u.i);
#elif defined(__arm__) || defined(__aarch64__)
Expand Down
24 changes: 15 additions & 9 deletions test_common/harness/testHarness.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,28 @@
class Version {
public:
Version(): m_major(0), m_minor(0) {}
Version(uint major, uint minor): m_major(major), m_minor(minor) {}
bool operator>(const Version &rhs) const { return to_int() > rhs.to_int(); }
bool operator<(const Version &rhs) const { return to_int() < rhs.to_int(); }
Version(cl_uint major, cl_uint minor): m_major(major), m_minor(minor) {}
bool operator>(const Version &rhs) const
{
return to_uint() > rhs.to_uint();
}
bool operator<(const Version &rhs) const
{
return to_uint() < rhs.to_uint();
}
bool operator<=(const Version &rhs) const
{
return to_int() <= rhs.to_int();
return to_uint() <= rhs.to_uint();
}
bool operator>=(const Version &rhs) const
{
return to_int() >= rhs.to_int();
return to_uint() >= rhs.to_uint();
}
bool operator==(const Version &rhs) const
{
return to_int() == rhs.to_int();
return to_uint() == rhs.to_uint();
}
int to_int() const { return m_major * 10 + m_minor; }
cl_uint to_uint() const { return m_major * 10 + m_minor; }
std::string to_string() const
{
std::stringstream ss;
Expand All @@ -50,8 +56,8 @@ class Version {
}

private:
uint m_major;
uint m_minor;
cl_uint m_major;
cl_uint m_minor;
};

Version get_device_cl_version(cl_device_id device);
Expand Down
8 changes: 5 additions & 3 deletions test_conformance/basic/test_preprocessors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ int test_kernel_preprocessor_macros(cl_device_id deviceID, cl_context context, c
// The OpenCL version reported by the macro reports the feature level supported by the compiler. Since
// this doesn't directly match any property we can query, we just check to see if it's a sane value
auto device_cl_version = get_device_cl_version(deviceID);
int device_cl_version_int = device_cl_version.to_int() * 10;
int device_cl_version_int = device_cl_version.to_uint() * 10;
if ((results[2] < 100) || (results[2] > device_cl_version_int))
{
log_error("ERROR: Kernel preprocessor __OPENCL_VERSION__ does not make "
Expand All @@ -241,14 +241,16 @@ int test_kernel_preprocessor_macros(cl_device_id deviceID, cl_context context, c
int cl_c_minor_version = (results[3] / 10) % 10;
if ((results[3] < 100)
|| (!device_supports_cl_c_version(
deviceID, Version{ cl_c_major_version, cl_c_minor_version })))
deviceID,
Version{ (cl_uint)cl_c_major_version,
(cl_uint)cl_c_minor_version })))
{
auto device_version = get_device_cl_c_version(deviceID);
log_error(
"ERROR: Kernel preprocessor __OPENCL_C_VERSION__ does not make "
"sense w.r.t. device's version string! "
"(preprocessor states %d, CL_DEVICE_OPENCL_C_VERSION is %d (%s))\n",
results[3], device_version.to_int() * 10,
results[3], device_version.to_uint() * 10,
device_version.to_string().c_str());
log_error("This means that CL_DEVICE_OPENCL_C_VERSION < "
"__OPENCL_C_VERSION__");
Expand Down

0 comments on commit f46c622

Please sign in to comment.