From 8100ad24d681c9dd4c2f498f6e0fa9ceb3a51a7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Baylac=20Jacqu=C3=A9?= Date: Fri, 2 Dec 2022 09:49:10 +0100 Subject: [PATCH] DSO scanning: separately scan the cuda drivers We create a new function in charge of finding the CUDA DSOs. We also modify the find_nvidia_dsos function and remove the cuda-related libraries from its output. We take advantage of this new feature to factor out the file searching logic in its own function. --- nixglhost-wrapper.py | 41 +++++++++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/nixglhost-wrapper.py b/nixglhost-wrapper.py index d43fa78..949d26a 100755 --- a/nixglhost-wrapper.py +++ b/nixglhost-wrapper.py @@ -24,9 +24,7 @@ else: # # TODO: find a more systematic way to figure out these names *not # requiring to build/fetch the nvidia driver at runtime*. -NVIDIA_DSO_NAMES = [ - "libcudadebugger\.so.*$", - "libcuda\.so.*$", +NVIDIA_DSO_PATTERNS = [ "libEGL_nvidia\.so.*$", "libGLESv1_CM_nvidia\.so.*$", "libGLESv2_nvidia\.so.*$", @@ -81,29 +79,48 @@ NVIDIA_DSO_NAMES = [ ] -def find_nvidia_dsos(path): - """Scans the PATH directory looking for the Nvidia driver shared - libraries and their dependencies. A shared library is considered - as a Nvidia one if its name maches a pattern contained in - NVIDIA_DSO_NAMES. +CUDA_DSO_PATTERNS = [ + "libcudadebugger\.so.*$", + "libcuda\.so.*$" +] + +def find_files(path, files_patterns): + """Scans the PATH directory looking for the files complying with + the FILES_PATTERNS regexes list. Returns the list of the DSOs absolute paths.""" - files = [] - def is_nvidia_dso(filename): - for pattern in NVIDIA_DSO_NAMES: + def is_dso_matching_pattern(filename): + for pattern in files_patterns: if re.search(pattern, filename): return True return False for f in os.listdir(path): abs_file_path = os.path.abspath(os.path.join(path, f)) - if os.path.isfile(abs_file_path) and is_nvidia_dso(abs_file_path): + if os.path.isfile(abs_file_path) and is_dso_matching_pattern(abs_file_path): files.append(abs_file_path) return files +def find_nvidia_dsos(path): + """Scans the PATH directory looking for the Nvidia driver shared + libraries and their dependencies. A shared library is considered + as a Nvidia one if its name maches a pattern contained in + CUDA_DSO_PATTERNS. + + Returns the list of the DSOs absolute paths.""" + return find_files(path, NVIDIA_DSO_PATTERNS) + +def find_cuda_dsos(path): + """Scans the PATH directory looking for the cuda driver shared + libraries. A shared library is considered + as a cuda one if its name maches a pattern contained in + CUDA_DSO_PATTERNS. + + Returns the list of the DSOs absolute paths.""" + return find_files(path, CUDA_DSO_PATTERNS) def copy_and_patch_dsos_to_libs_dir(dsos, libs_dir): """Copies the graphic vendor DSOs to the cache directory before