Skip to content

Commit 775dccb

Browse files
[SYCL] Allow empty and unsupported case for component_devices (#13931)
This commit allows the backend to return an empty result or an unsupported-feature error when being queried about component devices. Signed-off-by: Larsen, Steffen <[email protected]>
1 parent 5d839a0 commit 775dccb

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

sycl/source/detail/device_info.hpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1210,11 +1210,22 @@ struct get_device_info_impl<
12101210
return {};
12111211
size_t ResultSize = 0;
12121212
// First call to get DevCount.
1213-
Dev->getPlugin()->call<PiApiKind::piDeviceGetInfo>(
1213+
pi_result Err = Dev->getPlugin()->call_nocheck<PiApiKind::piDeviceGetInfo>(
12141214
Dev->getHandleRef(),
12151215
PiInfoCode<
12161216
ext::oneapi::experimental::info::device::component_devices>::value,
12171217
0, nullptr, &ResultSize);
1218+
1219+
// If the feature is unsupported or if the result was empty, return an empty
1220+
// list of devices.
1221+
if (Err == PI_ERROR_UNSUPPORTED_FEATURE ||
1222+
(Err == PI_SUCCESS && ResultSize == 0))
1223+
return {};
1224+
1225+
// Otherwise, if there was an error from PI it is unexpected and we should
1226+
// handle it accordingly.
1227+
Dev->getPlugin()->checkPiResult(Err);
1228+
12181229
size_t DevCount = ResultSize / sizeof(pi_device);
12191230
// Second call to get the list.
12201231
std::vector<pi_device> Devs(DevCount);

sycl/unittests/Extensions/CompositeDevice.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,22 @@ pi_result after_piDeviceGetInfo_unsupported(pi_device device,
7979
}
8080
}
8181

82+
pi_result after_piDeviceGetInfo_no_component_devices(
83+
pi_device device, pi_device_info param_name, size_t param_value_size,
84+
void *param_value, size_t *param_value_size_ret) {
85+
switch (param_name) {
86+
case PI_EXT_ONEAPI_DEVICE_INFO_COMPOSITE_DEVICE:
87+
return PI_ERROR_UNSUPPORTED_FEATURE;
88+
case PI_EXT_ONEAPI_DEVICE_INFO_COMPONENT_DEVICES:
89+
if (param_value_size_ret)
90+
*param_value_size_ret = 0;
91+
return PI_SUCCESS;
92+
93+
default:
94+
return PI_SUCCESS;
95+
}
96+
}
97+
8298
thread_local std::vector<pi_device> DevicesUsedInContextCreation;
8399

84100
pi_result after_piContextCreate(const pi_context_properties *,
@@ -176,3 +192,19 @@ TEST(CompositeDeviceTest, UnsupportedNegative) {
176192
ASSERT_EQ(E.code(), sycl::make_error_code(sycl::errc::invalid));
177193
}
178194
}
195+
196+
TEST(CompositeDeviceTest, NoComponentDevices) {
197+
sycl::unittest::PiMock Mock;
198+
Mock.redefine<sycl::detail::PiApiKind::piDevicesGet>(redefine_piDevicesGet);
199+
Mock.redefineAfter<sycl::detail::PiApiKind::piDeviceGetInfo>(
200+
after_piDeviceGetInfo_no_component_devices);
201+
202+
sycl::platform Plt = Mock.getPlatform();
203+
204+
sycl::device ComponentDevice = Plt.get_devices()[0];
205+
ASSERT_FALSE(ComponentDevice.has(sycl::aspect::ext_oneapi_is_composite));
206+
207+
std::vector<sycl::device> ComponentDevices = ComponentDevice.get_info<
208+
sycl::ext::oneapi::experimental::info::device::component_devices>();
209+
ASSERT_TRUE(ComponentDevices.empty());
210+
}

0 commit comments

Comments
 (0)