Coverage for cuda / bindings / _test_helpers / mempool.py: 25.00%

36 statements  

« prev     ^ index     » next       coverage.py v7.14.0, created at 2026-05-22 01:37 +0000

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

2# SPDX-License-Identifier: LicenseRef-NVIDIA-SOFTWARE-LICENSE 

3 

4import sys 

5 

6import pytest 

7 

8from cuda.bindings import driver, runtime 

9 

10 

11def is_windows_mcdm_device(device=0): 

12 if sys.platform != "win32": 

13 return False 

14 import cuda.bindings.nvml as nvml 

15 

16 device_id = int(getattr(device, "device_id", device)) 

17 (err,) = driver.cuInit(0) 

18 if err != driver.CUresult.CUDA_SUCCESS: 

19 return False 

20 err, pci_bus_id = driver.cuDeviceGetPCIBusId(13, device_id) 

21 if err != driver.CUresult.CUDA_SUCCESS: 

22 return False 

23 pci_bus_id = pci_bus_id.split(b"\x00", 1)[0].decode("ascii") 

24 nvml.init_v2() 

25 try: 

26 handle = nvml.device_get_handle_by_pci_bus_id_v2(pci_bus_id) 

27 current, _ = nvml.device_get_driver_model_v2(handle) 

28 return current == nvml.DriverModel.DRIVER_MCDM 

29 finally: 

30 nvml.shutdown() 

31 

32 

33def xfail_if_mempool_oom(err_or_exc, api_name=None, device=0): 

34 if api_name is not None and not isinstance(api_name, str): 1bcd

35 device = api_name 

36 api_name = None 

37 

38 is_oom = err_or_exc in ( 1bcd

39 driver.CUresult.CUDA_ERROR_OUT_OF_MEMORY, 

40 runtime.cudaError_t.cudaErrorMemoryAllocation, 

41 ) or "CUDA_ERROR_OUT_OF_MEMORY" in str(err_or_exc) 

42 

43 if not is_oom: 1bcd

44 return 1bcd

45 try: 

46 is_windows_mcdm = is_windows_mcdm_device(device) 

47 except Exception: 

48 # If MCDM detection fails, leave the primary test failure visible. 

49 return 

50 if not is_windows_mcdm: 

51 return 

52 

53 api_context = f"{api_name} " if api_name else "" 

54 pytest.xfail(f"{api_context}could not reserve VA for mempool operations on Windows MCDM")