[pathfinder] Use LOAD_WITH_ALTERED_SEARCH_PATH for system DLL search on Windows#1506
Draft
rwgk wants to merge 1 commit intoNVIDIA:mainfrom
Draft
[pathfinder] Use LOAD_WITH_ALTERED_SEARCH_PATH for system DLL search on Windows#1506rwgk wants to merge 1 commit intoNVIDIA:mainfrom
LOAD_WITH_ALTERED_SEARCH_PATH for system DLL search on Windows#1506rwgk wants to merge 1 commit intoNVIDIA:mainfrom
Conversation
…n Windows When loading CUDA DLLs via system search on Windows, the previous approach using LoadLibraryExW with flags=0 would find the DLL on PATH but fail to locate its co-located dependencies (error 126). This fix uses SearchPathW to first find the DLL's full path, then loads it with LOAD_WITH_ALTERED_SEARCH_PATH so Windows searches for dependencies starting from the DLL's directory.
Contributor
|
Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually. Contributors can view more details about this message here. |
Collaborator
Author
|
Archiving proof-of-concept code: # LoadLibraryExW_nvrtc64_130_0_dll.py
import ctypes
kernel32 = ctypes.WinDLL("kernel32", use_last_error=True)
dll_path = r"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v13.1\bin\x64\nvrtc64_130_0.dll"
LOAD_WITH_ALTERED_SEARCH_PATH = 0x8
print("Trying with full path + LOAD_WITH_ALTERED_SEARCH_PATH...")
handle = kernel32.LoadLibraryExW(dll_path, None, LOAD_WITH_ALTERED_SEARCH_PATH)
if handle:
print(f"SUCCESS: handle={handle}")
else:
error = ctypes.get_last_error()
print(f"Error code: {error}")
print(f"Error message: {ctypes.FormatError(error)}") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
WIP WIP WIP — Bug discovered while testing suggested code for NVIDIA/numba-cuda#308
This fix was generated by Cursor. I still need to review it myself.
The bug went unnoticed because on Windows we always have
CUDA_HOMEorCUDA_PATHset in our testing.When loading CUDA DLLs via system search on Windows, the previous approach using
LoadLibraryExWwithflags=0would find the DLL onPATHbut fail to locate its co-located dependencies (error 126).This fix uses
SearchPathWto first find the DLL's full path, then loads it withLOAD_WITH_ALTERED_SEARCH_PATHso Windows searches for dependencies starting from the DLL's directory.