-
Notifications
You must be signed in to change notification settings - Fork 787
[SYCL]Replaced LoadLibraryA() with LoadLibraryEx() #10914
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
Signed-off-by: Kim, Euna <[email protected]>
Signed-off-by: Kim, Euna <[email protected]>
sycl/source/detail/windows_pi.cpp
Outdated
@@ -31,7 +31,8 @@ void *loadOsLibrary(const std::string &LibraryPath) { | |||
if (!SetDllDirectoryA("")) { | |||
assert(false && "Failed to update DLL search path"); | |||
} | |||
auto Result = (void *)LoadLibraryA(LibraryPath.c_str()); | |||
// auto Result = (void *)LoadLibraryA(LibraryPath.c_str()); |
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.
Will remove this comment
@@ -151,25 +151,26 @@ void preloadLibraries() { | |||
MapT &dllMap = getDllMap(); | |||
|
|||
std::string ocl_path = LibSYCLDir + __SYCL_OPENCL_PLUGIN_NAME; | |||
dllMap.emplace(ocl_path, LoadLibraryA(ocl_path.c_str())); | |||
dllMap.emplace(ocl_path, LoadLibraryExA(ocl_path.c_str(), NULL, NULL)); |
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 mind this change, but it seems like if flags are NULL then LoadLibraryExA is doing the same as LoadLibraryA.
See https://learn.microsoft.com/en-us/windows/win32/api/libloaderapi/nf-libloaderapi-loadlibraryexa
If no flags are specified, the behavior of this function is identical to that of the LoadLibrary function. This parameter can be one of the following values.
My fix passed all tests before and I removed one comment afterwards. The test fail in SYCL E2E on AWS CUDA is not relevant to my code. This PR is ready to merge @intel/llvm-gatekeepers. |
@eunakim0103 post-merge nit comment: avoid using |
Replaced LoadLibraryA() with LoadLibraryEx() and added SetDllDirectoryA() to remove the working directory from the standard search path. LoadLibraryExA() was used because "path" is of type c-string.
The libloaderapi.h header defines LoadLibraryEx as an alias which automatically selects the ANSI or Unicode version of this function based on the definition of the UNICODE preprocessor constant.
https://learn.microsoft.com/en-us/windows/win32/api/libloaderapi/nf-libloaderapi-loadlibraryexw
HMODULE LoadLibraryEx(
[in] LPCSTR lpLibFileName, //==> library path as a string
HANDLE hFile, //==> reserved as NULL for future use
[in] DWORD dwFlags //==> dwFlags determine the behavior of LoadLibaryEx(). When it is NULL, it behaves same as LoadLibaryA()
);
https://learn.microsoft.com/en-us/windows/win32/api/libloaderapi/nf-libloaderapi-loadlibraryexa