Skip to content

Commit 21b59c1

Browse files
committed
Fix findplatforms issue due to CL weirdness for return types. Add multictxt tests.
Signed-off-by: James Brodman <[email protected]>
1 parent b00e08a commit 21b59c1

File tree

5 files changed

+94
-8
lines changed

5 files changed

+94
-8
lines changed

sycl/test/lit.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ if getDeviceCount("cpu"):
9494
print("Found available CPU device")
9595
cpu_run_substitute = "env SYCL_DEVICE_TYPE=CPU "
9696
cpu_check_substitute = "| FileCheck %s"
97+
config.available_features.add('cpu')
9798
config.substitutions.append( ('%CPU_RUN_PLACEHOLDER', cpu_run_substitute) )
9899
config.substitutions.append( ('%CPU_CHECK_PLACEHOLDER', cpu_check_substitute) )
99100

sycl/test/usm/findplatforms.hpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,31 @@
55
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66
//
77
//===----------------------------------------------------------------------===//
8+
#include <iostream>
9+
810
bool findPlatformAndDevice(cl_device_type deviceType,
911
cl_platform_id &platformOut, cl_device_id &deviceOut) {
1012
cl_uint numPlatforms;
1113
cl_int errorCode;
1214

1315
errorCode = clGetPlatformIDs(0, nullptr, &numPlatforms);
14-
if (errorCode != CL_SUCCESS) return false;
1516

1617
std::vector<cl_platform_id> platforms(numPlatforms);
1718
errorCode = clGetPlatformIDs(numPlatforms, platforms.data(), nullptr);
18-
if (errorCode != CL_SUCCESS) return false;
1919

2020
for (auto platform : platforms) {
2121
cl_uint numDevices = 0;
2222
errorCode =
2323
clGetDeviceIDs(platform, deviceType, 0, nullptr, &numDevices);
24-
if (errorCode != CL_SUCCESS) return false;
25-
26-
std::vector<cl_device_id> devices(numDevices);
27-
errorCode = clGetDeviceIDs(platform, deviceType, numDevices,
28-
devices.data(), nullptr);
29-
if (errorCode != CL_SUCCESS) return false;
24+
if (!(errorCode == CL_SUCCESS || errorCode == CL_DEVICE_NOT_FOUND))
25+
return false;
3026

3127
if (numDevices) {
28+
std::vector<cl_device_id> devices(numDevices);
29+
errorCode = clGetDeviceIDs(platform, deviceType, numDevices,
30+
devices.data(), nullptr);
31+
if (errorCode != CL_SUCCESS) return false;
32+
3233
platformOut = platform;
3334
deviceOut = devices[0];
3435
return true;

sycl/test/usm/multictxtcpu.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// REQUIRES: cpu,gpu
2+
// RUN: %clangxx -fsycl %s -o %t1.out -lOpenCL
3+
// RUN: %t1.out
4+
5+
//==----------------- multictxtcpu.cpp - Multi Context USM CPU test --------==//
6+
//
7+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
8+
// See https://llvm.org/LICENSE.txt for license information.
9+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#include <CL/sycl.hpp>
14+
15+
using namespace cl::sycl;
16+
17+
int main() {
18+
queue gpu_q(gpu_selector{});
19+
queue cpu_q(cpu_selector{});
20+
device dev = cpu_q.get_device();
21+
context ctx = cpu_q.get_context();
22+
23+
void *ptr = malloc_shared(128, dev, ctx);
24+
25+
free(ptr, ctx);
26+
27+
return 0;
28+
}

sycl/test/usm/multictxtgpu.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// REQUIRES: cpu, gpu
2+
// RUN: %clangxx -fsycl %s -o %t1.out -lOpenCL
3+
// RUN: %t1.out
4+
5+
//==----------------- multictxtgpu.cpp - Multi Context USM GPU test --------==//
6+
//
7+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
8+
// See https://llvm.org/LICENSE.txt for license information.
9+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#include <CL/sycl.hpp>
14+
15+
using namespace cl::sycl;
16+
17+
int main() {
18+
queue cpu_q(cpu_selector{});
19+
queue gpu_q(gpu_selector{});
20+
device dev = gpu_q.get_device();
21+
context ctx = gpu_q.get_context();
22+
23+
void *ptr = malloc_shared(128, dev, ctx);
24+
25+
free(ptr, ctx);
26+
27+
return 0;
28+
}

sycl/test/usm/multictxtgpu2.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// REQUIRES: cpu, gpu
2+
// RUN: %clangxx -fsycl %s -o %t1.out -lOpenCL
3+
// RUN: %t1.out
4+
5+
//==----------------- multictxtgpu2.cpp - Multi Context USM GPU test -------==//
6+
//
7+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
8+
// See https://llvm.org/LICENSE.txt for license information.
9+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#include <CL/sycl.hpp>
14+
15+
using namespace cl::sycl;
16+
17+
int main() {
18+
queue gpu_q(gpu_selector{});
19+
queue cpu_q(cpu_selector{});
20+
device dev = gpu_q.get_device();
21+
context ctx = gpu_q.get_context();
22+
23+
void *ptr = malloc_shared(128, dev, ctx);
24+
25+
free(ptr, ctx);
26+
27+
return 0;
28+
}

0 commit comments

Comments
 (0)