Skip to content

Commit 3f21371

Browse files
authored
[SYCL] Fix check-sycl test suite on systems w/o OpenCL (#1503)
get_device_count_by_type cpu opencl return error code if there is OpenCL runtime on the system. This causes LIT config script for check-sycl test suite to report an error w/o running the test suite on the host device. This change makes get_device_cout_by_type return 0 on the system w/o OpenCL runtime to let script handle this situation as normal case. Some code is cleaned up. Signed-off-by: Alexey Bader <[email protected]>
1 parent 1084685 commit 3f21371

File tree

1 file changed

+18
-38
lines changed

1 file changed

+18
-38
lines changed

sycl/tools/get_device_count_by_type.cpp

Lines changed: 18 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
//==-- get_device_count_by_type.cpp - Get device count by type -------------==//
32
//
43
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
@@ -12,7 +11,6 @@
1211

1312
#ifdef USE_PI_CUDA
1413
#include <cuda.h>
15-
// #include <cuda_device_runtime_api.h>
1614
#endif // USE_PI_CUDA
1715

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

39-
const char *deviceTypeToString(cl_device_type deviceType) {
40-
const char *str = "unknown";
37+
static const char *deviceTypeToString(cl_device_type deviceType) {
4138
switch (deviceType) {
4239
case CL_DEVICE_TYPE_CPU:
43-
str = "cpu";
44-
break;
40+
return "cpu";
4541
case CL_DEVICE_TYPE_GPU:
46-
str = "gpu";
47-
break;
42+
return "gpu";
4843
case CL_DEVICE_TYPE_ACCELERATOR:
49-
str = "accelerator";
50-
break;
44+
return "accelerator";
5145
case CL_DEVICE_TYPE_CUSTOM:
52-
str = "custom";
53-
break;
46+
return "custom";
5447
case CL_DEVICE_TYPE_DEFAULT:
55-
str = "default";
56-
break;
48+
return "default";
5749
case CL_DEVICE_TYPE_ALL:
58-
str = "all";
59-
break;
60-
default:
61-
// str already set to express unknown device type.
62-
break;
50+
return "all";
6351
}
6452

65-
return str;
53+
return "unknown";
6654
}
6755

6856
static bool queryOpenCL(cl_device_type deviceType, cl_uint &deviceCount,
6957
std::string &msg) {
7058
deviceCount = 0u;
71-
cl_int iRet = CL_SUCCESS;
72-
cl_uint platformCount = 0;
7359

74-
iRet = clGetPlatformIDs(0, nullptr, &platformCount);
60+
cl_uint platformCount = 0;
61+
cl_int iRet = clGetPlatformIDs(0, nullptr, &platformCount);
7562
if (iRet != CL_SUCCESS) {
7663
if (iRet == CL_PLATFORM_NOT_FOUND_KHR) {
77-
msg = "ERROR: OpenCL error runtime not found";
78-
} else {
79-
std::stringstream stream;
80-
stream << "ERROR: OpenCL error calling clGetPlatformIDs " << iRet
81-
<< std::endl;
82-
msg = stream.str();
64+
msg = "OpenCL error runtime not found";
65+
return true;
8366
}
84-
return false;
67+
std::stringstream stream;
68+
stream << "ERROR: OpenCL error calling clGetPlatformIDs " << iRet
69+
<< std::endl;
70+
msg = stream.str();
71+
return true;
8572
}
8673

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

9784
for (cl_uint i = 0; i < platformCount; i++) {
@@ -100,13 +87,6 @@ static bool queryOpenCL(cl_device_type deviceType, cl_uint &deviceCount,
10087
clGetDeviceIDs(platforms[i], deviceType, 0, nullptr, &deviceCountPart);
10188
if (iRet == CL_SUCCESS || iRet == CL_DEVICE_NOT_FOUND) {
10289
deviceCount += deviceCountPart;
103-
} else {
104-
deviceCount = 0u;
105-
std::stringstream stream;
106-
stream << "ERROR: OpenCL error calling clGetDeviceIDs " << iRet
107-
<< std::endl;
108-
msg = stream.str();
109-
return false;
11090
}
11191
}
11292

0 commit comments

Comments
 (0)