From 627752be5aeef33be3778d12c44705202ab8bf07 Mon Sep 17 00:00:00 2001 From: Rob Parolin Date: Wed, 25 Nov 2026 12:59:24 -0700 Subject: [PATCH 1/2] refactor(pathfinder): remove library tables that the package never reads `supported_nvidia_libs.py` derived about 30 tables from the catalog. The package reads five names from it. This removes the other 20 tables (139 -> 83 lines). Nothing is rewritten: the kept statements are unchanged and their values are identical. Tests: - Tests that only compared a removed table with the catalog field it was derived from are removed. - Two tests stated real catalog rules through a removed table. They now read the catalog directly and check the same rule. - The two flag tables implied "a platform load flag needs that platform's filenames". That rule is now an explicit catalog test. Risk: these are private names (`cuda.pathfinder._dynamic_libs`). No project on public GitHub imports them, but code outside public GitHub could. Co-Authored-By: Claude Fable 5.2 Signed-off-by: Rob Parolin --- cuda_pathfinder/AGENTS.md | 4 +- .../_dynamic_libs/supported_nvidia_libs.py | 62 +------------------ .../tests/test_descriptor_catalog.py | 7 +++ cuda_pathfinder/tests/test_lib_descriptor.py | 59 +----------------- .../tests/test_load_nvidia_dynamic_lib.py | 40 +++++------- 5 files changed, 28 insertions(+), 144 deletions(-) diff --git a/cuda_pathfinder/AGENTS.md b/cuda_pathfinder/AGENTS.md index f6fd69ac6b02..923f20cf88bd 100644 --- a/cuda_pathfinder/AGENTS.md +++ b/cuda_pathfinder/AGENTS.md @@ -19,8 +19,8 @@ Windows. defines canonical metadata for known libraries. - **Registry layers**: - `lib_descriptor.py` builds the name-keyed runtime registry from the catalog. - - `supported_nvidia_libs.py` keeps legacy exported tables derived from the - catalog for compatibility. + - `supported_nvidia_libs.py` derives the name sets and filename tables that + the package itself reads from the catalog. - **Search pipeline**: - `search_steps.py` implements composable find steps (`site-packages`, `CONDA_PREFIX`, `CUDA_HOME`/`CUDA_PATH`, canary-assisted CTK root flow). diff --git a/cuda_pathfinder/cuda/pathfinder/_dynamic_libs/supported_nvidia_libs.py b/cuda_pathfinder/cuda/pathfinder/_dynamic_libs/supported_nvidia_libs.py index 02951cba52eb..850002b87686 100644 --- a/cuda_pathfinder/cuda/pathfinder/_dynamic_libs/supported_nvidia_libs.py +++ b/cuda_pathfinder/cuda/pathfinder/_dynamic_libs/supported_nvidia_libs.py @@ -1,17 +1,10 @@ # SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. # SPDX-License-Identifier: Apache-2.0 -"""Legacy table exports derived from the authored descriptor catalog. +"""Library-name sets and filename tables derived from the authored descriptor catalog. -The canonical data entry point is :mod:`descriptor_catalog`. This module keeps -historical constant names for backward compatibility by deriving them from the -catalog. - -The unsuffixed ``SUPPORTED_LIBNAMES_WINDOWS`` and -``SITE_PACKAGES_LIBDIRS_WINDOWS*`` constants retain their historical x64 -meaning for compatibility, but are not recommended for new code. Use the -explicit ``*_X64`` or ``*_ARM64`` projection instead. Never combine the two -architecture projections. +The canonical data entry point is :mod:`descriptor_catalog`. This module holds +only the projections that the package itself reads. """ from __future__ import annotations @@ -22,7 +15,6 @@ _CTK_DESCRIPTORS = tuple(desc for desc in DESCRIPTOR_CATALOG if desc.packaged_with == "ctk") _OTHER_DESCRIPTORS = tuple(desc for desc in DESCRIPTOR_CATALOG if desc.packaged_with == "other") _DRIVER_DESCRIPTORS = tuple(desc for desc in DESCRIPTOR_CATALOG if desc.packaged_with == "driver") -_NON_CTK_DESCRIPTORS = _OTHER_DESCRIPTORS + _DRIVER_DESCRIPTORS def _legacy_least_preferred_first(names: tuple[str, ...]) -> tuple[str, ...]: @@ -34,9 +26,6 @@ def _legacy_least_preferred_first(names: tuple[str, ...]) -> tuple[str, ...]: SUPPORTED_LIBNAMES_LINUX_ONLY = tuple( desc.name for desc in _CTK_DESCRIPTORS if desc.linux_sonames and not desc.windows_dlls ) -SUPPORTED_LIBNAMES_WINDOWS_ONLY = tuple( - desc.name for desc in _CTK_DESCRIPTORS if desc.windows_dlls and not desc.linux_sonames -) if not IS_WINDOWS: ALL_AVAILABLE_LIBNAMES = frozenset(desc.name for desc in DESCRIPTOR_CATALOG if desc.linux_sonames) @@ -52,9 +41,6 @@ def _legacy_least_preferred_first(names: tuple[str, ...]) -> tuple[str, ...]: SUPPORTED_LIBNAMES_WINDOWS_ARM64 = tuple( desc.name for desc in _CTK_DESCRIPTORS if "arm64" in desc.supported_windows_arch ) -# Backward-compatible alias preserves the historical x64 meaning. -SUPPORTED_LIBNAMES_WINDOWS = SUPPORTED_LIBNAMES_WINDOWS_X64 -SUPPORTED_LIBNAMES_ALL = SUPPORTED_LIBNAMES_COMMON + SUPPORTED_LIBNAMES_LINUX_ONLY + SUPPORTED_LIBNAMES_WINDOWS_ONLY if not IS_WINDOWS: SUPPORTED_LIBNAMES = SUPPORTED_LIBNAMES_LINUX elif IS_WINDOWS_X64: @@ -63,9 +49,6 @@ def _legacy_least_preferred_first(names: tuple[str, ...]) -> tuple[str, ...]: assert IS_WINDOWS_ARM64 SUPPORTED_LIBNAMES = SUPPORTED_LIBNAMES_WINDOWS_ARM64 -DIRECT_DEPENDENCIES_CTK = {desc.name: desc.dependencies for desc in _CTK_DESCRIPTORS if desc.dependencies} -DIRECT_DEPENDENCIES = {desc.name: desc.dependencies for desc in DESCRIPTOR_CATALOG if desc.dependencies} - SUPPORTED_LINUX_SONAMES_CTK = { desc.name: _legacy_least_preferred_first(desc.linux_sonames) for desc in _CTK_DESCRIPTORS if desc.linux_sonames } @@ -88,45 +71,6 @@ def _legacy_least_preferred_first(names: tuple[str, ...]) -> tuple[str, ...]: } SUPPORTED_WINDOWS_DLLS = SUPPORTED_WINDOWS_DLLS_CTK | SUPPORTED_WINDOWS_DLLS_OTHER | SUPPORTED_WINDOWS_DLLS_DRIVER -LIBNAMES_REQUIRING_OS_ADD_DLL_DIRECTORY = tuple( - desc.name for desc in DESCRIPTOR_CATALOG if desc.requires_add_dll_directory and desc.windows_dlls -) -LIBNAMES_REQUIRING_RTLD_DEEPBIND = tuple( - desc.name for desc in DESCRIPTOR_CATALOG if desc.requires_rtld_deepbind and desc.linux_sonames -) - -SITE_PACKAGES_LIBDIRS_LINUX_CTK = { - desc.name: desc.site_packages_linux for desc in _CTK_DESCRIPTORS if desc.site_packages_linux -} -SITE_PACKAGES_LIBDIRS_LINUX_OTHER = { - desc.name: desc.site_packages_linux for desc in _NON_CTK_DESCRIPTORS if desc.site_packages_linux -} -SITE_PACKAGES_LIBDIRS_LINUX = SITE_PACKAGES_LIBDIRS_LINUX_CTK | SITE_PACKAGES_LIBDIRS_LINUX_OTHER - -# Architecture-specific Windows projections. Keep these separate: combining -# them would make the table unsafe to consume for either process ABI. -SITE_PACKAGES_LIBDIRS_WINDOWS_CTK_X64 = { - desc.name: desc.site_packages_windows.x64 for desc in _CTK_DESCRIPTORS if desc.site_packages_windows.x64 -} -SITE_PACKAGES_LIBDIRS_WINDOWS_CTK_ARM64 = { - desc.name: desc.site_packages_windows.arm64 for desc in _CTK_DESCRIPTORS if desc.site_packages_windows.arm64 -} -SITE_PACKAGES_LIBDIRS_WINDOWS_OTHER_X64 = { - desc.name: desc.site_packages_windows.x64 for desc in _NON_CTK_DESCRIPTORS if desc.site_packages_windows.x64 -} -SITE_PACKAGES_LIBDIRS_WINDOWS_OTHER_ARM64 = { - desc.name: desc.site_packages_windows.arm64 for desc in _NON_CTK_DESCRIPTORS if desc.site_packages_windows.arm64 -} -SITE_PACKAGES_LIBDIRS_WINDOWS_X64 = SITE_PACKAGES_LIBDIRS_WINDOWS_CTK_X64 | SITE_PACKAGES_LIBDIRS_WINDOWS_OTHER_X64 -SITE_PACKAGES_LIBDIRS_WINDOWS_ARM64 = ( - SITE_PACKAGES_LIBDIRS_WINDOWS_CTK_ARM64 | SITE_PACKAGES_LIBDIRS_WINDOWS_OTHER_ARM64 -) - -# Backward-compatible aliases preserve the historical x64 meaning. -SITE_PACKAGES_LIBDIRS_WINDOWS_CTK = SITE_PACKAGES_LIBDIRS_WINDOWS_CTK_X64 -SITE_PACKAGES_LIBDIRS_WINDOWS_OTHER = SITE_PACKAGES_LIBDIRS_WINDOWS_OTHER_X64 -SITE_PACKAGES_LIBDIRS_WINDOWS = SITE_PACKAGES_LIBDIRS_WINDOWS_X64 - def is_suppressed_dll_file(path_basename: str) -> bool: if path_basename.startswith("nvrtc"): diff --git a/cuda_pathfinder/tests/test_descriptor_catalog.py b/cuda_pathfinder/tests/test_descriptor_catalog.py index 60a779274862..172baf51772d 100644 --- a/cuda_pathfinder/tests/test_descriptor_catalog.py +++ b/cuda_pathfinder/tests/test_descriptor_catalog.py @@ -41,6 +41,13 @@ def test_has_at_least_one_soname_or_dll(spec: DescriptorSpec): assert spec.linux_sonames or spec.windows_dlls, f"{spec.name} has no sonames or DLLs" +@pytest.mark.parametrize("spec", DESCRIPTOR_CATALOG, ids=lambda s: s.name) +@pytest.mark.agent_authored(model="claude-fable-5-2") +def test_platform_load_flags_require_that_platform_filenames(spec: DescriptorSpec): + assert not spec.requires_add_dll_directory or spec.windows_dlls + assert not spec.requires_rtld_deepbind or spec.linux_sonames + + @pytest.mark.parametrize("spec", DESCRIPTOR_CATALOG, ids=lambda s: s.name) def test_dependencies_reference_existing_entries(spec: DescriptorSpec): for dep in spec.dependencies: diff --git a/cuda_pathfinder/tests/test_lib_descriptor.py b/cuda_pathfinder/tests/test_lib_descriptor.py index d56ee4643788..fc63822f6635 100644 --- a/cuda_pathfinder/tests/test_lib_descriptor.py +++ b/cuda_pathfinder/tests/test_lib_descriptor.py @@ -1,26 +1,14 @@ # SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. # SPDX-License-Identifier: Apache-2.0 -"""Tests for the canonical library descriptors and their legacy projections.""" +"""Tests for the canonical library descriptors and the tables derived from them.""" import pytest from cuda.pathfinder._dynamic_libs.lib_descriptor import LIB_DESCRIPTORS from cuda.pathfinder._dynamic_libs.supported_nvidia_libs import ( - DIRECT_DEPENDENCIES, - LIBNAMES_REQUIRING_OS_ADD_DLL_DIRECTORY, - LIBNAMES_REQUIRING_RTLD_DEEPBIND, - SITE_PACKAGES_LIBDIRS_LINUX, - SITE_PACKAGES_LIBDIRS_WINDOWS, - SITE_PACKAGES_LIBDIRS_WINDOWS_ARM64, - SITE_PACKAGES_LIBDIRS_WINDOWS_CTK, - SITE_PACKAGES_LIBDIRS_WINDOWS_CTK_X64, - SITE_PACKAGES_LIBDIRS_WINDOWS_OTHER, - SITE_PACKAGES_LIBDIRS_WINDOWS_OTHER_X64, - SITE_PACKAGES_LIBDIRS_WINDOWS_X64, SUPPORTED_LIBNAMES, SUPPORTED_LIBNAMES_LINUX, - SUPPORTED_LIBNAMES_WINDOWS, SUPPORTED_LIBNAMES_WINDOWS_ARM64, SUPPORTED_LIBNAMES_WINDOWS_X64, SUPPORTED_LINUX_SONAMES, @@ -61,36 +49,6 @@ def test_windows_dlls_match(name): assert tuple(reversed(LIB_DESCRIPTORS[name].windows_dlls)) == SUPPORTED_WINDOWS_DLLS.get(name, ()) -@pytest.mark.parametrize("name", sorted(LIB_DESCRIPTORS)) -def test_site_packages_linux_match(name): - assert LIB_DESCRIPTORS[name].site_packages_linux == SITE_PACKAGES_LIBDIRS_LINUX.get(name, ()) - - -@pytest.mark.parametrize( - ("target_arch", "site_packages_libdirs"), - [ - ("x64", SITE_PACKAGES_LIBDIRS_WINDOWS_X64), - ("arm64", SITE_PACKAGES_LIBDIRS_WINDOWS_ARM64), - ], -) -@pytest.mark.parametrize("name", sorted(LIB_DESCRIPTORS)) -@pytest.mark.agent_authored(model="gpt-5") -def test_site_packages_windows_match(name, target_arch, site_packages_libdirs): - assert LIB_DESCRIPTORS[name].site_packages_windows.for_arch(target_arch) == site_packages_libdirs.get(name, ()) - - -@pytest.mark.agent_authored(model="gpt-5") -def test_legacy_site_packages_windows_tables_are_x64_aliases(): - assert SITE_PACKAGES_LIBDIRS_WINDOWS_CTK is SITE_PACKAGES_LIBDIRS_WINDOWS_CTK_X64 - assert SITE_PACKAGES_LIBDIRS_WINDOWS_OTHER is SITE_PACKAGES_LIBDIRS_WINDOWS_OTHER_X64 - assert SITE_PACKAGES_LIBDIRS_WINDOWS is SITE_PACKAGES_LIBDIRS_WINDOWS_X64 - - -@pytest.mark.agent_authored(model="gpt-5") -def test_legacy_supported_libnames_windows_is_x64_alias(): - assert SUPPORTED_LIBNAMES_WINDOWS is SUPPORTED_LIBNAMES_WINDOWS_X64 - - @pytest.mark.agent_authored(model="gpt-5") def test_supported_libnames_selects_current_platform_and_arch(): if not IS_WINDOWS: @@ -111,21 +69,6 @@ def test_arch_specific_ctk_libname_projections(): assert "nvjpeg" in SUPPORTED_LIBNAMES_WINDOWS_ARM64 -@pytest.mark.parametrize("name", sorted(LIB_DESCRIPTORS)) -def test_dependencies_match(name): - assert LIB_DESCRIPTORS[name].dependencies == DIRECT_DEPENDENCIES.get(name, ()) - - -@pytest.mark.parametrize("name", sorted(LIB_DESCRIPTORS)) -def test_requires_add_dll_directory_match(name): - assert LIB_DESCRIPTORS[name].requires_add_dll_directory == (name in LIBNAMES_REQUIRING_OS_ADD_DLL_DIRECTORY) - - -@pytest.mark.parametrize("name", sorted(LIB_DESCRIPTORS)) -def test_requires_rtld_deepbind_match(name): - assert LIB_DESCRIPTORS[name].requires_rtld_deepbind == (name in LIBNAMES_REQUIRING_RTLD_DEEPBIND) - - # --------------------------------------------------------------------------- # Strategy classification # --------------------------------------------------------------------------- diff --git a/cuda_pathfinder/tests/test_load_nvidia_dynamic_lib.py b/cuda_pathfinder/tests/test_load_nvidia_dynamic_lib.py index 629d70a95bfd..1ba77154c24f 100644 --- a/cuda_pathfinder/tests/test_load_nvidia_dynamic_lib.py +++ b/cuda_pathfinder/tests/test_load_nvidia_dynamic_lib.py @@ -38,37 +38,34 @@ def test_supported_libnames_linux_sonames_consistency(): ) +_CTK_DESCRIPTORS = tuple( + desc for desc in load_nvidia_dynamic_lib_module.LIB_DESCRIPTORS.values() if desc.packaged_with == "ctk" +) + + +@pytest.mark.agent_authored(model="claude-fable-5-2") def test_supported_libnames_linux_site_packages_libdirs_ctk_consistency(): assert tuple(sorted(supported_nvidia_libs.SUPPORTED_LIBNAMES_LINUX)) == tuple( - sorted(supported_nvidia_libs.SITE_PACKAGES_LIBDIRS_LINUX_CTK.keys()) + sorted(desc.name for desc in _CTK_DESCRIPTORS if desc.site_packages_linux) ) @pytest.mark.parametrize( - ("site_packages_libdirs", "supported_libnames"), + ("target_arch", "supported_libnames"), [ - pytest.param( - supported_nvidia_libs.SITE_PACKAGES_LIBDIRS_WINDOWS_CTK_X64, - supported_nvidia_libs.SUPPORTED_LIBNAMES_WINDOWS_X64, - id="x64", - ), - pytest.param( - supported_nvidia_libs.SITE_PACKAGES_LIBDIRS_WINDOWS_CTK_ARM64, - supported_nvidia_libs.SUPPORTED_LIBNAMES_WINDOWS_ARM64, - id="arm64", - ), + pytest.param("x64", supported_nvidia_libs.SUPPORTED_LIBNAMES_WINDOWS_X64, id="x64"), + pytest.param("arm64", supported_nvidia_libs.SUPPORTED_LIBNAMES_WINDOWS_ARM64, id="arm64"), ], ) -@pytest.mark.human_reviewed -def test_supported_libnames_windows_site_packages_libdirs_ctk_consistency( - site_packages_libdirs, - supported_libnames, -): +@pytest.mark.agent_authored(model="claude-fable-5-2") +def test_supported_libnames_windows_site_packages_libdirs_ctk_consistency(target_arch, supported_libnames): # Not every Windows CTK library ships in a pip wheel (e.g. cudla is loaded # from the local CUDA Toolkit only), so a library may legitimately omit # site_packages_windows. Only assert that every site-packages entry maps to # a supported Windows libname, not the other way around. - site_packages_libnames = set(site_packages_libdirs) + site_packages_libnames = { + desc.name for desc in _CTK_DESCRIPTORS if desc.site_packages_windows.for_arch(target_arch) + } assert site_packages_libnames <= set(supported_libnames) @@ -84,13 +81,6 @@ def test_libname_dict_values_are_unique(dict_name): libname_for_value[value] = libname -def test_supported_libnames_windows_libnames_requiring_os_add_dll_directory_consistency(): - assert not ( - set(supported_nvidia_libs.LIBNAMES_REQUIRING_OS_ADD_DLL_DIRECTORY) - - set(supported_nvidia_libs.SUPPORTED_WINDOWS_DLLS) - ) - - def test_runtime_error_on_non_64bit_python(mocker): # Ensure this test is not affected by any prior cached calls. load_nvidia_dynamic_lib.cache_clear() From 5fde05ea6d95f89a8a49298909e36c025f31124d Mon Sep 17 00:00:00 2001 From: "Ralf W. Grosse-Kunstleve" Date: Thu, 26 Nov 2026 11:17:27 -0800 Subject: [PATCH 2/2] ci: require manual copy-pr-bot approval Signed-off-by: Ralf W. Grosse-Kunstleve