Skip to content

Commit 0cc31ce

Browse files
[SYCL] Fix exception thrown for composite_devices query (#13868)
The sycl_ext_oneapi_composite_device extension specifies that the composite_devices query should throw if a device returns false for device::has with ext_oneapi_is_composite. However, the current implementation simply returns an empty device list if the backend of the device is not L0. This commit fixes this discrepancy. Signed-off-by: Larsen, Steffen <[email protected]>
1 parent 17e589e commit 0cc31ce

File tree

3 files changed

+43
-10
lines changed

3 files changed

+43
-10
lines changed

sycl/source/detail/device_impl.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -697,14 +697,14 @@ bool device_impl::has(aspect Aspect) const {
697697
if (getBackend() != backend::ext_oneapi_level_zero)
698698
return false;
699699

700-
typename sycl_to_pi<device>::type Result;
701-
getPlugin()->call<PiApiKind::piDeviceGetInfo>(
702-
getHandleRef(),
703-
PiInfoCode<
704-
ext::oneapi::experimental::info::device::composite_device>::value,
705-
sizeof(Result), &Result, nullptr);
706-
707-
return Result != nullptr;
700+
typename sycl_to_pi<device>::type Result = nullptr;
701+
bool CallSuccessful = getPlugin()->call_nocheck<PiApiKind::piDeviceGetInfo>(
702+
getHandleRef(),
703+
PiInfoCode<ext::oneapi::experimental::info::
704+
device::composite_device>::value,
705+
sizeof(Result), &Result, nullptr) == PI_SUCCESS;
706+
707+
return CallSuccessful && Result != nullptr;
708708
}
709709
case aspect::ext_oneapi_graph: {
710710
pi_bool SupportsCommandBufferUpdate = false;

sycl/source/detail/device_info.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1235,8 +1235,6 @@ template <>
12351235
struct get_device_info_impl<
12361236
sycl::device, ext::oneapi::experimental::info::device::composite_device> {
12371237
static sycl::device get(const DeviceImplPtr &Dev) {
1238-
if (Dev->getBackend() != backend::ext_oneapi_level_zero)
1239-
return {};
12401238
if (!Dev->has(sycl::aspect::ext_oneapi_is_component))
12411239
throw sycl::exception(make_error_code(errc::invalid),
12421240
"Only devices with aspect::ext_oneapi_is_component "

sycl/unittests/Extensions/CompositeDevice.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,21 @@ pi_result after_piDeviceGetInfo(pi_device device, pi_device_info param_name,
6464
}
6565
}
6666

67+
pi_result after_piDeviceGetInfo_unsupported(pi_device device,
68+
pi_device_info param_name,
69+
size_t param_value_size,
70+
void *param_value,
71+
size_t *param_value_size_ret) {
72+
switch (param_name) {
73+
case PI_EXT_ONEAPI_DEVICE_INFO_COMPOSITE_DEVICE:
74+
case PI_EXT_ONEAPI_DEVICE_INFO_COMPONENT_DEVICES:
75+
return PI_ERROR_UNSUPPORTED_FEATURE;
76+
77+
default:
78+
return PI_SUCCESS;
79+
}
80+
}
81+
6782
thread_local std::vector<pi_device> DevicesUsedInContextCreation;
6883

6984
pi_result after_piContextCreate(const pi_context_properties *,
@@ -141,3 +156,23 @@ TEST(CompositeDeviceTest, DescendentDeviceSupportInQueue) {
141156
// so there should be no errors during queue creation below.
142157
sycl::queue Queue(CompositeDevContext, ComponentDevice);
143158
}
159+
160+
TEST(CompositeDeviceTest, UnsupportedNegative) {
161+
// For the unsupported case, the backend does not need to be L0.
162+
sycl::unittest::PiMock Mock;
163+
Mock.redefine<sycl::detail::PiApiKind::piDevicesGet>(redefine_piDevicesGet);
164+
Mock.redefineAfter<sycl::detail::PiApiKind::piDeviceGetInfo>(
165+
after_piDeviceGetInfo_unsupported);
166+
167+
sycl::platform Plt = Mock.getPlatform();
168+
169+
sycl::device ComponentDevice = Plt.get_devices()[0];
170+
ASSERT_FALSE(ComponentDevice.has(sycl::aspect::ext_oneapi_is_component));
171+
172+
try {
173+
std::ignore = ComponentDevice.get_info<
174+
sycl::ext::oneapi::experimental::info::device::composite_device>();
175+
} catch (sycl::exception &E) {
176+
ASSERT_EQ(E.code(), sycl::make_error_code(sycl::errc::invalid));
177+
}
178+
}

0 commit comments

Comments
 (0)