Skip to content

[SYCL] Fix check-sycl test suite on systems w/o OpenCL #1503

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 14, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 18 additions & 38 deletions sycl/tools/get_device_count_by_type.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

//==-- get_device_count_by_type.cpp - Get device count by type -------------==//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
Expand All @@ -12,7 +11,6 @@

#ifdef USE_PI_CUDA
#include <cuda.h>
// #include <cuda_device_runtime_api.h>
#endif // USE_PI_CUDA

#include <algorithm>
Expand All @@ -36,52 +34,41 @@ std::string lowerString(const std::string &str) {
return result;
}

const char *deviceTypeToString(cl_device_type deviceType) {
const char *str = "unknown";
static const char *deviceTypeToString(cl_device_type deviceType) {
switch (deviceType) {
case CL_DEVICE_TYPE_CPU:
str = "cpu";
break;
return "cpu";
case CL_DEVICE_TYPE_GPU:
str = "gpu";
break;
return "gpu";
case CL_DEVICE_TYPE_ACCELERATOR:
str = "accelerator";
break;
return "accelerator";
case CL_DEVICE_TYPE_CUSTOM:
str = "custom";
break;
return "custom";
case CL_DEVICE_TYPE_DEFAULT:
str = "default";
break;
return "default";
case CL_DEVICE_TYPE_ALL:
str = "all";
break;
default:
// str already set to express unknown device type.
break;
return "all";
}

return str;
return "unknown";
}

static bool queryOpenCL(cl_device_type deviceType, cl_uint &deviceCount,
std::string &msg) {
deviceCount = 0u;
cl_int iRet = CL_SUCCESS;
cl_uint platformCount = 0;

iRet = clGetPlatformIDs(0, nullptr, &platformCount);
cl_uint platformCount = 0;
cl_int iRet = clGetPlatformIDs(0, nullptr, &platformCount);
if (iRet != CL_SUCCESS) {
if (iRet == CL_PLATFORM_NOT_FOUND_KHR) {
msg = "ERROR: OpenCL error runtime not found";
} else {
std::stringstream stream;
stream << "ERROR: OpenCL error calling clGetPlatformIDs " << iRet
<< std::endl;
msg = stream.str();
msg = "OpenCL error runtime not found";
return true;
}
return false;
std::stringstream stream;
stream << "ERROR: OpenCL error calling clGetPlatformIDs " << iRet
<< std::endl;
msg = stream.str();
return true;
}

std::vector<cl_platform_id> platforms(platformCount);
Expand All @@ -91,7 +78,7 @@ static bool queryOpenCL(cl_device_type deviceType, cl_uint &deviceCount,
stream << "ERROR: OpenCL error calling clGetPlatformIDs " << iRet
<< std::endl;
msg = stream.str();
return false;
return true;
}

for (cl_uint i = 0; i < platformCount; i++) {
Expand All @@ -100,13 +87,6 @@ static bool queryOpenCL(cl_device_type deviceType, cl_uint &deviceCount,
clGetDeviceIDs(platforms[i], deviceType, 0, nullptr, &deviceCountPart);
if (iRet == CL_SUCCESS || iRet == CL_DEVICE_NOT_FOUND) {
deviceCount += deviceCountPart;
} else {
deviceCount = 0u;
std::stringstream stream;
stream << "ERROR: OpenCL error calling clGetDeviceIDs " << iRet
<< std::endl;
msg = stream.str();
return false;
}
}

Expand Down