Coverage for cuda/pathfinder/_binaries/windows_nsight.py: 100.00%

41 statements  

« prev     ^ index     » next       coverage.py v7.16.0, created at 2026-09-03 02:41 +0000

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

2# SPDX-License-Identifier: Apache-2.0 

3 

4import importlib 

5import os 

6from collections.abc import Iterator 

7from typing import Any 

8 

9from cuda.pathfinder._utils.windows_arch import windows_machine_arch 

10 

11_REGISTRY_ROOT = r"SOFTWARE\NVIDIA Corporation\Installed Products\Nsight" 

12 

13_NSYS_TARGET_DIR_BY_ARCH = { 

14 "x64": "target-windows-x64", 

15 "arm64": "target-windows-armv8", 

16} 

17 

18_NCU_TARGET_DIR_BY_ARCH = { 

19 "x64": os.path.join("target", "windows-desktop-win7-x64"), 

20 "arm64": os.path.join("target", "windows-desktop-win10-t23x-a64"), 

21} 

22 

23 

24def _installed_product_root(product: str) -> str | None: 

25 """Return the active Nsight product installation recorded by its MSI.""" 

26 # ``winreg`` attributes are absent from the type stubs on non-Windows hosts. 

27 winreg: Any = importlib.import_module("winreg") 1mnqaijklbcdeofgp

28 

29 access = winreg.KEY_READ | winreg.KEY_WOW64_64KEY 1mnqaijklbcdeofgp

30 product_key_path = rf"{_REGISTRY_ROOT}\{product}" 1mnqaijklbcdeofgp

31 try: 1mnqaijklbcdeofgp

32 product_context = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, product_key_path, 0, access) 1mnqaijklbcdeofgp

33 except FileNotFoundError: 1mnqp

34 return None 1mnp

35 

36 try: 1aijklbcdeofg

37 with product_context as product_key: 1aijklbcdeofg

38 current_version, _ = winreg.QueryValueEx(product_key, "CurrentVersion") 1aijklbcdeofg

39 if not isinstance(current_version, str) or not current_version.strip(): 1aijklbcdefg

40 raise RuntimeError( 1ijkl

41 f"Invalid CurrentVersion value {current_version!r} in " 

42 f"Nsight {product!r} registry registration at {product_key_path!r}" 

43 ) 

44 with winreg.OpenKey(product_key, current_version, 0, access) as version_key: 1abcdefg

45 install_root, _ = winreg.QueryValueEx(version_key, None) 1abcdef

46 except FileNotFoundError as exc: 1ijklofg

47 raise RuntimeError(f"Incomplete Nsight {product!r} registry registration at {product_key_path!r}") from exc 1ofg

48 

49 if not isinstance(install_root, str) or not install_root.strip(): 1abcde

50 raise RuntimeError( 1bcde

51 f"Invalid installation directory {install_root!r} in Nsight {product!r} " 

52 f"registry registration at {product_key_path!r} version {current_version!r}" 

53 ) 

54 return install_root 1a

55 

56 

57def nsys_candidate_paths() -> Iterator[str]: 

58 install_root = _installed_product_root("Systems") 1nzABCGDEF

59 if install_root is None: 1nzABCGDEF

60 return 1nG

61 

62 target_dir = _NSYS_TARGET_DIR_BY_ARCH[windows_machine_arch()] 1zABCDEF

63 yield os.path.join(install_root, target_dir, "nsys.exe") 1zABCDEF

64 

65 

66def ncu_candidate_paths() -> Iterator[str]: 

67 install_root = _installed_product_root("Compute") 1mHrstuIvwxyJ

68 if install_root is None: 1mHrstuIvwxyJ

69 return 1mI

70 

71 yield os.path.join(install_root, "ncu.bat") 1HrstuvwxyJ

72 

73 target_dir = _NCU_TARGET_DIR_BY_ARCH[windows_machine_arch()] 1rstuvwxy

74 yield os.path.join(install_root, target_dir, "ncu.exe") 1rstuvwxy