|
3 | 3 |
|
4 | 4 | import os |
5 | 5 | import platform |
| 6 | +import subprocess |
6 | 7 |
|
7 | 8 | import pytest |
8 | 9 | from child_load_nvidia_dynamic_lib_helper import ( |
| 10 | + LOAD_NVIDIA_DYNAMIC_LIB_SUBPROCESS_CWD, |
| 11 | + LOAD_NVIDIA_DYNAMIC_LIB_SUBPROCESS_MODE, |
9 | 12 | build_child_process_failed_for_libname_message, |
10 | 13 | run_load_nvidia_dynamic_lib_in_subprocess, |
11 | 14 | ) |
|
14 | 17 | from cuda.pathfinder import DynamicLibNotAvailableError, DynamicLibUnknownError, load_nvidia_dynamic_lib |
15 | 18 | from cuda.pathfinder._dynamic_libs import load_nvidia_dynamic_lib as load_nvidia_dynamic_lib_module |
16 | 19 | from cuda.pathfinder._dynamic_libs import supported_nvidia_libs |
17 | | -from cuda.pathfinder._dynamic_libs.subprocess_protocol import STATUS_NOT_FOUND, parse_dynamic_lib_subprocess_payload |
| 20 | +from cuda.pathfinder._dynamic_libs.subprocess_protocol import ( |
| 21 | + STATUS_NOT_FOUND, |
| 22 | + build_dynamic_lib_subprocess_command, |
| 23 | + parse_dynamic_lib_subprocess_payload, |
| 24 | +) |
18 | 25 | from cuda.pathfinder._utils.platform_aware import IS_WINDOWS, quote_for_shell |
19 | 26 |
|
20 | 27 | STRICTNESS = os.environ.get("CUDA_PATHFINDER_TEST_LOAD_NVIDIA_DYNAMIC_LIB_STRICTNESS", "see_what_works") |
@@ -134,3 +141,54 @@ def raise_child_process_failed(): |
134 | 141 | assert abs_path is not None |
135 | 142 | info_summary_append(f"abs_path={quote_for_shell(abs_path)}") |
136 | 143 | assert os.path.isfile(abs_path) # double-check the abs_path |
| 144 | + |
| 145 | + |
| 146 | +def test_load_nvrtc_without_cuda_home_or_cuda_path(info_summary_append): |
| 147 | + """Regression test for issue #1781: nvrtc must load without CUDA_HOME/CUDA_PATH. |
| 148 | +
|
| 149 | + On Windows, when CUDA DLLs are discovered via PATH (system search), the |
| 150 | + previous LoadLibraryExW(flags=0) call would find the DLL but fail to |
| 151 | + resolve co-located dependencies like nvrtc-builtins (error 126). |
| 152 | +
|
| 153 | + The fix uses SearchPathW to resolve the full path, then loads with |
| 154 | + LOAD_WITH_ALTERED_SEARCH_PATH so dependency search starts from the |
| 155 | + DLL's directory. |
| 156 | +
|
| 157 | + This test strips CUDA_HOME and CUDA_PATH, then loads nvrtc in a fresh |
| 158 | + subprocess. In CI environments where nvrtc is only available via system |
| 159 | + search, this exercises the exact code path that was broken. |
| 160 | + """ |
| 161 | + env = os.environ.copy() |
| 162 | + env.pop("CUDA_HOME", None) |
| 163 | + env.pop("CUDA_PATH", None) |
| 164 | + |
| 165 | + timeout = 120 if IS_WINDOWS else 30 |
| 166 | + command = build_dynamic_lib_subprocess_command(LOAD_NVIDIA_DYNAMIC_LIB_SUBPROCESS_MODE, "nvrtc") |
| 167 | + result = subprocess.run( # noqa: S603 |
| 168 | + command, |
| 169 | + capture_output=True, |
| 170 | + text=True, |
| 171 | + timeout=timeout, |
| 172 | + check=False, |
| 173 | + env=env, |
| 174 | + cwd=LOAD_NVIDIA_DYNAMIC_LIB_SUBPROCESS_CWD, |
| 175 | + ) |
| 176 | + |
| 177 | + if result.returncode != 0: |
| 178 | + raise RuntimeError(build_child_process_failed_for_libname_message("nvrtc", result)) |
| 179 | + assert not result.stderr |
| 180 | + |
| 181 | + payload = parse_dynamic_lib_subprocess_payload( |
| 182 | + result.stdout, |
| 183 | + libname="nvrtc", |
| 184 | + error_label="Load subprocess child process (no CUDA_HOME/CUDA_PATH)", |
| 185 | + ) |
| 186 | + |
| 187 | + if payload.status == STATUS_NOT_FOUND: |
| 188 | + info_summary_append("nvrtc not found without CUDA_HOME/CUDA_PATH") |
| 189 | + pytest.skip("nvrtc not available without CUDA_HOME/CUDA_PATH") |
| 190 | + |
| 191 | + abs_path = payload.abs_path |
| 192 | + assert abs_path is not None |
| 193 | + info_summary_append(f"nvrtc (no CUDA_HOME/CUDA_PATH): abs_path={quote_for_shell(abs_path)}") |
| 194 | + assert os.path.isfile(abs_path) |
0 commit comments