Repository navigation
Using LoadLibraryEX [Reland] - #38302
peterjc123 wants to merge 4 commits into
Conversation
…LIBRARY_SEARCH_* flag for loading DLLs o…" This reverts commit 1ab4f35.
💊 CI failures summary and remediationsAs of commit d01f449 (more details on the Dr. CI page):
ci.pytorch.org: 2 failed
This comment was automatically generated by Dr. CI (expand for details).Follow this link to opt-out of these comments for your Pull Requests.Please report bugs/suggestions on the GitHub issue tracker. This comment has been revised 8 times. |
malfet
left a comment
There was a problem hiding this comment.
@peterjc123 can you please change PR title "Using LoadLibraryEX [Reland]" and change description to original PR description
|
@malfet Done. |
facebook-github-bot
left a comment
There was a problem hiding this comment.
@malfet is landing this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
|
There may be a similar bug for Linux, in case gcc's multilib/multisys system directories in sysroot contain some important shared library dependency prior to conda install (and at some point there was a similar bug for include paths, system ones were searched before the local directory, so system-wide install of cudnn was preventing conda cudnn from begin found). I don't know if these "potential bugs" currently actually may happen in PyTorch or not |
Summary: This reverts commit 1ab4f35. Without this PR, the OS try to find the DLL in the following directories. - The directory from which the application loaded. - The system directory. Use the GetSystemDirectory function to get the path of this directory. - The 16-bit system directory. There is no function that obtains the path of this directory, but it is searched. - The Windows directory. Use the GetWindowsDirectory function to get the path of this directory. - The current directory. - The directories that are listed in the PATH environment variable. Note that this does not include the per-application path specified by the App Paths registry key. The App Paths key is not used when computing the DLL search path. If we use LoadLibraryEx with LOAD_LIBRARY_SEARCH_* flags, the directories are searched in the following order. - The directory that contains the DLL (LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR). This directory is searched only for dependencies of the DLL to be loaded. - The application directory (LOAD_LIBRARY_SEARCH_APPLICATION_DIR). - Paths explicitly added to the application search path with the AddDllDirectory function (LOAD_LIBRARY_SEARCH_USER_DIRS) or the SetDllDirectory function. If more than one path has been added, the order in which the paths are searched is unspecified. - The System32 directory (LOAD_LIBRARY_SEARCH_SYSTEM32). Advantages: 1. The directory that contains the DLL comes first and it's desirable for us, because the dependencies in `lib` should always be preferred. 2. The system directory is considered in the last place. According to some of the bug reports, the DLL load failure are caused by loading the conflicting ones in systemroot. Neural: 1. The directories in `PATH` are not considered. Similar things happen as described in the previous point. So it may be beneficial for normal users. However, it may cause failures if there are some new dependencies if built from source. (Resolved by making the fallback to `LoadLibraryW` if error code is `126`) Disadvantages: 1. LoadLibraryEx with LOAD_LIBRARY_SEARCH_* flags is only available for Win7/2008 R2 + KB2533623 and up. (Resolved by making the fallback to `LoadLibraryW` if it is not supported) 2. Failure during the call of `LoadLibraryEx` will lead to the OS to pop up a modal dialog, which can block the process if user is using a CLI-only interface. This can be switched off by calling `SetErrorMode`. (Resolved by calling `SetErrorMode`) Pull Request resolved: pytorch#38302 Test Plan: Test some common cases (in a new repo maybe) including 1. Python 3.6/3.7/3.8, conda python, conda install 2. Python 3.6/3.7/3.8, conda python, pip install 3. Python 3.6/3.7/3.8, official python, pip install Plus some corner cases like 1. Conflicting DLLs in systemroot or `PATH` 2. Remove some local dependencies and use global ones References: 1. https://docs.microsoft.com/en-us/windows/win32/api/errhandlingapi/nf-errhandlingapi-seterrormode 2. https://docs.microsoft.com/en-us/windows/win32/api/libloaderapi/nf-libloaderapi-loadlibraryexa 3. https://docs.microsoft.com/en-us/windows/win32/dlls/dynamic-link-library-search-order#standard-search-order-for-desktop-applications Differential Revision: D21524090 Pulled By: malfet fbshipit-source-id: 0cf5e260c91759b0af8c7aa0950a488e3b653ef5
Summary: Addresses pytorch#27840 (comment). Contains a bunch of fixes (pytorch#39376 + pytorch#39334 + pytorch#38302 + pytorch#35362) Pull Request resolved: pytorch#39513 Differential Revision: D22190761 Pulled By: malfet fbshipit-source-id: b2d52f6cb16c233d16071e9c0670dfff7da2710e (cherry picked from commit e2201e2)
This reverts commit 1ab4f35.
Without this PR, the OS try to find the DLL in the following directories.
If we use LoadLibraryEx with LOAD_LIBRARY_SEARCH_* flags, the directories are searched in the following order.
Advantages:
libshould always be preferred.Neural:
PATHare not considered. Similar things happen as described in the previous point. So it may be beneficial for normal users. However, it may cause failures if there are some new dependencies if built from source. (Resolved by making the fallback toLoadLibraryWif error code is126)Disadvantages:
LoadLibraryWif it is not supported)LoadLibraryExwill lead to the OS to pop up a modal dialog, which can block the process if user is using a CLI-only interface. This can be switched off by callingSetErrorMode. (Resolved by callingSetErrorMode)Test plan:
Test some common cases (in a new repo maybe) including
Plus some corner cases like
PATHReferences: