-
Notifications
You must be signed in to change notification settings - Fork 787
[SYCL] Add delayloading for ze_loader #11902
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
Conversation
@jandres742 friendly ping! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
break; | ||
case dliNotePreLoadLibrary: { | ||
if (strcmp(pdli->szDll, "ze_loader.dll") == 0) { | ||
return (FARPROC)LoadLibraryExA("ze_loader.dll", nullptr, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are you doing the same to ur_loader?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No I am not sure/familiar if ur_loader also has load-time linking but this change is specific for ze_loader.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as ze_loader:
UnifiedRuntimeLoader |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, now that I look at it, ur_loader.dll is not present in the C:\System32 folder instead i think we package and install it with sycl in sycl..\bin folder. So I don't think the same can be done for ur_loader., i.e we can't use LOAD_LIBRARY_SEARCH_SYSTEM32 flag, we would have to load it using an absolute path. In any case, i don't think it should be a part of this change, it needs separate PR in the UR repo.
add_dependencies(pi_level_zero ze-api) | ||
|
||
if (WIN32) | ||
target_link_libraries(pi_level_zero PRIVATE delayimp) | ||
target_link_options(pi_level_zero PRIVATE /DELAYLOAD:ze_loader.dll) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we somehow use LevelZeroLoader
as above at https://github.com/intel/llvm/pull/11902/files#diff-e162c7afd5dbcb57ced84354c427518f0f37b190538d136e871855d78975533bR98 and not hardcode ze_loader.dll
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Passing LevelZeroLoader to /DELAYLOAD doesn't seem to work, it needs the exact name of the DLL.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
target_link_options supports generator expressions and LevelZeroLoader
is a target, try TARGET_FILE like this:
target_link_options(pi_level_zero PRIVATE /DELAYLOAD:ze_loader.dll) | |
target_link_options(pi_level_zero PRIVATE /DELAYLOAD:$<TARGET_FILE:LevelZeroLoader>) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the suggestion @kbenzie! However, i get a build error: Error evaluating generator expression:
$<TARGET_FILE:LevelZeroLoader>
Target "LevelZeroLoader" is not an executable or library.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are these changes which should be mirrored in UR so this functionality doesn't get dropped when we switch to UR by default later on?
Yes, these changes should be mirrored in UR as well. |
Okay, would you be able to do that please? Here's our Contribution Guide. |
Created a draft PR here: oneapi-src/unified-runtime#1117 |
|
||
// Defined in tracing.cpp | ||
void enableZeTracing(); | ||
void disableZeTracing(); | ||
#ifdef _WIN32 | ||
FARPROC WINAPI delayHook(unsigned dliNotify, PDelayLoadInfo pdli) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will have to remove this hook function from here since we plan to mirror these changes in UR otherwise we will get multiple definition build error. @kbenzie please review my UR changes(oneapi-src/unified-runtime#1117) and I will update this PR accordingly. FYI, I have tested both the changes together in this draft PR- #12030
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@kbenzie can you approve and merge this PR? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't have merge permissions so can't merge myself.
This reverts commit 3045806.
Currently, on Windows, ze_loader is loaded using load-time linking and since the OS loads it we don't have any control over the search path. To control the search path add /DELAYLOAD link option for ze_loader to load it securely from the Sytem32 folder.