Skip to content

Commit 269a0af

Browse files
[SYCL] Fix descendent device support for composite/component devices (#13513)
Fixed a case where it was not possible to create a queue for a component device using context for a composite device.
1 parent 9191ceb commit 269a0af

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

sycl/source/detail/context_impl.hpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,17 @@ class context_impl {
186186
return hasDevice(Device);
187187

188188
while (!hasDevice(Device)) {
189-
if (Device->isRootDevice())
189+
if (Device->isRootDevice()) {
190+
if (Device->has(aspect::ext_oneapi_is_component)) {
191+
// Component devices should be implicitly usable in context created
192+
// for a composite device they belong to.
193+
auto CompositeDevice = Device->get_info<
194+
ext::oneapi::experimental::info::device::composite_device>();
195+
return hasDevice(detail::getSyclObjImpl(CompositeDevice));
196+
}
197+
190198
return false;
199+
}
191200
Device = detail::getSyclObjImpl(
192201
Device->get_info<info::device::parent_device>());
193202
}

sycl/unittests/Extensions/CompositeDevice.cpp

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ pi_result after_piContextCreate(const pi_context_properties *,
7979

8080
} // namespace
8181

82-
TEST(CompositeDeviceTest, DescendentDeviceSupport) {
82+
TEST(CompositeDeviceTest, DescendentDeviceSupportInContext) {
8383
sycl::unittest::PiMock Mock(sycl::backend::ext_oneapi_level_zero);
8484
Mock.redefine<sycl::detail::PiApiKind::piDevicesGet>(redefine_piDevicesGet);
8585
Mock.redefineAfter<sycl::detail::PiApiKind::piDeviceGetInfo>(
@@ -119,3 +119,25 @@ TEST(CompositeDeviceTest, DescendentDeviceSupport) {
119119
ASSERT_EQ(CompositeDevContext.get_devices().size(), 1u);
120120
ASSERT_EQ(CompositeDevContext.get_devices().front(), CompositeDevice);
121121
}
122+
123+
TEST(CompositeDeviceTest, DescendentDeviceSupportInQueue) {
124+
sycl::unittest::PiMock Mock(sycl::backend::ext_oneapi_level_zero);
125+
Mock.redefine<sycl::detail::PiApiKind::piDevicesGet>(redefine_piDevicesGet);
126+
Mock.redefineAfter<sycl::detail::PiApiKind::piDeviceGetInfo>(
127+
after_piDeviceGetInfo);
128+
Mock.redefineAfter<sycl::detail::PiApiKind::piContextCreate>(
129+
after_piContextCreate);
130+
131+
sycl::platform Plt = Mock.getPlatform();
132+
ASSERT_EQ(Plt.get_backend(), sycl::backend::ext_oneapi_level_zero);
133+
134+
sycl::device ComponentDevice = Plt.get_devices()[0];
135+
ASSERT_TRUE(ComponentDevice.has(sycl::aspect::ext_oneapi_is_component));
136+
137+
auto CompositeDevice = ComponentDevice.get_info<
138+
sycl::ext::oneapi::experimental::info::device::composite_device>();
139+
sycl::context CompositeDevContext(CompositeDevice);
140+
// Component device should be implicitly usable as part of composite context,
141+
// so there should be no errors during queue creation below.
142+
sycl::queue Queue(CompositeDevContext, ComponentDevice);
143+
}

0 commit comments

Comments
 (0)