Skip to content

Commit 2f024a5

Browse files
committed
test: add regression test for NVIDIA#1781 (nvrtc loading without CUDA_HOME/CUDA_PATH)
Loads nvrtc in a subprocess with CUDA_HOME and CUDA_PATH stripped from the environment. On Windows CI where nvrtc is only reachable via PATH, this exercises the LOAD_WITH_ALTERED_SEARCH_PATH fix; on other platforms the test passes harmlessly via whatever search path finds nvrtc first. Made-with: Cursor
1 parent b63275e commit 2f024a5

1 file changed

Lines changed: 59 additions & 1 deletion

File tree

‎cuda_pathfinder/tests/test_load_nvidia_dynamic_lib.py‎

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@
33

44
import os
55
import platform
6+
import subprocess
67

78
import pytest
89
from child_load_nvidia_dynamic_lib_helper import (
10+
LOAD_NVIDIA_DYNAMIC_LIB_SUBPROCESS_CWD,
11+
LOAD_NVIDIA_DYNAMIC_LIB_SUBPROCESS_MODE,
912
build_child_process_failed_for_libname_message,
1013
run_load_nvidia_dynamic_lib_in_subprocess,
1114
)
@@ -14,7 +17,11 @@
1417
from cuda.pathfinder import DynamicLibNotAvailableError, DynamicLibUnknownError, load_nvidia_dynamic_lib
1518
from cuda.pathfinder._dynamic_libs import load_nvidia_dynamic_lib as load_nvidia_dynamic_lib_module
1619
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+
)
1825
from cuda.pathfinder._utils.platform_aware import IS_WINDOWS, quote_for_shell
1926

2027
STRICTNESS = os.environ.get("CUDA_PATHFINDER_TEST_LOAD_NVIDIA_DYNAMIC_LIB_STRICTNESS", "see_what_works")
@@ -134,3 +141,54 @@ def raise_child_process_failed():
134141
assert abs_path is not None
135142
info_summary_append(f"abs_path={quote_for_shell(abs_path)}")
136143
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

Comments
 (0)