Skip to content

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 <chris.perkins@intel.com>
Signed-off-by: Chris Perkins <chris.perkins@intel.com>
Signed-off-by: Chris Perkins <chris.perkins@intel.com>
Signed-off-by: Chris Perkins <chris.perkins@intel.com>
@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 <chris.perkins@intel.com>
Signed-off-by: Chris Perkins <chris.perkins@intel.com>
Signed-off-by: Chris Perkins <chris.perkins@intel.com>
Signed-off-by: Chris Perkins <chris.perkins@intel.com>
@cperkinsintel cperkinsintel marked this pull request as ready for review September 4, 2025 22:33
Copy link
Contributor

@steffenlarsen steffenlarsen left a comment

Choose a reason for hiding this comment

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

Yes! Looks like a solid solution to me! 🚀

@cperkinsintel
Copy link
Contributor Author

@intel/dpcpp-tools-reviewers - ping for review

M.getOrInsertFunction("__sycl_register_lib", RegTargetTy);

// `atexit` takes a `void(*)()` function pointer. In LLVM IR, this is
// typically represented as `i32 (ptr)`.
Copy link
Contributor

Choose a reason for hiding this comment

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

im not sure i understand this comment, to me it seems like the abi would be different so we can't use i32 (ptr) to represent void(*)()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I simplified it. I just wanted to describe atexit.

@uditagarwal97 uditagarwal97 merged commit 61de220 into intel:sycl Sep 8, 2025
59 of 61 checks passed
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.

6 participants