Skip to content

Commit c3ddf79

Browse files
rwgkcursoragent
andcommitted
pathfinder: harden guard-rails dispatch and prune dead code
* Add nccl_device to _BITCODE_LIBS_PACKAGED_WITH so the guard-rails resolver layer no longer raises KeyError for a name that is already in SUPPORTED_BITCODE_LIBS; lock the dispatch tables in place with parametrized tests that walk every supported bitcode/static/binary name through _resolve_*_item. * Remove unreachable helpers _pipeline_compatibility_result, _dynamic_lib_pipeline_items, and CompatibilityGuardRails._enforce_declared_dynamic_lib_pipelines_for_pair. The pipeline check still fires from _enforce_declared_dynamic_lib_pipelines_for_item after _remember, which is the only code path that ever produced a result. * Re-export DriverCtkCompatibilityError from cuda.pathfinder so the driver-vs-CTK case (already advertised by the env-var hint) can be caught by type instead of message text, and list it in api.rst. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 6da23cf commit c3ddf79

4 files changed

Lines changed: 36 additions & 33 deletions

File tree

cuda_pathfinder/cuda/pathfinder/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
from cuda.pathfinder._compatibility_guard_rails import (
1818
CompatibilityInsufficientMetadataError as CompatibilityInsufficientMetadataError,
1919
)
20+
from cuda.pathfinder._compatibility_guard_rails import (
21+
DriverCtkCompatibilityError as DriverCtkCompatibilityError,
22+
)
2023
from cuda.pathfinder._dynamic_libs.load_dl_common import (
2124
DynamicLibNotAvailableError as DynamicLibNotAvailableError,
2225
)

cuda_pathfinder/cuda/pathfinder/_compatibility_guard_rails.py

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ class DeclaredDynamicLibPipeline:
116116
}
117117
_BITCODE_LIBS_PACKAGED_WITH: dict[str, PackagedWith] = {
118118
"device": "ctk",
119+
"nccl_device": "other",
119120
"nvshmem_device": "other",
120121
}
121122
_BINARY_PACKAGED_WITH: dict[str, PackagedWith] = dict.fromkeys(SUPPORTED_BINARIES_ALL, "ctk")
@@ -688,14 +689,6 @@ def _ctk_coherence_result(
688689
return CompatibilityResult(status="incompatible", message=_ctk_pair_mismatch_message(item1, item2, relation))
689690

690691

691-
def _pipeline_compatibility_result(_item1: ResolvedItem, _item2: ResolvedItem) -> CompatibilityResult | None:
692-
# Generic pairwise policy stays artifact-coherence-only. Milestone 6 adds
693-
# explicit pipeline-aware rules via declared dynamic-lib pipeline contexts,
694-
# because producer/consumer direction and artifact kind are not inferable
695-
# from bare item pairs alone.
696-
return None
697-
698-
699692
def _pairwise_policy_result(
700693
item1: ResolvedItem,
701694
item2: ResolvedItem,
@@ -706,27 +699,10 @@ def _pairwise_policy_result(
706699
if relation.kind == _PAIRWISE_ITEM_RELATION_NONE:
707700
return None
708701
if relation.kind == _PAIRWISE_ITEM_RELATION_EXACT_CTK_MATCH_REQUIRED:
709-
result = _ctk_coherence_result(item1, item2, relation)
710-
if result is not None:
711-
return result
712-
return _pipeline_compatibility_result(item1, item2)
702+
return _ctk_coherence_result(item1, item2, relation)
713703
raise AssertionError(f"Unhandled pairwise item relation: {relation.kind!r}")
714704

715705

716-
def _dynamic_lib_pipeline_items(
717-
item1: ResolvedItem,
718-
item2: ResolvedItem,
719-
pipeline: DeclaredDynamicLibPipeline,
720-
) -> tuple[ResolvedItem, ResolvedItem] | None:
721-
if item1.kind != "dynamic-lib" or item2.kind != "dynamic-lib":
722-
return None
723-
if item1.name == pipeline.producer_libname and item2.name == pipeline.consumer_libname:
724-
return item1, item2
725-
if item2.name == pipeline.producer_libname and item1.name == pipeline.consumer_libname:
726-
return item2, item1
727-
return None
728-
729-
730706
def _declared_dynamic_lib_pipeline_result(
731707
producer_item: ResolvedItem,
732708
consumer_item: ResolvedItem,
@@ -939,7 +915,6 @@ def _enforce_pairwise_compatibility(self, prior_item: ResolvedItem, item: Resolv
939915
result = _pairwise_policy_result(prior_item, item)
940916
if result is not None:
941917
result.require_compatible()
942-
self._enforce_declared_dynamic_lib_pipelines_for_pair(prior_item, item)
943918

944919
def _remembered_item(self, *, kind: ItemKind, name: str) -> ResolvedItem | None:
945920
for item in reversed(self._resolved_items):
@@ -961,12 +936,6 @@ def _enforce_declared_dynamic_lib_pipeline_if_ready(self, pipeline: DeclaredDyna
961936
result.require_compatible()
962937
self._checked_dynamic_lib_pipelines.add(pipeline)
963938

964-
def _enforce_declared_dynamic_lib_pipelines_for_pair(self, item1: ResolvedItem, item2: ResolvedItem) -> None:
965-
for pipeline in self._declared_dynamic_lib_pipelines:
966-
if _dynamic_lib_pipeline_items(item1, item2, pipeline) is None:
967-
continue
968-
self._enforce_declared_dynamic_lib_pipeline_if_ready(pipeline)
969-
970939
def _enforce_declared_dynamic_lib_pipelines_for_item(self, item: ResolvedItem) -> None:
971940
if item.kind != "dynamic-lib":
972941
return

cuda_pathfinder/docs/source/api.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ CUDA bitcode and static libraries.
2222
process_wide_compatibility_guard_rails
2323
CompatibilityCheckError
2424
CompatibilityInsufficientMetadataError
25+
DriverCtkCompatibilityError
2526
SUPPORTED_NVIDIA_LIBNAMES
2627
load_nvidia_dynamic_lib
2728
LoadedDL

cuda_pathfinder/tests/test_compatibility_guard_rails.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
CompatibilityInsufficientMetadataError,
2828
LocatedHeaderDir,
2929
)
30+
from cuda.pathfinder._binaries.supported_nvidia_binaries import SUPPORTED_BINARIES_ALL
31+
from cuda.pathfinder._static_libs.find_bitcode_lib import SUPPORTED_BITCODE_LIBS
32+
from cuda.pathfinder._static_libs.find_static_lib import SUPPORTED_STATIC_LIBS
3033
from cuda.pathfinder._utils.driver_info import (
3134
DriverCudaVersion,
3235
DriverReleaseVersion,
@@ -447,6 +450,33 @@ def test_resolved_items_capture_relation_metadata(tmp_path):
447450
assert binary_item.ctk_version == dynamic_item.ctk_version
448451

449452

453+
@pytest.mark.parametrize("name", SUPPORTED_BITCODE_LIBS)
454+
def test_resolve_bitcode_lib_item_covers_every_supported_name(tmp_path, name):
455+
abs_path = _touch(tmp_path / "site-packages" / f"{name}.bc")
456+
item = compatibility_module._resolve_bitcode_lib_item(_located_bitcode_lib(name, abs_path))
457+
assert item.name == name
458+
assert item.kind == "bitcode-lib"
459+
assert item.packaged_with in ("ctk", "other")
460+
461+
462+
@pytest.mark.parametrize("name", SUPPORTED_STATIC_LIBS)
463+
def test_resolve_static_lib_item_covers_every_supported_name(tmp_path, name):
464+
abs_path = _touch(tmp_path / "site-packages" / f"{name}.a")
465+
item = compatibility_module._resolve_static_lib_item(_located_static_lib(name, abs_path))
466+
assert item.name == name
467+
assert item.kind == "static-lib"
468+
assert item.packaged_with in ("ctk", "other")
469+
470+
471+
@pytest.mark.parametrize("utility_name", SUPPORTED_BINARIES_ALL)
472+
def test_resolve_binary_item_covers_every_supported_name(tmp_path, utility_name):
473+
abs_path = _touch(tmp_path / "bin" / utility_name)
474+
item = compatibility_module._resolve_binary_item(utility_name, abs_path)
475+
assert item.name == utility_name
476+
assert item.kind == "binary"
477+
assert item.packaged_with in ("ctk", "other")
478+
479+
450480
def test_static_bitcode_and_binary_methods_participate_in_checks(monkeypatch, tmp_path):
451481
ctk_root = _make_ctk_root(tmp_path / "cuda-12.9", "12.9.20250531")
452482

0 commit comments

Comments
 (0)