Skip to content

[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

Merged
merged 3 commits into from
Aug 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions sycl/pi_win_proxy_loader/pi_win_proxy_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Copy link
Contributor

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.


std::string l0_path = LibSYCLDir + __SYCL_LEVEL_ZERO_PLUGIN_NAME;
dllMap.emplace(l0_path, LoadLibraryA(l0_path.c_str()));
dllMap.emplace(l0_path, LoadLibraryExA(l0_path.c_str(), NULL, NULL));

std::string cuda_path = LibSYCLDir + __SYCL_CUDA_PLUGIN_NAME;
dllMap.emplace(cuda_path, LoadLibraryA(cuda_path.c_str()));
dllMap.emplace(cuda_path, LoadLibraryExA(cuda_path.c_str(), NULL, NULL));

std::string esimd_path = LibSYCLDir + __SYCL_ESIMD_EMULATOR_PLUGIN_NAME;
dllMap.emplace(esimd_path, LoadLibraryA(esimd_path.c_str()));
dllMap.emplace(esimd_path, LoadLibraryExA(esimd_path.c_str(), NULL, NULL));

std::string hip_path = LibSYCLDir + __SYCL_HIP_PLUGIN_NAME;
dllMap.emplace(hip_path, LoadLibraryA(hip_path.c_str()));
dllMap.emplace(hip_path, LoadLibraryExA(hip_path.c_str(), NULL, NULL));

std::string ur_path = LibSYCLDir + __SYCL_UNIFIED_RUNTIME_PLUGIN_NAME;
dllMap.emplace(ur_path, LoadLibraryA(ur_path.c_str()));
dllMap.emplace(ur_path, LoadLibraryExA(ur_path.c_str(), NULL, NULL));

std::string nativecpu_path = LibSYCLDir + __SYCL_NATIVE_CPU_PLUGIN_NAME;
dllMap.emplace(nativecpu_path, LoadLibraryA(nativecpu_path.c_str()));
dllMap.emplace(nativecpu_path,
LoadLibraryExA(nativecpu_path.c_str(), NULL, NULL));

// Restore system error handling.
(void)SetErrorMode(SavedMode);
Expand Down
3 changes: 2 additions & 1 deletion sycl/source/detail/windows_pi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 *)LoadLibraryExA(LibraryPath.c_str(), NULL, NULL);
(void)SetErrorMode(SavedMode);
if (!SetDllDirectoryA(nullptr)) {
assert(false && "Failed to restore DLL search path");
Expand Down
11 changes: 10 additions & 1 deletion xpti/include/xpti/xpti_trace_framework.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,10 +228,19 @@ class PlatformHelper {
xpti_plugin_handle_t loadLibrary(const char *path, std::string &error) {
xpti_plugin_handle_t handle = 0;
#if defined(_WIN32) || defined(_WIN64)
handle = LoadLibraryA(path);
UINT SavedMode = SetErrorMode(SEM_FAILCRITICALERRORS);
// Exclude current directory from DLL search path
if (!SetDllDirectoryA("")) {
assert(false && "Failed to update DLL search path");
}
handle = LoadLibraryExA(path, NULL, NULL);
if (!handle) {
error = getLastError();
}
(void)SetErrorMode(SavedMode);
if (!SetDllDirectoryA(nullptr)) {
assert(false && "Failed to restore DLL search path");
}
#else
handle = dlopen(path, RTLD_LAZY);
if (!handle) {
Expand Down