Coverage for cuda / pathfinder / _dynamic_libs / platform_loader.py: 100.00%

10 statements  

« prev     ^ index     » next       coverage.py v7.13.4, created at 2026-03-08 01:07 +0000

1# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. 

2# SPDX-License-Identifier: Apache-2.0 

3 

4"""Platform loader seam for OS-specific dynamic linking. 

5 

6This module provides a small interface that hides the Linux vs Windows 

7implementation details of: 

8 

9- already-loaded checks 

10- system-search loading 

11- absolute-path loading 

12 

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""" 

16 

17from __future__ import annotations 

18 

19from typing import Protocol 

20 

21from cuda.pathfinder._dynamic_libs.lib_descriptor import LibDescriptor 

22from cuda.pathfinder._dynamic_libs.load_dl_common import LoadedDL 

23from cuda.pathfinder._utils.platform_aware import IS_WINDOWS 

24 

25 

26class PlatformLoader(Protocol): 

27 def check_if_already_loaded_from_elsewhere(self, desc: LibDescriptor, have_abs_path: bool) -> LoadedDL | None: ... 

28 

29 def load_with_system_search(self, desc: LibDescriptor) -> LoadedDL | None: ... 

30 

31 def load_with_abs_path(self, desc: LibDescriptor, found_path: str, found_via: str | None = None) -> LoadedDL: ... 

32 

33 

34if IS_WINDOWS: 

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 

38 

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