-
Notifications
You must be signed in to change notification settings - Fork 792
[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
Merged
uditagarwal97
merged 17 commits into
intel:sycl
from
cperkinsintel:cperkins-win-fix-sycl-unregister-lib
Sep 8, 2025
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
c480714
fix for __sycl_unregister_lib() on Windows and tests
cperkinsintel 8c1905e
no sycl.hpp in tests
cperkinsintel 8688a67
test fixes
cperkinsintel 6742db0
better to ask forgiveness than permission
cperkinsintel 154eaf0
unsupported-tracker
cperkinsintel 44bef0d
comment
cperkinsintel d8bc95a
reviewer feedback
cperkinsintel 496c746
resolve merge conflicts
cperkinsintel d1c48c8
bump to latest SYCL and reprise fix
cperkinsintel c415c15
Merge branch 'sycl' into cperkins-win-fix-sycl-unregister-lib
cperkinsintel 455bdf8
merge conflicts resolved
cperkinsintel e2458f3
reviewer feedback
cperkinsintel c6afa75
interim commit for testing on Win
cperkinsintel 843a961
record
cperkinsintel a6ef7e0
move to weak_ptr and avoid double dispose
cperkinsintel 8c7d1d5
logging to try to get insight into CI issue
cperkinsintel 2a193e0
reviewer feedback, comment changes
cperkinsintel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1293,6 +1293,48 @@ class BinaryWrapper { | |
appendToGlobalDtors(M, Func, /*Priority*/ 1); | ||
} | ||
|
||
void createSyclRegisterWithAtexitUnregister(GlobalVariable *BinDesc) { | ||
auto *UnregFuncTy = | ||
FunctionType::get(Type::getVoidTy(C), /*isVarArg*/ false); | ||
auto *UnregFunc = | ||
Function::Create(UnregFuncTy, GlobalValue::InternalLinkage, | ||
"sycl.descriptor_unreg.atexit", &M); | ||
UnregFunc->setSection(".text.startup"); | ||
|
||
// Declaration for __sycl_unregister_lib(void*). | ||
auto *UnregTargetTy = | ||
FunctionType::get(Type::getVoidTy(C), getPtrTy(), /*isVarArg=*/false); | ||
FunctionCallee UnregTargetC = | ||
M.getOrInsertFunction("__sycl_unregister_lib", UnregTargetTy); | ||
|
||
IRBuilder<> UnregBuilder(BasicBlock::Create(C, "entry", UnregFunc)); | ||
UnregBuilder.CreateCall(UnregTargetC, BinDesc); | ||
UnregBuilder.CreateRetVoid(); | ||
|
||
auto *RegFuncTy = FunctionType::get(Type::getVoidTy(C), /*isVarArg*/ false); | ||
auto *RegFunc = Function::Create(RegFuncTy, GlobalValue::InternalLinkage, | ||
"sycl.descriptor_reg", &M); | ||
RegFunc->setSection(".text.startup"); | ||
|
||
auto *RegTargetTy = | ||
FunctionType::get(Type::getVoidTy(C), getPtrTy(), false); | ||
FunctionCallee RegTargetC = | ||
M.getOrInsertFunction("__sycl_register_lib", RegTargetTy); | ||
|
||
// `atexit` takes a `void(*)()` function pointer arg and returns an i32. | ||
FunctionType *AtExitTy = | ||
FunctionType::get(Type::getInt32Ty(C), getPtrTy(), false); | ||
FunctionCallee AtExitC = M.getOrInsertFunction("atexit", AtExitTy); | ||
|
||
IRBuilder<> RegBuilder(BasicBlock::Create(C, "entry", RegFunc)); | ||
RegBuilder.CreateCall(RegTargetC, BinDesc); | ||
RegBuilder.CreateCall(AtExitC, UnregFunc); | ||
RegBuilder.CreateRetVoid(); | ||
|
||
// Add this function to global destructors. | ||
appendToGlobalCtors(M, RegFunc, /*Priority*/ 1); | ||
} | ||
|
||
public: | ||
BinaryWrapper(StringRef Target, StringRef ToolName, | ||
StringRef SymPropBCFiles = "") | ||
|
@@ -1370,8 +1412,13 @@ class BinaryWrapper { | |
|
||
if (EmitRegFuncs) { | ||
GlobalVariable *Desc = *DescOrErr; | ||
createRegisterFunction(Kind, Desc); | ||
createUnregisterFunction(Kind, Desc); | ||
if (Kind == OffloadKind::SYCL && | ||
Triple(M.getTargetTriple()).isOSWindows()) { | ||
createSyclRegisterWithAtexitUnregister(Desc); | ||
} else { | ||
createRegisterFunction(Kind, Desc); | ||
createUnregisterFunction(Kind, Desc); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It doesn't necessarily have to be part of this patch, but could you please document this approach in a design document? |
||
} | ||
} | ||
return &M; | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
// UNSUPPORTED: hip | ||
// UNSUPPORTED-TRACKER: CMPLRLLVM-69478 | ||
|
||
// RUN: %{build} -o %t.out | ||
// RUN: %{run} %t.out | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#include <sycl/detail/core.hpp> | ||
|
||
#if defined(_WIN32) | ||
#define API_EXPORT __declspec(dllexport) | ||
#else | ||
#define API_EXPORT | ||
#endif | ||
|
||
#ifndef INC | ||
#define INC 1 | ||
#endif | ||
|
||
#ifndef CLASSNAME | ||
#define CLASSNAME same | ||
#endif | ||
|
||
#ifdef WITH_DEVICE_GLOBALS | ||
// Using device globals within the shared libraries only | ||
// works if the names do not collide. Note that we cannot | ||
// load a library multiple times if it has a device global. | ||
#define CONCAT_HELPER(a, b) a##b | ||
#define CONCAT(a, b) CONCAT_HELPER(a, b) | ||
|
||
using SomeProperties = decltype(sycl::ext::oneapi::experimental::properties{}); | ||
sycl::ext::oneapi::experimental::device_global<int, SomeProperties> | ||
CONCAT(DGVar, CLASSNAME) __attribute__((visibility("default"))); | ||
|
||
#endif // WITH_DEVICE_GLOBALS | ||
|
||
extern "C" API_EXPORT void performIncrementation(sycl::queue &q, | ||
sycl::buffer<int, 1> &buf) { | ||
sycl::range<1> r = buf.get_range(); | ||
q.submit([&](sycl::handler &cgh) { | ||
auto acc = buf.get_access<sycl::access::mode::write>(cgh); | ||
cgh.parallel_for<class CLASSNAME>( | ||
r, [=](sycl::id<1> idx) { acc[idx] += INC; }); | ||
}); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.