Skip to content

Commit 156a67e

Browse files
authored
[UR] Handle cases where UR can't provide IP ver. (#15169)
UR may respond with `UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION` when querying for the device's IP version. This patch handles that case by falling back to unknown or x86_64. Closes: #15149
1 parent bac6fe6 commit 156a67e

File tree

3 files changed

+61
-25
lines changed

3 files changed

+61
-25
lines changed

sycl/source/detail/device_info.hpp

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -688,22 +688,31 @@ struct get_device_info_impl<
688688
ext::oneapi::experimental::info::device::architecture> {
689689
static ext::oneapi::experimental::architecture get(const DeviceImplPtr &Dev) {
690690
backend CurrentBackend = Dev->getBackend();
691-
if (Dev->is_gpu() && (backend::ext_oneapi_level_zero == CurrentBackend ||
692-
backend::opencl == CurrentBackend)) {
693-
auto MapArchIDToArchName = [](const int arch) {
694-
for (const auto &Item : IntelGPUArchitectures) {
695-
if (Item.first == arch)
696-
return Item.second;
697-
}
698-
return ext::oneapi::experimental::architecture::unknown;
699-
};
691+
auto LookupIPVersion = [&](auto &ArchList)
692+
-> std::optional<ext::oneapi::experimental::architecture> {
700693
uint32_t DeviceIp;
701-
Dev->getPlugin()->call(
694+
ur_result_t Err = Dev->getPlugin()->call_nocheck(
702695
urDeviceGetInfo, Dev->getHandleRef(),
703696
UrInfoCode<
704697
ext::oneapi::experimental::info::device::architecture>::value,
705698
sizeof(DeviceIp), &DeviceIp, nullptr);
706-
return MapArchIDToArchName(DeviceIp);
699+
if (Err == UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION) {
700+
// Not all devices support this device info query
701+
return std::nullopt;
702+
}
703+
Dev->getPlugin()->checkUrResult(Err);
704+
705+
for (const auto &Item : ArchList) {
706+
if (Item.first == static_cast<int>(DeviceIp))
707+
return Item.second;
708+
}
709+
return std::nullopt;
710+
};
711+
712+
if (Dev->is_gpu() && (backend::ext_oneapi_level_zero == CurrentBackend ||
713+
backend::opencl == CurrentBackend)) {
714+
return LookupIPVersion(IntelGPUArchitectures)
715+
.value_or(ext::oneapi::experimental::architecture::unknown);
707716
} else if (Dev->is_gpu() && (backend::ext_oneapi_cuda == CurrentBackend ||
708717
backend::ext_oneapi_hip == CurrentBackend)) {
709718
auto MapArchIDToArchName = [](const char *arch) {
@@ -726,20 +735,8 @@ struct get_device_info_impl<
726735
DeviceArchCopy.substr(0, DeviceArchCopy.find(":"));
727736
return MapArchIDToArchName(DeviceArchSubstr.data());
728737
} else if (Dev->is_cpu() && backend::opencl == CurrentBackend) {
729-
auto MapArchIDToArchName = [](const int arch) {
730-
for (const auto &Item : IntelCPUArchitectures) {
731-
if (Item.first == arch)
732-
return Item.second;
733-
}
734-
return sycl::ext::oneapi::experimental::architecture::x86_64;
735-
};
736-
uint32_t DeviceIp;
737-
Dev->getPlugin()->call(
738-
urDeviceGetInfo, Dev->getHandleRef(),
739-
UrInfoCode<
740-
ext::oneapi::experimental::info::device::architecture>::value,
741-
sizeof(DeviceIp), &DeviceIp, nullptr);
742-
return MapArchIDToArchName(DeviceIp);
738+
return LookupIPVersion(IntelCPUArchitectures)
739+
.value_or(ext::oneapi::experimental::architecture::x86_64);
743740
} // else is not needed
744741
// TODO: add support of other architectures by extending with else if
745742
return ext::oneapi::experimental::architecture::unknown;

sycl/unittests/Extensions/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ add_sycl_unittest(ExtensionsTests OBJECT
1414
DiscardEvent.cpp
1515
ProfilingTag.cpp
1616
KernelProperties.cpp
17+
NoDeviceIPVersion.cpp
1718
)
1819

1920
add_subdirectory(CommandGraph)
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
//==------------------- NoDeviceIPVersion.cpp ------------------------------==//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include "sycl/ext/oneapi/experimental/device_architecture.hpp"
10+
#include <gtest/gtest.h>
11+
#include <helpers/UrMock.hpp>
12+
#include <sycl/sycl.hpp>
13+
14+
static ur_result_t afterDeviceGetInfo(void *pParams) {
15+
auto params = *static_cast<ur_device_get_info_params_t *>(pParams);
16+
if (*params.ppropName == UR_DEVICE_INFO_IP_VERSION) {
17+
return UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION;
18+
}
19+
return UR_RESULT_SUCCESS;
20+
}
21+
22+
namespace syclex = sycl::ext::oneapi::experimental;
23+
TEST(NoDeviceIPVersionTest, NoDeviceIPVersion) {
24+
sycl::unittest::UrMock<> Mock;
25+
mock::getCallbacks().set_after_callback("urDeviceGetInfo",
26+
&afterDeviceGetInfo);
27+
sycl::platform Plt = sycl::platform();
28+
auto Dev = Plt.get_devices()[0];
29+
if (Dev.get_backend() != sycl::backend::opencl &&
30+
Dev.get_backend() != sycl::backend::ext_oneapi_level_zero) {
31+
GTEST_SKIP();
32+
}
33+
34+
syclex::architecture DevArch =
35+
Dev.get_info<syclex::info::device::architecture>();
36+
ASSERT_TRUE(DevArch == syclex::architecture::unknown ||
37+
DevArch == syclex::architecture::x86_64);
38+
}

0 commit comments

Comments
 (0)