Skip to content

Commit 5f6dc36

Browse files
authored
[UR] call urGetAdapter before creating a platform from native handle (#12432)
Calling urAdapterGet is required for the global adapter to be initialized, but it was missing when creating a platform from a native handle. This meant that the adapter's state never got initialized and its refcount remained at 0 (and overflowed on teardown). This had no visible side-effects until changes in #12403.
1 parent b04f894 commit 5f6dc36

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

sycl/plugins/unified_runtime/pi2ur.hpp

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -794,11 +794,7 @@ inline pi_result piTearDown(void *PluginParameter) {
794794
return PI_SUCCESS;
795795
}
796796

797-
///////////////////////////////////////////////////////////////////////////////
798-
// Platform
799-
inline pi_result piPlatformsGet(pi_uint32 NumEntries, pi_platform *Platforms,
800-
pi_uint32 *NumPlatforms) {
801-
797+
inline pi_result PiGetAdapter(ur_adapter_handle_t &adapter) {
802798
// We're not going through the UR loader so we're guaranteed to have exactly
803799
// one adapter (whichever is statically linked). The PI plugin for UR has its
804800
// own implementation of piPlatformsGet.
@@ -809,9 +805,23 @@ inline pi_result piPlatformsGet(pi_uint32 NumEntries, pi_platform *Platforms,
809805
[&Ret]() { Ret = urAdapterGet(1, &Adapter, nullptr); });
810806
HANDLE_ERRORS(Ret);
811807

808+
adapter = Adapter;
809+
810+
return PI_SUCCESS;
811+
}
812+
813+
///////////////////////////////////////////////////////////////////////////////
814+
// Platform
815+
inline pi_result piPlatformsGet(pi_uint32 NumEntries, pi_platform *Platforms,
816+
pi_uint32 *NumPlatforms) {
817+
ur_adapter_handle_t adapter = nullptr;
818+
if (auto res = PiGetAdapter(adapter); res != PI_SUCCESS) {
819+
return res;
820+
}
821+
812822
auto phPlatforms = reinterpret_cast<ur_platform_handle_t *>(Platforms);
813823
HANDLE_ERRORS(
814-
urPlatformGet(&Adapter, 1, NumEntries, phPlatforms, NumPlatforms));
824+
urPlatformGet(&adapter, 1, NumEntries, phPlatforms, NumPlatforms));
815825
return PI_SUCCESS;
816826
}
817827

@@ -838,6 +848,12 @@ piextPlatformCreateWithNativeHandle(pi_native_handle NativeHandle,
838848
PI_ASSERT(Platform, PI_ERROR_INVALID_PLATFORM);
839849
PI_ASSERT(NativeHandle, PI_ERROR_INVALID_VALUE);
840850

851+
ur_adapter_handle_t adapter = nullptr;
852+
if (auto res = PiGetAdapter(adapter); res != PI_SUCCESS) {
853+
return res;
854+
}
855+
(void)adapter;
856+
841857
ur_platform_handle_t UrPlatform{};
842858
ur_native_handle_t UrNativeHandle =
843859
reinterpret_cast<ur_native_handle_t>(NativeHandle);

0 commit comments

Comments
 (0)