Coverage for cuda/pathfinder/_dynamic_libs/platform_loader.py: 100.00%
10 statements
« prev ^ index » next coverage.py v7.16.0, created at 2026-09-03 02:41 +0000
« prev ^ index » next coverage.py v7.16.0, created at 2026-09-03 02:41 +0000
1# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2# SPDX-License-Identifier: Apache-2.0
4"""Platform loader seam for OS-specific dynamic linking.
6This module provides a small interface that hides the Linux vs Windows
7implementation details of:
9- already-loaded checks
10- system-search loading
11- absolute-path loading
13The orchestration logic in :mod:`load_nvidia_dynamic_lib` should not need to
14branch on platform; it calls through the loader instance exported here.
15"""
17from __future__ import annotations
19import sys
20from typing import Protocol
22from cuda.pathfinder._dynamic_libs.lib_descriptor import LibDescriptor
23from cuda.pathfinder._dynamic_libs.load_dl_common import LoadedDL
26class PlatformLoader(Protocol):
27 def check_if_already_loaded_from_elsewhere(self, desc: LibDescriptor) -> LoadedDL | None: ...
29 def load_with_system_search(self, desc: LibDescriptor) -> LoadedDL | None: ...
31 def load_with_abs_path(self, desc: LibDescriptor, found_path: str, found_via: str | None = None) -> LoadedDL: ...
34if sys.platform == "win32":
35 from cuda.pathfinder._dynamic_libs import load_dl_windows as _impl
36else:
37 from cuda.pathfinder._dynamic_libs import load_dl_linux as _impl
39# The platform modules already expose functions matching the PlatformLoader
40# protocol. Wrap in a simple namespace so callers use LOADER.method() syntax.
41LOADER: PlatformLoader = _impl