Skip to content

Commit 5fb2d1f

Browse files
committed
Remove _find_nvidia_dynamic_library.retry_with_anchor_abs_path() method. Move run_python_code_safely.py to test/ directory.
1 parent a576327 commit 5fb2d1f

File tree

5 files changed

+11
-61
lines changed

5 files changed

+11
-61
lines changed

cuda_bindings/cuda/bindings/_path_finder/find_nvidia_dynamic_library.py

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -108,17 +108,6 @@ def _find_dll_using_lib_dir(lib_dir, libname, error_messages, attachments):
108108
return None
109109

110110

111-
def _find_nvvm_lib_dir_from_anchor_abs_path(anchor_abs_path):
112-
nvvm_subdir = "bin" if IS_WINDOWS else "lib64"
113-
while anchor_abs_path:
114-
if os.path.isdir(anchor_abs_path):
115-
nvvm_lib_dir = os.path.join(anchor_abs_path, "nvvm", nvvm_subdir)
116-
if os.path.isdir(nvvm_lib_dir):
117-
return nvvm_lib_dir
118-
anchor_abs_path = os.path.dirname(anchor_abs_path)
119-
return None
120-
121-
122111
class _find_nvidia_dynamic_library:
123112
def __init__(self, libname: str):
124113
self.libname = libname
@@ -151,18 +140,6 @@ def retry_with_cuda_home_priority_last(self):
151140
cuda_home_lib_dir, self.lib_searched_for, self.error_messages, self.attachments
152141
)
153142

154-
def retry_with_anchor_abs_path(self, anchor_abs_path):
155-
assert self.libname == "nvvm"
156-
nvvm_lib_dir = _find_nvvm_lib_dir_from_anchor_abs_path(anchor_abs_path)
157-
if nvvm_lib_dir is None:
158-
return
159-
if IS_WINDOWS:
160-
self.abs_path = _find_dll_using_lib_dir(nvvm_lib_dir, self.libname, self.error_messages, self.attachments)
161-
else:
162-
self.abs_path = _find_so_using_lib_dir(
163-
nvvm_lib_dir, self.lib_searched_for, self.error_messages, self.attachments
164-
)
165-
166143
def raise_if_abs_path_is_None(self):
167144
if self.abs_path:
168145
return self.abs_path

cuda_bindings/cuda/bindings/_path_finder/load_dl_common.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
from dataclasses import dataclass
55
from typing import Callable, Optional
66

7-
from cuda.bindings._path_finder.run_python_code_safely import run_python_code_safely
87
from cuda.bindings._path_finder.supported_libs import DIRECT_DEPENDENCIES, IS_WINDOWS
98

109
if IS_WINDOWS:
@@ -35,16 +34,3 @@ def load_dependencies(libname: str, load_func: Callable[[str], LoadedDL]) -> Non
3534
"""
3635
for dep in DIRECT_DEPENDENCIES.get(libname, ()):
3736
load_func(dep)
38-
39-
40-
def load_in_subprocess(python_code, timeout=30):
41-
# This is to avoid loading libraries into the parent process.
42-
return run_python_code_safely(python_code, timeout=timeout)
43-
44-
45-
def build_subprocess_failed_for_libname_message(libname, result):
46-
return (
47-
f"Subprocess failed for {libname=!r} with exit code {result.returncode}\n"
48-
f"--- stdout-from-subprocess ---\n{result.stdout}<end-of-stdout-from-subprocess>\n"
49-
f"--- stderr-from-subprocess ---\n{result.stderr}<end-of-stderr-from-subprocess>\n"
50-
)

cuda_bindings/cuda/bindings/_path_finder/load_nvidia_dynamic_library.py

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,9 @@
22
# SPDX-License-Identifier: LicenseRef-NVIDIA-SOFTWARE-LICENSE
33

44
import functools
5-
import json
65

76
from cuda.bindings._path_finder.find_nvidia_dynamic_library import _find_nvidia_dynamic_library
8-
from cuda.bindings._path_finder.load_dl_common import (
9-
LoadedDL,
10-
build_subprocess_failed_for_libname_message,
11-
load_dependencies,
12-
load_in_subprocess,
13-
)
7+
from cuda.bindings._path_finder.load_dl_common import LoadedDL, load_dependencies
148
from cuda.bindings._path_finder.supported_libs import IS_WINDOWS
159

1610
if IS_WINDOWS:
@@ -27,21 +21,6 @@
2721
)
2822

2923

30-
def _load_anchor_in_subprocess(libname, error_messages):
31-
code = f"""\
32-
from cuda.bindings._path_finder.load_nvidia_dynamic_library import load_nvidia_dynamic_library
33-
import json
34-
import sys
35-
loaded = load_nvidia_dynamic_library({libname!r})
36-
sys.stdout.write(json.dumps(loaded.abs_path, ensure_ascii=True))
37-
"""
38-
result = load_in_subprocess(code)
39-
if result.returncode == 0:
40-
return json.loads(result.stdout)
41-
error_messages.extend(build_subprocess_failed_for_libname_message(libname, result).splitlines())
42-
return None
43-
44-
4524
def _load_nvidia_dynamic_library_no_cache(libname: str) -> LoadedDL:
4625
# Check whether the library is already loaded into the current process by
4726
# some other component. This check uses OS-level mechanisms (e.g.,

cuda_bindings/tests/test_path_finder_load.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
import sys
66

77
import pytest
8+
from run_python_code_safely import run_python_code_safely
89

910
from cuda.bindings import path_finder
1011
from cuda.bindings._path_finder import supported_libs
11-
from cuda.bindings._path_finder.load_dl_common import build_subprocess_failed_for_libname_message, load_in_subprocess
1212

1313
ALL_LIBNAMES = path_finder._SUPPORTED_LIBNAMES + supported_libs.PARTIALLY_SUPPORTED_LIBNAMES_ALL
1414
ALL_LIBNAMES_LINUX = path_finder._SUPPORTED_LIBNAMES + supported_libs.PARTIALLY_SUPPORTED_LIBNAMES_LINUX
@@ -38,6 +38,14 @@ def test_all_libnames_expected_lib_symbols_consistency():
3838
assert tuple(sorted(ALL_LIBNAMES)) == tuple(sorted(supported_libs.EXPECTED_LIB_SYMBOLS.keys()))
3939

4040

41+
def build_subprocess_failed_for_libname_message(libname, result):
42+
return (
43+
f"Subprocess failed for {libname=!r} with exit code {result.returncode}\n"
44+
f"--- stdout-from-subprocess ---\n{result.stdout}<end-of-stdout-from-subprocess>\n"
45+
f"--- stderr-from-subprocess ---\n{result.stderr}<end-of-stderr-from-subprocess>\n"
46+
)
47+
48+
4149
@pytest.mark.parametrize("libname", TEST_FIND_OR_LOAD_LIBNAMES)
4250
def test_find_or_load_nvidia_dynamic_library(info_summary_append, libname):
4351
# We intentionally run each dynamic library operation in a subprocess
@@ -68,7 +76,7 @@ def test_find_or_load_nvidia_dynamic_library(info_summary_append, libname):
6876
6977
print(f"{{loaded_dl_fresh.abs_path!r}}")
7078
"""
71-
result = load_in_subprocess(code)
79+
result = run_python_code_safely(code, timeout=30)
7280
if result.returncode == 0:
7381
info_summary_append(f"abs_path={result.stdout.rstrip()}")
7482
else:

0 commit comments

Comments
 (0)