Skip to content

Commit 055c607

Browse files
jbrodmanbader
authored andcommitted
Fix tests to deal with multiple CLs being installed
Signed-off-by: James Brodman <james.brodman@intel.com>
1 parent df410a5 commit 055c607

File tree

2 files changed

+70
-23
lines changed

2 files changed

+70
-23
lines changed

sycl/test/usm/clext.cpp

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,37 @@
1414

1515
using namespace cl::sycl::detail::usm;
1616

17+
static int SIZE = 6;
18+
19+
bool findPlatformAndDevice(cl_device_type deviceType,
20+
cl_platform_id& platformOut,
21+
cl_device_id& deviceOut) {
22+
cl_platform_id platforms[SIZE];
23+
cl_uint numPlatforms;
24+
cl_device_id device;
25+
cl_int errorCode;
26+
bool foundDevice = false;
27+
28+
errorCode = clGetPlatformIDs(SIZE, platforms, &numPlatforms);
29+
30+
for (int i = 0; (!foundDevice) && (i < numPlatforms); i++) {
31+
cl_uint numDevices;
32+
errorCode = clGetDeviceIDs(platforms[i],
33+
deviceType,
34+
1,
35+
&device,
36+
&numDevices);
37+
38+
if (numDevices) {
39+
platformOut = platforms[i];
40+
deviceOut = device;
41+
foundDevice = true;
42+
}
43+
}
44+
45+
return foundDevice;
46+
}
47+
1748
int main(int argc, char** argv) {
1849
if (argc != 2) {
1950
std::cerr << "Please specify -cpu or -gpu!" << std::endl;
@@ -38,22 +69,14 @@ int main(int argc, char** argv) {
3869
: CL_DEVICE_TYPE_GPU;
3970

4071
cl_int errorCode;
41-
4272
cl_platform_id platform;
43-
errorCode = clGetPlatformIDs(1, &platform, nullptr);
44-
45-
GetCLUSM()->initExtensions(platform);
46-
47-
if (errorCode != CL_SUCCESS) return 2;
48-
4973
cl_device_id device;
50-
errorCode = clGetDeviceIDs(platform,
51-
deviceType,
52-
1,
53-
&device,
54-
nullptr);
5574

56-
if (errorCode != CL_SUCCESS) return 3;
75+
if (!findPlatformAndDevice(deviceType, platform, device)) {
76+
return 2;
77+
}
78+
79+
GetCLUSM()->initExtensions(platform);
5780

5881
cl_context_properties ctxtProps[] =
5982
{

sycl/test/usm/clusm.cpp

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,37 @@
1414

1515
using namespace cl::sycl::detail::usm;
1616

17+
static int SIZE = 6;
18+
19+
bool findPlatformAndDevice(cl_device_type deviceType,
20+
cl_platform_id& platformOut,
21+
cl_device_id& deviceOut) {
22+
cl_platform_id platforms[SIZE];
23+
cl_uint numPlatforms;
24+
cl_device_id device;
25+
cl_int errorCode;
26+
bool foundDevice = false;
27+
28+
errorCode = clGetPlatformIDs(SIZE, platforms, &numPlatforms);
29+
30+
for (int i = 0; (!foundDevice) && (i < numPlatforms); i++) {
31+
cl_uint numDevices;
32+
errorCode = clGetDeviceIDs(platforms[i],
33+
deviceType,
34+
1,
35+
&device,
36+
&numDevices);
37+
38+
if (numDevices) {
39+
platformOut = platforms[i];
40+
deviceOut = device;
41+
foundDevice = true;
42+
}
43+
}
44+
45+
return foundDevice;
46+
}
47+
1748
int main(int argc, char** argv) {
1849
if (argc != 2) {
1950
std::cerr << "Please specify -cpu or -gpu!" << std::endl;
@@ -42,18 +73,11 @@ int main(int argc, char** argv) {
4273
cl_int errorCode;
4374

4475
cl_platform_id platform;
45-
errorCode = clGetPlatformIDs(1, &platform, nullptr);
46-
47-
if (errorCode != CL_SUCCESS) return 2;
48-
4976
cl_device_id device;
50-
errorCode = clGetDeviceIDs(platform,
51-
deviceType,
52-
1,
53-
&device,
54-
nullptr);
5577

56-
if (errorCode != CL_SUCCESS) return 3;
78+
if (!findPlatformAndDevice(deviceType, platform, device)) {
79+
return 2;
80+
}
5781

5882
cl_context_properties ctxtProps[] =
5983
{

0 commit comments

Comments
 (0)