Coverage for cuda / core / system / _nvml_context.pxd: 57.14%

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

3# SPDX-License-Identifier: Apache-2.0 

4  

5  

6cdef extern from *: 

7 """ 

8 #if defined(_WIN32) || defined(_WIN64) 

9 #include <process.h> 

10 #else 

11 #include <unistd.h> 

12 #endif 

13 """ 

14 int getpid() nogil 

15  

16  

17ctypedef enum _NVMLState: 

18 UNINITIALIZED = 0 

19 INITIALIZED = 1 

20 DISABLED_LIBRARY_NOT_FOUND = 2 

21  

22  

23# Initialisation must occur per-process, so an initialised state is a 

24# (state, pid) pair 

25cdef _NVMLState _NVML_STATE 

26  

27  

28cdef int _NVML_OWNER_PID 

29  

30  

31cpdef _initialize() 

32  

33  

34cpdef inline initialize(): 

35 """ 

36 Initializes Nvidia Management Library (NVML), ensuring it only happens once per process. 

37 """ 

38 if _NVML_STATE == _NVMLState.DISABLED_LIBRARY_NOT_FOUND or ( 1cdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVaWXYZ0123b456789!#$%'()*+,-./:;=?@[]^

39 _NVML_STATE == _NVMLState.INITIALIZED and getpid() == _NVML_OWNER_PID 1cdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVaWXYZ0123b456789!#$%'()*+,-./:;=?@[]^

40 ): 

41 return 1cdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVaWXYZ0123b456789!#$%'()*+,-./:;=?@[]^

42  

43 _initialize() 1ab

44  

45  

46cpdef inline bint is_initialized(): 

47 """ 

48 Check whether the NVML context is initialized on this process. 

49  

50 Returns 

51 ------- 

52 result: bool 

53 Whether the NVML context is initialized on this process. 

54 """ 

55 return _NVML_STATE == _NVMLState.INITIALIZED and getpid() == _NVML_OWNER_PID 

56  

57  

58cpdef validate()