Skip to content

[SYCL] fix for __sycl_unregister_lib() on Windows and tests #19633

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: sycl
Choose a base branch
from

Conversation

cperkinsintel
Copy link
Contributor

__sycl_unregister_lib() is not being called on Windows when using shared libraries due to a limitation in LLVM/clang To work around this, on Windows we register both __sycl_register_lib() and an std::atexit handler that will call __sycl_unregister_lib() . Further, it was discovered that freeing of the device globals during device images destruction is duplicate and unnecessary. The ~context_impl destructor handles that (and handles it correctly, because a context is needed to free USM memory). So we remove the unneeded duplication. Adding a test that stresses __sycl_unregister_lib() and makes sure there are no resource leaks

Signed-off-by: Chris Perkins <[email protected]>
Signed-off-by: Chris Perkins <[email protected]>
@cperkinsintel
Copy link
Contributor Author

PVC failures is unrelated: #19662

@cperkinsintel cperkinsintel marked this pull request as ready for review August 1, 2025 00:10
@cperkinsintel cperkinsintel requested review from a team as code owners August 1, 2025 00:10
Signed-off-by: Chris Perkins <[email protected]>
Signed-off-by: Chris Perkins <[email protected]>
// DEFINE: %{shared_lib_ext} = %if windows %{dll%} %else %{so%}

// clang-format off
// IMPORTANT -DSO_PATH='R"(%T)"' WTF ??
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// IMPORTANT -DSO_PATH='R"(%T)"' WTF ??
// IMPORTANT -DSO_PATH='R"(%T)"'

// Because on Windows, the path delimiters are \,
// which C++ preprocessor converts to escape sequences,
// which becomes a nightmare.
// SO the hack here is to put heredoc in the definition
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// SO the hack here is to put heredoc in the definition
// So the hack here is to put heredoc in the definition

Comment on lines +1 to +4
// UNSUPPORTED: cuda || hip
// UNSUPPORTED-TRACKER: CMPLRLLVM-69415

// REQUIRES: level_zero
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we remove "REQUIRES: level_zero"? It looks like test is supposed to work on OpenCL backend as well.
If you want to additionally check leaks on level_zero backend, then probably something like this should be done:
// RUN: %if level_zero %{%{l0_leak_check} %{run} %t.out 2>&1 | FileCheck %s --implicit-check-not=LEAK %}

RegBuilder.CreateRetVoid();

// Add this function to global destructors.
// Match priority of __tgt_register_lib
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Match priority of __tgt_register_lib
// Match priority of __sycl_register_lib

Comment on lines -306 to -315
{
sycl::detail::DeviceGlobalMap &DeviceGlobalMap = PM.getDeviceGlobals();
EXPECT_EQ(DeviceGlobalMap.size(), ExpectedCount) << Comment;
EXPECT_TRUE(DeviceGlobalMap.count(generateRefName("A", "DeviceGlobal")) > 0)
<< Comment;
EXPECT_TRUE(DeviceGlobalMap.count(generateRefName("B", "DeviceGlobal")) > 0)
<< Comment;
EXPECT_EQ(DeviceGlobalMap.getPointerMap().size(), ExpectedCount) << Comment;
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to add a test for new behavior to compensate the removed test?

@againull
Copy link
Contributor

againull commented Aug 6, 2025

__sycl_unregister_lib() is not being called on Windows when using shared libraries due to a limitation in LLVM/clang

For my own education, could you please point me to some info regarding this limitation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants