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

Commit 3654a30

Browse files
[SYCL] Add a test for pointer queries with a descendent device (#1232)
1 parent 124e3bd commit 3654a30

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// RUN: %clangxx -fsycl %s -o %t1.out
2+
// RUN: %GPU_RUN_PLACEHOLDER %t1.out
3+
4+
// Use of descendent devices in opencl contexts is not supported yet.
5+
// UNSUPPORTED: opencl
6+
//==------ pointer_query_descendent_device.cpp - Pointer Query test --------==//
7+
//
8+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
9+
// See https://llvm.org/LICENSE.txt for license information.
10+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
11+
//
12+
//===----------------------------------------------------------------------===//
13+
#include <CL/sycl.hpp>
14+
#include <cassert>
15+
16+
std::vector<sycl::device> getSubDevices(sycl::device &Dev) {
17+
uint32_t MaxSubDevices =
18+
Dev.get_info<sycl::info::device::partition_max_sub_devices>();
19+
if (MaxSubDevices == 0)
20+
return {};
21+
try {
22+
return Dev
23+
.create_sub_devices<sycl::info::partition_property::partition_equally>(
24+
1);
25+
} catch (sycl::exception &e) {
26+
assert(e.code() == sycl::errc::feature_not_supported);
27+
}
28+
try {
29+
std::vector<size_t> Counts(MaxSubDevices, 1);
30+
return Dev.create_sub_devices<
31+
sycl::info::partition_property::partition_by_counts>(Counts);
32+
} catch (sycl::exception &e) {
33+
assert(e.code() == sycl::errc::feature_not_supported);
34+
}
35+
try {
36+
return Dev.create_sub_devices<
37+
sycl::info::partition_property::partition_by_affinity_domain>(
38+
sycl::info::partition_affinity_domain::next_partitionable);
39+
} catch (sycl::exception &e) {
40+
assert(e.code() == sycl::errc::feature_not_supported);
41+
}
42+
assert(false &&
43+
"MaxSubDevices is not 0, but none of the partition types worked");
44+
return {};
45+
}
46+
47+
int main() {
48+
sycl::device Dev;
49+
sycl::context Ctx{Dev};
50+
51+
std::vector<sycl::device> SubDevices = getSubDevices(Dev);
52+
if (SubDevices.empty())
53+
return 0;
54+
sycl::queue Q{Ctx, SubDevices[0]};
55+
void *Data = sycl::malloc_device(64, Q);
56+
assert(sycl::get_pointer_type(Data, Ctx) == sycl::usm::alloc::device);
57+
assert(sycl::get_pointer_device(Data, Ctx) == SubDevices[0]);
58+
59+
free(Data, Ctx);
60+
}

0 commit comments

Comments
 (0)