Skip to content

[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

Merged
merged 12 commits into from
Dec 5, 2023
Merged

[SYCL] Add delayloading for ze_loader #11902

merged 12 commits into from
Dec 5, 2023

Conversation

ykhatav
Copy link
Contributor

@ykhatav ykhatav commented Nov 15, 2023

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.

@ykhatav ykhatav marked this pull request as ready for review November 17, 2023 14:03
@ykhatav ykhatav requested a review from a team as a code owner November 17, 2023 14:03
@kbenzie kbenzie requested a review from jandres742 November 17, 2023 14:05
@ykhatav
Copy link
Contributor Author

ykhatav commented Nov 21, 2023

@jandres742 friendly ping!

Copy link
Contributor

@jandres742 jandres742 left a comment

Choose a reason for hiding this comment

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

thanks @ykhatav.

+1

@smaslov-intel : could you take a look?

break;
case dliNotePreLoadLibrary: {
if (strcmp(pdli->szDll, "ze_loader.dll") == 0) {
return (FARPROC)LoadLibraryExA("ze_loader.dll", nullptr,
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

Same as ze_loader:

Copy link
Contributor Author

@ykhatav ykhatav Nov 23, 2023

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)
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

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.

Copy link
Contributor

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:

Suggested change
target_link_options(pi_level_zero PRIVATE /DELAYLOAD:ze_loader.dll)
target_link_options(pi_level_zero PRIVATE /DELAYLOAD:$<TARGET_FILE:LevelZeroLoader>)

Copy link
Contributor Author

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.

Copy link
Contributor

@kbenzie kbenzie left a 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?

@ykhatav
Copy link
Contributor Author

ykhatav commented Nov 23, 2023

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.

@kbenzie
Copy link
Contributor

kbenzie commented Nov 23, 2023

Yes, these changes should be mirrored in UR as well.

Okay, would you be able to do that please?

Here's our Contribution Guide.

@ykhatav
Copy link
Contributor Author

ykhatav commented Nov 23, 2023

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) {
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 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

Copy link
Contributor

Choose a reason for hiding this comment

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

LGTM

@ykhatav
Copy link
Contributor Author

ykhatav commented Dec 4, 2023

@kbenzie can you approve and merge this PR?

@againull againull requested a review from kbenzie December 4, 2023 22:21
Copy link
Contributor

@kbenzie kbenzie left a 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.

@againull againull merged commit 3045806 into intel:sycl Dec 5, 2023
ykhatav added a commit to ykhatav/llvm that referenced this pull request Dec 19, 2023
againull pushed a commit that referenced this pull request Dec 19, 2023
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.

5 participants