diff --git a/SYCL/USM/pointer_query_descendent_device.cpp b/SYCL/USM/pointer_query_descendent_device.cpp new file mode 100644 index 0000000000..0913d9d34f --- /dev/null +++ b/SYCL/USM/pointer_query_descendent_device.cpp @@ -0,0 +1,60 @@ +// RUN: %clangxx -fsycl %s -o %t1.out +// RUN: %GPU_RUN_PLACEHOLDER %t1.out + +// Use of descendent devices in opencl contexts is not supported yet. +// UNSUPPORTED: opencl +//==------ pointer_query_descendent_device.cpp - Pointer Query test --------==// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +#include +#include + +std::vector getSubDevices(sycl::device &Dev) { + uint32_t MaxSubDevices = + Dev.get_info(); + if (MaxSubDevices == 0) + return {}; + try { + return Dev + .create_sub_devices( + 1); + } catch (sycl::exception &e) { + assert(e.code() == sycl::errc::feature_not_supported); + } + try { + std::vector Counts(MaxSubDevices, 1); + return Dev.create_sub_devices< + sycl::info::partition_property::partition_by_counts>(Counts); + } catch (sycl::exception &e) { + assert(e.code() == sycl::errc::feature_not_supported); + } + try { + return Dev.create_sub_devices< + sycl::info::partition_property::partition_by_affinity_domain>( + sycl::info::partition_affinity_domain::next_partitionable); + } catch (sycl::exception &e) { + assert(e.code() == sycl::errc::feature_not_supported); + } + assert(false && + "MaxSubDevices is not 0, but none of the partition types worked"); + return {}; +} + +int main() { + sycl::device Dev; + sycl::context Ctx{Dev}; + + std::vector SubDevices = getSubDevices(Dev); + if (SubDevices.empty()) + return 0; + sycl::queue Q{Ctx, SubDevices[0]}; + void *Data = sycl::malloc_device(64, Q); + assert(sycl::get_pointer_type(Data, Ctx) == sycl::usm::alloc::device); + assert(sycl::get_pointer_device(Data, Ctx) == SubDevices[0]); + + free(Data, Ctx); +}