Skip to content

[SYCL] Fix descendent device support for composite/component devices #13513

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion sycl/source/detail/context_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,17 @@ class context_impl {
return hasDevice(Device);

while (!hasDevice(Device)) {
if (Device->isRootDevice())
if (Device->isRootDevice()) {
if (Device->has(aspect::ext_oneapi_is_component)) {
// Component devices should be implicitly usable in context created
// for a composite device they belong to.
auto CompositeDevice = Device->get_info<
ext::oneapi::experimental::info::device::composite_device>();
return hasDevice(detail::getSyclObjImpl(CompositeDevice));
}

return false;
}
Device = detail::getSyclObjImpl(
Device->get_info<info::device::parent_device>());
}
Expand Down
24 changes: 23 additions & 1 deletion sycl/unittests/Extensions/CompositeDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ pi_result after_piContextCreate(const pi_context_properties *,

} // namespace

TEST(CompositeDeviceTest, DescendentDeviceSupport) {
TEST(CompositeDeviceTest, DescendentDeviceSupportInContext) {
sycl::unittest::PiMock Mock(sycl::backend::ext_oneapi_level_zero);
Mock.redefine<sycl::detail::PiApiKind::piDevicesGet>(redefine_piDevicesGet);
Mock.redefineAfter<sycl::detail::PiApiKind::piDeviceGetInfo>(
Expand Down Expand Up @@ -119,3 +119,25 @@ TEST(CompositeDeviceTest, DescendentDeviceSupport) {
ASSERT_EQ(CompositeDevContext.get_devices().size(), 1u);
ASSERT_EQ(CompositeDevContext.get_devices().front(), CompositeDevice);
}

TEST(CompositeDeviceTest, DescendentDeviceSupportInQueue) {
sycl::unittest::PiMock Mock(sycl::backend::ext_oneapi_level_zero);
Mock.redefine<sycl::detail::PiApiKind::piDevicesGet>(redefine_piDevicesGet);
Mock.redefineAfter<sycl::detail::PiApiKind::piDeviceGetInfo>(
after_piDeviceGetInfo);
Mock.redefineAfter<sycl::detail::PiApiKind::piContextCreate>(
after_piContextCreate);

sycl::platform Plt = Mock.getPlatform();
ASSERT_EQ(Plt.get_backend(), sycl::backend::ext_oneapi_level_zero);

sycl::device ComponentDevice = Plt.get_devices()[0];
ASSERT_TRUE(ComponentDevice.has(sycl::aspect::ext_oneapi_is_component));

auto CompositeDevice = ComponentDevice.get_info<
sycl::ext::oneapi::experimental::info::device::composite_device>();
sycl::context CompositeDevContext(CompositeDevice);
// Component device should be implicitly usable as part of composite context,
// so there should be no errors during queue creation below.
sycl::queue Queue(CompositeDevContext, ComponentDevice);
}