Skip to content
This repository was archived by the owner on Mar 28, 2023. It is now read-only.

Commit 26e147d

Browse files
[SYCL] tests to validate sub-devices have parent (or not) (#1346)
These are the tests for intel/llvm#7167 All devices available when using ONEAPI_DEVICE_SELECTOR are root devices, even those which are gotten via the sub-device selection choices ( e.g. ONEAPI_DEVICE_SELECTOR=level_zero:*.* ). In this PR we are ensuring that all devices gotten with that environment variable are root devices that have no parent. And, conversely, that when not using it, any sub-devices do report the correct parent.
1 parent cb7d25a commit 26e147d

File tree

1 file changed

+79
-0
lines changed

1 file changed

+79
-0
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
// works on PVC or ATS, however, the gpu-intel-gen12 identifier seems to
2+
// not be working with REQUIRES ,
3+
// TODO : fix gpu-intel-XXXX identifiers for REQUIRE and UNSUPPORTED
4+
5+
// REQUIRES: gpu
6+
7+
// open question on whether this will work with CUDA or Hip.
8+
9+
// RUN: %clangxx -fsycl %s -o %t.out
10+
11+
// select sub-devices
12+
// ONEAPI_DEVICE_SELECTOR=(any backend):(any
13+
// device).(all-the-sub-devices).(all-sub-sub-devices)
14+
// RUN: env ONEAPI_DEVICE_SELECTOR="*:*.*" %t.out
15+
// RUN: env ONEAPI_DEVICE_SELECTOR="*:*.*.*" %t.out
16+
17+
// select root devices and pass arg to test so it knows.
18+
// RUN: env ONEAPI_DEVICE_SELECTOR="*:gpu" %t.out 1
19+
// RUN: %t.out 1
20+
21+
#include <sycl/sycl.hpp>
22+
using namespace sycl;
23+
24+
int main(int Argc, const char *Argv[]) {
25+
std::vector<device> devices = device::get_devices();
26+
std::cout << devices.size() << " devices found." << std::endl;
27+
// root devices, no matter the selector should not have parents.
28+
for (const device &dev : devices) {
29+
std::cout << "name: " << dev.get_info<info::device::name>() << std::endl;
30+
try {
31+
// unlike sub-devices gotten from device.get_info<device::parent_device>
32+
// sub-devices gotten via ONEAPI_DEVICE_SELECTOR pretend to be root
33+
// devices and do NOT have parents.
34+
device parentDev = dev.get_info<info::device::parent_device>();
35+
std::cout << "unexpected parent name: "
36+
<< parentDev.get_info<info::device::name>() << std::endl;
37+
assert(false && "we should not be here. asking for a parent should throw "
38+
"an exception");
39+
40+
} catch (sycl::exception &e) {
41+
std::cout << "Yay. No parent device gotten" << std::endl;
42+
}
43+
}
44+
// any argument indicates "normal" usage, no sub-devices promoted by
45+
// ONEAPI_DEVICE_SELECTOR
46+
if (Argc > 1) {
47+
constexpr info::partition_property partitionProperty =
48+
info::partition_property::partition_by_affinity_domain;
49+
constexpr info::partition_affinity_domain affinityDomain =
50+
info::partition_affinity_domain::next_partitionable;
51+
device d = device(gpu_selector_v);
52+
try {
53+
std::vector<device> sub_devices =
54+
d.create_sub_devices<partitionProperty>(affinityDomain);
55+
for (const device &sub_dev : sub_devices) {
56+
std::cout << "child name: " << sub_dev.get_info<info::device::name>()
57+
<< std::endl;
58+
try {
59+
// sub-devices gotten from device.get_info<device::parent_device>
60+
// should have parents.
61+
device parentDev = sub_dev.get_info<info::device::parent_device>();
62+
std::cout << "cool parent name: "
63+
<< parentDev.get_info<info::device::name>() << std::endl;
64+
} catch (sycl::exception &e) {
65+
std::cout << "exception: " << e.what() << std::endl;
66+
assert(false && "we should not be here. asking for a parent of a "
67+
"sub-device should NOT throw an exception ");
68+
}
69+
}
70+
} catch (sycl::exception &e) {
71+
// whatever GPU device we are on does not support sub-devices at all.
72+
// Nothing to do.
73+
std::cout << "this device " << d.get_info<info::device::name>()
74+
<< " does not support sub-devices. Nothing tested."
75+
<< std::endl;
76+
}
77+
}
78+
return 0;
79+
}

0 commit comments

Comments
 (0)