Skip to content

Conversation

@rwgk
Copy link
Collaborator

@rwgk rwgk commented Jan 16, 2026

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_HOME or CUDA_PATH set in our testing.


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.

…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.
@copy-pr-bot
Copy link
Contributor

copy-pr-bot bot commented Jan 16, 2026

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.

@rwgk
Copy link
Collaborator Author

rwgk commented Jan 16, 2026

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)}")

@leofang leofang added this to the cuda.pathfinder 1.4.0 milestone Jan 16, 2026
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.

2 participants