Skip to content

Commit 5671d66

Browse files
pbalcerkbenzie
authored andcommitted
[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 4fd28dd commit 5671d66

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

sycl/plugins/unified_runtime/pi2ur.hpp

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -798,12 +798,7 @@ inline pi_result piTearDown(void *PluginParameter) {
798798
return PI_SUCCESS;
799799
}
800800

801-
///////////////////////////////////////////////////////////////////////////////
802-
// Platform
803-
inline pi_result piPlatformsGet(pi_uint32 NumEntries, pi_platform *Platforms,
804-
pi_uint32 *NumPlatforms) {
805-
806-
urInit(0, nullptr);
801+
inline pi_result PiGetAdapter(ur_adapter_handle_t &adapter) {
807802
// We're not going through the UR loader so we're guaranteed to have exactly
808803
// one adapter (whichever is statically linked). The PI plugin for UR has its
809804
// own implementation of piPlatformsGet.
@@ -814,9 +809,23 @@ inline pi_result piPlatformsGet(pi_uint32 NumEntries, pi_platform *Platforms,
814809
[&Ret]() { Ret = urAdapterGet(1, &Adapter, nullptr); });
815810
HANDLE_ERRORS(Ret);
816811

812+
adapter = Adapter;
813+
814+
return PI_SUCCESS;
815+
}
816+
817+
///////////////////////////////////////////////////////////////////////////////
818+
// Platform
819+
inline pi_result piPlatformsGet(pi_uint32 NumEntries, pi_platform *Platforms,
820+
pi_uint32 *NumPlatforms) {
821+
ur_adapter_handle_t adapter = nullptr;
822+
if (auto res = PiGetAdapter(adapter); res != PI_SUCCESS) {
823+
return res;
824+
}
825+
817826
auto phPlatforms = reinterpret_cast<ur_platform_handle_t *>(Platforms);
818827
HANDLE_ERRORS(
819-
urPlatformGet(&Adapter, 1, NumEntries, phPlatforms, NumPlatforms));
828+
urPlatformGet(&adapter, 1, NumEntries, phPlatforms, NumPlatforms));
820829
return PI_SUCCESS;
821830
}
822831

@@ -843,6 +852,12 @@ piextPlatformCreateWithNativeHandle(pi_native_handle NativeHandle,
843852
PI_ASSERT(Platform, PI_ERROR_INVALID_PLATFORM);
844853
PI_ASSERT(NativeHandle, PI_ERROR_INVALID_VALUE);
845854

855+
ur_adapter_handle_t adapter = nullptr;
856+
if (auto res = PiGetAdapter(adapter); res != PI_SUCCESS) {
857+
return res;
858+
}
859+
(void)adapter;
860+
846861
ur_platform_handle_t UrPlatform{};
847862
ur_native_handle_t UrNativeHandle =
848863
reinterpret_cast<ur_native_handle_t>(NativeHandle);

0 commit comments

Comments
 (0)